File tree Expand file tree Collapse file tree 5 files changed +29
-29
lines changed
tests/regression_tests/level-11-helpers-and-partials/helper_and_partial Expand file tree Collapse file tree 5 files changed +29
-29
lines changed Original file line number Diff line number Diff line change @@ -4,13 +4,12 @@ Let's save the following file a `script.py` under `helper_and_partial` folder:
4
4
5
5
.. code-block:: python
6
6
7
- from moban_handlebars.helpers import HandlebarHelper
8
- from moban_handlebars.partials import register_partial
7
+ from moban_handlebars.api import Helper, register_partial
9
8
10
9
register_partial('header', '<h1>People</h1>')
11
10
12
11
13
- @HandlebarHelper ('list')
12
+ @Helper ('list')
14
13
def _list(this, options, items):
15
14
result = [u'<ul>']
16
15
for thing in items:
@@ -24,7 +23,7 @@ Let's save the following file a `script.py` under `helper_and_partial` folder:
24
23
Let invoke handlebar template:
25
24
{% raw %}
26
25
27
- .. code-block: bash
26
+ .. code-block:: bash
28
27
29
28
$ moban --template-type hbs -pd helper_and_partial -c data.json "{{>header}}{{#list people}}{{name}} {{age}}{{/list}}"
30
29
Handlebars-ing {{>header}... to moban.output
Original file line number Diff line number Diff line change
1
+ from pybars import Compiler
2
+ from lml .plugin import PluginInfo
3
+
4
+ from moban_handlebars .constants import HELPER_EXTENSION , PARTIALS_EXTENSION
5
+
6
+
7
+ class Helper (PluginInfo ):
8
+ """
9
+ @Helper('tag_used_inside_handlebar')
10
+ def the_actual_implementation(this, options, items):
11
+ ...
12
+ """
13
+ def __init__ (self , helper ):
14
+ super (Helper , self ).__init__ (HELPER_EXTENSION )
15
+ self .helper = helper
16
+
17
+ def tags (self ):
18
+ yield self .helper
19
+
20
+
21
+ def register_partial (identifier , partial ):
22
+ plugin = PluginInfo (PARTIALS_EXTENSION , tags = [identifier ])
23
+ partial = Compiler ().compile (partial )
24
+ plugin ({identifier : partial })
Load Diff This file was deleted.
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
- from moban_handlebars .helpers import HandlebarHelper
2
- from moban_handlebars .partials import register_partial
1
+ from moban_handlebars .api import Helper , register_partial
3
2
4
3
register_partial ("header" , "<h1>People</h1>" )
5
4
6
5
7
- @HandlebarHelper ("list" )
6
+ @Helper ("list" )
8
7
def _list (this , options , items ):
9
8
result = [u"<ul>" ]
10
9
for thing in items :
You can’t perform that action at this time.
0 commit comments