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

Commit ac54ffb

Browse files
committed
We now pass all tests and build "successfully," but pseudo-patterns
don't render at all, and are missing in the menu. The quest continues...
1 parent 5217108 commit ac54ffb

File tree

8 files changed

+93
-20
lines changed

8 files changed

+93
-20
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"no-eval": 2,
4242
"no-extend-native": 2,
4343
"no-extra-parens": 0,
44-
"no-irregular-whitespace": 2,
44+
"no-irregular-whitespace": 1,
4545
"no-iterator": 2,
4646
"no-loop-func": 2,
4747
"no-multi-str": 2,

builder/object_factory.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*
2-
* patternlab-node - v0.14.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.14.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*
@@ -14,7 +14,11 @@
1414
var patternEngines = require('./pattern_engines/pattern_engines');
1515
var path = require('path');
1616

17+
// oPattern properties
18+
1719
var oPattern = function(abspath, subdir, filename, data){
20+
console.log('new oPattern');
21+
console.log('absPath:', abspath, 'subdir:', subdir, 'filename:', filename, 'data:', data);
1822
this.fileName = filename.substring(0, filename.indexOf('.'));
1923
this.fileExtension = path.extname(abspath);
2024
this.abspath = abspath;
@@ -37,10 +41,22 @@
3741
this.lineageR = [];
3842
this.lineageRIndex = [];
3943
this.engine = patternEngines.getEngineForPattern(this);
44+
this.isPseudoPattern = false;
4045
};
46+
47+
// oPattern methods
48+
4149
// render method on oPatterns; this acts as a proxy for the PatternEngine's
4250
// render function
4351
oPattern.prototype.render = function (data, partials) {
52+
if (this.isPseudoPattern) {
53+
console.log(this.name + ' is a pseudo-pattern');
54+
} else {
55+
console.log('this is NOT a pseudo-pattern');
56+
}
57+
// console.log('this does ' + (this.template ? '' : 'NOT ') + 'have template');
58+
// console.log('this does ' + (this.extendedTemplate ? '' : 'NOT ') + 'have extendedTemplate');
59+
4460
return this.engine.renderPattern(this.template, data, partials);
4561
};
4662

@@ -55,6 +71,7 @@
5571
this.patternItemsIndex = [];
5672
};
5773

74+
5875
var oNavItem = function(name){
5976
this.sectionNameLC = name;
6077
this.sectionNameUC = name.split('-').reduce(function(val, working){
@@ -64,6 +81,7 @@
6481
this.navSubItemsIndex = [];
6582
};
6683

84+
6785
var oNavSubItem = function(name){
6886
this.patternPath = '';
6987
this.patternPartial = '';
@@ -72,6 +90,7 @@
7290
}, '').trim();
7391
};
7492

93+
7594
module.exports = {
7695
oPattern: oPattern,
7796
oBucket: oBucket,

builder/pattern_assembler.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,20 @@
8787
} else {
8888
// otherwise, assume it's a plain mustache template string and act
8989
// accordingly
90-
console.log('rendering plain mustache string');
90+
console.log('rendering plain mustache string:', pattern.substring(0, 20) + '...');
9191
return patternEngines.mustache.renderPattern(pattern, data, partials);
9292
}
9393
}
9494

95-
// ignore _underscored patterns, dotfiles, and anything not recognized by
96-
// a loaded pattern engine
95+
// ignore _underscored patterns, dotfiles, and anything not recognized by a
96+
// loaded pattern engine. Pseudo-pattern .json files ARE considered to be
97+
// pattern files!
9798
function isPatternFile(filename) {
9899
// skip hidden patterns/files without a second thought
99-
if (filename.charAt(0) === '_' || filename.charAt(0) === '.') {
100+
var extension = path.extname(filename);
101+
if(filename.charAt(0) === '.' ||
102+
filename.charAt(0) === '_' ||
103+
(extension === '.json' && filename.indexOf('~') === -1)) {
100104
return false;
101105
}
102106

@@ -105,17 +109,27 @@
105109
var supportedPatternFileExtensions = engineNames.map(function (engineName) {
106110
return patternEngines[engineName].fileExtension;
107111
});
108-
var extension = path.extname(filename);
109112
return (supportedPatternFileExtensions.lastIndexOf(extension) !== -1);
110113
}
111114

112115
function processPatternIterative(file, patternlab){
116+
var fs = require('fs-extra'),
117+
of = require('./object_factory'),
118+
path = require('path');
119+
113120
//extract some information
114121
var subdir = path.dirname(path.relative(patternlab.config.patterns.source, file)).replace('\\', '/');
115122
var filename = path.basename(file);
116123
var ext = path.extname(filename);
117124

125+
console.log('processPatternIterative:', 'filename:', filename);
126+
118127
// skip non-pattern files
128+
//ignore dotfiles and non-variant .json files
129+
if(filename.charAt(0) === '.' || (ext === '.json' && filename.indexOf('~') === -1)){
130+
return;
131+
}
132+
119133
if (!isPatternFile(filename, patternlab)) { return; }
120134
console.log('found pattern', file);
121135

builder/pattern_engines/pattern_engines.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@
4343
return 'mustache';
4444
},
4545
getEngineForPattern: function (pattern) {
46-
var engineName = this.getEngineNameForPattern(pattern);
47-
return this[engineName];
46+
if (pattern.isPseudoPattern) {
47+
return this.getEngineForPattern(pattern.basePattern);
48+
} else {
49+
var engineName = this.getEngineNameForPattern(pattern);
50+
return this[engineName];
51+
}
4852
}
4953
});
5054

