1
0
Fork 0
forked from github/pelican
pelican-theme/pelican/contents.py

57 lines
1.6 KiB
Python
Raw Normal View History

from pelican.utils import slugify, truncate_html_words
class Page(object):
"""Represents a page
Given a content, and metadatas, create an adequate object.
:param string: the string to parse, containing the original content.
:param markup: the markup language to use while parsing.
"""
2010-10-30 20:17:23 +01:00
mandatory_properties = ('title',)
2010-11-06 02:03:32 +00:00
def __init__(self, content, metadatas={}, settings={}, filename=None):
self.content = content
2010-11-15 18:58:54 +00:00
self.status = "published" # default value
for key, value in metadatas.items():
setattr(self, key, value)
if not hasattr(self, 'author'):
if 'AUTHOR' in settings:
self.author = settings['AUTHOR']
if not hasattr(self, 'slug'):
self.slug = slugify(self.title)
if not hasattr(self, 'url'):
self.url = '%s.html' % self.slug
2010-11-06 02:03:32 +00:00
if filename:
self.filename = filename
def check_properties(self):
"""test that each mandatory property is set."""
for prop in self.mandatory_properties:
if not hasattr(self, prop):
raise NameError(prop)
@property
def summary(self):
return truncate_html_words(self.content, 50)
class Article(Page):
Put the notmyidea theme by default. --HG-- rename : samples/themes/notmyidea/css/main.css => pelican/themes/notmyidea/css/main.css rename : samples/themes/notmyidea/css/pygment.css => pelican/themes/notmyidea/css/pygment.css rename : samples/themes/notmyidea/css/reset.css => pelican/themes/notmyidea/css/reset.css rename : samples/themes/notmyidea/images/icons/delicious.png => pelican/themes/notmyidea/images/icons/delicious.png rename : samples/themes/notmyidea/images/icons/lastfm.png => pelican/themes/notmyidea/images/icons/lastfm.png rename : samples/themes/notmyidea/images/icons/rss.png => pelican/themes/notmyidea/images/icons/rss.png rename : samples/themes/notmyidea/images/icons/twitter.png => pelican/themes/notmyidea/images/icons/twitter.png rename : samples/themes/notmyidea/templates/archives.html => pelican/themes/notmyidea/templates/archives.html rename : samples/themes/notmyidea/templates/article.html => pelican/themes/notmyidea/templates/article.html rename : samples/themes/notmyidea/templates/base.html => pelican/themes/notmyidea/templates/base.html rename : samples/themes/notmyidea/templates/categories.html => pelican/themes/notmyidea/templates/categories.html rename : samples/themes/notmyidea/templates/category.html => pelican/themes/notmyidea/templates/category.html rename : samples/themes/notmyidea/templates/index.html => pelican/themes/notmyidea/templates/index.html rename : samples/themes/notmyidea/templates/tag.html => pelican/themes/notmyidea/templates/tag.html rename : samples/themes/notmyidea/templates/tags.html => pelican/themes/notmyidea/templates/tags.html rename : pelican/themes/templates/archives.html => pelican/themes/simple/templates/archives.html rename : pelican/themes/templates/article.html => pelican/themes/simple/templates/article.html rename : pelican/themes/templates/base.html => pelican/themes/simple/templates/base.html rename : pelican/themes/templates/categories.html => pelican/themes/simple/templates/categories.html rename : pelican/themes/templates/category.html => pelican/themes/simple/templates/category.html rename : pelican/themes/templates/index.html => pelican/themes/simple/templates/index.html rename : pelican/themes/templates/tag.html => pelican/themes/simple/templates/tag.html rename : pelican/themes/templates/tags.html => pelican/themes/simple/templates/tags.html
2010-10-30 16:47:59 +01:00
mandatory_properties = ('title', 'date', 'category')
class Quote(Page):
base_properties = ('author', 'date')
def is_valid_content(content, f):
try:
content.check_properties()
return True
except NameError as e:
print u" [info] Skipping %s: impossible to find informations about '%s'" % (f, e)
return False