Assign a css-id to each source

This commit is contained in:
Sam Ruby 2006-11-16 20:18:34 -05:00
parent bf0c7b736d
commit 1ce96ca53b
4 changed files with 16 additions and 2 deletions

View File

@ -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)

View File

@ -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)

View File

@ -1,4 +1,5 @@
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:planet="http://planet.intertwingly.net/"
@ -139,7 +140,7 @@
</xsl:if>
<xsl:text>&#10;&#10;</xsl:text>
<div class="news">
<div class="news {atom:source/planet:css-id}">
<xsl:if test="@xml:lang">
<xsl:attribute name="xml:lang">

View File

@ -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;
}