From 4091cf865dae8a6a8ed585b60937024091311f66 Mon Sep 17 00:00:00 2001 From: chfw Date: Wed, 27 Feb 2019 07:54:53 +0000 Subject: [PATCH] :books: provide documentation on template_types under configuration. fix #237 --- .../.moban.cd/data.base.yaml | 2 ++ .../.moban.yml | 11 ++++++ .../README.rst | 35 +++++++++++++++++++ .../a.template.file_type_of_my_choice | 2 ++ .../data.yml | 2 ++ moban/mobanfile/__init__.py | 2 +- tests/test_docs.py | 7 ++++ 7 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 docs/level-18-user-defined-template-types/.moban.cd/data.base.yaml create mode 100644 docs/level-18-user-defined-template-types/.moban.yml create mode 100644 docs/level-18-user-defined-template-types/README.rst create mode 100644 docs/level-18-user-defined-template-types/a.template.file_type_of_my_choice create mode 100644 docs/level-18-user-defined-template-types/data.yml diff --git a/docs/level-18-user-defined-template-types/.moban.cd/data.base.yaml b/docs/level-18-user-defined-template-types/.moban.cd/data.base.yaml new file mode 100644 index 00000000..2c16d47a --- /dev/null +++ b/docs/level-18-user-defined-template-types/.moban.cd/data.base.yaml @@ -0,0 +1,2 @@ +nihao: shijie +hello: shijie \ No newline at end of file diff --git a/docs/level-18-user-defined-template-types/.moban.yml b/docs/level-18-user-defined-template-types/.moban.yml new file mode 100644 index 00000000..5a7870a2 --- /dev/null +++ b/docs/level-18-user-defined-template-types/.moban.yml @@ -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 diff --git a/docs/level-18-user-defined-template-types/README.rst b/docs/level-18-user-defined-template-types/README.rst new file mode 100644 index 00000000..49abd720 --- /dev/null +++ b/docs/level-18-user-defined-template-types/README.rst @@ -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 diff --git a/docs/level-18-user-defined-template-types/a.template.file_type_of_my_choice b/docs/level-18-user-defined-template-types/a.template.file_type_of_my_choice new file mode 100644 index 00000000..b6f2647e --- /dev/null +++ b/docs/level-18-user-defined-template-types/a.template.file_type_of_my_choice @@ -0,0 +1,2 @@ +{% now 'utc' %} + diff --git a/docs/level-18-user-defined-template-types/data.yml b/docs/level-18-user-defined-template-types/data.yml new file mode 100644 index 00000000..7813e820 --- /dev/null +++ b/docs/level-18-user-defined-template-types/data.yml @@ -0,0 +1,2 @@ +overrides: data.base.yaml +hello: world \ No newline at end of file diff --git a/moban/mobanfile/__init__.py b/moban/mobanfile/__init__.py index c4a2d3d9..455b30f2 100644 --- a/moban/mobanfile/__init__.py +++ b/moban/mobanfile/__init__.py @@ -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: diff --git a/tests/test_docs.py b/tests/test_docs.py index 1d6db334..3baa045a 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -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"