| 68 |
|
if openTagCount<0: raise ParseError, "Too many closing tags '%s' for '%s ... %s ...'"%(closingTag, openingTag, text)
|
| 69 |
|
i=template.find(openingTag, startIndex)
|
| 70 |
|
j=template.find(closingTag, startIndex)
|
| 71 |
|
#print "text:", text, "openCount:", openTagCount, "i:", i, "j:",j
|
| 72 |
|
#if i!=-1: print "i20:", template[i:i+20]
|
| 73 |
|
#if j!=-1: print "j20:", template[j:j+20]
|
| 74 |
|
if j==-1: raise ParseError, "No matching '%s' tag for '%s ... %s ...'"%(closingTag, openingTag, text)
|
| 75 |
|
if i==-1 or j<i: # closingTag is first
|
| 76 |
|
if openTagCount==0: return j # found it !
|
| |
68 |
if openTagCount < 0:
|
| |
69 |
raise ParseError, \
|
| |
70 |
"Too many closing tags '%s' for '%s ... %s ...'" % (
|
| |
71 |
closingTag, openingTag, text
|
| |
72 |
)
|
| |
73 |
i = template.find(openingTag, startIndex)
|
| |
74 |
j = template.find(closingTag, startIndex)
|
| |
75 |
if j == -1: raise ParseError, "No matching '%s' tag for '%s ... %s ...'"%(closingTag, openingTag, text)
|
| |
76 |
if i == -1 or j < i: # closingTag is first
|
| |
77 |
if openTagCount == 0:
|
| |
78 |
return j # found it !
|
| |
149 |
# New cherrytemplate syntax
|
| |
150 |
tagList = ['<%=', '<%', '<--']
|
| |
151 |
minI = len(template)
|
| |
152 |
minTag = ""
|
| |
153 |
for tag in tagList:
|
| |
154 |
i = template.find(tag)
|
| |
155 |
if i == -1: continue
|
| |
156 |
if i < minI:
|
| |
157 |
minI = i
|
| |
158 |
minTag = tag
|
| |
159 |
if minTag == '<%':
|
| |
160 |
j = _findClosingTag(template, '<%', '%>', 0, minI + 1, '')
|
| |
161 |
execStr = template[minI+2:j]
|
| |
162 |
# Try to indent execStr correctly
|
| |
163 |
lines=[]
|
| |
164 |
minIndent=1000
|
| |
165 |
lastIndent=0
|
| |
166 |
for line in execStr.split('\n'):
|
| |
167 |
if line.split():
|
| |
168 |
indentCount = _firstNonSpace(line)
|
| |
169 |
lastIndent = indentCount
|
| |
170 |
if line.strip()[-1] == ':':
|
| |
171 |
lastIndent += 4
|
| |
172 |
if indentCount < minIndent: minIndent=indentCount
|
| |
173 |
lines.append(line)
|
| |
174 |
if minIndent==1000: minIndent=0
|
| |
175 |
lastIndent -= minIndent
|
| |
176 |
|
| |
177 |
_writeTemplate(f, template[:minI-1], tab)
|
| |
178 |
lastLineIndent = ''
|
| |
179 |
for line in lines:
|
| |
180 |
# Remove "minIndent" tabs and add "tab" tabs from each line
|
| |
181 |
sLine = line.strip()
|
| |
182 |
if sLine.startswith('# end') or sLine.startswith('#end'):
|
| |
183 |
tab = tab[4:]
|
| |
184 |
continue
|
| |
185 |
f.write(tab+line[minIndent:]+'\n')
|
| |
186 |
_writeTemplate(f, template[j+2:], tab + ' ' * lastIndent)
|
| |
187 |
return
|
| |
188 |
|
| |
189 |
elif minTag == '<%=':
|
| |
190 |
j = _findClosingTag(template, '<%=', '%>', 0, minI + 1, '')
|
| |
191 |
evalStr = template[minI+3:j]
|
| |
192 |
_writeInTripleQuotes(f, template[:minI-1], tab)
|
| |
193 |
f.write(tab+'yield %s\n' % evalStr)
|
| |
194 |
_writeTemplate(f, template[j+2:], tab)
|
| |
195 |
return
|
| |
196 |
|
| |
197 |
|
| |
198 |
# Old cherrytemplate syntax
|