Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

token tracker driven impl

+ forced id
  • Loading branch information...
commit 9e3b83a4664a8c68b3d6b537a32a81f059ff6da0 1 parent a7865e6
@thepian authored
View
26 test/test_populate.py
@@ -231,3 +231,29 @@ def test_populate_areas():
# assert False
#TODO document properties if stateful
+def test_populate_trackers():
+ from webpages.populate import populate, save_expander
+
+ config = prep_site_config("w10",**{"browser": "desktop"})
+
+ populate(save_expander,config)
+ assert exists(join(pages_test_root,"output","index.html"))
+
+ soup = get_soup(join(pages_test_root,"output","index.html"))
+
+ assert soup.find("article",id="a1").contents[0].strip() == "top bit"
+ assert soup.find("section",id="s1").string.strip() == "section one"
+ sectionTwo = soup.find("article",id="a1").contents[3]
+ s2id = sectionTwo["id"]
+ assert s2id is not None
+ assert soup("script")[2].string.strip() == """\
+declare("a1",{"area-names": ["upper", "lower"], "encoding": "utf-8", "layouter": "area-stage"});
+declare("s1",{"area-names": ["upper"], "encoding": "utf-8", "laidout": "area-member"});
+declare("%(s2id)s",{"driven-by": "", "tracker-driven": ["left", "top"]});""" % { "s2id": s2id }
+
+ assert soup("article",id="a1")[0]["class"] == "upper-area-inactive lower-area-inactive"
+ assert soup("section",id="s1")[0]["class"] == "in-upper-area in-upper-order-0"
+ # assert soup("section",id="s2")[0]["class"] == "in-lower-area in-lower-order-0"
+ # assert False
+ #TODO document properties if stateful
+
View
1  test/w10/_config.yml
@@ -0,0 +1 @@
+exclude: mymodule, myother
View
3  test/w10/_parts/a1.article.html
@@ -0,0 +1,3 @@
+---
+---
+top bit
View
3  test/w10/_parts/a2.aside.html
@@ -0,0 +1,3 @@
+---
+layouter: deck
+---
View
24 test/w10/_parts/common.document.html
@@ -0,0 +1,24 @@
+---
+---
+<!DOCTYPE HTML>
+<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
+<!--[if lt IE 7 ]><html class="no-js ie6" lang="en"><![endif]-->
+<!--[if IE 7 ]><html class="no-js ie7" lang="en"><![endif]-->
+<!--[if IE 8 ]><html class="no-js ie8" lang="en"><![endif]-->
+<!--[if (gte IE 9)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
+<head>
+ <meta charset="utf-8">
+
+ <title>Placeholder Title</title>
+ <meta name="description" content="{{ site.description }}">
+ <meta name="author" content="{{ site.author }}">
+
+ <!-- All JavaScript at the bottom, except for Modernizr. -->
+ <script src="/js/modernizr-2.0.6.min.js"></script>
+ <script src="/js/essential.js"></script>
+
+</head>
+<body>
+
+</body>
+</html>
View
3  test/w10/_parts/s1.section.html
@@ -0,0 +1,3 @@
+---
+---
+section one
View
3  test/w10/_parts/s2.section.html
@@ -0,0 +1,3 @@
+---
+---
+section two
View
9 test/w10/index.md
@@ -0,0 +1,9 @@
+---
+document: common
+stateful: yes
+---
+<article id="a1" area-stage="upper lower">
+ <section id="s1" in-area="upper"></section>
+ <section tracker-driven="left top"></section>
+</article>
+
View
41 webpages/browsers.py
@@ -58,10 +58,10 @@ def init_html(self,specific,name,tag):
path = join(prefix, "%s.%s.html" % (just_name,tag))
return path
-auto_config_id = 1 #TODO make it top doc unique
-
class PartDocument(object):
+ auto_config_id = 1 #TODO make it top doc unique
+
def __init__(self,specific,name,config):
self.specific = specific
self.name = name
@@ -157,16 +157,18 @@ def expandTags(self,soup,tagName,attrs=("id",)):
#TODO parse with soup to support breaking out header/footer ?
#TODO script
- def forceConfigId(self,element):
- if hasattr(element,'config_id'):
- return getattr(element,'config_id')
-
- auto_config_id += 1
- return "es%s" % auto_config_id
+ def forceConfigId(self,element,forceAttribute=False):
+ if not hasattr(element,'config_id') or getattr(element,'config_id') is None:
+ self.auto_config_id += 1
+ setattr(element,'config_id',"es-%s" % self.auto_config_id)
+ if forceAttribute and ("id" not in element or element["id"] is None) and ("src" not in element or element["src"] is None):
+ element["id"] = getattr(element,'config_id')
+
+ return getattr(element,'config_id')
def saveStageConfig(self,element,areaNames):
config_id = self.forceConfigId(element)
- matter = self.statefulConfigs[config_id] = self.statefulConfigs[config_id] or {}
+ matter = self.statefulConfigs[config_id] = config_id in self.statefulConfigs and self.statefulConfigs[config_id] or {}
matter["area-names"] = areaNames
classNames = self.getAreaClasses(areaNames)
if "class" in element: classNames = element["class"].split(" ") + classNames
@@ -176,7 +178,7 @@ def saveStageConfig(self,element,areaNames):
def saveMemberConfig(self,element,areaNames):
config_id = self.forceConfigId(element)
- matter = self.statefulConfigs[config_id] = self.statefulConfigs[config_id] or {}
+ matter = self.statefulConfigs[config_id] = config_id in self.statefulConfigs and self.statefulConfigs[config_id] or {}
matter["area-names"] = areaNames
classNames = []
if "class" in element: classNames = element["class"].split(" ")
@@ -188,11 +190,20 @@ def saveMemberConfig(self,element,areaNames):
if "laidout" not in matter:
matter["laidout"] = "area-member"
- def saveTrackerDrivenConfig(self,element,props):
- config_id = self.forceConfigId(element)
- matter = self.statefulConfigs[config_id] = self.statefulConfigs[config_id] or {}
+ def saveTrackerDrivenConfig(self,element,props,soup):
+ config_id = self.forceConfigId(element,forceAttribute=True)
+ matter = self.statefulConfigs[config_id] = config_id in self.statefulConfigs and self.statefulConfigs[config_id] or {}
matter["tracker-driven"] = props
+ tracker = Tag(soup,"div")
+ classNames = []
+ if "class" in element: classNames = element["class"].split(" ")
+ classNames += ["tracker", "%s-tracker" % element.tag]
+ tracker["class"] = " ".join(classNames)
+ # tracker.insertBefore(element)
+
+ matter["driven-by"] = "" #TODO tracker["id"]
+
def getAreaOrder(self,element,areaName):
if areaName not in self.areas:
self.areas[areaName] = AreaInfo(areaName)
@@ -240,8 +251,8 @@ def expandSoup(self,content):
tracked = soup.findAll( attrs={"tracker-driven":re.compile(r".*")} )
for t in tracked:
- self.saveTrackerDrivenConfig(member,member["tracker-driven"].split(" "))
- del member["tracker-driven"]
+ self.saveTrackerDrivenConfig(t,t["tracker-driven"].split(" "),soup)
+ del t["tracker-driven"]
return soup
Please sign in to comment.
Something went wrong with that request. Please try again.