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
22486f51
Commit
22486f51
authored
Feb 01, 2013
by
tschmidt-dev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added kwargs logic to macros plugin and depth kwarg to article_list macro
parent
0751cc87
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
14 deletions
+16
-14
wiki/plugins/macros/markdown_extensions.py
+11
-10
wiki/plugins/macros/templates/wiki/plugins/macros/article_list.html
+1
-1
wiki/plugins/macros/templates/wiki/plugins/templatetags/article_list.html
+2
-2
wiki/plugins/macros/templatetags/wiki_macro_tags.py
+2
-1
No files found.
wiki/plugins/macros/markdown_extensions.py
View file @
22486f51
...
@@ -4,7 +4,8 @@ import re
...
@@ -4,7 +4,8 @@ import re
from
django.template.loader
import
render_to_string
from
django.template.loader
import
render_to_string
from
django.template
import
Context
from
django.template
import
Context
MACRO_RE
=
re
.
compile
(
r'.*(\[(?P<macro>\w+)(\:(?P<arg>\w+))?\]).*'
,
re
.
IGNORECASE
)
MACRO_RE
=
re
.
compile
(
r'.*(\[(?P<macro>\w+)(?P<kwargs>\s\w+\:.+)*\]).*'
,
re
.
IGNORECASE
)
KWARG_RE
=
re
.
compile
(
r'([^ |:]+):([^ |$]+)'
,
re
.
IGNORECASE
)
class
MacroExtension
(
markdown
.
Extension
):
class
MacroExtension
(
markdown
.
Extension
):
...
@@ -17,7 +18,7 @@ class MacroExtension(markdown.Extension):
...
@@ -17,7 +18,7 @@ class MacroExtension(markdown.Extension):
class
MacroPreprocessor
(
markdown
.
preprocessors
.
Preprocessor
):
class
MacroPreprocessor
(
markdown
.
preprocessors
.
Preprocessor
):
"""django-wiki macro preprocessor - parse text for various [some_macro] and
"""django-wiki macro preprocessor - parse text for various [some_macro] and
[some_macro
:arg
] references. """
[some_macro
(kw:arg)*
] references. """
allowed_methods
=
(
'article_list'
,)
allowed_methods
=
(
'article_list'
,)
...
@@ -29,22 +30,22 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
...
@@ -29,22 +30,22 @@ class MacroPreprocessor(markdown.preprocessors.Preprocessor):
macro
=
m
.
group
(
'macro'
)
.
strip
()
macro
=
m
.
group
(
'macro'
)
.
strip
()
if
not
macro
in
MacroPreprocessor
.
allowed_methods
:
if
not
macro
in
MacroPreprocessor
.
allowed_methods
:
continue
continue
arg
=
m
.
group
(
'arg'
)
kwargs
=
m
.
group
(
'kwargs'
)
if
arg
:
if
kwargs
:
arg
=
arg
.
strip
()
kwargs
=
eval
(
'{'
+
KWARG_RE
.
sub
(
r'"\1":"\2",'
,
kwargs
)
+
'}'
)
try
:
line
=
getattr
(
self
,
macro
)(
**
kwargs
)
line
=
getattr
(
self
,
macro
)(
arg
)
else
:
except
AttributeError
:
line
=
getattr
(
self
,
macro
)()
pass
if
not
line
is
None
:
if
not
line
is
None
:
new_text
.
append
(
line
)
new_text
.
append
(
line
)
return
new_text
return
new_text
def
article_list
(
self
,
arg
=
None
):
def
article_list
(
self
,
depth
=
2
):
html
=
render_to_string
(
html
=
render_to_string
(
"wiki/plugins/macros/article_list.html"
,
"wiki/plugins/macros/article_list.html"
,
Context
({
Context
({
'article_children'
:
self
.
markdown
.
article
.
get_children
,
'article_children'
:
self
.
markdown
.
article
.
get_children
,
'depth'
:
int
(
depth
)
+
1
,
})
})
)
)
return
self
.
markdown
.
htmlStash
.
store
(
html
,
safe
=
True
)
return
self
.
markdown
.
htmlStash
.
store
(
html
,
safe
=
True
)
...
...
wiki/plugins/macros/templates/wiki/plugins/macros/article_list.html
View file @
22486f51
...
@@ -5,7 +5,7 @@
...
@@ -5,7 +5,7 @@
<h3>
{% trans "Articles" %}
</h3>
<h3>
{% trans "Articles" %}
</h3>
<br/>
<br/>
{% for child in article_children %}
{% for child in article_children %}
{% article_list child %}
{% article_list child
depth
%}
{% endfor %}
{% endfor %}
</div>
</div>
{% endif %}
{% endif %}
wiki/plugins/macros/templates/wiki/plugins/templatetags/article_list.html
View file @
22486f51
...
@@ -2,11 +2,11 @@
...
@@ -2,11 +2,11 @@
{% load url from future %}
{% load url from future %}
<p><a
href=
"{% url 'wiki:get' path=parent.path article_id=parent.article.id %}"
>
{{ parent.article }}
</a></p>
<p><a
href=
"{% url 'wiki:get' path=parent.path article_id=parent.article.id %}"
>
{{ parent.article }}
</a></p>
{% if parent.children.count %}
{% if parent.children.count
and parent.level
<
depth
%}
<
div
class=
"wiki-article-sublist"
>
<
div
class=
"wiki-article-sublist"
>
<ul>
<ul>
{% for child in parent.children.all %}
{% for child in parent.children.all %}
<li>
{% article_list child %}
</li>
<li>
{% article_list child
depth
%}
</li>
{% endfor %}
{% endfor %}
</ul>
</ul>
</div>
</div>
...
...
wiki/plugins/macros/templatetags/wiki_macro_tags.py
View file @
22486f51
...
@@ -7,8 +7,9 @@ register = template.Library()
...
@@ -7,8 +7,9 @@ register = template.Library()
'wiki/plugins/templatetags/article_list.html'
,
'wiki/plugins/templatetags/article_list.html'
,
takes_context
=
True
takes_context
=
True
)
)
def
article_list
(
context
,
urlpath
):
def
article_list
(
context
,
urlpath
,
depth
):
context
[
'parent'
]
=
urlpath
context
[
'parent'
]
=
urlpath
context
[
'depth'
]
=
depth
return
context
return
context
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