From 1ce96ca53b2859fca09f9e214e1f44df90bf3879 Mon Sep 17 00:00:00 2001 From: Sam Ruby Date: Thu, 16 Nov 2006 20:18:34 -0500 Subject: [PATCH] Assign a css-id to each source --- planet/reconstitute.py | 11 +++++++++++ tests/test_spider.py | 1 + themes/asf/index.html.xslt | 3 ++- themes/asf/personalize.js | 3 ++- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/planet/reconstitute.py b/planet/reconstitute.py index 989a107..6d7f43d 100644 --- a/planet/reconstitute.py +++ b/planet/reconstitute.py @@ -50,6 +50,15 @@ def ncr2c(value): value=unichr(int(value)) return value +nonalpha=re.compile('\W+',re.UNICODE) +def cssid(name): + """ generate a css id from a name """ + try: + name = nonalpha.sub('-',name.decode('utf-8')).lower().encode('utf-8') + except: + name = nonalpha.sub('-',name).lower() + return name.strip('-') + def normalize(text, bozo): """ convert everything to well formed XML """ if text.has_key('type'): @@ -198,6 +207,8 @@ def source(xsource, source, bozo, format): if not bozo == None: source['planet_bozo'] = bozo and 'true' or 'false' # propagate planet inserted information + if source.has_key('planet_name') and not source.has_key('planet_css-id'): + source['planet_css-id'] = cssid(source['planet_name']) for key, value in source.items(): if key.startswith('planet_'): createTextElement(xsource, key.replace('_',':',1), value) diff --git a/tests/test_spider.py b/tests/test_spider.py index 418364c..2bef04a 100644 --- a/tests/test_spider.py +++ b/tests/test_spider.py @@ -91,6 +91,7 @@ class SpiderTest(unittest.TestCase): self.assertEqual(['application/rss+xml'], [link.type for link in data.entries[0].source.links if link.rel=='self']) self.assertEqual('three', data.entries[0].source.author_detail.name) + self.assertEqual('three', data.entries[0].source['planet_css-id']) def test_spiderPlanet(self): config.load(configfile) diff --git a/themes/asf/index.html.xslt b/themes/asf/index.html.xslt index b3d2063..1c7468e 100644 --- a/themes/asf/index.html.xslt +++ b/themes/asf/index.html.xslt @@ -1,4 +1,5 @@ -
+
diff --git a/themes/asf/personalize.js b/themes/asf/personalize.js index 83db3a3..afcec17 100644 --- a/themes/asf/personalize.js +++ b/themes/asf/personalize.js @@ -159,7 +159,8 @@ function findEntries() { var date = localizeDate(span[i]); var parent = span[i]; - while (parent && parent.className != 'news') { + while (parent && + (!parent.className || parent.className.split(' ')[0] != 'news')) { parent = parent.parentNode; }