Skip to content

Commit

Permalink
Add support for handlebars partials
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman committed Apr 5, 2020
1 parent c006887 commit 5da10c0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion js/src/html/beautifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,13 @@ var TagOpenParserToken = function(parent, raw_token) {
tag_check_match = raw_token.text.match(/^<([^\s>]*)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';
} else {
tag_check_match = raw_token.text.match(/^{{[#\^]?([^\s}]+)/);
tag_check_match = raw_token.text.match(/^{{(?:[\^]|#\*?)?([^\s}]+)/);
this.tag_check = tag_check_match ? tag_check_match[1] : '';

// handle "{{#> myPartial}}
if (raw_token.text === '{{#>' && this.tag_check === '>' && raw_token.next !== null) {
this.tag_check = raw_token.next.text;
}
}
this.tag_check = this.tag_check.toLowerCase();

Expand Down
10 changes: 10 additions & 0 deletions js/test/generated/beautify-html-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6542,6 +6542,16 @@ function run_html_tests(test_obj, Urlencoded, js_beautify, html_beautify, css_be
'{{^inverted-condition}}\n' +
' <p>Unfortunately this condition is false.</p>\n' +
'{{/inverted-condition}}');

// Issue #1756 - Fix indentation of partials
bth(
'{{#*inline "myPartial"}}\n' +
' <p>Unfortunately this condition is false.</p>\n' +
'{{/inline}}');
bth(
'{{#> myPartial}}\n' +
' <p>Unfortunately this condition is false.</p>\n' +
'{{/myPartial}}');


//============================================================
Expand Down
16 changes: 16 additions & 0 deletions test/data/html/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,22 @@ exports.test_data = {
' <p>Unfortunately this condition is false.</p>',
'{{/inverted-condition}}'
]
},
// Indentation of partials
{
comment: "Issue #1756 - Fix indentation of partials",
unchanged: [
'{{#*inline "myPartial"}}',
' <p>Unfortunately this condition is false.</p>',
'{{/inline}}'
]
},
{
unchanged: [
'{{#> myPartial}}',
' <p>Unfortunately this condition is false.</p>',
'{{/myPartial}}'
]
}
]
}, {
Expand Down

0 comments on commit 5da10c0

Please sign in to comment.