Permalink
Browse files

combine head elements from all parts

  • Loading branch information...
1 parent ff5ff10 commit c1e845131cc465e01bd60d5e5dd7fe84a64631bc @thepian committed Apr 28, 2012
Showing with 22 additions and 5 deletions.
  1. +2 −1 test/test_populate.py
  2. +3 −0 test/w4/_parts/article.document.html
  3. +1 −1 test/w4/index.html
  4. +16 −3 webpages/browsers.py
View
@@ -228,8 +228,9 @@ def test_populate_html_expansion():
soup = get_soup(pages_test_root,"output","desktop","index.html")
assert soup.script["src"] == "head.js"
- assert soup.body.contents[0].string.strip() == "index page"
+ assert soup.body.article.contents[0].string.strip() == "index page"
+ assert soup.find(id="article-head")
#TODO test that derived parts head is mixed in
# assert False
@@ -2,4 +2,7 @@
document: body
content-tag: article
---
+<head>
+ <link id="article-head">
+</head>
<article id="a"></article>
View
@@ -1,4 +1,4 @@
---
-document: body
+document: article
---
index page
View
@@ -28,13 +28,17 @@ class HtmlContent(object):
def __init__(self,html):
self.soup = BeautifulSoup(html,"html5lib")
- def inject(self,dest):
+ def injectBody(self,dest):
contents = self.soup.contents
if self.soup.body: contents = self.soup.body.contents
for c in reversed(contents):
dest.insert(0,c)
+ def injectHead(self,dest):
+ if self.soup.head:
+ for c in reversed(self.soup.head.contents):
+ dest.insert(0,c)
class PartFile(object):
""" Fetch Browser Specific Part
@@ -120,7 +124,11 @@ def wrapDocumentSoup(self,content):
content_tag = "content-tag" in self.header and self.header["content-tag"] or "body"
dest = soup.findAll(content_tag)[0]
- HtmlContent(content).inject(dest)
+ htmlContent = HtmlContent(content)
+ htmlContent.injectBody(dest)
+
+ #TODO priority for links and scripts added
+ htmlContent.injectHead(soup.find("head"))
return soup
@@ -162,7 +170,7 @@ def expandTags(self,soup,tagName,attrs=("id",)):
if part and exists(part.path):
header,rest = self.config.split_matter_and_utf8_content(part.read(),{})
- HtmlContent(rest).inject(tag)
+ HtmlContent(rest).injectBody(tag)
if config_id:
setattr(tag,'config_id',config_id)
self.statefulConfigs[config_id] = header
@@ -258,6 +266,11 @@ def getAreaClasses(self,areaNames):
def expandSoup(self,content):
+ """Expand content into the body or content-tag of the PartDocument
+ expand elements with id or src.
+ construct areas and stages
+ construct tracker driven
+ """
import re
soup = self.wrapDocumentSoup(content)

0 comments on commit c1e8451

Please sign in to comment.