Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keeping source tree in sync with 0.14.0 release on pypi. #123

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion chevron/metadata.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = '0.13.1'
version = '0.14.0'
25 changes: 10 additions & 15 deletions chevron/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _html_escape(string):
return string


def _get_key(key, scopes, warn, keep, def_ldel, def_rdel):
def _get_key(key, scopes, warn=False):
"""Get a key from the current scope"""

# If the key is a dot
Expand Down Expand Up @@ -94,9 +94,6 @@ def _get_key(key, scopes, warn, keep, def_ldel, def_rdel):
if warn:
sys.stderr.write("Could not find key '%s'%s" % (key, linesep))

if keep:
return "%s %s %s" % (def_ldel, key, def_rdel)

return ''


Expand Down Expand Up @@ -130,7 +127,7 @@ def _get_partial(name, partials_dict, partials_path, partials_ext):

def render(template='', data={}, partials_path='.', partials_ext='mustache',
partials_dict={}, padding='', def_ldel='{{', def_rdel='}}',
scopes=None, warn=False, keep=False):
scopes=None, warn=False):
"""Render a mustache template.

Renders a mustache template with a data scope and partial capability.
Expand Down Expand Up @@ -175,9 +172,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',

scopes -- The list of scopes that get_key will look through

warn -- Issue a warning to stderr when a template substitution isn't found in the data

keep -- Keep unreplaced tags when a template substitution isn't found in the data
warn -- Issue a warning to stderr when a template substitution isn't found in the data


Returns:
Expand Down Expand Up @@ -230,7 +225,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
# If we're a variable tag
elif tag == 'variable':
# Add the html escaped key to the output
thing = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
thing = _get_key(key, scopes, warn=warn)
if thing is True and key == '.':
# if we've coerced into a boolean by accident
# (inverted tags do this)
Expand All @@ -243,15 +238,15 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
# If we're a no html escape tag
elif tag == 'no escape':
# Just lookup the key and add it
thing = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
thing = _get_key(key, scopes, warn=warn)
if not isinstance(thing, unicode_type):
thing = unicode(str(thing), 'utf-8')
output += thing

# If we're a section tag
elif tag == 'section':
# Get the sections scope
scope = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
scope = _get_key(key, scopes, warn=warn)

# If the scope is a callable (as described in
# https://mustache.github.io/mustache.5.html)
Expand Down Expand Up @@ -292,7 +287,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
padding=padding,
def_ldel=def_ldel, def_rdel=def_rdel,
scopes=data and [data]+scopes or scopes,
warn=warn, keep=keep))
warn=warn))

if python3:
output += rend
Expand Down Expand Up @@ -329,7 +324,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
partials_ext=partials_ext,
partials_dict=partials_dict,
def_ldel=def_ldel, def_rdel=def_rdel,
warn=warn, keep=keep)
warn=warn)

if python3:
output += rend
Expand All @@ -343,7 +338,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
# If we're an inverted section
elif tag == 'inverted section':
# Add the flipped scope to the scopes
scope = _get_key(key, scopes, warn=warn, keep=keep, def_ldel=def_ldel, def_rdel=def_rdel)
scope = _get_key(key, scopes, warn=warn)
scopes.insert(0, not scope)

# If we're a partial
Expand All @@ -364,7 +359,7 @@ def render(template='', data={}, partials_path='.', partials_ext='mustache',
partials_dict=partials_dict,
def_ldel=def_ldel, def_rdel=def_rdel,
padding=part_padding, scopes=scopes,
warn=warn, keep=keep)
warn=warn)

# If the partial was indented
if left.isspace():
Expand Down