diff --git a/acrylamid/views/articles.py b/acrylamid/views/articles.py index 49678876..323f1ee0 100644 --- a/acrylamid/views/articles.py +++ b/acrylamid/views/articles.py @@ -10,14 +10,39 @@ class Articles(View): - """Generates a overview of all articles.""" + """Generates an overview of all articles using *layouts/articles.html* as + default jinja2 template (`Example `_). + + To enable Articles view, add: + + .. code-block:: python + + '/articles/' : { + 'view': 'articles', + 'template': 'articles.html' # default + } + + to your :doc:`conf.py` where */articles/* is the default URL for this view. + + We filter articles that are drafts and add them to the *articles* + dictionary using ``(entry.year, entry.month)`` as key. During templating + we sort all keys by value, hence we get a listing of years > months > entries. + + Variables available during Templating: + + - *articles* containing the articles + - *num_entries* count of articles + - *conf*, *env*""" + + def init(self, template='articles.html'): + self.template = template def generate(self, request): entrylist = sorted((e for e in request['entrylist'] if not e.draft), key=lambda k: k.date, reverse=True) - tt = self.env.jinja2.get_template('articles.html') + tt = self.env.jinja2.get_template(self.template) path = joinurl(self.conf['output_dir'], self.path, 'index.html') hv = md5(*entrylist, attr=lambda o: o.md5) diff --git a/acrylamid/views/entry.py b/acrylamid/views/entry.py index 2c971840..a2692c62 100644 --- a/acrylamid/views/entry.py +++ b/acrylamid/views/entry.py @@ -9,11 +9,31 @@ class Entry(View): - """Creates single full-length entry.""" + """Creates single full-length entry + (`Example `_). + + To enable Entry view, add this to your :doc:`conf.py`: + + .. code-block:: python + + '/:year/:slug/': { + 'view': 'entry', + 'template': 'main.html' # default, includes entry.html + } + + The entry view renders an post to a unique location and should be used as + permalink URL. The url is user configurable using the ``PERMALINK_FORMAT`` + variable and defaults to */:year/:slug/(index.html)*. + + This view takes no other arguments and uses *main.html* and *entry.html* as + template.""" + + def init(self, template='main.html'): + self.template = template def generate(self, request): - tt = self.env.jinja2.get_template('main.html') + tt = self.env.jinja2.get_template(self.template) entrylist = request['entrylist'] pathes = dict() diff --git a/acrylamid/views/index.py b/acrylamid/views/index.py index e2aafef6..09b27619 100644 --- a/acrylamid/views/index.py +++ b/acrylamid/views/index.py @@ -10,19 +10,30 @@ class Index(View): + """Creates nicely paged listing of your posts. First page renders to ``route`` + (defaults to */*) with a recent list of your (e.g. summarized) articles. Other + pages enumerate to the variable ``pagination`` (*/page/:num/* per default). - def init(self, items_per_page=10, pagination='/page/:num/'): + + .. code-block:: python + + '/' : { + 'view': 'index', + 'template': 'main.html', + 'pagination': '/page/:num', + 'items_per_page': 10 + } + """ + + def init(self, template='main.html', items_per_page=10, pagination='/page/:num/'): + self.template = template self.items_per_page = items_per_page self.pagination = pagination def generate(self, request): - """Creates nicely paged listing of your posts. First page is the - index.hml used to have this nice url: http://yourblog.com/ with a recent - list of your (e.g. summarized) Posts. Other pages are enumerated to /page/n+1 - """ ipp = self.items_per_page - tt = self.env.jinja2.get_template('main.html') + tt = self.env.jinja2.get_template(self.template) entrylist = [entry for entry in request['entrylist'] if not entry.draft] paginator = paginate(entrylist, ipp, orphans=self.conf['default_orphans']) diff --git a/acrylamid/views/sitemap.py b/acrylamid/views/sitemap.py index c3b3af82..813af757 100644 --- a/acrylamid/views/sitemap.py +++ b/acrylamid/views/sitemap.py @@ -38,7 +38,14 @@ def read(self): class Sitemap(View): """Create an XML-Sitemap where permalinks have the highest priority (1.0) and do never - change and all other ressources have a changefreq of weekly.""" + change and all other ressources have a changefreq of weekly. + + .. code-block:: python + + '/sitemap.xml': { + 'view': 'Sitemap' + } + """ priority = 0.0 diff --git a/acrylamid/views/tag.py b/acrylamid/views/tag.py index 6b1c0702..b4dc2bf9 100644 --- a/acrylamid/views/tag.py +++ b/acrylamid/views/tag.py @@ -45,8 +45,16 @@ def __iter__(self): class Tag(View): + """Same behaviour like Index except ``route`` that defaults to */tag/:name/* and + ``pagination`` that defaults to */tag/:name/:num/* where :name is the current + tag identifier. - def init(self, items_per_page=10, pagination='/tag/:name/:num/'): + To create a tag cloud head over to :doc:`conf.py`. + """ + + + def init(self, template='main.html', items_per_page=10, pagination='/tag/:name/:num/'): + self.template = template self.items_per_page = items_per_page self.pagination = pagination @@ -83,7 +91,7 @@ def generate(self, request): """Creates paged listing by tag.""" ipp = self.items_per_page - tt = self.env.jinja2.get_template('main.html') + tt = self.env.jinja2.get_template(self.template) entrylist = [entry for entry in request['entrylist'] if not entry.draft] diff --git a/docs/views.rst b/docs/views.rst index c2e93025..04b277ec 100644 --- a/docs/views.rst +++ b/docs/views.rst @@ -31,50 +31,18 @@ To make the next section more easier to read, we define "/path/" as route, Built-in Views ************** -Articles --------- +.. autoclass:: acrylamid.views.articles.Articles() -- `Articles Example `_ +.. autoclass:: acrylamid.views.entry.Entry() -Creates a single page overview of all articles in the form of (year) date and -title. This view uses *articles.html* as jinja2 template to function. +.. autoclass:: acrylamid.views.index.Index() -The default configuration outputs this to */articles/* and is (currently) -hardcoded into *base.html*. +.. autoclass:: acrylamid.views.tag.Tag() -Entry ------ +.. autoclass:: acrylamid.views.sitemap.Sitemap() -- `Entry Example `_ -The entry view renders an post to a unique location and should be used as -permalink URL. The url is user configurable using the ``PERMALINK_FORMAT`` -variable and defaults to */:year/:slug/(index.html)*. - -This view takes no other arguments and uses *main.html* and *entry.html* as -template. - -Index ------ - -Creates nicely paged listing of your posts. First page renders to ``route`` -(defaults to */*) with a recent list of your (e.g. summarized) articles. Other -pages enumerate to the variable ``pagination`` (*/page/:num/* per default). - -The Index view uses *main.html* and *entry.html* as template and yields -``items_per_page`` items per page (default: 10). - -Tag ---- - -Same behaviour like Index except ``route`` that defaults to */tag/:name/* and -``pagination`` that defaults to */tag/:name/:num/* where :name is the current -tag identifier. - -To create a tag cloud head over to :doc:`conf.py`. - -Feed ----- +.. note:: TODO: Feeds!