Skip to content
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

📚 provide documentation on template_types under configuration. … #240

Merged
merged 1 commit into from
Feb 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nihao: shijie
hello: shijie
ayan-b marked this conversation as resolved.
Show resolved Hide resolved
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
ayan-b marked this conversation as resolved.
Show resolved Hide resolved
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