Skip to content

Commit

Permalink
📚 provide documentation on template_types under configuration. fix mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw authored and ayan-b committed Apr 21, 2019
1 parent f3689d8 commit 6bb2196
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nihao: shijie
hello: shijie
11 changes: 11 additions & 0 deletions docs/level-18-user-defined-template-types/.moban.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
configuration:
template_types:
my_own_type:
base_type: jinja2
file_extensions:
- file_type_of_my_choice
options:
extensions:
- jinja2_time.TimeExtension
targets:
- a.output: a.template.file_type_of_my_choice
35 changes: 35 additions & 0 deletions docs/level-18-user-defined-template-types/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Level 18: User defined template types
================================================================================

Since moban version 4.1, custom template types can be defined to deviate from
default configurations of the template engines. In addition, the configuration
possibilities are:

#. associate your own file extensions
#. choose your own template engine extensions
#.


Evaluation
--------------------------------------------------------------------------------

Please go to `docs/level-4-single-command` directory.


Here is the `.moban.yml`, which inserts `template_types` on top of the moban
file found in level 4::

configuration:
template_types:
my_own_type:
base_type: jinja2
file_extensions:
- file_type_of_my_choice
options:
extensions:
- jinja2_time.TimeExtension
targets:
- a.output: a.template.file_type_of_my_choice


where `template_types` is a dictionary of different custom types
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% now 'utc' %}

2 changes: 2 additions & 0 deletions docs/level-18-user-defined-template-types/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
overrides: data.base.yaml
hello: world
2 changes: 1 addition & 1 deletion moban/mobanfile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def handle_moban_file_v1(moban_file_configurations, command_line_options):
if extensions:
plugins.ENGINES.register_extensions(extensions)

template_types = moban_file_configurations.get(
template_types = merged_options.get(
constants.LABEL_TEMPLATE_TYPES
)
if template_types:
Expand Down
7 changes: 7 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,13 @@ def test_level_17_force_template_type_from_moban_file(self):
folder = "level-17-force-template-type-from-moban-file"
self._raw_moban(["moban"], folder, expected, "simple.file")

def test_level_18_user_defined_template_types(self):
from datetime import datetime
expected = "{date}\n".format(date=datetime.now().strftime("%Y-%m-%d"))

folder = "level-18-user-defined-template-types"
self._raw_moban(["moban"], folder, expected, "a.output")

def test_misc_1(self):
expected = "test file\n"

Expand Down

0 comments on commit 6bb2196

Please sign in to comment.