Skip to content

Commit df67d87

Browse files
authored
Merge pull request #403 from moremoban/dev
release 0.8.2
2 parents f15c958 + c852a35 commit df67d87

File tree

21 files changed

+261
-42
lines changed

21 files changed

+261
-42
lines changed

.github/workflows/moban-update.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
python-version: '3.7'
1515
- name: check changes
1616
run: |
17-
pip install moban gitfs2 pypifs moban-jinja2-github
17+
pip install moban gitfs2 pypifs moban-jinja2-github moban-ansible
1818
make update
1919
git status
2020
git diff --exit-code

.moban.cd/changelog.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
name: moban
22
organisation: moremoban
33
releases:
4+
- changes:
5+
- action: Fixed
6+
details:
7+
- Use any functions, any data structure of any python packages
8+
as jinja2 filters, tests, globals
9+
date: 04.09.2020
10+
version: 0.8.2
411
- changes:
512
- action: Fixed
613
details:

.moban.cd/moban.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ organisation: moremoban
44
author: chfw
55
66
license: MIT
7-
version: 0.8.1
8-
current_version: 0.8.1
9-
release: 0.8.1
7+
version: 0.8.2
8+
current_version: 0.8.2
9+
release: 0.8.2
1010
branch: master
1111
master: index
1212
command_line_interface: "moban"

.moban.d/moban_readme.jj2

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ package. `moban.plugins.jinja2.filters.github` is moved to moban-jinja2-github
4040
package Please install them for backward compatibility.
4141

4242

43-
From 2020 onwards, minimum requirement is Python 3.6
44-
45-
46-
For existing moban users, python 2 support has been dropped. Please stay with
47-
versions lower than 0.7.0 if you are still using python 2.
48-
49-
50-
51-
5243
Quick start
5344
================================================================================
5445

@@ -139,7 +130,32 @@ moban allows the injection of user preferred jinja2 extensions:
139130

140131
$ moban -e jj2=jinja2_time.TimeExtension ...
141132

142-
Can I write my own jinja2 test, filter and/or globals
133+
134+
Well, can I nick some existing functions as filters, tests? Or create a global from another library?
135+
-----------------------------------------------------------------------------------------------------
136+
137+
Sure, you can use the same '-e' syntax:
138+
139+
.. code-block:: bash
140+
141+
$ moban -e jinja2=filter:module.path.filter_function \
142+
jinja2=test:module.path.test_function \
143+
jinja2=global:identifier=module.path.variable
144+
145+
In this case, you would have to include the external library in your own requirements.txt
146+
147+
Here is an example:
148+
149+
{% raw %}
150+
.. code-block:: bash
151+
152+
$ moban -e jinja2=filter:moban.externals.file_system.url_join \
153+
jinja2=test:moban.externals.file_system.exists \
154+
jinja2=global:description=moban.constants.PROGRAM_DESCRIPTION \
155+
-t "{{ 'a'|url_join('b')}} {{'b' is exists}}"
156+
{% endraw %}
157+
158+
Can I write my own jinja2 test, filter and/or globals?
143159
-----------------------------------------------------------
144160

145161
moban allows the freedom of craftsmanship. Please refer to the docs for more

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Change log
22
================================================================================
33

4+
0.8.2 - 04.09.2020
5+
--------------------------------------------------------------------------------
6+
7+
**Fixed**
8+
9+
#. Use any functions, any data structure of any python packages as jinja2
10+
filters, tests, globals
11+
412
0.8.1 - 04.09.2020
513
--------------------------------------------------------------------------------
614

README.rst

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ package. `moban.plugins.jinja2.filters.github` is moved to moban-jinja2-github
4040
package Please install them for backward compatibility.
4141

4242

43-
From 2020 onwards, minimum requirement is Python 3.6
44-
45-
46-
For existing moban users, python 2 support has been dropped. Please stay with
47-
versions lower than 0.7.0 if you are still using python 2.
48-
49-
50-
51-
5243
Quick start
5344
================================================================================
5445

