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

Commit 30f8000

Browse files
committed
First steps toward a .render() method directly on the oPattern
object. The pattern_engines module returns an instance, but I now realize that this is a terrible idea.
1 parent 4899cd9 commit 30f8000

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

builder/object_factory.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
/*
2-
* patternlab-node - v0.10.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.10.1 - 2015
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

1111
(function () {
1212
"use strict";
1313

14+
var PatternEngines = require('pattern_engines/pattern_engines');
15+
1416
var oPattern = function(subdir, filename, data){
1517
this.fileName = filename.substring(0, filename.indexOf('.'));
1618
this.subdir = subdir;
@@ -29,6 +31,11 @@
2931
this.lineageIndex = [];
3032
this.lineageR = [];
3133
this.lineageRIndex = [];
34+
this.engine = PatternEngines.getEngineForPattern(this);
35+
};
36+
// render method on oPatterns; this acts as a proxy for the
37+
oPattern.prototype.render = function (data, partials) {
38+
return this.engine.render(this.template, data, partials);
3239
};
3340

3441
var oBucket = function(name){

builder/parameter_hunter.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* patternlab-node - v0.10.1 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.10.1 - 2015
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -14,9 +14,9 @@
1414
var parameter_hunter = function(){
1515

1616
var extend = require('util')._extend,
17-
pa = require('./pattern_assembler'),
18-
mustache = require('mustache'),
19-
pattern_assembler = new pa();
17+
pa = require('./pattern_asbsembler'),
18+
mustache = require('mustache'),
19+
pattern_assembler = new pa();
2020

2121
function findparameters(pattern, patternlab){
2222

@@ -47,7 +47,7 @@
4747
for (var prop in paramData) {
4848
if (existingData.hasOwnProperty(prop)) {
4949
existingData[prop] = paramData[prop];
50-
}
50+
}
5151
}
5252

5353
//extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally

builder/pattern_engines/engine_mustache.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
/*
2-
* mustache pattern engine for patternlab-node - v0.10.1 - 2015
3-
*
1+
/*
2+
* mustache pattern engine for patternlab-node - v0.10.1 - 2015
3+
*
44
* 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.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
88
*
99
*/
1010

@@ -31,6 +31,6 @@
3131
return matches;
3232
}
3333
};
34-
34+
3535
module.exports = engine_mustache;
3636
})();

builder/pattern_engines/pattern_engines.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,25 @@
1717
'handlebars'
1818
];
1919

20-
// hash of all loaded pattern engines, empty at first
21-
var patternEngines = {};
20+
// object/hash of all loaded pattern engines, empty at first
21+
function PatternEngines () {
22+
// do nothing
23+
}
24+
PatternEngines.prototype = {
25+
getEngineForPattern: function (pattern) {
26+
console.log('pattern file name: ', pattern.fileName);
27+
return 'mustache';
28+
}
29+
};
2230

2331
// try to load all supported engines
2432
supportedPatternEngineNames.forEach(function (engineName) {
2533
try {
26-
patternEngines[engineName] = require('./engine_' + engineName);
34+
PatternEngines[engineName] = require('./engine_' + engineName);
2735
} catch (err) {
2836
console.log(err, 'pattern engine "' + engineName + '" not loaded. Did you install its dependency with npm?');
2937
}
3038
});
3139

32-
patternEngines.getEngineForPattern = function (pattern) {
33-
34-
};
35-
36-
module.exports = patternEngines;
37-
40+
module.exports = new PatternEngines();
3841
})();

0 commit comments

Comments
 (0)