Skip to content

Commit

Permalink
Adding 'on' as a truthy value to boolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikogan committed Apr 28, 2020
1 parent d3acef6 commit 05eeee2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ Finally, the following additionals filters are avilable:

**boolean(str)**:
Convert the argument into a boolean. A case insensitive comparison to
"true", "yes", and "1" will return `True`. Everything else is false.
"true", "yes", "on", and "1" will return `True`. Everything else is false.

**b64encode(str)**:
Base 64 encode the value.
Expand Down
2 changes: 1 addition & 1 deletion j2tmpl/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def boolean_filter(value):
if isinstance(value, Undefined):
return value

return str(value).lower() in ['true', 'yes', '1']
return str(value).lower() in ['true', 'yes', 'on', '1']


def b64encode_filter(value):
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
long_description = fh.read()

install_requires = ["jinja2"]
tests_requires = ["pytest", "flake8", "pytest-cover", "pytest-flake8"]
tests_requires = ["pytest", "flake8<3.8.0", "pytest-cover", "pytest-flake8"]

setup(
name="j2tmpl",
version="0.0.12",
version="0.0.13",
author="Ilya Kogan",
author_email="[email protected]",
url="https://github.com/ikogan/j2tmpl",
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ def common_environment():
'TEST_BOOLEAN_TRUE': 'true',
'TEST_BOOLEAN_YES': 'yes',
'TEST_BOOLEAN_ONE': '1',
'TEST_BOOLEAN_ON': 'on',
'TEST_BOOLEAN_FALSE': 'false',
'TEST_BOOLEAN_NO': 'no',
'TEST_BOOLEAN_ZERO': '0',
'TEST_BOOLEAN_OFF': 'off',
'SHELL': '/bin/bash',
'SHLVL': '2',
'_': 'whatisthis',
Expand Down Expand Up @@ -50,4 +52,4 @@ def common_rendered():
CAMEL_CASE_VARIABLE=handlethistoo
JAVA_camelCaseVariable=thisshouldbefun
ITERATION_TEST_1_VALUE=first
ITERATION_TEST_2_VALUE=second"""
ITERATION_TEST_2_VALUE=second"""
4 changes: 4 additions & 0 deletions tests/templates/filters/boolean.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

{% if test.boolean.one|boolean %}cool{% else %}bad{% endif %}

{% if test.boolean.on|boolean %}cool{% else %}bad{% endif %}

{% if test.boolean.false|boolean %}bad{% else %}cool{% endif %}

{% if test.boolean.false|upper|boolean %}bad{% else %}cool{% endif %}
Expand All @@ -16,4 +18,6 @@

{% if test.boolean.zero|boolean %}bad{% else %}cool{% endif %}

{% if test.boolean.off|boolean %}bad{% else %}cool{% endif %}

{% if test.boolean.undefined|boolean %}bad{% else %}cool{% endif %}

0 comments on commit 05eeee2

Please sign in to comment.