Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 4a9dec6

Browse files
committed
Add first draft of pattern engines
1 parent 7454424 commit 4a9dec6

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* mustache pattern engine for patternlab-node - v0.10.1 - 2015
3+
*
4+
* Brian Muenzenmeyer, and the web community.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
8+
*
9+
*/
10+
11+
(function () {
12+
"use strict";
13+
14+
var Mustache = require('mustache');
15+
16+
var engine_mustache = {
17+
engine: Mustache,
18+
fileExtension: '.mustache',
19+
20+
// render it
21+
renderPattern: function renderPattern(template, data, partials) {
22+
if (partials) {
23+
return Mustache.render(template, data, partials);
24+
}
25+
return Mustache.render(template, data);
26+
},
27+
28+
// find and return any {{> template-name }} within pattern
29+
findPartials: function findPartials(pattern) {
30+
var matches = pattern.template.match(/{{>([ ])?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g);
31+
return matches;
32+
}
33+
};
34+
35+
module.exports = engine_mustache;
36+
})();
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* patternlab-node - v0.10.1 - 2015
3+
*
4+
* Brian Muenzenmeyer, and the web community.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
8+
*
9+
*/
10+
11+
(function () {
12+
'use strict';
13+
14+
// list of supported pattern engines
15+
var supportedPatternEngineNames = [
16+
'mustache',
17+
'handlebars'
18+
];
19+
20+
// hash of all loaded pattern engines, empty at first
21+
var patternEngines = {};
22+
23+
// try to load all supported engines
24+
supportedPatternEngineNames.forEach(function (engineName) {
25+
try {
26+
patternEngines[engineName] = require('./engine_' + engineName);
27+
} catch (err) {
28+
console.log(err, 'pattern engine "' + engineName + '" not loaded. Did you install its dependency with npm?');
29+
}
30+
});
31+
32+
patternEngines.getEngineForPattern = function (pattern) {
33+
34+
};
35+
36+
module.exports = patternEngines;
37+
38+
})();

0 commit comments

Comments
 (0)