mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Welcome Pelican 2.0 ! Refactoring of the internals to be more extensible.
--HG-- rename : pelican/bloggenerator.py => pelican/generators.py
This commit is contained in:
parent
5e2ca2dd56
commit
fdb920e50a
9 changed files with 430 additions and 337 deletions
42
pelican/contents.py
Normal file
42
pelican/contents.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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.
|
||||
"""
|
||||
mandatory_properties = ('author', 'title')
|
||||
|
||||
def __init__(self, content, metadatas={}, settings={}):
|
||||
self.content = content
|
||||
for key, value in metadatas.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
if not hasattr(self, 'author'):
|
||||
if 'AUTHOR' in settings:
|
||||
self.author = settings['AUTHOR']
|
||||
|
||||
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 url(self):
|
||||
return '%s.html' % slugify(self.title)
|
||||
|
||||
@property
|
||||
def summary(self):
|
||||
return truncate_html_words(self.content, 50)
|
||||
|
||||
|
||||
class Article(Page):
|
||||
mandatory_properties = ('author', 'title', 'date', 'category')
|
||||
|
||||
|
||||
class Quote(Page):
|
||||
base_properties = ('author', 'date')
|
||||
Loading…
Add table
Add a link
Reference in a new issue