Skip to content

Commit db286ac

Browse files
authored
Plugin dir cli (#385)
* ✨enabled plugins dir via command line * 📚 update exit code * 🔬 test -pd on command line * 📚 update readme * 🐛 fix unit test which failed to detect the missing feature * 🔨 code refactor copy engine and strip content processor * 📚 here is the way to write modelines remover. #36 * 🔨 code refactoring
1 parent a9c47c5 commit db286ac

File tree

31 files changed

+303
-130
lines changed

31 files changed

+303
-130
lines changed

.moban.cd/changelog.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
name: moban
22
organisation: moremoban
33
releases:
4+
- changes:
5+
- action: Added
6+
details:
7+
- "`-pd` for command line to include custom plugin directories"
8+
- action: Fixed
9+
details:
10+
- "strip did not work in 0.7.6"
11+
date: tbd
12+
version: 0.7.7
413
- changes:
514
- action: Added
615
details:

.moban.cd/moban.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ organisation: moremoban
44
author: C. W.
55
66
license: MIT
7-
version: 0.7.6
8-
current_version: 0.7.6
7+
version: 0.7.7
8+
current_version: 0.7.7
99
release: 0.7.6
1010
branch: master
1111
master: index

CHANGELOG.rst

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

4+
0.7.7 - tbd
5+
--------------------------------------------------------------------------------
6+
7+
**Added**
8+
9+
#. `-pd` for command line to include custom plugin directories
10+
11+
**Fixed**
12+
13+
#. strip did not work in 0.7.6
14+
415
0.7.6 - 22.5.2020
516
--------------------------------------------------------------------------------
617

README.rst

Lines changed: 62 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -42,57 +42,6 @@ For existing moban users, python 2 support has been dropped. Please stay with
4242
versions lower than 0.7.0 if you are still using python 2.
4343

4444

45-
Introduction
46-
================================================================================
47-
48-
**moban** enabled **continuous templating** in `pyexcel <https://github.com/pyexcel/pyexcel>`_ and
49-
`coala <https://github.com//coala/coala>`_ project to keep
50-
documentation consistent across the documentations of individual libraries in the same
51-
organisation. Here is the primary use case of moban, as of now:
52-
53-
.. image:: https://github.com/moremoban/yehua/raw/dev/docs/source/_static/yehua-story.png
54-
:width: 600px
55-
56-
57-
And here is a list of other usages:
58-
59-
#. `Django Mobans <https://github.com/django-mobans>`_, templates for django, docker etc.
60-
#. `Math Sheets <https://github.com/chfw/math-sheets>`_, generate custom math sheets in pdf
61-
62-
All use cases are documented `here <http://moban.readthedocs.org/en/latest/#tutorial>`_
63-
64-
Support
65-
================================================================================
66-
67-
If you like moban, please support me on github,
68-
`patreon <https://www.patreon.com/bePatron?u=5537627>`_
69-
or `bounty source <https://salt.bountysource.com/teams/chfw-pyexcel>`_ to maintain
70-
the project and develop it further.
71-
72-
With your financial support, I will be able to invest
73-
a little bit more time in coding, documentation and writing interesting extensions.
74-
75-
Vision
76-
================================================================================
77-
78-
Any template, any data in any location
79-
80-
**moban** started with bringing the high performance template engine (JINJA2) for web
81-
into static text generation.
82-
83-
**moban** can use other python template engine: mako, handlebars, velocity,
84-
haml, slim and tornado, can read other data format: json and yaml, and can access both
85-
template file and configuration file in
86-
any location: zip, git, pypi package, s3, etc.
87-
88-
89-
Credit
90-
================================================================================
91-
92-
`jinja2-fsloader <https://github.com/althonos/jinja2-fsloader>`_ is the key component to enable PyFilesystem2 support in moban
93-
v0.6x. Please show your stars there too!
94-
95-
9645
Quick start
9746
================================================================================
9847

@@ -229,9 +178,63 @@ Then you can access your files in s3 bucket:
229178
$ cat moban.output
230179
world
231180
232-
Where the configuration sits in a s3 bucket, the output is a file in a zip. The content of s3data.yaml is::
181+
Where the configuration sits in a s3 bucket, the output is a file in a zip. The content of s3data.yaml is:
182+
183+
184+
.. code-block:
233185
234186
hello: world
187+
188+
189+
Introduction
190+
================================================================================
191+
192+
**moban** enabled **continuous templating** in `pyexcel <https://github.com/pyexcel/pyexcel>`_ and
193+
`coala <https://github.com//coala/coala>`_ project to keep
194+
documentation consistent across the documentations of individual libraries in the same
195+
organisation. Here is the primary use case of moban, as of now:
196+
197+
.. image:: https://github.com/moremoban/yehua/raw/dev/docs/source/_static/yehua-story.png
198+
:width: 600px
199+
200+
201+
And here is a list of other usages:
202+
203+
#. `Django Mobans <https://github.com/django-mobans>`_, templates for django, docker etc.
204+
#. `Math Sheets <https://github.com/chfw/math-sheets>`_, generate custom math sheets in pdf
205+
206+
All use cases are documented `here <http://moban.readthedocs.org/en/latest/#tutorial>`_
207+
208+
Support
209+
================================================================================
210+
211+
If you like moban, please support me on github,
212+
`patreon <https://www.patreon.com/bePatron?u=5537627>`_
213+
or `bounty source <https://salt.bountysource.com/teams/chfw-pyexcel>`_ to maintain
214+
the project and develop it further.
215+
216+
With your financial support, I will be able to invest
217+
a little bit more time in coding, documentation and writing interesting extensions.
218+
219+
Vision
220+
================================================================================
221+
222+
Any template, any data in any location
223+
224+
**moban** started with bringing the high performance template engine (JINJA2) for web
225+
into static text generation.
226+
227+
**moban** can use other python template engine: mako, handlebars, velocity,
228+
haml, slim and tornado, can read other data format: json and yaml, and can access both
229+
template file and configuration file in
230+
any location: zip, git, pypi package, s3, etc.
231+
232+
233+
Credit
234+
================================================================================
235+
236+
`jinja2-fsloader <https://github.com/althonos/jinja2-fsloader>`_ is the key component to enable PyFilesystem2 support in moban
237+
v0.6x. Please show your stars there too!
235238

236239

237240
Installation
@@ -258,7 +261,8 @@ CLI documentation
258261
.. code-block:: bash
259262
260263
usage: moban [-h] [-c CONFIGURATION] [-t TEMPLATE] [-o OUTPUT]
261-
[-td [TEMPLATE_DIR [TEMPLATE_DIR ...]]] [-cd CONFIGURATION_DIR]
264+
[-td [TEMPLATE_DIR [TEMPLATE_DIR ...]]]
265+
[-pd [PLUGIN_DIR [PLUGIN_DIR ...]]] [-cd CONFIGURATION_DIR]
262266
[-m MOBANFILE] [-g GROUP] [--template-type TEMPLATE_TYPE]
263267
[-d DEFINE [DEFINE ...]] [-e EXTENSION [EXTENSION ...]] [-f]
264268
[--exit-code] [-V] [-v]
@@ -285,6 +289,8 @@ CLI documentation
285289
add more directories for template file lookup
286290
-cd CONFIGURATION_DIR, --configuration_dir CONFIGURATION_DIR
287291
the directory for configuration file lookup
292+
-pd [PLUGIN_DIR [PLUGIN_DIR ...]], --plugin_dir [PLUGIN_DIR [PLUGIN_DIR ...]]
293+
add more directories for plugin lookup
288294
-m MOBANFILE, --mobanfile MOBANFILE
289295
custom moban file
290296
-g GROUP, --group GROUP
@@ -302,19 +308,8 @@ CLI documentation
302308
Developer options:
303309
For debugging and development
304310
305-
--exit-code tell moban to change exit code
311+
--exit-code by default, exist code 0 means no error, 1 means error
312+
occured. It tells moban to change 1 for changes, 2 for
313+
error occured
306314
-V, --version show program's version number and exit
307315
-v show verbose, try -v, -vv, -vvv
308-
309-
Exit codes
310-
--------------------------------------------------------------------------------
311-
By default:
312-
313-
- 0 : no error
314-
- 1 : error occured
315-
316-
With `--exit-code`:
317-
318-
- 0 : no changes
319-
- 1 : has changes
320-
- 2 : error occured

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
copyright = '2017-2020 Onni Software Ltd.'
2626
author = 'C. W.'
2727
# The short X.Y version
28-
version = '0.7.6'
28+
version = '0.7.7'
2929
# The full version, including alpha/beta/rc tags
3030
release = '0.7.6'
3131

docs/extension.rst

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Development guide
22
=======================
3-
3+
44
Jinja2 extensions for Moban
55
------------------------------
66

@@ -14,7 +14,7 @@ your plugins will NOT be loaded.
1414
Jinja2 Filter
1515
*******************
1616

17-
.. literalinclude:: ../moban/filters/repr.py
17+
.. literalinclude:: ../moban/plugins/jinja2/filters/repr.py
1818

1919
split_length
2020
--------------------------------------------------------------------------------
@@ -66,7 +66,7 @@ Built-in Tests
6666
Jinja2 Test
6767
*******************
6868

69-
.. literalinclude:: ../moban/tests/files.py
69+
.. literalinclude:: ../moban/plugins/jinja2/tests/files.py
7070

7171

7272
`exists`
@@ -104,16 +104,16 @@ is an example starting point for any template engine.
104104
"""
105105
A list template directories will be given to your engine class
106106
"""
107-
107+
108108
def get_template(self, template_file):
109109
"""
110110
Given a relative path to your template file, please return a templatable thing that does
111111
the templating function in next function below
112112
"""
113-
113+
114114
def apply_template(self, template, data, output):
115115
"""
116-
Given the template object from `get_template` function, and data as python dictionary,
116+
Given the template object from `get_template` function, and data as python dictionary,
117117
and output as intended output file, please return "utf-8" encoded string.
118118
"""
119119
@@ -122,5 +122,27 @@ After you will have finished the engine plugin, you can either place it in `plug
122122
in order to get it loaded, or make an installable python package. In the latter case,
123123
please refer to `yehua`_: doing that in less than 5 minutes.
124124

125+
126+
Custom content processors for Moban
127+
----------------------------------------
128+
129+
Since version 0.7.7, it became easy to write a content processor for moban.
130+
What you need is a content processing function, which will be fed the
131+
content of `template_file` and which is expected to return a string. And
132+
decorate your function with `ContentProcessor`:
133+
134+
.. code-block:: python
135+
136+
@ContentProcessor('strip', 'Stripping', 'Stripped'):
137+
def strip(template_file: str) -> str:
138+
ret = template_file.strip()
139+
return ret
140+
141+
142+
Here is how `copy` template type is coded:
143+
144+
.. literalinclude:: ../moban/plugins/copy.py
145+
146+
125147
.. _lml: http://lml.readthedocs.io
126148
.. _yehua: http://yehua.readthedocs.io

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ For example::
2121
Please also note that the following extensions are included by default:
2222
`jinja2.ext.do`, `jinja2.ext.loopcontrols`
2323

24+
.. note::
25+
26+
if you intend to use extensions for one off usage, please use '-e' cli option
2427

2528
Evaluation
2629
--------------------------------------------------------------------------------

docs/level-26-strip-rendered-content/final

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/level-7-use-custom-jinja2-filter-test-n-global/README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ It is very important to have `__init__.py`, otherwise, it will NOT work. Other t
2323
files are named to show case the feature. You can choose whichever name you prefer,
2424
as long as you and your team could make sense of the names.
2525

26+
.. note::
27+
28+
if you intend to use extensions for one off usage, please use '-pd' cli option.
29+
i.e. `moban -td my-templates/ -t filter.jj2 -pd custom-jj2-plugin`
2630

2731
Evaluation
2832
--------------------------------------------------------------------------------

moban/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
__version__ = "0.7.6"
1+
__version__ = "0.7.7"
22
__author__ = "C. W."

0 commit comments

Comments
 (0)