From 9d42baf626070f9cb54bc4ac6f4dffca1b90b34d Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 23 Jan 2023 11:09:31 -0600 Subject: [PATCH] fix(handlebars each): fixed bug in handlebars tags w/ trailing pipe closes #529 --- docs/.eleventy.js | 5 ++++- docs/src/docs/languages/nunjucks.md | 1 - docs/src/static/js/editor.js | 8 ++++---- src/djlint/formatter/expand.py | 4 ++-- tests/test_handlebars/test_each.py | 11 ++++++++++- 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/docs/.eleventy.js b/docs/.eleventy.js index 4423fae..2f4b078 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -85,7 +85,10 @@ const widont = (string) => { }; module.exports = function (eleventyConfig) { - eleventyConfig.addGlobalData("djlint_version", require('../package.json').version); + eleventyConfig.addGlobalData( + 'djlint_version', + require('../package.json').version, + ); eleventyConfig.setUseGitIgnore(false); eleventyConfig.addFilter('widont', widont); eleventyConfig.addWatchTarget('./src/static/'); diff --git a/docs/src/docs/languages/nunjucks.md b/docs/src/docs/languages/nunjucks.md index e8b623c..1caccec 100644 --- a/docs/src/docs/languages/nunjucks.md +++ b/docs/src/docs/languages/nunjucks.md @@ -33,4 +33,3 @@ profile="{{ tool }}" ## 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) - diff --git a/docs/src/static/js/editor.js b/docs/src/static/js/editor.js index cb8340d..908f3f1 100644 --- a/docs/src/static/js/editor.js +++ b/docs/src/static/js/editor.js @@ -89,11 +89,11 @@ if (typeof Worker !== 'undefined') { } if ((type == 'error' || type == 'html') && id == session_id) { setOutput(message); - } else if (type == "status") { - console.log(message) - } else if (type == "version") { + } else if (type == 'status') { + console.log(message); + } else if (type == 'version') { document.getElementById('djlint-version').textContent = message; - }else { + } else { console.log(event.data); } }; diff --git a/src/djlint/formatter/expand.py b/src/djlint/formatter/expand.py index 098ec6d..d661dcf 100644 --- a/src/djlint/formatter/expand.py +++ b/src/djlint/formatter/expand.py @@ -89,7 +89,7 @@ def expand_html(html: str, config: Config) -> str: break_char + r"\K((?:{%|{{\#)[ ]*?(?:" + config.break_template_tags - + ")[^}]+?[%|}]})", + + ")[^}]+?[%}]})", flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE, ), partial(should_i_move_template_tag, "\n%s"), @@ -101,7 +101,7 @@ def expand_html(html: str, config: Config) -> str: re.compile( r"((?:{%|{{\#)[ ]*?(?:" + config.break_template_tags - + ")[^}]+?[%|}]})(?=[^\n])", + + ")[^}]+?[%}]})(?=[^\n])", flags=re.IGNORECASE | re.MULTILINE | re.VERBOSE, ), partial(should_i_move_template_tag, "%s\n"), diff --git a/tests/test_handlebars/test_each.py b/tests/test_handlebars/test_each.py index ae08e54..c0804ff 100644 --- a/tests/test_handlebars/test_each.py +++ b/tests/test_handlebars/test_each.py @@ -5,7 +5,7 @@ run:: pytest tests/test_handlebars.py --cov=src/djlint --cov-branch \ --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 """ @@ -34,3 +34,12 @@ def test_each(runner: CliRunner, tmp_file: TextIO) -> None: {{/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