From db286acfadd369dd203c6b7e2fb69d5998bf2ad3 Mon Sep 17 00:00:00 2001 From: jaska Date: Sun, 24 May 2020 22:09:08 +0100 Subject: [PATCH] Plugin dir cli (#385) * :sparkles:enabled plugins dir via command line * :books: update exit code * :microscope: test -pd on command line * :books: update readme * :bug: fix unit test which failed to detect the missing feature * :hammer: code refactor copy engine and strip content processor * :books: here is the way to write modelines remover. #36 * :hammer: code refactoring --- .moban.cd/changelog.yml | 9 ++ .moban.cd/moban.yml | 4 +- CHANGELOG.rst | 11 ++ README.rst | 129 +++++++++--------- docs/conf.py | 2 +- docs/extension.rst | 34 ++++- .../README.rst | 3 + docs/level-26-strip-rendered-content/final | 1 - .../README.rst | 4 + moban/_version.py | 2 +- moban/constants.py | 1 + moban/core/content_processor.py | 51 +++++++ moban/core/mobanfile/__init__.py | 26 +--- moban/core/utils.py | 23 ++++ moban/main.py | 17 ++- moban/plugins/copy.py | 26 +--- moban/plugins/strip.py | 7 + setup.py | 2 +- .../level-7-plugin-dir-cli/README.rst | 5 + .../custom-jj2-plugin/__init__.py | 0 .../custom-jj2-plugin/filter.py | 14 ++ .../custom-jj2-plugin/global.py | 3 + .../custom-jj2-plugin/test.py | 6 + .../level-7-plugin-dir-cli/data.yml | 2 + .../my-templates/filter.jj2 | 1 + .../my-templates/global.jj2 | 1 + .../my-templates/test.jj2 | 11 ++ tests/test_copy_engine.py | 4 +- tests/test_docs.py | 4 +- tests/test_regression.py | 18 +++ tests/test_store.py | 12 ++ 31 files changed, 303 insertions(+), 130 deletions(-) delete mode 100644 docs/level-26-strip-rendered-content/final create mode 100644 moban/core/content_processor.py create mode 100644 moban/plugins/strip.py create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/README.rst create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/__init__.py create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/filter.py create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/global.py create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/test.py create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/data.yml create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/my-templates/filter.jj2 create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/my-templates/global.jj2 create mode 100644 tests/regression_tests/level-7-plugin-dir-cli/my-templates/test.jj2 create mode 100644 tests/test_store.py diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index bfb773f4..a236ca63 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -1,6 +1,15 @@ name: moban organisation: moremoban releases: + - changes: + - action: Added + details: + - "`-pd` for command line to include custom plugin directories" + - action: Fixed + details: + - "strip did not work in 0.7.6" + date: tbd + version: 0.7.7 - changes: - action: Added details: diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index 38b71d78..71cc8152 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -4,8 +4,8 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.7.6 -current_version: 0.7.6 +version: 0.7.7 +current_version: 0.7.7 release: 0.7.6 branch: master master: index diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 0b7af0b0..c4c3c0c7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,17 @@ Change log ================================================================================ +0.7.7 - tbd +-------------------------------------------------------------------------------- + +**Added** + +#. `-pd` for command line to include custom plugin directories + +**Fixed** + +#. strip did not work in 0.7.6 + 0.7.6 - 22.5.2020 -------------------------------------------------------------------------------- diff --git a/README.rst b/README.rst index f8bb340d..a2d97265 100644 --- a/README.rst +++ b/README.rst @@ -42,57 +42,6 @@ For existing moban users, python 2 support has been dropped. Please stay with versions lower than 0.7.0 if you are still using python 2. -Introduction -================================================================================ - -**moban** enabled **continuous templating** in `pyexcel `_ and -`coala `_ project to keep -documentation consistent across the documentations of individual libraries in the same -organisation. Here is the primary use case of moban, as of now: - -.. image:: https://github.com/moremoban/yehua/raw/dev/docs/source/_static/yehua-story.png - :width: 600px - - -And here is a list of other usages: - -#. `Django Mobans `_, templates for django, docker etc. -#. `Math Sheets `_, generate custom math sheets in pdf - -All use cases are documented `here `_ - -Support -================================================================================ - -If you like moban, please support me on github, -`patreon `_ -or `bounty source `_ to maintain -the project and develop it further. - -With your financial support, I will be able to invest -a little bit more time in coding, documentation and writing interesting extensions. - -Vision -================================================================================ - -Any template, any data in any location - -**moban** started with bringing the high performance template engine (JINJA2) for web -into static text generation. - -**moban** can use other python template engine: mako, handlebars, velocity, -haml, slim and tornado, can read other data format: json and yaml, and can access both -template file and configuration file in -any location: zip, git, pypi package, s3, etc. - - -Credit -================================================================================ - -`jinja2-fsloader `_ is the key component to enable PyFilesystem2 support in moban -v0.6x. Please show your stars there too! - - Quick start ================================================================================ @@ -229,9 +178,63 @@ Then you can access your files in s3 bucket: $ cat moban.output world -Where the configuration sits in a s3 bucket, the output is a file in a zip. The content of s3data.yaml is:: +Where the configuration sits in a s3 bucket, the output is a file in a zip. The content of s3data.yaml is: + + +.. code-block: hello: world + + +Introduction +================================================================================ + +**moban** enabled **continuous templating** in `pyexcel `_ and +`coala `_ project to keep +documentation consistent across the documentations of individual libraries in the same +organisation. Here is the primary use case of moban, as of now: + +.. image:: https://github.com/moremoban/yehua/raw/dev/docs/source/_static/yehua-story.png + :width: 600px + + +And here is a list of other usages: + +#. `Django Mobans `_, templates for django, docker etc. +#. `Math Sheets `_, generate custom math sheets in pdf + +All use cases are documented `here `_ + +Support +================================================================================ + +If you like moban, please support me on github, +`patreon `_ +or `bounty source `_ to maintain +the project and develop it further. + +With your financial support, I will be able to invest +a little bit more time in coding, documentation and writing interesting extensions. + +Vision +================================================================================ + +Any template, any data in any location + +**moban** started with bringing the high performance template engine (JINJA2) for web +into static text generation. + +**moban** can use other python template engine: mako, handlebars, velocity, +haml, slim and tornado, can read other data format: json and yaml, and can access both +template file and configuration file in +any location: zip, git, pypi package, s3, etc. + + +Credit +================================================================================ + +`jinja2-fsloader `_ is the key component to enable PyFilesystem2 support in moban +v0.6x. Please show your stars there too! Installation @@ -258,7 +261,8 @@ CLI documentation .. code-block:: bash usage: moban [-h] [-c CONFIGURATION] [-t TEMPLATE] [-o OUTPUT] - [-td [TEMPLATE_DIR [TEMPLATE_DIR ...]]] [-cd CONFIGURATION_DIR] + [-td [TEMPLATE_DIR [TEMPLATE_DIR ...]]] + [-pd [PLUGIN_DIR [PLUGIN_DIR ...]]] [-cd CONFIGURATION_DIR] [-m MOBANFILE] [-g GROUP] [--template-type TEMPLATE_TYPE] [-d DEFINE [DEFINE ...]] [-e EXTENSION [EXTENSION ...]] [-f] [--exit-code] [-V] [-v] @@ -285,6 +289,8 @@ CLI documentation add more directories for template file lookup -cd CONFIGURATION_DIR, --configuration_dir CONFIGURATION_DIR the directory for configuration file lookup + -pd [PLUGIN_DIR [PLUGIN_DIR ...]], --plugin_dir [PLUGIN_DIR [PLUGIN_DIR ...]] + add more directories for plugin lookup -m MOBANFILE, --mobanfile MOBANFILE custom moban file -g GROUP, --group GROUP @@ -302,19 +308,8 @@ CLI documentation Developer options: For debugging and development - --exit-code tell moban to change exit code + --exit-code by default, exist code 0 means no error, 1 means error + occured. It tells moban to change 1 for changes, 2 for + error occured -V, --version show program's version number and exit -v show verbose, try -v, -vv, -vvv - -Exit codes --------------------------------------------------------------------------------- -By default: - -- 0 : no error -- 1 : error occured - -With `--exit-code`: - -- 0 : no changes -- 1 : has changes -- 2 : error occured diff --git a/docs/conf.py b/docs/conf.py index fa31fa2c..18fd3919 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,7 +25,7 @@ copyright = '2017-2020 Onni Software Ltd.' author = 'C. W.' # The short X.Y version -version = '0.7.6' +version = '0.7.7' # The full version, including alpha/beta/rc tags release = '0.7.6' diff --git a/docs/extension.rst b/docs/extension.rst index 1cf2d9d9..db85e5f8 100644 --- a/docs/extension.rst +++ b/docs/extension.rst @@ -1,6 +1,6 @@ Development guide ======================= - + Jinja2 extensions for Moban ------------------------------ @@ -14,7 +14,7 @@ your plugins will NOT be loaded. Jinja2 Filter ******************* -.. literalinclude:: ../moban/filters/repr.py +.. literalinclude:: ../moban/plugins/jinja2/filters/repr.py split_length -------------------------------------------------------------------------------- @@ -66,7 +66,7 @@ Built-in Tests Jinja2 Test ******************* -.. literalinclude:: ../moban/tests/files.py +.. literalinclude:: ../moban/plugins/jinja2/tests/files.py `exists` @@ -104,16 +104,16 @@ is an example starting point for any template engine. """ A list template directories will be given to your engine class """ - + def get_template(self, template_file): """ Given a relative path to your template file, please return a templatable thing that does the templating function in next function below """ - + def apply_template(self, template, data, output): """ - Given the template object from `get_template` function, and data as python dictionary, + Given the template object from `get_template` function, and data as python dictionary, and output as intended output file, please return "utf-8" encoded string. """ @@ -122,5 +122,27 @@ After you will have finished the engine plugin, you can either place it in `plug in order to get it loaded, or make an installable python package. In the latter case, please refer to `yehua`_: doing that in less than 5 minutes. + +Custom content processors for Moban +---------------------------------------- + +Since version 0.7.7, it became easy to write a content processor for moban. +What you need is a content processing function, which will be fed the +content of `template_file` and which is expected to return a string. And +decorate your function with `ContentProcessor`: + +.. code-block:: python + + @ContentProcessor('strip', 'Stripping', 'Stripped'): + def strip(template_file: str) -> str: + ret = template_file.strip() + return ret + + +Here is how `copy` template type is coded: + +.. literalinclude:: ../moban/plugins/copy.py + + .. _lml: http://lml.readthedocs.io .. _yehua: http://yehua.readthedocs.io diff --git a/docs/level-12-use-template-engine-extensions/README.rst b/docs/level-12-use-template-engine-extensions/README.rst index 587e91b0..49435d86 100644 --- a/docs/level-12-use-template-engine-extensions/README.rst +++ b/docs/level-12-use-template-engine-extensions/README.rst @@ -21,6 +21,9 @@ For example:: Please also note that the following extensions are included by default: `jinja2.ext.do`, `jinja2.ext.loopcontrols` +.. note:: + + if you intend to use extensions for one off usage, please use '-e' cli option Evaluation -------------------------------------------------------------------------------- diff --git a/docs/level-26-strip-rendered-content/final b/docs/level-26-strip-rendered-content/final deleted file mode 100644 index f3a01533..00000000 --- a/docs/level-26-strip-rendered-content/final +++ /dev/null @@ -1 +0,0 @@ -a world \ No newline at end of file diff --git a/docs/level-7-use-custom-jinja2-filter-test-n-global/README.rst b/docs/level-7-use-custom-jinja2-filter-test-n-global/README.rst index ed8d0a1f..ab2b89d4 100644 --- a/docs/level-7-use-custom-jinja2-filter-test-n-global/README.rst +++ b/docs/level-7-use-custom-jinja2-filter-test-n-global/README.rst @@ -23,6 +23,10 @@ It is very important to have `__init__.py`, otherwise, it will NOT work. Other t 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. +.. note:: + + if you intend to use extensions for one off usage, please use '-pd' cli option. + i.e. `moban -td my-templates/ -t filter.jj2 -pd custom-jj2-plugin` Evaluation -------------------------------------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index 6f0f436f..ca73c7a5 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.7.6" +__version__ = "0.7.7" __author__ = "C. W." diff --git a/moban/constants.py b/moban/constants.py index d03a167f..c4a96f90 100644 --- a/moban/constants.py +++ b/moban/constants.py @@ -29,6 +29,7 @@ LABEL_TEMPLATE = "template" POSITIONAL_LABEL_TEMPLATE = "template_in_string" LABEL_TMPL_DIRS = "template_dir" +LABEL_PLUGIN_DIRS = "plugin_dir" LABEL_EXIT_CODE = "exit-code" LABEL_OUTPUT = "output" LABEL_TEMPLATE_TYPE = "template_type" diff --git a/moban/core/content_processor.py b/moban/core/content_processor.py new file mode 100644 index 00000000..195c7908 --- /dev/null +++ b/moban/core/content_processor.py @@ -0,0 +1,51 @@ +import logging + +from lml.plugin import PluginInfo + +from moban import constants + +LOG = logging.getLogger(__name__) + + +class ContentProcessor(PluginInfo): + """ + @ContentProcessor('strip', 'Stripping', 'Stripped'): + def strip(template_file: str) -> str: + ret = template_file.strip() + return ret + """ + + def __init__(self, action, action_continuing_tense, action_past_tense): + super(ContentProcessor, self).__init__( + constants.TEMPLATE_ENGINE_EXTENSION, tags=[action] + ) + self.action = action + self.action_continuing_tense = action_continuing_tense + self.action_past_tense = action_continuing_tense + + def __call__(self, a_content_processor_function): + continuing_tense = self.action_continuing_tense + past_tense = self.action_past_tense + + class CustomEngine(object): + ACTION_IN_PRESENT_CONTINUOUS_TENSE = continuing_tense + ACTION_IN_PAST_TENSE = past_tense + + def __init__(self, template_fs, extensions=None): + self.template_fs = template_fs + + def get_template(self, template_file): + content = self.template_fs.readbytes(template_file) + ret = a_content_processor_function(content) + return ret + + def get_template_from_string(self, a_string): + ret = a_content_processor_function(a_string) + return ret + + def apply_template(self, template, *_): + ret = a_content_processor_function(template) + return ret + + super(ContentProcessor, self).__call__(CustomEngine) + return a_content_processor_function diff --git a/moban/core/mobanfile/__init__.py b/moban/core/mobanfile/__init__.py index 6d875d67..ae7e5cbf 100644 --- a/moban/core/mobanfile/__init__.py +++ b/moban/core/mobanfile/__init__.py @@ -1,14 +1,12 @@ -import os -import re -import sys import logging from collections import OrderedDict -from lml.utils import do_import - from moban import core, constants from moban.externals import reporter -from moban.core.utils import verify_the_existence_of_directories +from moban.core.utils import ( + handle_plugin_dirs, + verify_the_existence_of_directories, +) from moban.deprecated import handle_copy, handle_requires from moban.core.data_loader import merge from moban.core.moban_factory import expand_template_directories @@ -127,19 +125,3 @@ def handle_targets(merged_options, targets): engine.report() count = count + engine.number_of_templated_files() return count - - -def handle_plugin_dirs(plugin_dirs): - LOG.info("handling plugin dirs {}".format(",".join(plugin_dirs))) - for plugin_dir in plugin_dirs: - plugin_path = os.path.normcase( - os.path.dirname(os.path.abspath(plugin_dir)) - ) - if plugin_path not in sys.path: - sys.path.append(plugin_path) - pysearchre = re.compile(".py$", re.IGNORECASE) - pluginfiles = filter(pysearchre.search, os.listdir(plugin_dir)) - plugins = list(map(lambda fp: os.path.splitext(fp)[0], pluginfiles)) - for plugin in plugins: - plugin_module = os.path.basename(plugin_dir) + "." + plugin - do_import(plugin_module) diff --git a/moban/core/utils.py b/moban/core/utils.py index f00a89fd..2d0109fd 100644 --- a/moban/core/utils.py +++ b/moban/core/utils.py @@ -1,5 +1,10 @@ +import os +import re +import sys import logging +from lml.utils import do_import + from moban import constants from moban.externals import file_system @@ -24,3 +29,21 @@ def verify_the_existence_of_directories(dirs): if file_system.exists(constants.DEFAULT_TEMPLATE_DIRNAME): dirs.append(constants.DEFAULT_TEMPLATE_DIRNAME) return dirs + + +def handle_plugin_dirs(plugin_dirs): + if plugin_dirs is None: + return + LOG.info("handling plugin dirs {}".format(",".join(plugin_dirs))) + for plugin_dir in plugin_dirs: + plugin_path = os.path.normcase( + os.path.dirname(os.path.abspath(plugin_dir)) + ) + if plugin_path not in sys.path: + sys.path.append(plugin_path) + pysearchre = re.compile(".py$", re.IGNORECASE) + pluginfiles = filter(pysearchre.search, os.listdir(plugin_dir)) + plugins = list(map(lambda fp: os.path.splitext(fp)[0], pluginfiles)) + for plugin in plugins: + plugin_module = os.path.basename(plugin_dir) + "." + plugin + do_import(plugin_module) diff --git a/moban/main.py b/moban/main.py index 4890a458..701de86f 100644 --- a/moban/main.py +++ b/moban/main.py @@ -21,6 +21,7 @@ from moban.core import ENGINES, plugins, hashstore, mobanfile, data_loader from moban._version import __version__ from moban.externals import reporter, file_system +from moban.core.utils import handle_plugin_dirs from moban.program_options import OPTIONS LOG = logging.getLogger() @@ -36,9 +37,8 @@ def main(): options[constants.CLI_DICT] = handle_custom_variables( options.pop(constants.LABEL_DEFINE) ) - options[constants.EXTENSION_DICT] = handle_custom_extensions( - options.pop(constants.LABEL_EXTENSION) - ) + handle_custom_extensions(options.pop(constants.LABEL_EXTENSION)) + handle_plugin_dirs(options.pop(constants.LABEL_PLUGIN_DIRS)) OPTIONS.update(options) moban_file = options[constants.LABEL_MOBANFILE] @@ -112,6 +112,12 @@ def create_parser(): f"--{constants.LABEL_CONFIG_DIR}", help="the directory for configuration file lookup", ) + advanced.add_argument( + "-pd", + f"--{constants.LABEL_PLUGIN_DIRS}", + nargs="*", + help="add more directories for plugin lookup", + ) advanced.add_argument( "-m", "--%s" % constants.LABEL_MOBANFILE, help="custom moban file" ) @@ -152,7 +158,10 @@ def create_parser(): action="store_true", dest=constants.LABEL_EXIT_CODE, default=False, - help="tell moban to change exit code", + help=( + "by default, exist code 0 means no error, 1 means error occured. " + + "It tells moban to change 1 for changes, 2 for error occured" + ), ) developer.add_argument( "-V", diff --git a/moban/plugins/copy.py b/moban/plugins/copy.py index 2b5913fe..d871af3e 100644 --- a/moban/plugins/copy.py +++ b/moban/plugins/copy.py @@ -1,12 +1,8 @@ -from lml.plugin import PluginInfo +from moban.core.content_processor import ContentProcessor -from moban import constants - -@PluginInfo( - constants.TEMPLATE_ENGINE_EXTENSION, tags=[constants.TEMPLATE_COPY] -) -class ContentForwardEngine(object): +@ContentProcessor("copy", "Copying", "Copied") +def copy(content: str) -> str: """ Does no templating, works like 'copy'. @@ -19,18 +15,4 @@ class ContentForwardEngine(object): the source file. Everything else is taken care of by moban templating mechanism. """ - - ACTION_IN_PRESENT_CONTINUOUS_TENSE = "Copying" - ACTION_IN_PAST_TENSE = "Copied" - - def __init__(self, template_fs, extensions=None): - self.template_fs = template_fs - - def get_template(self, template_file): - return self.template_fs.readbytes(template_file) - - def get_template_from_string(self, string): - return string - - def apply_template(self, template, *_): - return template + return content diff --git a/moban/plugins/strip.py b/moban/plugins/strip.py new file mode 100644 index 00000000..89ec76b4 --- /dev/null +++ b/moban/plugins/strip.py @@ -0,0 +1,7 @@ +from moban.core.content_processor import ContentProcessor + + +@ContentProcessor("strip", "Stripping", "Stripped") +def strip(content: str) -> str: + """Works like 'copy', but strip empty spaces before and after""" + return content.strip() diff --git a/setup.py b/setup.py index 684a176e..4143efb5 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ NAME = "moban" AUTHOR = "C. W." -VERSION = "0.7.6" +VERSION = "0.7.7" EMAIL = "wangc_2011@hotmail.com" LICENSE = "MIT" ENTRY_POINTS = { diff --git a/tests/regression_tests/level-7-plugin-dir-cli/README.rst b/tests/regression_tests/level-7-plugin-dir-cli/README.rst new file mode 100644 index 00000000..f77c7c52 --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/README.rst @@ -0,0 +1,5 @@ +Level 7: Custom jinja filters, tests and globals on cli +================================================================================ + +We will test this on '-pd' cli option + diff --git a/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/__init__.py b/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/filter.py b/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/filter.py new file mode 100644 index 00000000..9c28e198 --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/filter.py @@ -0,0 +1,14 @@ +import sys +import base64 + +from moban.plugins.jinja2.extensions import JinjaFilter + + +@JinjaFilter() +def base64encode(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 diff --git a/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/global.py b/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/global.py new file mode 100644 index 00000000..3f4aac11 --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/global.py @@ -0,0 +1,3 @@ +from moban.plugins.jinja2.extensions import jinja_global + +jinja_global("global", dict(hello="world")) diff --git a/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/test.py b/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/test.py new file mode 100644 index 00000000..d78c75a0 --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/custom-jj2-plugin/test.py @@ -0,0 +1,6 @@ +from moban.plugins.jinja2.extensions import JinjaTest + + +@JinjaTest() +def level7(value): + return value == "level7" diff --git a/tests/regression_tests/level-7-plugin-dir-cli/data.yml b/tests/regression_tests/level-7-plugin-dir-cli/data.yml new file mode 100644 index 00000000..25ca76fe --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/data.yml @@ -0,0 +1,2 @@ +level: level7 +level8: level8 diff --git a/tests/regression_tests/level-7-plugin-dir-cli/my-templates/filter.jj2 b/tests/regression_tests/level-7-plugin-dir-cli/my-templates/filter.jj2 new file mode 100644 index 00000000..d2c70d73 --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/my-templates/filter.jj2 @@ -0,0 +1 @@ +{{ 'abc' | base64encode }} diff --git a/tests/regression_tests/level-7-plugin-dir-cli/my-templates/global.jj2 b/tests/regression_tests/level-7-plugin-dir-cli/my-templates/global.jj2 new file mode 100644 index 00000000..2f8b8a71 --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/my-templates/global.jj2 @@ -0,0 +1 @@ +{{ global.hello }} \ No newline at end of file diff --git a/tests/regression_tests/level-7-plugin-dir-cli/my-templates/test.jj2 b/tests/regression_tests/level-7-plugin-dir-cli/my-templates/test.jj2 new file mode 100644 index 00000000..3a18d1ec --- /dev/null +++ b/tests/regression_tests/level-7-plugin-dir-cli/my-templates/test.jj2 @@ -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 %} diff --git a/tests/test_copy_engine.py b/tests/test_copy_engine.py index f590d21a..0dcb42d3 100644 --- a/tests/test_copy_engine.py +++ b/tests/test_copy_engine.py @@ -3,14 +3,15 @@ import fs.path from nose.tools import eq_ +from moban.core import ENGINES from moban.externals import file_system -from moban.plugins.copy import ContentForwardEngine class TestContentForwardEngine: def setUp(self): template_path = os.path.join("tests", "fixtures") fs = file_system.get_multi_fs([template_path]) + ContentForwardEngine = ENGINES.load_me_now("copy") self.engine = ContentForwardEngine(fs) def test_get_template(self): @@ -39,6 +40,7 @@ class TestCopyEncoding: def setUp(self): template_path = fs.path.join("tests", "fixtures") template_fs = file_system.get_multi_fs([template_path]) + ContentForwardEngine = ENGINES.load_me_now("copy") self.engine = ContentForwardEngine(template_fs) def test_encoding_of_template(self): diff --git a/tests/test_docs.py b/tests/test_docs.py index fa3e524b..d40587cf 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -333,9 +333,9 @@ def test_level_25_delete_intermediate_targets(self): assert not os.path.exists("intermediate3.jj2") def test_level_26_strip_intermediate_targets(self): - expected = "a world\n" + expected = "a world" - folder = "level-25-delete-intermediate-targets" + folder = "level-26-strip-rendered-content" self.run_moban(["moban"], folder, [("final", expected)]) assert not os.path.exists("intermediate.strip") diff --git a/tests/test_regression.py b/tests/test_regression.py index a91acabd..81e6e74b 100644 --- a/tests/test_regression.py +++ b/tests/test_regression.py @@ -24,6 +24,24 @@ def test_coping_binary_file(self): "regression-test.png", ) + def test_level_7(self): + expected = "YWJj\n" + + folder = "level-7-plugin-dir-cli" + self.run_moban( + [ + "moban", + "-td", + "my-templates/", + "-t", + "filter.jj2", + "-pd", + "custom-jj2-plugin", + ], + folder, + [("moban.output", expected)], + ) + def test_level_21_copy_templates_into_tars(self): expected = "test file\n" diff --git a/tests/test_store.py b/tests/test_store.py new file mode 100644 index 00000000..6fa8309f --- /dev/null +++ b/tests/test_store.py @@ -0,0 +1,12 @@ +from nose.tools import eq_ + +from moban.core.definitions import TemplateTarget +from moban.core.mobanfile.store import Store + + +def test_store(): + store = Store() + output = "output" + target = TemplateTarget("template_file", "data_file", output) + store.add(target) + eq_(target, store.look_up_by_output.get(output))