@@ -137,7 +128,31 @@ moban allows the injection of user preferred jinja2 extensions:
137128
138129
$ moban -e jj2=jinja2_time.TimeExtension ...
139130
140-
Can I write my own jinja2 test, filter and/or globals
131+
132+
Well, can I nick some existing functions as filters, tests? Or create a global from another library?
133+
-----------------------------------------------------------------------------------------------------
134+
135+
Sure, you can use the same '-e' syntax:
136+
137+
.. code-block:: bash
138+
139+
$ moban -e jinja2=filter:module.path.filter_function \
140+
jinja2=test:module.path.test_function \
141+
jinja2=global:identifier=module.path.variable
142+
143+
In this case, you would have to include the external library in your own requirements.txt
144+
145+
Here is an example:
146+
147+
148+
.. code-block:: bash
149+
150+
$ moban -e jinja2=filter:moban.externals.file_system.url_join \
151+
jinja2=test:moban.externals.file_system.exists \
152+
jinja2=global:description=moban.constants.PROGRAM_DESCRIPTION \
153+
-t "{{ 'a'|url_join('b')}} {{'b' is exists}}"
154+
155+
Can I write my own jinja2 test, filter and/or globals?
141156
-----------------------------------------------------------
142157

143158
moban allows the freedom of craftsmanship. Please refer to the docs for more

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
copyright = '2017-2020 Onni Software Ltd.'
2626
author = 'chfw'
2727
# The short X.Y version
28-
version = '0.8.1'
28+
version = '0.8.2'
2929
# The full version, including alpha/beta/rc tags
30-
release = '0.8.1'
30+
release = '0.8.2'
3131

3232
# -- General configuration ---------------------------------------------------
3333

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Migration Notes
5959

6060
.. toctree::
6161

62+
trouble-shooting-guide
6263
migration-note
6364

6465

docs/level-12-use-template-engine-extensions/.moban.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ targets:
44
extensions:
55
jinja2:
66
- jinja2.ext.with_
7+
- filter:moban.externals.file_system.url_join
8+
- test:moban.externals.file_system.exists
9+
- global:description=moban.constants.PROGRAM_DESCRIPTION

docs/level-12-use-template-engine-extensions/README.rst

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Level 12: use template engine extensions
22
================================================================================
33

4+
There are three possible ways to provide extensions for your template engine.
5+
Let's take jinja2 as an example.
6+
7+
1. Ready made extensions
8+
-----------------------------
9+
410
jinja2 comes with a lot of extensions. In order not to be the blocker in the
511
middle, **extensions** is allowed in moban file to initialize jinja2 engine
612
with desired extensions. Two extensions, expression-statement and loop-controls
@@ -21,9 +27,61 @@ For example::
2127
Please also note that the following extensions are included by default:
2228
`jinja2.ext.do`, `jinja2.ext.loopcontrols`
2329

24-
.. note::
2530

26-
if you intend to use extensions for one off usage, please use '-e' cli option
31+
**Command line**
32+
33+
if you intend to use extensions for one off usage, please use '-e' cli option.
34+
for example: `moban -e jinja2=your_custom_jinja2_extension <https://github.com/chfw/math-sheets/blob/master/reception/a_op_b_op_c/make.sh>`_
35+
36+
37+
2. Ad-hoc declaration
38+
-----------------------------
39+
40+
Let's say you are fond of some existing functions, for example, ansible's combine
41+
filter. With moban, you can immediately include it for your template via the following
42+
syntax:
43+
44+
.. code-block::
45+
46+
extensions:
47+
jinja2:
48+
- filter:module.path.filter_function
49+
- test:module.path.test_function
50+
- global:identifier=module.path.variable
51+
52+
For example::
53+
54+
extensions:
55+
jinja2:
56+
- filter:ansible.plugins.filter.core.combine
57+
- test:moban.externals.file_system.exists
58+
59+
**Command line**
60+
61+
.. code-block:: bash
62+
63+
$ moban -e jinja2=filter:module.path.filter_function jinja2=test:module.path.test_function jinja2=global:identifier=module.path.variable
64+
65+
you can do this::
66+
67+
$ moban -e jinja2=filter:module.path.filter_function \
68+
jinja2=test:module.path.test_function \
69+
jinja2=global:identifier=module.path.variable
70+
71+
72+
3. Make your own extensions
73+
--------------------------------
74+
75+
You can choose to write an extension for the template type of your choice.
76+
For example, you can write a reusable extension for jinja2. moban will be
77+
able to load it as it is.
78+
79+
If you decide that you only want to write them for moban but for your own
80+
use, you can follow `Level 7: Custom jinja filters, tests and globals` and
81+
write your own. When you would like to make yours avaiable for all moban
82+
users, you can follow `moban-jinja2-github <https://github.com/moremoban/moban-jinja2-github>`_ and
83+
`moban-ansible <https://github.com/moremoban/moban-ansible>`_
84+
2785

2886
Evaluation
2987
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)