Check Django block tags in check-templates.

(imported from commit a5d6336eeba63df365d3e59dce4d7f32aae637c7)
This commit is contained in:
Steve Howell 2014-02-27 16:59:36 -05:00 committed by Jessica McKellar
parent 5d0abd6f3f
commit f4764e58c6
1 changed files with 36 additions and 0 deletions

View File

@ -99,11 +99,38 @@ def validate(fn, check_indent=True):
advance(len(s)) advance(len(s))
continue continue
# Django tags
if looking_at("{% ") and not looking_at("{% end"):
s = get_django_tag(text, state.i)
tag = s[3:-2].split()[0]
if is_django_block_tag(tag):
start_tag_matcher(s, tag)
advance(len(s))
continue
if looking_at("{% end"):
s = get_django_tag(text, state.i)
end_tag = s[6:-3]
state.matcher(end_tag)
advance(len(s))
continue
advance(1) advance(1)
if state.depth != 0: if state.depth != 0:
return state.matcher("(NO TAG)") return state.matcher("(NO TAG)")
def is_django_block_tag(tag):
return tag in [
'autoescape',
'block',
'comment',
'for',
'if',
'ifequal',
'verbatim',
]
def get_handlebars_tag(text, i): def get_handlebars_tag(text, i):
end = i + 2 end = i + 2
while end < len(text) -1 and text[end] != '}': while end < len(text) -1 and text[end] != '}':
@ -113,6 +140,15 @@ def get_handlebars_tag(text, i):
s = text[i:end+2] s = text[i:end+2]
return s return s
def get_django_tag(text, i):
end = i + 2
while end < len(text) -1 and text[end] != '%':
end += 1
if text[end] != '%' or text[end+1] != '}':
raise Exception('Tag missing %}')
s = text[i:end+2]
return s
def get_html_tag(text, i): def get_html_tag(text, i):
end = i + 1 end = i + 1
while end < len(text) and text[end] != '>': while end < len(text) and text[end] != '>':