Skip to content

Commit

Permalink
configurable templates, closes #24
Browse files Browse the repository at this point in the history
and add previously stashed docs.
  • Loading branch information
posativ committed Jun 2, 2012
1 parent 545d39f commit 1d8ecff
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 51 deletions.
29 changes: 27 additions & 2 deletions acrylamid/views/articles.py
Expand Up @@ -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 <http://blog.posativ.org/articles/>`_).
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)
Expand Down
24 changes: 22 additions & 2 deletions acrylamid/views/entry.py
Expand Up @@ -9,11 +9,31 @@


class Entry(View):
"""Creates single full-length entry."""
"""Creates single full-length entry
(`Example <http://blog.posativ.org/2012/nginx/>`_).
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()
Expand Down
23 changes: 17 additions & 6 deletions acrylamid/views/index.py
Expand Up @@ -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'])
Expand Down
9 changes: 8 additions & 1 deletion acrylamid/views/sitemap.py
Expand Up @@ -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

Expand Down
12 changes: 10 additions & 2 deletions acrylamid/views/tag.py
Expand Up @@ -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

Expand Down Expand Up @@ -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]

Expand Down
44 changes: 6 additions & 38 deletions docs/views.rst
Expand Up @@ -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 <http://blog.posativ.org/articles/>`_
.. 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 <http://blog.posativ.org/2012/nginx/>`_

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!



Expand Down

0 comments on commit 1d8ecff

Please sign in to comment.