11
11
var patternlab_engine = function ( ) {
12
12
var path = require ( 'path' ) ,
13
13
fs = require ( 'fs-extra' ) ,
14
+ extend = require ( 'util' ) . _extend ,
14
15
diveSync = require ( 'diveSync' ) ,
15
16
mustache = require ( 'mustache' ) ,
16
17
of = require ( './object_factory' ) ,
@@ -59,6 +60,7 @@ var patternlab_engine = function(){
59
60
patternlab . patterns = [ ] ;
60
61
patternlab . patternIndex = [ ] ;
61
62
patternlab . partials = { } ;
63
+ patternlab . data . link = { } ;
62
64
63
65
diveSync ( './source/_patterns' , function ( err , file ) {
64
66
@@ -108,18 +110,8 @@ var patternlab_engine = function(){
108
110
catch ( e ) {
109
111
110
112
}
111
-
112
113
currentPattern . template = fs . readFileSync ( abspath , 'utf8' ) ;
113
-
114
- //render the pattern. pass partials object just in case.
115
- if ( currentPattern . data ) { // Pass JSON as data
116
- currentPattern . patternPartial = renderPattern ( currentPattern . template , currentPattern . data , patternlab . partials ) ;
117
- } else { // Pass global patternlab data
118
- currentPattern . patternPartial = renderPattern ( currentPattern . template , patternlab . data , patternlab . partials ) ;
119
- }
120
114
121
- currentPattern . patternLink = currentPattern . name + '/' + currentPattern . name + '.html' ; ;
122
-
123
115
//find pattern lineage
124
116
var lineage_hunter = new lh ( ) ;
125
117
lineage_hunter . find_lineage ( currentPattern , patternlab ) ;
@@ -138,9 +130,10 @@ var patternlab_engine = function(){
138
130
partialname = currentPattern . patternGroup + '-' + patternName . substring ( patternName . indexOf ( '-' ) + 1 ) ;
139
131
}
140
132
patternlab . partials [ partialname ] = currentPattern . template ;
141
-
142
- //add to patternlab arrays so we can look these up later. this could probably just be an object .
133
+
134
+ //add to patternlab object so we can look these up later.
143
135
patternlab . patternIndex . push ( currentPattern . name ) ;
136
+ patternlab . data . link [ currentPattern . patternGroup + '-' + currentPattern . patternName ] = '/patterns/' + currentPattern . patternLink ;
144
137
patternlab . patterns . push ( currentPattern ) ;
145
138
} ) ;
146
139
@@ -149,6 +142,17 @@ var patternlab_engine = function(){
149
142
//render all patterns last, so lineageR works
150
143
patternlab . patterns . forEach ( function ( pattern , index , patterns ) {
151
144
145
+ //render the pattern. pass partials and data
146
+ if ( pattern . data ) { // Pass found pattern-specific JSON as data
147
+
148
+ //extend patternIndex into link for pattern link shortcuts to work. we do this locally and globally
149
+ pattern . data . link = extend ( { } , patternlab . data . link ) ;
150
+
151
+ pattern . patternPartial = renderPattern ( pattern . template , pattern . data , patternlab . partials ) ;
152
+ } else { // Pass global patternlab data
153
+ pattern . patternPartial = renderPattern ( pattern . template , patternlab . data , patternlab . partials ) ;
154
+ }
155
+
152
156
//add footer info before writing
153
157
var patternFooter = renderPattern ( patternlab . footer , pattern ) ;
154
158
0 commit comments