fix(handlebars each): fixed bug in handlebars tags w/ trailing pipe

closes #529
This commit is contained in:
Christopher Pickering 2023-01-23 11:09:31 -06:00
parent 749ec05a03
commit 9d42baf626
No known key found for this signature in database
GPG key ID: E14DB3B0A0FACF84
5 changed files with 20 additions and 9 deletions

View file

@ -85,7 +85,10 @@ const widont = (string) => {
}; };
module.exports = function (eleventyConfig) { module.exports = function (eleventyConfig) {
eleventyConfig.addGlobalData("djlint_version", require('../package.json').version); eleventyConfig.addGlobalData(
'djlint_version',
require('../package.json').version,
);
eleventyConfig.setUseGitIgnore(false); eleventyConfig.setUseGitIgnore(false);
eleventyConfig.addFilter('widont', widont); eleventyConfig.addFilter('widont', widont);
eleventyConfig.addWatchTarget('./src/static/'); eleventyConfig.addWatchTarget('./src/static/');

View file

@ -33,4 +33,3 @@ profile="{{ tool }}"
## Real Life Examples! ## Real Life Examples!
- [apostrophe](https://github.com/apostrophecms/apostrophe) source code [reformatted](https://github.com/Riverside-Healthcare/djLint/compare/apostrophe-source...Riverside-Healthcare:djLint:apostrophe-djlint) - [apostrophe](https://github.com/apostrophecms/apostrophe) source code [reformatted](https://github.com/Riverside-Healthcare/djLint/compare/apostrophe-source...Riverside-Healthcare:djLint:apostrophe-djlint)

View file

@ -89,11 +89,11 @@ if (typeof Worker !== 'undefined') {
} }
if ((type == 'error' || type == 'html') && id == session_id) { if ((type == 'error' || type == 'html') && id == session_id) {
setOutput(message); setOutput(message);
} else if (type == "status") { } else if (type == 'status') {
console.log(message) console.log(message);
} else if (type == "version") { } else if (type == 'version') {
document.getElementById('djlint-version').textContent = message; document.getElementById('djlint-version').textContent = message;
}else { } else {
console.log(event.data); console.log(event.data);
} }
}; };

View file

@ -89,7 +89,7 @@ def expand_html(html: str, config: Config) -> str:
break_char break_char
+ r"\K((?:{%|{{\#)[ ]*?(?:" + r"\K((?:{%|{{\#)[ ]*?(?:"
+ config.break_template_tags + config.break_template_tags
+ ")[^}]+?[%|}]})", + ")[^}]+?[%}]})",
flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE, flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE,
), ),
partial(should_i_move_template_tag, "\n%s"), partial(should_i_move_template_tag, "\n%s"),
@ -101,7 +101,7 @@ def expand_html(html: str, config: Config) -> str:
re.compile( re.compile(
r"((?:{%|{{\#)[ ]*?(?:" r"((?:{%|{{\#)[ ]*?(?:"
+ config.break_template_tags + config.break_template_tags
+ ")[^}]+?[%|}]})(?=[^\n])", + ")[^}]+?[%}]})(?=[^\n])",
flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE, flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE,
), ),
partial(should_i_move_template_tag, "%s\n"), partial(should_i_move_template_tag, "%s\n"),

View file

@ -5,7 +5,7 @@ run::
pytest tests/test_handlebars.py --cov=src/djlint --cov-branch \ pytest tests/test_handlebars.py --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing --cov-report xml:coverage.xml --cov-report term-missing
pytest tests/test_handlebars.py::test_each --cov=src/djlint --cov-branch \ pytest tests/test_handlebars/test_each.py::test_each_with_pipe --cov=src/djlint --cov-branch \
--cov-report xml:coverage.xml --cov-report term-missing --cov-report xml:coverage.xml --cov-report term-missing
""" """
@ -34,3 +34,12 @@ def test_each(runner: CliRunner, tmp_file: TextIO) -> None:
{{/each }} {{/each }}
""" """
) )
def test_each_with_pipe(runner: CliRunner, tmp_file: TextIO) -> None:
output = reformat(
tmp_file,
runner,
b"""{{#each (cprFindConfigObj "inventoryCategories") as |category c |}}\n""",
)
assert output.exit_code == 0