template_parser: Spell “Handlebars” correctly.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2022-09-08 23:58:17 -07:00 committed by Anders Kaseorg
parent 7d485aa58f
commit 8da2eb58ec
3 changed files with 14 additions and 14 deletions

View File

@ -42,7 +42,7 @@ def check_our_files(modified_only: bool, all_dups: bool, fix: bool, targets: Lis
exclude=EXCLUDED_FILES, exclude=EXCLUDED_FILES,
) )
check_handlebar_templates(by_lang["hbs"], fix) check_handlebars_templates(by_lang["hbs"], fix)
check_html_templates(by_lang["html"], all_dups, fix) check_html_templates(by_lang["html"], all_dups, fix)
@ -108,8 +108,8 @@ def check_html_templates(templates: Iterable[str], all_dups: bool, fix: bool) ->
sys.exit(1) sys.exit(1)
def check_handlebar_templates(templates: Iterable[str], fix: bool) -> None: def check_handlebars_templates(templates: Iterable[str], fix: bool) -> None:
# Check all our handlebars templates. # Check all our Handlebars templates.
templates = [fn for fn in templates if fn.endswith(".hbs")] templates = [fn for fn in templates if fn.endswith(".hbs")]
for fn in templates: for fn in templates:

View File

@ -111,7 +111,7 @@ def fix_indents_for_multi_line_tags(tokens: List[Token]) -> None:
if token.line_span == 1 or token.indent is None: if token.line_span == 1 or token.indent is None:
continue continue
if token.kind in ("django_comment", "handlebar_comment", "html_comment", "text"): if token.kind in ("django_comment", "handlebars_comment", "html_comment", "text"):
continue_indent = token.indent continue_indent = token.indent
else: else:
continue_indent = token.indent + " " continue_indent = token.indent + " "

View File

@ -66,13 +66,13 @@ def tokenize(text: str) -> List[Token]:
def looking_at_htmlcomment() -> bool: def looking_at_htmlcomment() -> bool:
return looking_at("<!--") return looking_at("<!--")
def looking_at_handlebarcomment() -> bool: def looking_at_handlebars_comment() -> bool:
return looking_at("{{!") return looking_at("{{!")
def looking_at_djangocomment() -> bool: def looking_at_djangocomment() -> bool:
return looking_at("{#") return looking_at("{#")
def looking_at_handlebarpartial() -> bool: def looking_at_handlebars_partial() -> bool:
return looking_at("{{>") return looking_at("{{>")
def looking_at_html_start() -> bool: def looking_at_html_start() -> bool:
@ -128,16 +128,16 @@ def tokenize(text: str) -> List[Token]:
s = get_html_comment(text, state.i) s = get_html_comment(text, state.i)
tag = s[4:-3] tag = s[4:-3]
kind = "html_comment" kind = "html_comment"
elif looking_at_handlebarcomment(): elif looking_at_handlebars_comment():
s = get_handlebar_comment(text, state.i) s = get_handlebars_comment(text, state.i)
tag = s[3:-2] tag = s[3:-2]
kind = "handlebar_comment" kind = "handlebars_comment"
elif looking_at_djangocomment(): elif looking_at_djangocomment():
s = get_django_comment(text, state.i) s = get_django_comment(text, state.i)
tag = s[2:-2] tag = s[2:-2]
kind = "django_comment" kind = "django_comment"
elif looking_at_handlebarpartial(): elif looking_at_handlebars_partial():
s = get_handlebar_partial(text, state.i) s = get_handlebars_partial(text, state.i)
tag = s[9:-2] tag = s[9:-2]
kind = "handlebars_singleton" kind = "handlebars_singleton"
elif looking_at_html_start(): elif looking_at_html_start():
@ -298,7 +298,7 @@ def tag_flavor(token: Token) -> Optional[str]:
if kind in ( if kind in (
"code", "code",
"django_comment", "django_comment",
"handlebar_comment", "handlebars_comment",
"handlebars_singleton", "handlebars_singleton",
"html_comment", "html_comment",
"html_doctype", "html_doctype",
@ -687,7 +687,7 @@ def get_html_comment(text: str, i: int) -> str:
raise TokenizationException("Unclosed comment", text[i:unclosed_end]) raise TokenizationException("Unclosed comment", text[i:unclosed_end])
def get_handlebar_comment(text: str, i: int) -> str: def get_handlebars_comment(text: str, i: int) -> str:
end = i + 5 end = i + 5
unclosed_end = 0 unclosed_end = 0
while end <= len(text): while end <= len(text):
@ -725,7 +725,7 @@ def get_django_comment(text: str, i: int) -> str:
raise TokenizationException("Unclosed comment", text[i:unclosed_end]) raise TokenizationException("Unclosed comment", text[i:unclosed_end])
def get_handlebar_partial(text: str, i: int) -> str: def get_handlebars_partial(text: str, i: int) -> str:
end = i + 10 end = i + 10
unclosed_end = 0 unclosed_end = 0
while end <= len(text): while end <= len(text):