Skip to content

Commit 0398e42

Browse files
committed
It works! We factor out the pattern prefix regex and make it tolerant of
more cases.
1 parent 98b2b4b commit 0398e42

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

core/lib/object_factory.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
var patternEngines = require('./pattern_engines');
44
var path = require('path');
55
var extend = require('util')._extend;
6+
// patternPrefixMatcher is intended to match the leading maybe-underscore,
7+
// zero or more digits, and maybe-dash at the beginning of a pattern file name we can hack them
8+
// off and get at the good part.
9+
var patternPrefixMatcher = /^_?(\d+-)?/;
610

711
// Pattern properties
812

@@ -22,21 +26,21 @@ var Pattern = function (relPath, data, patternlab) {
2226
this.jsonFileData = data || {};
2327

2428
// strip leading "00-" from the file name and flip tildes to dashes
25-
this.patternBaseName = this.fileName.replace(/^\d*\-/, '').replace('~', '-'); // 'colors'
29+
this.patternBaseName = this.fileName.replace(patternPrefixMatcher, '').replace('~', '-'); // 'colors'
2630

2731
// Fancy name. No idea how this works. 'Colors'
2832
this.patternName = this.patternBaseName.split('-').reduce(function (val, working) {
2933
return val.charAt(0).toUpperCase() + val.slice(1) + ' ' + working.charAt(0).toUpperCase() + working.slice(1);
3034
}, '').trim(); //this is the display name for the ui. strip numeric + hyphen prefixes
3135

3236
// the top-level pattern group this pattern belongs to. 'atoms'
33-
this.patternGroup = this.subdir.split(path.sep)[0].replace(/^\d*-/, '');
37+
this.patternGroup = this.subdir.split(path.sep)[0].replace(patternPrefixMatcher, '');
3438

3539
//00-atoms if needed
3640
this.patternType = this.subdir.split(path.sep)[0];
3741

3842
// the sub-group this pattern belongs to.
39-
this.patternSubGroup = path.basename(this.subdir).replace(/^\d*-/, ''); // 'global'
43+
this.patternSubGroup = path.basename(this.subdir).replace(patternPrefixMatcher, ''); // 'global'
4044

4145
//00-colors if needed
4246
this.patternSubType = path.basename(this.subdir);
@@ -52,6 +56,10 @@ var Pattern = function (relPath, data, patternlab) {
5256
// name of the pattern. UPDATE: this.key is now known as this.patternPartial
5357
this.patternPartial = this.patternGroup + '-' + this.patternBaseName;
5458

59+
// Let's calculate the verbose name ahead of time! We don't use path.sep here
60+
// on purpose. This isn't a file name!
61+
this.verbosePartial = this.subdir + '/' + this.fileName;
62+
5563
this.isPattern = true;
5664
this.isFlatPattern = this.patternGroup === this.patternSubGroup;
5765
this.patternState = '';

test/engine_handlebars_tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ exports['engine_handlebars'] = {
199199
pattern_assembler.process_pattern_recursive(testPatternPath, pl);
200200

201201
//act
202-
test.equals(testPattern.render(), 'Hello there!\nHere\'s the hidden atom: [This is the hidden atom]\n');
202+
test.equals(testPattern.render(), 'Here\'s the hidden atom: [I\'m the hidden atom\n]\n');
203203

204204
//assert
205205
// test.equals(patternlab.patterns.length, 1);

0 commit comments

Comments
 (0)