Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-wiki
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
django-wiki
Commits
b3365861
Commit
b3365861
authored
Feb 03, 2013
by
benjaoming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add help sidebar for macros and make allowed methods configurable
parent
0751cc87
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
3 deletions
+51
-3
wiki/plugins/macros/markdown_extensions.py
+9
-2
wiki/plugins/macros/settings.py
+3
-1
wiki/plugins/macros/templates/wiki/plugins/macros/sidebar.html
+20
-0
wiki/plugins/macros/templatetags/wiki_macro_tags.py
+11
-0
wiki/plugins/macros/wiki_plugin.py
+8
-0
No files found.
wiki/plugins/macros/markdown_extensions.py
View file @
b3365861
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.'
)}
)
wiki/plugins/macros/settings.py
View file @
b3365861
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
wiki/plugins/macros/templates/wiki/plugins/macros/sidebar.html
0 → 100644
View file @
b3365861
{% 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 %}
wiki/plugins/macros/templatetags/wiki_macro_tags.py
View file @
b3365861
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
wiki/plugins/macros/wiki_plugin.py
View file @
b3365861
# -*- 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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment