From 9e3b83a4664a8c68b3d6b537a32a81f059ff6da0 Mon Sep 17 00:00:00 2001 From: Thepian Date: Tue, 27 Mar 2012 20:27:50 +0100 Subject: [PATCH] token tracker driven impl + forced id --- test/test_populate.py | 26 ++++++++++++++++++ test/w10/_config.yml | 1 + test/w10/_parts/a1.article.html | 3 ++ test/w10/_parts/a2.aside.html | 3 ++ test/w10/_parts/common.document.html | 24 ++++++++++++++++ test/w10/_parts/s1.section.html | 3 ++ test/w10/_parts/s2.section.html | 3 ++ test/w10/index.md | 9 ++++++ webpages/browsers.py | 41 ++++++++++++++++++---------- 9 files changed, 98 insertions(+), 15 deletions(-) create mode 100644 test/w10/_config.yml create mode 100644 test/w10/_parts/a1.article.html create mode 100644 test/w10/_parts/a2.aside.html create mode 100644 test/w10/_parts/common.document.html create mode 100644 test/w10/_parts/s1.section.html create mode 100644 test/w10/_parts/s2.section.html create mode 100644 test/w10/index.md diff --git a/test/test_populate.py b/test/test_populate.py index 2954c42..5dcb99f 100644 --- a/test/test_populate.py +++ b/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 + diff --git a/test/w10/_config.yml b/test/w10/_config.yml new file mode 100644 index 0000000..4e8d241 --- /dev/null +++ b/test/w10/_config.yml @@ -0,0 +1 @@ +exclude: mymodule, myother diff --git a/test/w10/_parts/a1.article.html b/test/w10/_parts/a1.article.html new file mode 100644 index 0000000..2f29ada --- /dev/null +++ b/test/w10/_parts/a1.article.html @@ -0,0 +1,3 @@ +--- +--- +top bit diff --git a/test/w10/_parts/a2.aside.html b/test/w10/_parts/a2.aside.html new file mode 100644 index 0000000..4daee7c --- /dev/null +++ b/test/w10/_parts/a2.aside.html @@ -0,0 +1,3 @@ +--- +layouter: deck +--- diff --git a/test/w10/_parts/common.document.html b/test/w10/_parts/common.document.html new file mode 100644 index 0000000..0d32406 --- /dev/null +++ b/test/w10/_parts/common.document.html @@ -0,0 +1,24 @@ +--- +--- + + + + + + + + + + Placeholder Title + + + + + + + + + + + + diff --git a/test/w10/_parts/s1.section.html b/test/w10/_parts/s1.section.html new file mode 100644 index 0000000..8ef2094 --- /dev/null +++ b/test/w10/_parts/s1.section.html @@ -0,0 +1,3 @@ +--- +--- +section one diff --git a/test/w10/_parts/s2.section.html b/test/w10/_parts/s2.section.html new file mode 100644 index 0000000..12ee4ec --- /dev/null +++ b/test/w10/_parts/s2.section.html @@ -0,0 +1,3 @@ +--- +--- +section two diff --git a/test/w10/index.md b/test/w10/index.md new file mode 100644 index 0000000..51f1972 --- /dev/null +++ b/test/w10/index.md @@ -0,0 +1,9 @@ +--- +document: common +stateful: yes +--- +
+
+
+
+ \ No newline at end of file diff --git a/webpages/browsers.py b/webpages/browsers.py index c401841..9da30bd 100644 --- a/webpages/browsers.py +++ b/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