Skip to content

Commit

Permalink
feat: STRF-11523 Add the ability to use Handlebar Partial Blocks (#1167)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairo-bc authored Mar 29, 2024
1 parent 9be2b8c commit 39a7fbc
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 76 deletions.
5 changes: 4 additions & 1 deletion lib/template-assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const dynamicComponentRegex = /\{\{\s*?dynamicComponent\s*(?:'|")([_|\-|a-zA-Z0-
const includeRegex = /{{2}>\s*([_|\-|a-zA-Z0-9/]+)[^{]*?}{2}/g;
const pathStringRegex = /^["'].+["']$/;
const packageMarker = 'external/';
const partialBlock = '@partial-block';

/**
* indicates if a template source is a node modules dependency
Expand Down Expand Up @@ -169,7 +170,9 @@ function getTemplatePaths(templatesFolder, templates, options, callback) {
while (match !== null) {
[, partialPath] = match;
if (!templatePaths.includes(partialPath)) {
matches.push(partialPath);
if (partialPath !== partialBlock) {
matches.push(partialPath);
}
}
match = partialRegex.exec(content);
}
Expand Down
172 changes: 98 additions & 74 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"engines": {
"node": ">=16.0.0 <19.0.0",
"npm": ">=8.0.0 <10.0.0"
"npm": ">=8.0.0"
},
"scripts": {
"lint": "eslint . && prettier --check . --ignore-unknown",
Expand Down
6 changes: 6 additions & 0 deletions test/_mocks/themes/valid/templates/components/c.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Here is the list:
{{#> components/ul }}
{{> components/li text="Item 1" link="item_link_1"}}
{{> components/li text="Item 2" link="item_link_2"}}
{{> components/li text="Item 3" link="item_link_3"}}
{{/components/ul}}
3 changes: 3 additions & 0 deletions test/_mocks/themes/valid/templates/components/li.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li>
<a href="{{link}}">{{text}}</a>
</li>
3 changes: 3 additions & 0 deletions test/_mocks/themes/valid/templates/components/ul.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<ul>
{{> @partial-block }}
<ul>
Loading

0 comments on commit 39a7fbc

Please sign in to comment.