Skip to content

Commit

Permalink
✨ Add support for get_template_from_string()
Browse files Browse the repository at this point in the history
With this addition, moban-handlebars will be compatible with moban 0.3.8.

Closes moremoban#1
  • Loading branch information
CLiu13 committed Jan 20, 2019
1 parent a4bc1b3 commit da39e5a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions moban_handlebars/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def get_template(self, template_file):
hbr_template = Compiler().compile(source.read())
return hbr_template

def get_template_from_string(self, string):
return Compiler().compile(string)

def apply_template(self, template, data, _):
rendered_content = "".join(template(data))
rendered_content = rendered_content
Expand Down
11 changes: 11 additions & 0 deletions tests/test_handlebar_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,14 @@ def test_handlebars_file_tests():
content = output_file.read()
eq_(content, "here")
os.unlink(output)

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

0 comments on commit da39e5a

Please sign in to comment.