Commit b3365861 by benjaoming

Add help sidebar for macros and make allowed methods configurable

parent 0751cc87
import markdown
import re
from django.utils.translation import ugettext as _
from django.template.loader import render_to_string
from django.template import Context
MACRO_RE = re.compile(r'.*(\[(?P<macro>\w+)(\:(?P<arg>\w+))?\]).*', re.IGNORECASE)
from wiki.plugins.macros import settings
class MacroExtension(markdown.Extension):
""" Macro plugin markdown extension for django-wiki. """
......@@ -19,7 +21,7 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
"""django-wiki macro preprocessor - parse text for various [some_macro] and
[some_macro:arg] references. """
allowed_methods = ('article_list',)
allowed_methods = settings.METHODS
def run(self, lines):
new_text = []
......@@ -48,4 +50,9 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
})
)
return self.markdown.htmlStash.store(html, safe=True)
article_list.meta = dict(
short_description = _(u'Article list'),
help_text = _(u'Insert a list of articles in this level.'),
example_code = _(u'[article_list:depth=2]'),
args = {'depth': _('Maximum depth to show levels for.')}
)
from django.conf import settings as django_settings
from wiki.conf import settings as wiki_settings
SLUG = 'macros'
APP_LABEL = 'wiki'
METHODS = getattr(django_settings, 'WIKI_PLUGINS_METHODS', ('article_list',))
\ No newline at end of file
{% load i18n wiki_macro_tags %}
{% allowed_macros as macros %}
{% for macro in macros %}
<h4>{{ macro.short_description }}</h4>
{{ macro.help_text|linebreaks|safe }}
{% if macro.example_code %}
<pre>{{ macro.example_code }}</pre>
{% endif %}
{% if macro.args %}
<table class="table table-compact">
{% for arg,description in macro.args.items %}
<tr>
<th>{{ arg }}</th>
<td>{{ description }}</td>
</tr>
{% endfor %}
</table>
{% endif %}
{% endfor %}
from django import template
from wiki.plugins.macros import settings, markdown_extensions
register = template.Library()
......@@ -12,3 +13,12 @@ def article_list(context, urlpath):
return context
@register.assignment_tag
def allowed_macros():
for method in settings.METHODS:
try:
yield getattr(markdown_extensions.MacroPreprocessor, method).meta
except AttributeError:
continue
\ No newline at end of file
# -*- coding: utf-8 -*-
from django.utils.translation import ugettext as _
from wiki.core.plugins import registry
from wiki.core.plugins.base import BasePlugin
from wiki.plugins.macros import settings
......@@ -9,6 +11,12 @@ class MacroPlugin(BasePlugin):
slug = settings.SLUG
sidebar = {'headline': _('Macros'),
'icon_class': 'icon-play',
'template': 'wiki/plugins/macros/sidebar.html',
'form_class': None,
'get_form_kwargs': (lambda a: {})}
markdown_extensions = [MacroExtension()]
def __init__(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment