-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Moban extension #61
Merged
Merged
Moban extension #61
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
98f546e
:sparkles: make internal jinja2 filters as a pluginable filter. relat…
chfw 1debcf3
:sparkles: take jinja filters from plugin_dir. #23
chfw 9c4e3bc
:sparkles: support for jinja2 tests and globals. verification require…
chfw 77e4131
:fire: remove tests because the custom filters have been relocated to…
chfw 9a671ab
:sparkles: provide repr filter, fix #26
chfw ffe2343
:bug: fix format call for python 2.6
chfw 6843e81
:sparkles: deliver exists test and more. fix #18. related to #23
chfw 0fd443c
bring back the custom filters so as to avoid big impact of existing m…
chfw df8a0c9
:bug: minor fixes
chfw c4ea295
:bug: make plugin managers global in engine file so that each instanc…
chfw 42488eb
:sparkles: verfied jinja globals plugin
chfw 6e02d05
:newspaper: add test fixtures
chfw 26772c4
:green_heart: make unit test pass. note: lml does not really support …
chfw 79dd753
:books: document custom jinja extensions
chfw 35f0ad3
:art: treat plugin directory as a python module so as to avoid duplic…
chfw dbdd8e2
:fire: remove debug log
chfw ed44151
:books: document jinja plugin feature
chfw 277c0b6
:shirt: pump up the version number
chfw bd8467b
:handshake: Merge branch 'master' into moban-extension
chfw f12440f
:fire: sync with latest pypi-mobans
chfw 0889731
:bug: fix filter for python 3
chfw 16d2283
:books: update change log
chfw 4462f8f
:shirt: whitening the code
chfw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,8 @@ organisation: moremoban | |
author: C. W. | ||
contact: [email protected] | ||
license: MIT | ||
version: 0.1.4 | ||
current_version: 0.1.4 | ||
version: 0.2.0 | ||
current_version: 0.2.0 | ||
release: 0.1.4 | ||
branch: master | ||
command_line_interface: "moban" | ||
|
@@ -15,6 +15,7 @@ keywords: | |
dependencies: | ||
- pyyaml>=3.11 | ||
- jinja2>=2.7.1 | ||
- lml==0.0.2 | ||
- crayons | ||
description: Yet another jinja2 cli command for static text generation | ||
scm_host: github.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
Development guide | ||
======================= | ||
|
||
Jinja2 extensions for Moban | ||
------------------------------ | ||
|
||
Since version 0.2, mobanfile supports an extra field `plugin_dir`, along with | ||
`template_dir`. When you put your own jinja2 filters, tests and globals in | ||
your moban repo, you can let moban know about them via this keyword. | ||
|
||
Importantly, you have to have `__init__.py` file in your `plugin_dir`. Otherwise, | ||
your plugins will NOT be loaded. | ||
|
||
Jinja2 Filter | ||
******************* | ||
|
||
.. literalinclude:: ../../moban/filters/repr.py | ||
|
||
|
||
Jinja2 Test | ||
******************* | ||
|
||
.. literalinclude:: ../../moban/tests/files.py | ||
|
||
Jinja2 Globals | ||
******************* | ||
|
||
.. literalinclude:: ../../tests/test_engine.py | ||
:lines: 49-61 | ||
|
||
It is possible to write an installable package including your own jinja2 | ||
filters, tests and globals. Please email me for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
docs/level-7-use-custom-jinja2-filter-test-n-global/.moban.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
configuration: | ||
template_dir: | ||
- my-templates | ||
plugin_dir: | ||
- custom-jj2-plugin | ||
configuration: data.yml | ||
targets: | ||
- filter.output: filter.jj2 | ||
- test.output: test.jj2 | ||
- global.output: global.jj2 | ||
45 changes: 45 additions & 0 deletions
45
docs/level-7-use-custom-jinja2-filter-test-n-global/README.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Level 7: Custom jinja filters, tests and globals | ||
================================================================================ | ||
|
||
Level 7 example demonstrates advanced plugin capabilities of moban. The following | ||
moban file had `plugin_dir` specified:: | ||
|
||
|
||
configuration: | ||
template_dir: | ||
- my-templates | ||
plugin_dir: | ||
- custom-jj2-plugin | ||
configuration: data.yml | ||
targets: | ||
- filter.output: filter.jj2 | ||
- test.output: test.jj2 | ||
|
||
Where `custom-jj2-plugin` is a directory holding all jinja2 filters, tests | ||
and globals. Under it, there are 4 files:: | ||
|
||
__init__.py filter.py test.py global.py | ||
|
||
It is very important to have `__init__.py`, otherwise, it will NOT work. Other three | ||
files are named to show case the feature. You can choose whichever name you prefer, | ||
as long as you and your team could make sense of the names. | ||
|
||
|
||
Evaluation | ||
-------------------------------------------------------------------------------- | ||
|
||
Please go to `docs/level-7-use-custom-jinja2-filter-test-n-global` directory, | ||
|
||
Here is the command to launch it: | ||
|
||
.. code-block:: bash | ||
|
||
$ moban | ||
Templating filter.jj2 to filter.output | ||
Templating test.jj2 to test.output | ||
Templating global.jj2 to global.output | ||
Templated 3 files. | ||
Everything is up to date! | ||
|
||
Please examine individual template and its associated plugin for more details. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary trailing blank line? |
Empty file.
13 changes: 13 additions & 0 deletions
13
docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/filter.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import sys | ||
import base64 | ||
from moban.extensions import JinjaFilter | ||
|
||
|
||
@JinjaFilter('base64encode') | ||
def base64_encode(string): | ||
if sys.version_info[0] > 2: | ||
content = base64.b64encode(string.encode('utf-8')) | ||
content = content.decode('utf-8') | ||
else: | ||
content = base64.b64encode(string) | ||
return content |
4 changes: 4 additions & 0 deletions
4
docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/global.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from moban.extensions import jinja_global | ||
|
||
|
||
jinja_global('global', dict(hello='world')) |
6 changes: 6 additions & 0 deletions
6
docs/level-7-use-custom-jinja2-filter-test-n-global/custom-jj2-plugin/test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from moban.extensions import JinjaTest | ||
|
||
|
||
@JinjaTest('level7') | ||
def test_level7(value): | ||
return value == 'level7' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
level: level7 | ||
level8: level8 |
1 change: 1 addition & 0 deletions
1
docs/level-7-use-custom-jinja2-filter-test-n-global/filter.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
YWJj |
1 change: 1 addition & 0 deletions
1
docs/level-7-use-custom-jinja2-filter-test-n-global/global.output
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
world |
1 change: 1 addition & 0 deletions
1
docs/level-7-use-custom-jinja2-filter-test-n-global/my-templates/filter.jj2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ 'abc' | base64encode }} |
1 change: 1 addition & 0 deletions
1
docs/level-7-use-custom-jinja2-filter-test-n-global/my-templates/global.jj2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ global.hello }} |
11 changes: 11 additions & 0 deletions
11
docs/level-7-use-custom-jinja2-filter-test-n-global/my-templates/test.jj2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{% if level is level7%} | ||
Hello, you are in level 7 example | ||
{% else %} | ||
Hello, you are not in {{level}} | ||
{% endif %} | ||
|
||
{% if level8 is level7%} | ||
Hello, you are in level 7 example | ||
{% else %} | ||
Hello, you are not in level 7 | ||
{% endif %} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eol at eof |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eol at eof