Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
T
Template
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nimrod
Template
Commits
6cea160b
Commit
6cea160b
authored
8 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
- TOML filters (WIP).
parent
b62fddbc
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.rst
+2
-0
2 additions, 0 deletions
README.rst
setup.py
+1
-1
1 addition, 1 deletion
setup.py
template/filters.py
+10
-0
10 additions, 0 deletions
template/filters.py
tests.sh
+8
-0
8 additions, 0 deletions
tests.sh
with
21 additions
and
1 deletion
README.rst
+
2
−
0
View file @
6cea160b
...
...
@@ -42,6 +42,8 @@ The following Jinja filters were added:
- :code:`from_json`: Convert from json.
- :code:`pprint`: Pretty print variable.
- :code:`combine`: Combine 2 dictionaries.
- :code:`to_toml`: Convert to toml.
- :code:`from_toml`: Convert from toml.
Example usage can be seen in :code:`tests.sh`.
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
1
View file @
6cea160b
...
...
@@ -21,7 +21,7 @@ setup(
],
keywords
=
'
config configuration jinja template environment
'
,
packages
=
find_packages
(),
install_requires
=
[
'
Jinja2
'
,
'
PyYAML
'
],
install_requires
=
[
'
Jinja2
'
,
'
PyYAML
'
,
'
toml
'
],
extras_require
=
{
'
dev
'
:
[
'
tox
'
],
},
entry_points
=
{
...
...
This diff is collapsed.
Click to expand it.
template/filters.py
+
10
−
0
View file @
6cea160b
...
...
@@ -30,3 +30,13 @@ def combine(default, override):
combined
=
default
.
copy
()
combined
.
update
(
override
)
return
combined
def
from_toml
(
value
):
from
toml
import
loads
return
loads
(
value
)
def
to_toml
(
value
):
from
toml
import
dumps
return
dumps
(
value
)
This diff is collapsed.
Click to expand it.
tests.sh
+
8
−
0
View file @
6cea160b
...
...
@@ -39,4 +39,12 @@ echo Testing combining dictionaries.
echo
'{{ {"a": 1, "b": 2}|combine({"a": 11, "c": 33}) }}'
>
"
$infile
"
test
"
$(
template
$infile
)
"
=
"{'a': 11, 'c': 33, 'b': 2}"
echo
Testing TOML parsing.
echo
'{{ "[table]\n key = value" | from_toml }}'
>
"
$infile
"
test
"
$(
template
$infile
)
"
=
"table = {'key': 'value'}"
echo
Testing TOML output.
echo
"{{ {'key': [1, 2]} | to_toml }}"
>
"
$infile
"
test
"
$(
template
$infile
)
"
=
"key = [ 1, 2,]"
rm
"
$infile
"
"
$outfile
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment