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