Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Test
/
templar-min-old
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
55b67213
authored
2017-02-08 09:51:51 -0600
by
Marcos Cano
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
fix engine to template only if matches
1 parent
b9c9fb17
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
16 deletions
src/examples/recursive_examples/template.1.j2
src/examples/recursive_examples/template.2.j2
src/examples/recursive_examples/template.3.j2
src/examples/template.j2
src/templar.min.py
src/examples/recursive_examples/template.1.j2
View file @
55b6721
...
...
@@ -7,7 +7,7 @@ otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME
}]]
Term: [[{TERM
}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
...
...
src/examples/recursive_examples/template.2.j2
View file @
55b6721
...
...
@@ -7,7 +7,7 @@ otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME
}]]
Term: [[{TERM
}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
...
...
src/examples/recursive_examples/template.3.j2
View file @
55b6721
...
...
@@ -7,7 +7,7 @@ otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME
}]]
Term: [[{TERM
}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
...
...
src/examples/template.j2
View file @
55b6721
...
...
@@ -4,8 +4,12 @@ var = [[{variable}]]
otra_variable= [[{VAR}]]
some environment variables:
Hostname: [[{HOSTNAME}]]
Term: [[{TERM}]]
Path Variable: [[{PATH}]]
Current Working Directory: [[{PWD}]]
[[{}]]
...
...
src/templar.min.py
View file @
55b6721
...
...
@@ -21,7 +21,7 @@ class MyTemplate(string.Template):
(?P<escaped>\[\[\{)|
(?P<named>[_A-Z][_A-Z0-9]*)\}\]\]|
(?P<braced>[_A-Z][_A-Z0-9]*)\}\]\]|
(?P<invalid>)
(?P<invalid>
^$
)
)
'''
...
...
@@ -59,18 +59,23 @@ def engine(ifile,ofile,vars):
template
=
MyTemplate
(
template_content
)
#print 'MATCHES:', t.pattern.findall(t.template)
outputText
=
template
.
safe_substitute
(
vars
)
print
'MATCHES:'
,
template
.
pattern
.
findall
(
template
.
template
)
if
printit
:
print
"AFTER TEMPLATE:"
#print outputText
print
outputText
.
encode
(
'ascii'
,
'ignore'
)
else
:
f
=
open
(
ofile
,
'w'
)
f
.
write
(
outputText
.
encode
(
'ascii'
,
'ignore'
))
f
.
close
()
matches
=
template
.
pattern
.
findall
(
template
.
template
)
print
vars
if
len
(
matches
):
print
'[ MATCHES ] - '
,
matches
outputText
=
template
.
safe_substitute
(
vars
)
print
"[ TEMPLATING ] -
%
s "
%
ifile
if
printit
:
print
"AFTER TEMPLATE:"
#print outputText
print
outputText
.
encode
(
'ascii'
,
'ignore'
)
else
:
f
=
open
(
ofile
,
'w'
)
f
.
write
(
outputText
.
encode
(
'ascii'
,
'ignore'
))
f
.
close
()
...
...
@@ -144,6 +149,7 @@ def main(argv):
for
filename
in
files
:
fullpath
=
os
.
path
.
join
(
path
,
filename
)
if
os
.
path
.
isfile
(
fullpath
):
engine
(
fullpath
,
fullpath
,
vars
)
count
+=
1
else
:
...
...
Please
register
or
sign in
to post a comment