~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wiki/templatetags/creole.py

  • Committer: franku
  • Author(s): GunChleoc
  • Date: 2016-12-13 18:30:38 UTC
  • mfrom: (438.1.6 pyformat_util)
  • Revision ID: somal@arcor.de-20161213183038-5cgmvfh2fkgmoc1s
adding a script to run pyformat over the code base

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
 
""" Provides the `creole` template filter, to render
3
 
texts using the markup used by the MoinMoin wiki.
4
 
"""
 
2
"""Provides the `creole` template filter, to render texts using the markup used
 
3
by the MoinMoin wiki."""
5
4
 
6
5
from django import template
7
6
from django.conf import settings
21
20
 
22
21
@register.filter
23
22
def creole(text, **kw):
24
 
    """Returns the text rendered by the Creole markup.
25
 
    """
 
23
    """Returns the text rendered by the Creole markup."""
26
24
    if Creole is None and settings.DEBUG:
27
 
        raise template.TemplateSyntaxError("Error in creole filter: "
28
 
            "The Creole library isn't installed, try easy_install Creoleparser.")
 
25
        raise template.TemplateSyntaxError('Error in creole filter: '
 
26
                                           "The Creole library isn't installed, try easy_install Creoleparser.")
29
27
    parser = CreoleParser(dialect=dialect)
30
28
    return parser.render(text)
31
29
 
 
30
 
32
31
class CreoleTextNode(template.Node):
 
32
 
33
33
    def __init__(self, nodelist):
34
34
        self.nodelist = nodelist
35
35
 
36
36
    def render(self, context):
37
37
        return creole(self.nodelist.render(context))
38
38
 
39
 
@register.tag("creole")
 
39
 
 
40
@register.tag('creole')
40
41
def crl_tag(parser, token):
41
 
    """
42
 
    Render the Creole into html. Will pre-render template code first.
 
42
    """Render the Creole into html.
 
43
 
 
44
    Will pre-render template code first.
 
45
 
43
46
    """
44
47
    nodelist = parser.parse(('endcreole',))
45
48
    parser.delete_first_token()
46
49
    return CreoleTextNode(nodelist)
47