Skip to content

Commit

Permalink
Updated docs and bumped version.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffrimko committed Dec 14, 2017
1 parent 5b97049 commit 0b80adc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.adoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
= PopPage Changelog

== poppage-0.6.7 (2017-12-14)
=== Added
- YAML tag `!py` to allow executing Python code in defaults file; useful for processing other variables.

=== Fixed
- No longer throws error when running a file template without a given OUTPATH; output is sent to stdout.

== poppage-0.6.6 (2017-12-06)
=== Changed
- Can now render templates even if all the variables are not defined; useful for allowing default values in templates.
Expand Down
10 changes: 10 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ The following custom YAML tags are provided:
- `!opt` - Like `!yaml` but only for populating the `__opt__` key.
- `!cmd` - Reads value from a CLI command output.
- `!ask` - Prompts the user to input a value.
- `!py` - Executes Python code.

Check out this example:

Expand All @@ -95,6 +96,15 @@ Check out this example:

Hello Anakin Skywalker!

Sometimes it might be helpful to process variables in a defaults file. The `!py` tag can be used in this scenario:

--------
name: !ask &name "Enter a name" <1>
loud: !py ["'{0}'.upper()", *name] <2>
--------
<1> The anchor `&name` is created.
<2> A list must be provided to the `!py` tag. The code is the first element and it can contain standard Python string format variables (e.g. `{0}`) which will be replaced by the following list elements. Note that an anchor reference can be used as an element!

=== Option Defaults
Default utility options can be provided in the defaults file under the `__opt__` root key.

Expand Down
10 changes: 6 additions & 4 deletions app/poppage.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
##==============================================================#

#: Application version string.
__version__ = "0.6.6"
__version__ = "0.6.7"

#: Key separator.
KEYSEP = "::"
Expand Down Expand Up @@ -220,7 +220,7 @@ def render_file(tmplpath, tmpldict, bail_miss=False):
def make(inpath, tmpldict, outpath=None, **kwargs):
"""Generates a file or directory based on the given input
template/dictionary."""
if not outpath:
if not outpath and op.isdir(inpath):
outpath = os.getcwd()
if op.isfile(inpath):
return make_file(inpath, tmpldict, outpath=outpath)
Expand All @@ -232,6 +232,8 @@ def make_file(inpath, tmpldict, outpath=None):
if outpath:
outpath = render_str(outpath, tmpldict)
if op.isdir(outpath):
# TODO: (JRR@201712141826) This is dangerous as it could overwrite
# the input template file!
outpath = op.join(outpath, op.basename(inpath))
outpath = render_str(outpath, tmpldict)
if is_binary(inpath):
Expand Down Expand Up @@ -337,9 +339,9 @@ def main():
if utildict['command'] == "check":
check(utildict['inpath'], echo=True)
elif utildict['command'] == "make":
make(utildict['inpath'], tmpldict, outpath=utildict['outpath'])
make(utildict['inpath'], tmpldict, outpath=utildict.get('outpath'))
elif utildict['command'] == "run":
run(utildict['inpath'], tmpldict, outpath=utildict['outpath'], execute=utildict['execute'])
run(utildict['inpath'], tmpldict, outpath=utildict.get('outpath'), execute=utildict.get('execute'))
elif utildict['command'] == "debug":
qprompt.echo("Utility Dictionary:")
pprint(utildict)
Expand Down
2 changes: 1 addition & 1 deletion app/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

setup(
name = "poppage",
version = "0.6.6",
version = "0.6.7",
author = "Jeff Rimko",
author_email = "[email protected]",
description = "Utility for generating files and directories from templates.",
Expand Down

0 comments on commit 0b80adc

Please sign in to comment.