From ff9c7861497e9056df911bed95d26567b97749d3 Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Thu, 22 Dec 2011 16:22:34 +0000 Subject: [PATCH] Create a Author class which has a url property --- pelican/contents.py | 47 +++++++++---------- pelican/generators.py | 2 +- pelican/readers.py | 3 +- .../notmyidea/templates/article_infos.html | 2 +- pelican/themes/simple/templates/article.html | 2 +- pelican/themes/simple/templates/index.html | 2 +- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/pelican/contents.py b/pelican/contents.py index cca01911..8cd36186 100644 --- a/pelican/contents.py +++ b/pelican/contents.py @@ -37,9 +37,9 @@ class Page(object): # default author to the one in settings if not defined if not hasattr(self, 'author'): if 'AUTHOR' in settings: - self.author = settings['AUTHOR'] + self.author = Author(settings['AUTHOR']) else: - self.author = getenv('USER', 'John Doe') + self.author = Author(getenv('USER', 'John Doe')) warning(u"Author of `{0}' unknow, assuming that his name is `{1}'".format(filename or self.title, self.author)) # manage languages @@ -142,47 +142,44 @@ class Article(Page): class Quote(Page): base_properties = ('author', 'date') - -class Category(object): - def __init__(self, category): - self.category = unicode(category) +class URLWrapper(object): + def __init__(self, name): + self.name = unicode(name) def __hash__(self): - return hash(self.category) + return hash(self.name) def __eq__(self, other): - return self.category == unicode(other) + return self.name == unicode(other) def __str__(self): - return str(self.category) + return str(self.name) def __unicode__(self): - return self.category + return self.name + @property + def url(self): + return '%s.html' % self.name + +class Category(URLWrapper): @property def url(self): return 'category/%s.html' % self -class Tag(object): - def __init__(self, tag): - self.tag = unicode.strip(tag) - - def __hash__(self): - return hash(self.tag) - - def __eq__(self, other): - return self.tag == unicode(tag) - - def __str__(self): - return str(self.tag) - - def __unicode__(self): - return self.tag +class Tag(URLWrapper): + def __init__(self, name): + self.name = unicode.strip(name) @property def url(self): return 'tag/%s.html' % self +class Author(URLWrapper): + @property + def url(self): + return 'author/%s.html' % self + def is_valid_content(content, f): try: content.check_properties() diff --git a/pelican/generators.py b/pelican/generators.py index 816a6755..d9d584a4 100644 --- a/pelican/generators.py +++ b/pelican/generators.py @@ -195,7 +195,7 @@ class ArticlesGenerator(Generator): author_template = self.get_template('author') for aut, articles in self.authors: dates = [article for article in self.dates if article in articles] - write('author/%s.html' % aut, author_template, self.context, + write(aut.url, author_template, self.context, author=aut, articles=articles, dates=dates, paginated={'articles': articles, 'dates': dates}, page_name='author/%s' % aut) diff --git a/pelican/readers.py b/pelican/readers.py index 6011c272..e760b662 100644 --- a/pelican/readers.py +++ b/pelican/readers.py @@ -15,7 +15,7 @@ except ImportError: Markdown = False import re -from pelican.contents import Category, Tag +from pelican.contents import Category, Tag, Author from pelican.utils import get_date, open @@ -24,6 +24,7 @@ _METADATA_PROCESSORS = { 'date': lambda x: get_date(x), 'status': unicode.strip, 'category': Category, + 'author': Author, } def _process_metadata(name, value): diff --git a/pelican/themes/notmyidea/templates/article_infos.html b/pelican/themes/notmyidea/templates/article_infos.html index 09ecd595..a1993a09 100644 --- a/pelican/themes/notmyidea/templates/article_infos.html +++ b/pelican/themes/notmyidea/templates/article_infos.html @@ -5,7 +5,7 @@ {% if article.author %}
- By {{ article.author }} + By {{ article.author }}
{% endif %}

In {{ article.category }}. {% if PDF_PROCESSOR %}get the pdf{% endif %}

diff --git a/pelican/themes/simple/templates/article.html b/pelican/themes/simple/templates/article.html index 30d31fb6..d6c96a13 100644 --- a/pelican/themes/simple/templates/article.html +++ b/pelican/themes/simple/templates/article.html @@ -8,7 +8,7 @@ {% if article.author %}
- By {{ article.author }} + By {{ article.author }}
{% endif %} diff --git a/pelican/themes/simple/templates/index.html b/pelican/themes/simple/templates/index.html index fd8545df..ad2a3b2e 100644 --- a/pelican/themes/simple/templates/index.html +++ b/pelican/themes/simple/templates/index.html @@ -11,7 +11,7 @@

{{ article.title }}

{{ article.summary }}