Skip to content

Commit 25a0fe2

Browse files
dnwhtebmuenzenmeyer
authored andcommitted
Reimplement PL's default listitems feature with the mustache syntax
1 parent 5de2529 commit 25a0fe2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

packages/patternengine-node-nunjucks/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
To install the Nunjucks engine in your edition, `npm install patternengine-node-nunjucks` should do the trick.
66

7-
Level of Support is more or less full. Partial calls and lineage hunting are supported. Nunjucks does not support the mustache-specific syntax extensions, style modifiers and pattern parameters, because their use cases are addressed by the core Nunjucks feature set. Pattern Lab's listitems.json data does not appear to be accessible. However, it's still possible to create custom list style data.
7+
Level of Support is more or less full. Partial calls and lineage hunting are supported. Nunjucks does not support the mustache-specific syntax extensions, style modifiers and pattern parameters, because their use cases are addressed by the core Nunjucks feature set. Pattern Lab's listitems feature is still written in the mustache syntax.
88

99
## Extending the Nunjucks instance
1010

packages/patternengine-node-nunjucks/lib/engine_nunjucks.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
* Nunjucks does not support the mustache-specific syntax
1414
* extensions, style modifiers and pattern parameters, because
1515
* their use cases are addressed by the core Nunjucks feature set.
16-
* Pattern Lab's listitems.json data does not appear to be accessible.
17-
* However, it's still possible to create custom list style data.
16+
* Pattern Lab's listitems feature is still written in the
17+
* mustache syntax.
1818
*
1919
*/
2020

@@ -68,6 +68,7 @@ var engine_nunjucks = {
6868
// regexes, stored here so they're only compiled once
6969
findPartialsRE: /{%\s*(?:extends|include|import|from)\s+(?:.*)\s*%}/g,
7070
findPartialKeyRE: /{%\s*(?:extends|include|import|from)\s+('[^']+'|"[^"]+")/,
71+
findListItemsRE: /({{#( )?)(list(I|i)tems.)(one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty)( )?}}/g,
7172

7273
// render it
7374
renderPattern: function renderPattern(pattern, data) {
@@ -136,9 +137,10 @@ var engine_nunjucks = {
136137
}
137138
},
138139

139-
// handled by nunjucks. This is error to keep PL from erroring
140+
// still requires the mustache syntax because of the way PL handles lists
140141
findListItems: function (pattern) {
141-
return null;
142+
var matches = pattern.template.match(this.findListItemsRE);
143+
return matches;
142144
},
143145

144146
// handled by nunjucks. This is error to keep PL from erroring

0 commit comments

Comments
 (0)