Skip to content
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
4 changes: 4 additions & 0 deletions .moban.cd/changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ releases:
- action: Added
details:
- "global variables to store the target and template file names in the jinja2 engine"
- "moban-handlebars is tested to work well with this version and above"
- action: Updated
details:
- Template engine interface has been clarified and documented
date: 14-11-2018
version: 0.3.4
- changes:
Expand Down
3 changes: 1 addition & 2 deletions .moban.cd/moban.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ keywords:
dependencies:
- pyyaml>=3.11
- jinja2>=2.7.1
- lml==0.0.4
- lml>=0.0.7
- crayons
- pybars3
description: Yet another jinja2 cli command for static text generation
scm_host: github.com
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ Added

#. global variables to store the target and template file names in the jinja2
engine
#. moban-handlebars is tested to work well with this version and above

Updated
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#. Template engine interface has been clarified and documented

0.3.3 - 05-11-2018
--------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This section covers the use cases for moban. Please check them out individually.
#. `Pass a folder full of templates`_
#. `Use pypi package as a moban dependency`_
#. `Use git repository as a moban dependency`_
#. `Use handlebars template with moban`_

.. _Jinja2 command line: level-1-jinja2-cli
.. _Template inheritance: level-2-template-inheritance
Expand All @@ -24,3 +25,4 @@ This section covers the use cases for moban. Please check them out individually.
.. _Pass a folder full of templates: level-8-pass-a-folder-full-of-templates
.. _Use pypi package as a moban dependency: level-9-moban-dependency-as-pypi-package
.. _Use git repository as a moban dependency: level-10-moban-dependency-as-git-repo
.. _Use handlebars template with moban: level-11-use-handlebars
27 changes: 20 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
]
extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.doctest', 'sphinx.ext.intersphinx', 'sphinx.ext.viewcode',]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this format intentional? Used to be a list with each element separated by a newline.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one comes from pypi-mobans-pkg, which then comes from sphinx project. The fix is better to come from there.


# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
Expand All @@ -74,7 +69,7 @@
exclude_patterns = []

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = None


# -- Options for HTML output -------------------------------------------------
Expand Down Expand Up @@ -162,6 +157,24 @@
'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']

# -- Extension configuration -------------------------------------------------
# -- Options for intersphinx extension ---------------------------------------

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ examples folder.
level-8-pass-a-folder-full-of-templates/README.rst
level-9-moban-dependency-as-pypi-package/README.rst
level-10-moban-dependency-as-git-repo/README.rst
level-11-use-handlebars/README.rst

In pratice, the following use cases were found interesting to go along with.

Expand Down
2 changes: 2 additions & 0 deletions docs/level-11-use-handlebars/.moban.cd/data.base.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
nihao: shijie
hello: shijie
5 changes: 5 additions & 0 deletions docs/level-11-use-handlebars/.moban.td/base.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

{{hello}}

{{nihao}}

6 changes: 6 additions & 0 deletions docs/level-11-use-handlebars/.moban.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requires:
- moban-handlebars

targets:
- a.output: a.template.handlebars
- b.output: base.hbs
31 changes: 31 additions & 0 deletions docs/level-11-use-handlebars/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Level 11: use handlebars
================================================================================

moban is extensible via lml. Charlie Liu through Google Code-in 2018 has
kindly contributed moban-handlebars plugin.


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

Please go to `docs/level-11-use-handlebars` directory.


Here is the `.moban.yml`, which replaces `jj2` with handlebars files in level 4::

requires:
- moban-handlebars

targets:
- a.output: a.template.handlebars
- b.output: base.hbs


where `targets` should lead an array of dictionaries, `requires` installs
moban-handlebars extension. You can provide file suffixes: ".handlebars"
or ".hbs" to your handlebars template.

Here is how to launch it
.. code-block:: bash

moban
1 change: 1 addition & 0 deletions docs/level-11-use-handlebars/a.template.handlebars
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{no-inheritance}}
4 changes: 4 additions & 0 deletions docs/level-11-use-handlebars/b.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

world

shijie
3 changes: 3 additions & 0 deletions docs/level-11-use-handlebars/data.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
overrides: data.base.yaml
hello: world
no-inheritance: handlebars does not support inheritance
2 changes: 1 addition & 1 deletion docs/level-4-single-command/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Evaluation
Please go to `docs/level-4-single-command` directory.


Here is the `.moban.yml`, whihc replaces the command in level 3::
Here is the `.moban.yml`, which replaces the command in level 3::

targets:
- a.output: a.template
Expand Down
26 changes: 0 additions & 26 deletions moban/engine_handlebars.py

This file was deleted.

11 changes: 7 additions & 4 deletions moban/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from moban.strategy import Strategy
from moban.hashstore import HASH_STORE

