diff --git a/.moban.cd/changelog.yml b/.moban.cd/changelog.yml index 7d81a89d..956567d2 100644 --- a/.moban.cd/changelog.yml +++ b/.moban.cd/changelog.yml @@ -4,7 +4,13 @@ releases: - changes: - action: Updated details: - - "`#390`: single render action will print to stdout by defafult" + - "`#393`: Rendered content output to stdout once" + date: 16.08.2020 + version: 0.7.10 + - changes: + - action: Updated + details: + - "`#390`: single render action will print to stdout by default" date: 06.08.2020 version: 0.7.9 - changes: diff --git a/.moban.cd/moban.yml b/.moban.cd/moban.yml index fc36b34f..2b739e6b 100644 --- a/.moban.cd/moban.yml +++ b/.moban.cd/moban.yml @@ -4,9 +4,9 @@ organisation: moremoban author: C. W. contact: wangc_2011@hotmail.com license: MIT -version: 0.7.9 -current_version: 0.7.9 -release: 0.7.9 +version: 0.7.10 +current_version: 0.7.10 +release: 0.7.10 branch: master master: index command_line_interface: "moban" diff --git a/.moban.d/moban_readme.jj2 b/.moban.d/moban_readme.jj2 index 45d22d7c..9990ba5c 100644 --- a/.moban.d/moban_readme.jj2 +++ b/.moban.d/moban_readme.jj2 @@ -70,7 +70,7 @@ A bit formal example: .. code-block:: bash - $ moban -c data.yml -t my.template + $ moban -c data.yml -t my.template world Given data.yml as: @@ -222,9 +222,6 @@ You can start using it like this: .. code-block:: bash $ moban --template-type de-duplicate -pd custom-plugin -t duplicated_content.txt - De-duplicating duplicated_content.txt to moban.output - De-duplicating 1 file. - Everything is up to date! TOML data format diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 15c92b78..ae5dcfad 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,13 +1,21 @@ Change log ================================================================================ +0.7.10 - 16.08.2020 +-------------------------------------------------------------------------------- + +**Updated** + +#. `#393 `_: Rendered content + output to stdout once + 0.7.9 - 06.08.2020 -------------------------------------------------------------------------------- **Updated** #. `#390 `_: single render action - will print to stdout by defafult + will print to stdout by default 0.7.8 - 09.06.2020 -------------------------------------------------------------------------------- diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index fd901cbc..7b8bbafb 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -8,4 +8,5 @@ In alphabetical order: * `John Vandenberg `_ * `Joshua Chung `_ * `PRAJWAL M `_ +* `salotz `_ * `SerekKiri `_ diff --git a/README.rst b/README.rst index 5e5d2093..81830eb2 100644 --- a/README.rst +++ b/README.rst @@ -69,7 +69,7 @@ A bit formal example: .. code-block:: bash - $ moban -c data.yml -t my.template + $ moban -c data.yml -t my.template world Given data.yml as: @@ -216,9 +216,6 @@ Given a data.json file with the following content $ moban --template-type handlebars -c data.json "{{person.firstname}} {{person.lastname}}" - Handlebars-ing

