1+ /*
2+ * patternlab-node - v0.1.0 - 2014-01-21
3+ *
4+ * Brian Muenzenmeyer, 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+
111var path = require ( 'path' ) ;
212
313var oPattern = function ( name , subdir , filename , data ) {
@@ -6,7 +16,7 @@ var oPattern = function(name, subdir, filename, data){
616 this . filename = filename ;
717 this . data = data ;
818 this . template = '' ;
9- this . patternOutput = '' ;
19+ this . patternPartial = '' ;
1020 this . patternName = '' ; //this is the display name for the ui
1121 this . patternLink = '' ;
1222 this . patternGroup = name . substring ( name . indexOf ( '-' ) + 1 , name . indexOf ( '-' , 4 ) + 1 - name . indexOf ( '-' ) + 1 ) ;
@@ -91,11 +101,15 @@ module.exports = function(grunt) {
91101 currentPattern . template = grunt . file . read ( abspath ) ;
92102
93103 //render the pattern. pass partials object just in case.
94- currentPattern . patternOutput = mustache . render ( currentPattern . template , patternlab . data , patternlab . partials ) ;
104+ currentPattern . patternPartial = mustache . render ( currentPattern . template , patternlab . data , patternlab . partials ) ;
95105
96106 //write the compiled template to the public patterns directory
97107 flatPatternPath = currentPattern . name + '/' + currentPattern . name + '.html' ;
98- grunt . file . write ( './public/patterns/' + flatPatternPath , patternlab . header + currentPattern . patternOutput + patternlab . footer ) ;
108+
109+ //add footer info before writing
110+ var currentPatternFooter = mustache . render ( patternlab . footer , currentPattern ) ;
111+
112+ grunt . file . write ( './public/patterns/' + flatPatternPath , patternlab . header + currentPattern . patternPartial + currentPatternFooter ) ;
99113 currentPattern . patternLink = flatPatternPath ;
100114
101115 //add as a partial in case this is referenced later. convert to syntax needed by existing patterns
@@ -126,12 +140,17 @@ module.exports = function(grunt) {
126140 currentPattern . template = grunt . file . read ( abspath ) ;
127141
128142 //render the pattern. pass partials object just in case.
129- currentPattern . patternOutput = mustache . render ( currentPattern . template , currentPattern . data , patternlab . partials ) ;
143+ currentPattern . patternPartial = mustache . render ( currentPattern . template , currentPattern . data , patternlab . partials ) ;
130144 grunt . log . writeln ( 'template compiled with data!' ) ;
131145
132146 //write the compiled template to the public patterns directory
133147 flatPatternPath = currentPattern . name + '/' + currentPattern . name + '.html' ;
134- grunt . file . write ( './public/patterns/' + flatPatternPath , patternlab . header + currentPattern . patternOutput + patternlab . footer ) ;
148+
149+ //add footer info before writing
150+ var currentPatternFooter = mustache . render ( patternlab . footer , currentPattern ) ;
151+
152+ grunt . file . write ( './public/patterns/' + flatPatternPath , patternlab . header + currentPattern . patternPartial + currentPatternFooter ) ;
153+
135154 currentPattern . patternLink = flatPatternPath ;
136155
137156 //done
@@ -184,31 +203,32 @@ module.exports = function(grunt) {
184203 //assume the navSubItem does not exist.
185204 var navSubItem = new oNavSubItem ( navSubItemName ) ;
186205 navSubItem . patternPath = pattern . patternLink ;
187- navSubItem . patternPartial = bucketName + "-" + navSubItemName ;
206+ navSubItem . patternPartial = bucketName + "-" + pattern . patternName ; //add the hyphenated name
188207
189208 //if it is flat - we should not add the pattern to patternPaths
190209 if ( flatPatternItem ) {
191- //grunt.log.writeln('flat source structure found for ' + navItemName + " " + bucketName);
192210
193- //add the navItem to patternItems
194211 bucket . patternItems . push ( navSubItem ) ;
212+
213+ //add to patternPaths
214+ patternlab . patternPaths [ bucketName ] [ pattern . patternName ] = pattern . subdir + "/" + pattern . filename . substring ( 0 , pattern . filename . indexOf ( '.' ) ) ;
195215
196216 } else {
197- //add the more complex nav items
217+
198218 bucket . navItems . push ( navItem ) ;
199219 bucket . navItemsIndex . push ( navItemName ) ;
200220 navItem . navSubItems . push ( navSubItem ) ;
201221 navItem . navSubItemsIndex . push ( navSubItemName ) ;
202222
203223 //add to patternPaths
204- patternlab . patternPaths [ bucketName ] [ navSubItemName ] = pattern . subdir + "/" + pattern . filename . substring ( 0 , pattern . filename . indexOf ( '.' ) ) ;
205- }
224+ patternlab . patternPaths [ bucketName ] [ pattern . patternName ] = pattern . subdir + "/" + pattern . filename . substring ( 0 , pattern . filename . indexOf ( '.' ) ) ;
225+
226+ }
206227
207228 //add the bucket.
208229 patternlab . buckets . push ( bucket ) ;
209230 patternlab . bucketIndex . push ( bucketName ) ;
210231
211-
212232 //done
213233
214234 } else {
@@ -224,7 +244,7 @@ module.exports = function(grunt) {
224244 //assume the navSubItem does not exist.
225245 var navSubItem = new oNavSubItem ( navSubItemName ) ;
226246 navSubItem . patternPath = pattern . patternLink ;
227- navSubItem . patternPartial = bucketName + "-" + navSubItemName ;
247+ navSubItem . patternPartial = bucketName + "-" + pattern . patternName ; //add the hyphenated name
228248
229249 //test whether the pattern struture is flat or not - usually due to a template or page
230250 var flatPatternItem = false ;
@@ -234,10 +254,13 @@ module.exports = function(grunt) {
234254
235255 //if it is flat - we should not add the pattern to patternPaths
236256 if ( flatPatternItem ) {
237- //grunt.log.writeln('flat source structure found for ' + navItemName + " " + bucketName);
238257
239258 //add the navItem to patternItems
240259 bucket . patternItems . push ( navSubItem ) ;
260+
261+ //add to patternPaths
262+ patternlab . patternPaths [ bucketName ] [ pattern . patternName ] = pattern . subdir + "/" + pattern . filename . substring ( 0 , pattern . filename . indexOf ( '.' ) ) ;
263+
241264 } else {
242265 //check to see if navItem exists
243266 var navItemIndex = bucket . navItemsIndex . indexOf ( navItemName ) ;
@@ -258,12 +281,11 @@ module.exports = function(grunt) {
258281 navItem . navSubItemsIndex . push ( navSubItemName ) ;
259282 }
260283
261- //add to patternPaths
262- patternlab . patternPaths [ bucketName ] [ navSubItemName ] = pattern . subdir + "/" + pattern . filename . substring ( 0 , pattern . filename . indexOf ( '.' ) ) ;
284+ // just add to patternPaths
285+ patternlab . patternPaths [ bucketName ] [ pattern . patternName ] = pattern . subdir + "/" + pattern . filename . substring ( 0 , pattern . filename . indexOf ( '.' ) ) ;
263286
264287 }
265288
266-
267289 //check to see if this bucket has a View All yet. If not, add it.
268290 // var navItem = bucket.navItems[navItemIndex];
269291 // if(navItem){
0 commit comments