mirror of https://github.com/zulip/zulip.git
template_parser: Handle handlebar partial blocks.
This commit is contained in:
parent
8848359887
commit
606258e75b
|
@ -75,6 +75,9 @@ def tokenize(text: str) -> List[Token]:
|
|||
def looking_at_handlebars_partial() -> bool:
|
||||
return looking_at("{{>")
|
||||
|
||||
def looking_at_handlebars_partial_block() -> bool:
|
||||
return looking_at("{{#>")
|
||||
|
||||
def looking_at_html_start() -> bool:
|
||||
return looking_at("<") and not looking_at("</")
|
||||
|
||||
|
@ -140,6 +143,10 @@ def tokenize(text: str) -> List[Token]:
|
|||
s = get_handlebars_partial(text, state.i)
|
||||
tag = s[9:-2]
|
||||
kind = "handlebars_partial"
|
||||
elif looking_at_handlebars_partial_block():
|
||||
s = get_handlebars_partial(text, state.i)
|
||||
tag = s[5:-2]
|
||||
kind = "handlebars_partial_block"
|
||||
elif looking_at_html_start():
|
||||
s = get_html_tag(text, state.i)
|
||||
if s.endswith("/>"):
|
||||
|
@ -311,7 +318,7 @@ def tag_flavor(token: Token) -> Optional[str]:
|
|||
):
|
||||
return None
|
||||
|
||||
if kind in ("handlebars_start", "html_start"):
|
||||
if kind in ("handlebars_start", "handlebars_partial_block", "html_start"):
|
||||
return "start"
|
||||
elif kind in (
|
||||
"django_else",
|
||||
|
@ -726,6 +733,7 @@ def get_django_comment(text: str, i: int) -> str:
|
|||
|
||||
|
||||
def get_handlebars_partial(text: str, i: int) -> str:
|
||||
"""Works for both partials and partial blocks."""
|
||||
end = i + 10
|
||||
unclosed_end = 0
|
||||
while end <= len(text):
|
||||
|
|
|
@ -49,6 +49,22 @@ class ParserTest(unittest.TestCase):
|
|||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_handlebars_partial_block(self) -> None:
|
||||
my_html = """
|
||||
{{#> generic_thing }}
|
||||
<p>hello!</p>
|
||||
{{/generic_thing}}
|
||||
"""
|
||||
validate(text=my_html)
|
||||
|
||||
def test_validate_bad_handlebars_partial_block(self) -> None:
|
||||
my_html = """
|
||||
{{#> generic_thing }}
|
||||
<p>hello!</p>
|
||||
{{# generic_thing}}
|
||||
"""
|
||||
self._assert_validate_error("Missing end tag for the token at row 4 13!", text=my_html)
|
||||
|
||||
def test_validate_comment(self) -> None:
|
||||
my_html = """
|
||||
<!---
|
||||
|
@ -298,6 +314,11 @@ class ParserTest(unittest.TestCase):
|
|||
self.assertEqual(token.kind, "handlebars_end")
|
||||
self.assertEqual(token.tag, "with")
|
||||
|
||||
tag = "{{#> compose_banner }}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, "handlebars_partial_block")
|
||||
self.assertEqual(token.tag, "compose_banner")
|
||||
|
||||
tag = "{% if foo %}bla"
|
||||
token = tokenize(tag)[0]
|
||||
self.assertEqual(token.kind, "django_start")
|
||||
|
|
Loading…
Reference in New Issue