@@ -58,7 +58,6 @@ var patternlab_engine = function(){
58
58
patternlab . header = fs . readFileSync ( './source/_patternlab-files/pattern-header-footer/header.html' , 'utf8' ) ;
59
59
patternlab . footer = fs . readFileSync ( './source/_patternlab-files/pattern-header-footer/footer.html' , 'utf8' ) ;
60
60
patternlab . patterns = [ ] ;
61
- patternlab . patternIndex = [ ] ;
62
61
patternlab . partials = { } ;
63
62
patternlab . data . link = { } ;
64
63
@@ -75,25 +74,15 @@ var patternlab_engine = function(){
75
74
var subdir = path . dirname ( path . relative ( './source/_patterns' , file ) ) ;
76
75
var filename = path . basename ( file ) ;
77
76
78
- //check if the pattern already exists.
79
- var patternName = filename . substring ( 0 , filename . indexOf ( '.' ) ) ,
80
- patternIndex = patternlab . patternIndex . indexOf ( subdir + '-' + patternName ) ,
81
- currentPattern ,
82
- flatPatternPath ;
83
-
84
- //ignore _underscored patterns, json, and dotfiles
77
+ //ignore _underscored patterns, json (for now), and dotfiles
85
78
if ( filename . charAt ( 0 ) === '_' || path . extname ( filename ) === '.json' || filename . charAt ( 0 ) === '.' ) {
86
79
return ;
87
80
}
88
81
82
+ //check for pattern parameters before we do much else. need to remove them into a data object so the rest of the filename parsing works
83
+
89
84
//make a new Pattern Object
90
- var flatPatternName = subdir . replace ( / [ \/ \\ ] / g, '-' ) + '-' + patternName ;
91
-
92
- flatPatternName = flatPatternName . replace ( / \\ / g, '-' ) ;
93
- currentPattern = new of . oPattern ( flatPatternName , subdir , filename , { } ) ;
94
- currentPattern . patternName = patternName . substring ( patternName . indexOf ( '-' ) + 1 ) ;
95
- currentPattern . data = null ;
96
- currentPattern . key = currentPattern . patternGroup + '-' + currentPattern . patternName ;
85
+ currentPattern = new of . oPattern ( subdir , filename , { } ) ;
97
86
98
87
//see if this file has a state
99
88
if ( patternlab . config . patternStates [ currentPattern . patternName ] ) {
@@ -111,6 +100,8 @@ var patternlab_engine = function(){
111
100
112
101
}
113
102
currentPattern . template = fs . readFileSync ( abspath , 'utf8' ) ;
103
+
104
+ //look for a pseudo pattern by checking if there is a file containing same name, with ~ in it, ending in .json
114
105
115
106
//find pattern lineage
116
107
var lineage_hunter = new lh ( ) ;
@@ -125,14 +116,13 @@ var patternlab_engine = function(){
125
116
//look for the full path on nested patters, else expect it to be flat
126
117
var partialname = '' ;
127
118
if ( cleanSub !== '' ) {
128
- partialname = cleanSub + '-' + patternName . substring ( patternName . indexOf ( '-' ) + 1 ) ;
119
+ partialname = cleanSub + '-' + currentPattern . patternName ;
129
120
} else {
130
- partialname = currentPattern . patternGroup + '-' + patternName . substring ( patternName . indexOf ( '-' ) + 1 ) ;
121
+ partialname = currentPattern . patternGroup + '-' + currentPattern . patternName ;
131
122
}
132
123
patternlab . partials [ partialname ] = currentPattern . template ;
133
124
134
125
//add to patternlab object so we can look these up later.
135
- patternlab . patternIndex . push ( currentPattern . name ) ;
136
126
patternlab . data . link [ currentPattern . patternGroup + '-' + currentPattern . patternName ] = '/patterns/' + currentPattern . patternLink ;
137
127
patternlab . patterns . push ( currentPattern ) ;
138
128
} ) ;
@@ -145,7 +135,7 @@ var patternlab_engine = function(){
145
135
//render the pattern. pass partials and data
146
136
if ( pattern . data ) { // Pass found pattern-specific JSON as data
147
137
148
- //extend patternIndex into link for pattern link shortcuts to work. we do this locally and globally
138
+ //extend pattern data links into link for pattern link shortcuts to work. we do this locally and globally
149
139
pattern . data . link = extend ( { } , patternlab . data . link ) ;
150
140
151
141
pattern . patternPartial = renderPattern ( pattern . template , pattern . data , patternlab . partials ) ;
@@ -356,7 +346,7 @@ var patternlab_engine = function(){
356
346
357
347
function addToPatternPaths ( bucketName , pattern ) {
358
348
//this is messy, could use a refactor.
359
- patternlab . patternPaths [ bucketName ] [ pattern . patternName ] = pattern . subdir . replace ( / \\ / g, '/' ) + "/" + pattern . filename . substring ( 0 , pattern . filename . indexOf ( '.' ) ) ;
349
+ patternlab . patternPaths [ bucketName ] [ pattern . patternName ] = pattern . subdir . replace ( / \\ / g, '/' ) + "/" + pattern . fileName ;
360
350
}
361
351
362
352
return {
0 commit comments