{{first... to moban.output - Handlebarsed 1 file. - $ cat moban.output Yehuda Katz For `handlebars.js` users, yes, the example was copied from handlebarjs.com. The @@ -314,9 +311,6 @@ And given the following velocity.template: .. code-block:: bash $ moban --template-type velocity -c data.json -t velocity.template - Velocity-templating vo.t to moban.output - Velocity-templated 1 file. - $ cat moban.output Old people: Bill @@ -355,9 +349,6 @@ You can start using it like this: .. code-block:: bash $ moban --template-type de-duplicate -pd custom-plugin -t duplicated_content.txt - De-duplicating duplicated_content.txt to moban.output - De-duplicating 1 file. - Everything is up to date! TOML data format @@ -380,9 +371,6 @@ You can do: .. code-block:: bash $ moban -c sample.toml "{{owner.name}} made {{title}}" - Templating {{owner.na... to moban.output - Templated 1 file. - $ cat moban.output Tom Preston-Werner made TOML Example Not limited to toml, you can supply moban with the following data formats: diff --git a/docs/conf.py b/docs/conf.py index cccb501c..ca7afb4f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -25,9 +25,9 @@ copyright = '2017-2020 Onni Software Ltd.' author = 'C. W.' # The short X.Y version -version = '0.7.9' +version = '0.7.10' # The full version, including alpha/beta/rc tags -release = '0.7.9' +release = '0.7.10' # -- General configuration --------------------------------------------------- diff --git a/moban/_version.py b/moban/_version.py index 7c098b93..23c6e5ea 100644 --- a/moban/_version.py +++ b/moban/_version.py @@ -1,2 +1,2 @@ -__version__ = "0.7.9" +__version__ = "0.7.10" __author__ = "C. W." diff --git a/moban/core/moban_factory.py b/moban/core/moban_factory.py index 6413c022..7cbd6ec3 100644 --- a/moban/core/moban_factory.py +++ b/moban/core/moban_factory.py @@ -156,21 +156,42 @@ def render_string_to_file( self.buffered_writer.close() def apply_template(self, template_abs_path, template, data, output_file): + + # render the content rendered_content = self.engine.apply_template( template, data, output_file ) + + # convert to utf8 if not already if not isinstance(rendered_content, bytes): rendered_content = rendered_content.encode("utf-8") + # attempt to output to the file and printing to stdout instead + # if not found try: + + # check if any of the files have changed flag = HASH_STORE.is_file_changed( output_file, rendered_content, template_abs_path ) + + # if they have re-render things if flag: + + # write the content to the output file self.buffered_writer.write_file_out( output_file, rendered_content ) - if not file_system.is_zip_alike_url(output_file): + + # attempt to copy the file permissions of the template + # file to the output file + + # if it isn't an archive proceed or stdout + if ( + not file_system.is_zip_alike_url(output_file) + and output_file != "-" + ): + try: file_system.file_permissions_copy( template_abs_path, output_file diff --git a/setup.py b/setup.py index cc041626..87fb4fac 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ NAME = "moban" AUTHOR = "C. W." -VERSION = "0.7.9" +VERSION = "0.7.10" EMAIL = "wangc_2011@hotmail.com" LICENSE = "MIT" ENTRY_POINTS = { @@ -53,7 +53,7 @@ "General purpose static text generator" ) URL = "https://github.com/moremoban/moban" -DOWNLOAD_URL = "%s/archive/0.7.9.tar.gz" % URL +DOWNLOAD_URL = "%s/archive/0.7.10.tar.gz" % URL FILES = ["README.rst", "CONTRIBUTORS.rst", "CHANGELOG.rst"] KEYWORDS = [ "python", @@ -96,8 +96,8 @@ } # You do not need to read beyond this line PUBLISH_COMMAND = "{0} setup.py sdist bdist_wheel upload -r pypi".format(sys.executable) -GS_COMMAND = ("gs moban v0.7.9 " + - "Find 0.7.9 in changelog for more details") +GS_COMMAND = ("gs moban v0.7.10 " + + "Find 0.7.10 in changelog for more details") NO_GS_MESSAGE = ("Automatic github release is disabled. " + "Please install gease to enable it.") UPLOAD_FAILED_MSG = ( diff --git a/tests/integration_tests/test_command_line_options.py b/tests/integration_tests/test_command_line_options.py index 4ad67d70..9250e009 100644 --- a/tests/integration_tests/test_command_line_options.py +++ b/tests/integration_tests/test_command_line_options.py @@ -572,3 +572,19 @@ def test_stdout(): main() eq_(fake_stdout.getvalue(), "world\n") + + +def test_render_file_stdout(): + config_file = "config.yaml" + with open(config_file, "w") as f: + f.write("hello: world") + template_file = "t.jj2" + with open(template_file, "w") as f: + f.write("{{hello}}") + test_args = ["moban", "-t", "t.jj2", "-c", "config.yaml"] + with patch.object(sys, "argv", test_args): + with patch("sys.stdout", new_callable=StringIO) as fake_stdout: + from moban.main import main + + main() + eq_(fake_stdout.getvalue(), "world\n")