|
1 |
| -/* |
2 |
| - * patternlab-node - v0.10.1 - 2015 |
3 |
| - * |
| 1 | +/* |
| 2 | + * patternlab-node - v0.10.1 - 2015 |
| 3 | + * |
4 | 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. |
| 5 | + * Licensed under the MIT license. |
| 6 | + * |
| 7 | + * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. |
8 | 8 | *
|
9 | 9 | */
|
10 | 10 |
|
|
13 | 13 |
|
14 | 14 | var pattern_assembler = function(){
|
15 | 15 |
|
16 |
| - //find and return any {{> template-name }} within pattern |
| 16 | + var fs = require('fs-extra'), |
| 17 | + of = require('./object_factory'), |
| 18 | + path = require('path'), |
| 19 | + patternEngines = require('./pattern_engines/pattern_engines'); |
| 20 | + |
| 21 | + // find and return any {{> template-name }} within pattern |
| 22 | + // TODO: delete, factored out |
17 | 23 | function findPartials(pattern){
|
18 | 24 | var matches = pattern.template.match(/{{>([ ])?([A-Za-z0-9-]+)(?:\:[A-Za-z0-9-]+)?(?:(| )\(.*)?([ ])?}}/g);
|
19 | 25 | return matches;
|
|
33 | 39 | }
|
34 | 40 |
|
35 | 41 | function renderPattern(template, data, partials) {
|
| 42 | + debugger; |
| 43 | + // TODO: |
| 44 | + // choose an appropriate pattern engine |
| 45 | + // call and return result of its renderPattern method |
| 46 | + // OR MAYBE: this should just be a method of oPattern |
| 47 | + } |
36 | 48 |
|
37 |
| - var mustache = require('mustache'); |
38 |
| - |
39 |
| - if(partials) { |
40 |
| - return mustache.render(template, data, partials); |
41 |
| - } else{ |
42 |
| - return mustache.render(template, data); |
43 |
| - } |
| 49 | + function isPatternFile(filename, patternlab) { |
| 50 | + var engineNames = Object.keys(patternEngines); |
| 51 | + var supportedPatternFileExtensions = engineNames.map(function (engineName) { |
| 52 | + return patternEngines[engineName].fileExtension; |
| 53 | + }); |
| 54 | + var extension = path.extname(filename); |
| 55 | + return (supportedPatternFileExtensions.lastIndexOf(extension) != -1); |
44 | 56 | }
|
45 | 57 |
|
| 58 | + // given a pattern file, figure out what to do with it |
46 | 59 | function processPatternFile(file, patternlab){
|
47 |
| - var fs = require('fs-extra'), |
48 |
| - of = require('./object_factory'), |
49 |
| - path = require('path'); |
50 |
| - |
51 | 60 | //extract some information
|
52 | 61 | var abspath = file.substring(2);
|
53 | 62 | var subdir = path.dirname(path.relative('./source/_patterns', file)).replace('\\', '/');
|
54 | 63 | var filename = path.basename(file);
|
55 | 64 |
|
56 |
| - //ignore _underscored patterns, json (for now), and dotfiles |
57 |
| - if(filename.charAt(0) === '_' || path.extname(filename) === '.json' || filename.charAt(0) === '.'){ |
| 65 | + // ignore _underscored patterns, dotfiles, and anything not recognized by |
| 66 | + // a loaded pattern engine |
| 67 | + if (filename.charAt(0) === '_' || |
| 68 | + filename.charAt(0) === '.' || |
| 69 | + !isPatternFile(filename, patternlab)) { |
58 | 70 | return;
|
59 | 71 | }
|
| 72 | + console.log('found pattern', file); |
60 | 73 |
|
61 | 74 | //make a new Pattern Object
|
62 | 75 | var currentPattern = new of.oPattern(subdir, filename);
|
|
80 | 93 | }
|
81 | 94 |
|
82 | 95 | function processPattern(currentPattern, patternlab, additionalData){
|
83 |
| - |
84 |
| - var fs = require('fs-extra'), |
85 |
| - mustache = require('mustache'), |
86 |
| - lh = require('./lineage_hunter'), |
87 |
| - ph = require('./parameter_hunter'), |
88 |
| - pph = require('./pseudopattern_hunter'), |
89 |
| - path = require('path'); |
| 96 | + var lh = require('./lineage_hunter'), |
| 97 | + ph = require('./parameter_hunter'), |
| 98 | + pph = require('./pseudopattern_hunter'); |
90 | 99 |
|
91 | 100 | var parameter_hunter = new ph(),
|
92 |
| - lineage_hunter = new lh(), |
93 |
| - pseudopattern_hunter = new pph(); |
| 101 | + lineage_hunter = new lh(), |
| 102 | + pseudopattern_hunter = new pph(); |
94 | 103 |
|
95 | 104 | currentPattern.extendedTemplate = currentPattern.template;
|
96 | 105 |
|
|
0 commit comments