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

Commit a7236f7

Browse files
committed
'working' renderPattern function
1 parent f22551b commit a7236f7

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

builder/pattern_assembler.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,17 @@
6868
}
6969
}
7070

71-
// template: a string containing the template text, not an oPattern
72-
function renderPattern(template, data, partials) {
73-
// TODO:
74-
// choose an appropriate pattern engine
75-
// call and return result of its renderPattern method
76-
// OR MAYBE: this should just be a method of oPattern
77-
78-
var mustache = require('mustache');
79-
if (partials) {
80-
return mustache.render(template, data, partials);
71+
function renderPattern(pattern, data, partials) {
72+
// if we've been passed a full oPattern, it knows what kind of template it
73+
// is, and how to render itself, so we just call its render method
74+
if (pattern instanceof of.oPattern) {
75+
console.log('rendering full oPattern');
76+
return pattern.render(pattern, data, partials);
8177
} else {
82-
return mustache.render(template, data);
78+
// otherwise, assume it's a plain mustache template string and act
79+
// accordingly
80+
console.log('rendering plain mustache string');
81+
return patternEngines.mustache.renderPattern(pattern, data, partials);
8382
}
8483
}
8584

builder/pattern_engines/engine_mustache.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
var engine_mustache = {
1717
engine: Mustache,
18+
name: 'mustache',
1819
fileExtension: '.mustache',
1920

2021
// render it

builder/pattern_engines/pattern_engines.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
// var Mustache = PatternEngines['mustache'];
2626
//
2727
var PatternEngines = Object.create({
28-
getEngineForPattern: function (pattern) {
28+
getEngineNameForPattern: function (pattern) {
2929
console.log('pattern file name: ', pattern.fileName);
3030
return 'mustache';
31+
},
32+
getEngineForPattern: function (pattern) {
33+
var engineName = this.getEngineNameForPattern(pattern);
34+
return this[engineName];
3135
}
3236
});
3337

0 commit comments

Comments
 (0)