builder/patternlab.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*
2-
* patternlab-node - v0.14.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.14.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*

builder/pseudopattern_hunter.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/*
2-
* patternlab-node - v0.14.0 - 2015
3-
*
1+
/*
2+
* patternlab-node - v0.14.0 - 2015
3+
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
66
*
@@ -20,17 +20,19 @@
2020
pa = require('./pattern_assembler'),
2121
lh = require('./lineage_hunter'),
2222
of = require('./object_factory'),
23+
patternEngines = require('./pattern_engines/pattern_engines'),
2324
mustache = require('mustache');
2425

2526
var pattern_assembler = new pa();
2627
var lineage_hunter = new lh();
2728

28-
//look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json
29+
//look for a pseudo pattern by checking if there is a file containing same
30+
//name, with ~ in it, ending in .json
2931
var needle = currentPattern.subdir + '/' + currentPattern.fileName + '~*.json';
3032
var pseudoPatterns = glob.sync(needle, {
3133
cwd: 'source/_patterns/', //relative to gruntfile
3234
debug: false,
33-
nodir: true,
35+
nodir: true
3436
});
3537

3638
if(pseudoPatterns.length > 0){
@@ -47,7 +49,7 @@
4749
//extend any existing data with variant data
4850
variantFileData = pattern_assembler.merge_data(currentPattern.jsonFileData, variantFileData);
4951

50-
// GTP: mustache-specific stuff here
52+
// GTP: mustache-specific stuff here
5153
var variantName = pseudoPatterns[i].substring(pseudoPatterns[i].indexOf('~') + 1).split('.')[0];
5254
var variantFilePath = 'source/_patterns/' + currentPattern.subdir + '/' + currentPattern.fileName + '~' + variantName + '.json';
5355
var variantFileName = currentPattern.fileName + '-' + variantName + '.';
@@ -59,6 +61,9 @@
5961
//use the same template as the non-variant
6062
patternVariant.template = currentPattern.template;
6163
patternVariant.extendedTemplate = currentPattern.extendedTemplate;
64+
patternVariant.isPseudoPattern = true;
65+
patternVariant.basePattern = currentPattern;
66+
patternVariant.engine = patternEngines.getEngineForPattern(this);
6267

6368
//find pattern lineage
6469
lineage_hunter.find_lineage(patternVariant, patternlab);

builder/util.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* patternlab-node - v0.14.0 - 2015
3+
*
4+
* Brian Muenzenmeyer, Geoffrey Pursell 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+
var path = require('path');
13+
14+
var util = {
15+
// takes a string of the filename or path, and will tell you if it refers to
16+
isPseudoPattern: function () {
17+
18+
}
19+
};
20+
21+
module.exports = util;
22+
}());

test/pattern_engines_tests.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
// the mustache test pattern, stolen from object_factory unit tests
88
var mustacheTestPattern = new of.oPattern('source/_patterns/00-atoms/00-global/00-colors-alt.mustache', '00-atoms/00-global', '00-colors-alt.mustache', {d: 123});
9+
var mustacheTestPseudoPatternBasePattern = new of.oPattern('source/_patterns/04-pages/00-homepage.mustache', '04-pages', '00-homepage.mustache', {d: 123});
10+
var mustacheTestPseudoPattern = new of.oPattern('source/_patterns/04-pages/00-homepage~emergency.json', '04-pages', '00-homepage-emergency.', {d: 123});
11+
mustacheTestPseudoPattern.isPseudoPattern = true;
12+
mustacheTestPseudoPattern.basePattern = mustacheTestPseudoPatternBasePattern;
913
var engineNames = Object.keys(patternEngines);
1014

1115

@@ -19,6 +23,11 @@
1923
var engine = patternEngines.getEngineForPattern(mustacheTestPattern);
2024
test.equals(engine, patternEngines.mustache);
2125
test.done();
26+
},
27+
'getEngineForPattern returns a reference to the mustache engine from test pseudo-pattern': function (test) {
28+
var engine = patternEngines.getEngineForPattern(mustacheTestPseudoPattern);
29+
test.equals(engine, patternEngines.mustache);
30+
test.done();
2231
}
2332
};
2433

0 commit comments

Comments
 (0)