3
3
var patternEngines = require ( './pattern_engines' ) ;
4
4
var path = require ( 'path' ) ;
5
5
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 + - ) ? / ;
6
10
7
11
// Pattern properties
8
12
@@ -22,21 +26,21 @@ var Pattern = function (relPath, data, patternlab) {
22
26
this . jsonFileData = data || { } ;
23
27
24
28
// 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'
26
30
27
31
// Fancy name. No idea how this works. 'Colors'
28
32
this . patternName = this . patternBaseName . split ( '-' ) . reduce ( function ( val , working ) {
29
33
return val . charAt ( 0 ) . toUpperCase ( ) + val . slice ( 1 ) + ' ' + working . charAt ( 0 ) . toUpperCase ( ) + working . slice ( 1 ) ;
30
34
} , '' ) . trim ( ) ; //this is the display name for the ui. strip numeric + hyphen prefixes
31
35
32
36
// 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 , '' ) ;
34
38
35
39
//00-atoms if needed
36
40
this . patternType = this . subdir . split ( path . sep ) [ 0 ] ;
37
41
38
42
// 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'
40
44
41
45
//00-colors if needed
42
46
this . patternSubType = path . basename ( this . subdir ) ;
@@ -52,6 +56,10 @@ var Pattern = function (relPath, data, patternlab) {
52
56
// name of the pattern. UPDATE: this.key is now known as this.patternPartial
53
57
this . patternPartial = this . patternGroup + '-' + this . patternBaseName ;
54
58
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
+
55
63
this . isPattern = true ;
56
64
this . isFlatPattern = this . patternGroup === this . patternSubGroup ;
57
65
this . patternState = '' ;
0 commit comments