mirror of https://github.com/zulip/zulip.git
Check that handlebars tags are balanced in check-templates.
(imported from commit 4a36b874f5dab314cf5af5357bf0250d6fc1bd8b)
This commit is contained in:
parent
f22665e710
commit
bf5ebf1d2d
|
@ -24,7 +24,10 @@ def validate(fn, check_indent=True):
|
||||||
start_line = state.line
|
start_line = state.line
|
||||||
start_col = state.col
|
start_col = state.col
|
||||||
state.depth += 1
|
state.depth += 1
|
||||||
|
if s[0] == '<':
|
||||||
tag = s[1:-1]
|
tag = s[1:-1]
|
||||||
|
elif s[0] == '{':
|
||||||
|
tag = s[3:-2]
|
||||||
start_tag = tag.split()[0]
|
start_tag = tag.split()[0]
|
||||||
old_matcher = state.matcher
|
old_matcher = state.matcher
|
||||||
def f(end_tag):
|
def f(end_tag):
|
||||||
|
@ -63,6 +66,9 @@ def validate(fn, check_indent=True):
|
||||||
else:
|
else:
|
||||||
state.col += 1
|
state.col += 1
|
||||||
|
|
||||||
|
def looking_at(s):
|
||||||
|
return text[state.i:state.i+len(s)] == s
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if state.i >= len(text):
|
if state.i >= len(text):
|
||||||
break
|
break
|
||||||
|
@ -78,11 +84,33 @@ def validate(fn, check_indent=True):
|
||||||
start_tag_matcher(s)
|
start_tag_matcher(s)
|
||||||
advance(len(s))
|
advance(len(s))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if looking_at("{{#") or looking_at("{{^"):
|
||||||
|
s = get_handlebars_tag(text, state.i)
|
||||||
|
start_tag_matcher(s)
|
||||||
|
advance(len(s))
|
||||||
|
continue
|
||||||
|
|
||||||
|
if looking_at("{{/"):
|
||||||
|
s = get_handlebars_tag(text, state.i)
|
||||||
|
state.matcher(s)
|
||||||
|
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 get_handlebars_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] != '>':
|
||||||
|
@ -93,7 +121,10 @@ def get_html_tag(text, i):
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def matching_tags(start_tag, end_tag):
|
def matching_tags(start_tag, end_tag):
|
||||||
|
if end_tag[0] == '<':
|
||||||
return start_tag == end_tag[2:-1]
|
return start_tag == end_tag[2:-1]
|
||||||
|
if end_tag[0] == '{':
|
||||||
|
return start_tag == end_tag[3:-2]
|
||||||
|
|
||||||
def check_our_files():
|
def check_our_files():
|
||||||
git_files = map(str.strip, subprocess.check_output(['git', 'ls-files']).split('\n'))
|
git_files = map(str.strip, subprocess.check_output(['git', 'ls-files']).split('\n'))
|
||||||
|
|
Loading…
Reference in New Issue