Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.template
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
slapos.recipe.template
Commits
90772890
Commit
90772890
authored
Aug 02, 2013
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jinja2: add support for inline templates
parent
8b177917
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
10 deletions
+18
-10
CHANGES.txt
CHANGES.txt
+2
-2
setup.py
setup.py
+1
-1
slapos/recipe/template/README.jinja2.txt
slapos/recipe/template/README.jinja2.txt
+6
-4
slapos/recipe/template/jinja2_template.py
slapos/recipe/template/jinja2_template.py
+9
-3
No files found.
CHANGES.txt
View file @
90772890
2.4.3
-dev (unreleased
)
2.4.3
(2013-08-02
)
======================
======================
*
No changes yet
.
*
jinja2: add support for inline templates
.
2.4.2 (2012-08-21)
2.4.2 (2012-08-21)
==================
==================
...
...
setup.py
View file @
90772890
from
setuptools
import
setup
,
find_packages
from
setuptools
import
setup
,
find_packages
import
os
import
os
version
=
'2.4.3
-dev
'
version
=
'2.4.3'
name
=
'slapos.recipe.template'
name
=
'slapos.recipe.template'
long_description
=
open
(
"README.txt"
).
read
()
+
"
\
n
"
+
\
long_description
=
open
(
"README.txt"
).
read
()
+
"
\
n
"
+
\
open
(
os
.
path
.
join
(
'slapos'
,
'recipe'
,
open
(
os
.
path
.
join
(
'slapos'
,
'recipe'
,
...
...
slapos/recipe/template/README.jinja2.txt
View file @
90772890
...
@@ -65,6 +65,9 @@ Mandatory:
...
@@ -65,6 +65,9 @@ Mandatory:
``template``
``template``
Template url/path, as accepted by zc.buildout.download.Download.__call__ .
Template url/path, as accepted by zc.buildout.download.Download.__call__ .
For very short template, it can make sense to put it directly into
buildout.cfg: the value is the template itself, prefixed by the string
"inline:" + an optional newline.
``rendered``
``rendered``
Where rendered template should be stored.
Where rendered template should be stored.
...
@@ -390,14 +393,13 @@ Section dependency
...
@@ -390,14 +393,13 @@ Section dependency
You can use other part of buildout in the template. This way this parts
You can use other part of buildout in the template. This way this parts
will be installed as dependency::
will be installed as dependency::
>>> write('foo.in', '{{bar}}')
>>> write('buildout.cfg', '''
>>> write('buildout.cfg', '''
... [buildout]
... [buildout]
... parts = template
... parts = template
...
...
... [template]
... [template]
... recipe = slapos.recipe.template:jinja2
... recipe = slapos.recipe.template:jinja2
... template =
foo.in
... template =
inline:{{bar}}
... rendered = foo
... rendered = foo
... context = key bar dependency:foobar
... context = key bar dependency:foobar
...
...
...
@@ -443,7 +445,6 @@ Let's create a sample recipe modifying its option dict::
...
@@ -443,7 +445,6 @@ Let's create a sample recipe modifying its option dict::
Let's just use ``buildout.cfg`` using this egg::
Let's just use ``buildout.cfg`` using this egg::
>>> write('foo.in', '{{bar}}')
>>> write('buildout.cfg',
>>> write('buildout.cfg',
... '''
... '''
... [buildout]
... [buildout]
...
@@ -452,7 +453,8 @@ Let's just use ``buildout.cfg`` using this egg::
...
@@ -452,7 +453,8 @@ Let's just use ``buildout.cfg`` using this egg::
...
...
... [template]
... [template]
... recipe = slapos.recipe.template:jinja2
... recipe = slapos.recipe.template:jinja2
... template = foo.in
... template = inline:
... {{bar}}
... rendered = foo
... rendered = foo
... context = key bar sample:data
... context = key bar sample:data
...
...
...
...
slapos/recipe/template/jinja2_template.py
View file @
90772890
...
@@ -133,13 +133,19 @@ class Recipe(object):
...
@@ -133,13 +133,19 @@ class Recipe(object):
umask
=
None
umask
=
None
def
__init__
(
self
,
buildout
,
name
,
options
):
def
__init__
(
self
,
buildout
,
name
,
options
):
self
.
template
=
zc
.
buildout
.
download
.
Download
(
template
=
options
[
'template'
]
if
template
.
startswith
(
'inline:'
):
template
=
template
[
7
:].
lstrip
(
'
\
r
\
n
'
)
self
.
get_template
=
lambda
:
template
else
:
template
=
zc
.
buildout
.
download
.
Download
(
buildout
[
'buildout'
],
buildout
[
'buildout'
],
hash_name
=
True
,
hash_name
=
True
,
)(
)(
options
[
'template'
]
,
template
,
md5sum
=
options
.
get
(
'md5sum'
),
md5sum
=
options
.
get
(
'md5sum'
),
)[
0
]
)[
0
]
self
.
get_template
=
lambda
:
open
(
template
).
read
()
import_delimiter
=
options
.
get
(
'import-delimiter'
,
import_delimiter
=
options
.
get
(
'import-delimiter'
,
DEFAULT_IMPORT_DELIMITER
)
DEFAULT_IMPORT_DELIMITER
)
import_dict
=
{}
import_dict
=
{}
...
@@ -203,7 +209,7 @@ class Recipe(object):
...
@@ -203,7 +209,7 @@ class Recipe(object):
undefined
=
StrictUndefined
,
undefined
=
StrictUndefined
,
loader
=
self
.
loader
,
loader
=
self
.
loader
,
).
from_string
(
).
from_string
(
open
(
self
.
template
).
read
(),
self
.
get_template
(),
).
render
(
).
render
(
**
self
.
context
**
self
.
context
)
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment