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
b62fddbc
Commit
b62fddbc
authored
8 years ago
by
nimrod
Browse files
Options
Downloads
Patches
Plain Diff
- Updated documentation, tests.
parent
a02c13ad
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
README.rst
+12
-8
12 additions, 8 deletions
README.rst
template/__init__.py
+3
-1
3 additions, 1 deletion
template/__init__.py
template/filters.py
+3
-3
3 additions, 3 deletions
template/filters.py
tests.sh
+2
-0
2 additions, 0 deletions
tests.sh
with
20 additions
and
12 deletions
README.rst
+
12
−
8
View file @
b62fddbc
Template
########
A CLI tool for generating files from Jinja2 templates and environment variables.
A CLI tool for generating files from Jinja2 templates and environment
variables.
Examples
--------
...
...
@@ -11,6 +12,9 @@ Examples
$ template -h
usage: template [-h] [-o OUTPUT] [filename]
A CLI tool for generating files from Jinja2 templates and environment
variables.
positional arguments:
filename Input filename
...
...
@@ -23,7 +27,7 @@ Examples
Hello John.
$ echo '{{ USER }}' > username.j2
$ template --output username.txt username.j2
$ cat username
$ cat username
.txt
John
...
...
@@ -32,12 +36,12 @@ Jinja filters
The following Jinja filters were added:
- to_yaml: Convert to yaml.
- from_yaml: Convert from yaml.
- to_json: Convert to json.
- from_json: Convert from json.
- pprint: Pretty print variable.
- combine: Combine 2 dictionaries.
-
:code:`
to_yaml
`
: Convert to yaml.
-
:code:`
from_yaml
`
: Convert from yaml.
-
:code:`
to_json
`
: Convert to json.
-
:code:`
from_json
`
: Convert from json.
-
:code:`
pprint
`
: Pretty print variable.
-
:code:`
combine
`
: Combine 2 dictionaries.
Example usage can be seen in :code:`tests.sh`.
...
...
This diff is collapsed.
Click to expand it.
template/__init__.py
+
3
−
1
View file @
b62fddbc
...
...
@@ -21,7 +21,9 @@ def render(template_string):
def
main
():
parser
=
ArgumentParser
()
parser
=
ArgumentParser
(
description
=
'''
A CLI tool for generating files from Jinja2 templates
and environment variables.
'''
)
parser
.
add_argument
(
'
filename
'
,
help
=
'
Input filename
'
,
type
=
argparse
.
FileType
(
'
r
'
),
...
...
This diff is collapsed.
Click to expand it.
template/filters.py
+
3
−
3
View file @
b62fddbc
...
...
@@ -26,7 +26,7 @@ def pprint(value):
return
pformat
(
value
)
def
combine
(
l
ef
thand
,
righthand
):
combined
=
l
ef
thand
.
copy
()
combined
.
update
(
righthand
)
def
combine
(
d
ef
ault
,
override
):
combined
=
d
ef
ault
.
copy
()
combined
.
update
(
override
)
return
combined
This diff is collapsed.
Click to expand it.
tests.sh
+
2
−
0
View file @
b62fddbc
...
...
@@ -36,5 +36,7 @@ echo '{{ [1, ] + [2, ] }}' > "$infile"
test
"
$(
template
$infile
)
"
=
"[1, 2]"
echo
Testing combining dictionaries.
echo
'{{ {"a": 1, "b": 2}|combine({"a": 11, "c": 33}) }}'
>
"
$infile
"
test
"
$(
template
$infile
)
"
=
"{'a': 11, 'c': 33, 'b': 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