BUILTIN_EXENSIONS = ["moban.jinja2.engine", "moban.engine_handlebars"]
BUILTIN_EXENSIONS = ["moban.jinja2.engine"]


class LibraryManager(PluginManager):
Expand All @@ -24,7 +24,6 @@ class BaseEngine(object):
def __init__(self, template_dirs, context_dirs, engine_cls):
# pypi-moban-pkg cannot be found if removed
make_sure_all_pkg_are_loaded()

template_dirs = list(expand_template_directories(template_dirs))
verify_the_existence_of_directories(template_dirs)
context_dirs = expand_template_directory(context_dirs)
Expand Down Expand Up @@ -62,11 +61,15 @@ def apply_template(self, template_abs_path, template, data, output_file):
rendered_content = self.engine.apply_template(
template, data, output_file
)
rendered_content = utils.strip_off_trailing_new_lines(rendered_content)
rendered_content = rendered_content.encode("utf-8")
flag = HASH_STORE.is_file_changed(
output_file, rendered_content.encode("utf-8"), template_abs_path
output_file, rendered_content, template_abs_path
)
if flag:
utils.write_file_out(output_file, rendered_content)
utils.write_file_out(
output_file, rendered_content, strip=False, encode=False
)
utils.file_permissions_copy(template_abs_path, output_file)
return flag

Expand Down
3 changes: 1 addition & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pyyaml>=3.11
jinja2>=2.7.1
lml==0.0.4
lml>=0.0.7
crayons
pybars3
1 change: 1 addition & 0 deletions rnd_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/moremoban/moban-handlebars/archive/master.zip
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
DOWNLOAD_URL = '%s/archive/0.3.3.tar.gz' % URL
FILES = ['README.rst', 'CONTRIBUTORS.rst', 'CHANGELOG.rst']
KEYWORDS = [
'python',
'jinja2',
'moban',
'python'
]

CLASSIFIERS = [
Expand All @@ -48,9 +48,8 @@
INSTALL_REQUIRES = [
'pyyaml>=3.11',
'jinja2>=2.7.1',
'lml==0.0.4',
'lml>=0.0.7',
'crayons',
'pybars3',
]
SETUP_COMMANDS = {}

Expand Down
1 change: 0 additions & 1 deletion tests/fixtures/handlebars_tests/file_tests.json

This file was deleted.

1 change: 0 additions & 1 deletion tests/fixtures/handlebars_tests/file_tests.template

This file was deleted.

5 changes: 5 additions & 0 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def test_level_10(self):
folder = "level-10-moban-dependency-as-git-repo"
self._raw_moban(["moban"], folder, expected, "test.txt")

def test_level_11(self):
expected = "handlebars does not support inheritance\n"
folder = "level-11-use-handlebars"
self._raw_moban(["moban"], folder, expected, "a.output")

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

Expand Down
17 changes: 0 additions & 17 deletions tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
expand_template_directories,
)
from moban.jinja2.engine import Engine
from moban.engine_handlebars import EngineHandlebars


@PluginInfo("library", tags=["testmobans"])
Expand Down Expand Up @@ -42,11 +41,6 @@ def test_default_template_type():
assert engine.engine_cls == Engine


def test_handlebars_template_type():
engine = ENGINES.get_engine("hbs", [], "")
assert engine.engine_cls == EngineHandlebars


def test_default_mako_type(): # fake mako
engine = ENGINES.get_engine("mako", [], "")
assert engine.engine_cls.__name__ == "MakoEngine"
Expand Down Expand Up @@ -83,17 +77,6 @@ def test_file_tests():
os.unlink(output)


def test_handlebars_file_tests():
output = "test.txt"
path = os.path.join("tests", "fixtures", "handlebars_tests")
engine = BaseEngine([path], path, EngineHandlebars)
engine.render_to_file("file_tests.template", "file_tests.json", output)
with open(output, "r") as output_file:
content = output_file.read()
eq_(content, "here")
os.unlink(output)


def test_global_template_variables():
output = "test.txt"
path = os.path.join("tests", "fixtures", "globals")
Expand Down
14 changes: 0 additions & 14 deletions tests/test_handlebar_engine.py

This file was deleted.

8 changes: 4 additions & 4 deletions tests/test_jinja2_engine.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import os

from nose.tools import eq_
from moban.engine_handlebars import EngineHandlebars
from moban.jinja2.engine import Engine


def test_handlebars_template_not_found():
path = os.path.join("tests", "fixtures", "handlebars_tests")
engine = EngineHandlebars([path])
path = os.path.join("tests", "fixtures", "jinja_tests")
engine = Engine([path])
template = engine.get_template("file_tests.template")
data = dict(test="here")
result = engine.apply_template(template, data, None)
expected = "here"
expected = "yes\nhere"
eq_(expected, result)