Skip to content

Commit ede5839

Browse files
committed
more wip for tonight - getting closer with the documentation generation and writing of the view all files old code still working when you switch out patternlab.js call
1 parent 2a9b332 commit ede5839

File tree

10 files changed

+249
-34
lines changed

10 files changed

+249
-34
lines changed

core/lib/object_factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var Pattern = function (relPath, data) {
3939
// the sub-group this pattern belongs to.
4040
this.patternSubGroup = path.basename(this.subdir).replace(/^\d*-/, ''); // 'global'
4141

42-
// Not sure what this is used for.
42+
// the joined pattern group and subgroup directory
4343
this.flatPatternPath = this.subdir.replace(/[\/\\]/g, '-'); // '00-atoms-00-global'
4444

4545
// The canonical "key" by which this pattern is known. This is the callable

core/lib/patternlab.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,8 @@ var patternlab_engine = function (config) {
390390
},
391391
build: function (callback, deletePatternDir) {
392392
buildPatterns(deletePatternDir);
393-
new ui().buildFrontend(patternlab);
394-
//new ui2().buildFrontend2(patternlab);
393+
//new ui().buildFrontend(patternlab);
394+
new ui2().buildFrontend2(patternlab);
395395
printDebug();
396396
callback();
397397
},

core/lib/ui_builder.js

Lines changed: 129 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ var ui_builder = function() {
2222
patternlab.patternPaths[pattern.patternGroup][pattern.patternBaseName] = pattern.name;
2323
}
2424

25+
function writeFile(filePath, data, callback) {
26+
if (callback) {
27+
fs.outputFile(filePath, data, callback);
28+
} else {
29+
fs.outputFile(filePath, data);
30+
}
31+
}
32+
2533
/*
2634
* isPatternExcluded
2735
* returns whether or not the pattern should be excluded from direct rendering or navigation on the front end
@@ -123,27 +131,62 @@ var ui_builder = function() {
123131
return styleguidePatterns;
124132
}
125133

134+
/*
135+
* injectDocumentationBlock
136+
* take the given pattern, fina and construct the view-all pattern block for the group
137+
*/
138+
function injectDocumentationBlock(pattern, patternlab, isSubtypePattern) {
139+
140+
var docPattern = patternlab.subtypePatterns['viewall-' + pattern.patternGroup + (isSubtypePattern ? '-' + pattern.patternSubGroup : '')];
141+
142+
if (docPattern) {
143+
return docPattern;
144+
}
145+
146+
147+
console.log(pattern);
148+
149+
var docPattern = new Pattern.createEmpty(
150+
{
151+
name: pattern.flatPatternPath,
152+
patternDesc: '',
153+
patternPartial: 'viewall-' + pattern.patternGroup + (isSubtypePattern ? '-' + pattern.patternSubGroup : ''),
154+
patternSectionSubtype : true,
155+
patternLink: pattern.flatPatternPath + path.sep + 'index.html',
156+
isPattern: false,
157+
engine: null,
158+
flatPatternPath: pattern.patternGroup + (isSubtypePattern ? '-' + pattern.patternSubGroup: '')
159+
}
160+
);
161+
162+
return docPattern;
163+
}
164+
126165
/*
127166
* groupPatterns
128167
* returns an object representing how the front end styleguide and navigation is structured
129168
*/
130169
function groupPatterns(patternlab) {
131-
var groupedPatterns = {};
170+
var groupedPatterns = {
171+
patternGroups: {}
172+
};
132173

133174
_.forEach(patternlab.patterns, function(pattern) {
134175

135176
pattern.omitFromStyleguide = isPatternExcluded(pattern, patternlab);
136177

137-
if(pattern.omitFromStyleguide) { return; }
178+
if (pattern.omitFromStyleguide) { return; }
138179

139180
if (!groupedPatterns.patternGroups[pattern.patternGroup]) {
140181
groupedPatterns.patternGroups[pattern.patternGroup] = {};
182+
//todo: test this
183+
//groupedPatterns.patternGroups[pattern.patternGroup]['viewall-' + pattern.patternGroup] = injectDocumentationBlock(pattern, patternlab, false);
141184
}
142185
if (!groupedPatterns.patternGroups[pattern.patternGroup][pattern.patternSubGroup]) {
143186
groupedPatterns.patternGroups[pattern.patternGroup][pattern.patternSubGroup] = {};
187+
groupedPatterns.patternGroups[pattern.patternGroup][pattern.patternSubGroup]['viewall-' + pattern.patternGroup + '-' + pattern.patternSubGroup] = injectDocumentationBlock(pattern, patternlab, true);
144188
}
145189
groupedPatterns.patternGroups[pattern.patternGroup][pattern.patternSubGroup][pattern.patternBaseName] = pattern;
146-
147190
});
148191
return groupedPatterns;
149192
}
@@ -473,6 +516,36 @@ var ui_builder = function() {
473516
}
474517
}
475518

519+
function buildViewAllPages2(mainPageHeadHtml, patternlab, styleguidePatterns) {
520+
521+
console.log(mainPageHeadHtml);
522+
523+
var paths = patternlab.config.paths;
524+
525+
//loop through the grouped styleguide patterns, building at each level
526+
_.forEach(styleguidePatterns.patternGroups, function (patternTypeObj, patternType) {
527+
528+
_.forOwn(patternTypeObj, function(patternSubtypes, patternSubtype) {
529+
530+
var patternPartial = patternType + '-' + patternSubtype;
531+
console.log(patternPartial);
532+
533+
//render the footer needed for the viewall template
534+
var footerHTML = buildFooterHTML(patternlab, patternPartial);
535+
536+
//render the viewall template
537+
var subtypePatterns = _.values(patternSubtypes);
538+
var viewAllHTML = buildViewAllHTML(patternlab, subtypePatterns, patternPartial);
539+
540+
//todo this feels brittle, why doesn't [0] work?
541+
console.log(subtypePatterns[0]);
542+
writeFile(paths.public.patterns + subtypePatterns[1].flatPatternPath + '/index.html', mainPageHeadHtml + viewAllHTML + footerHTML);
543+
544+
});
545+
546+
});
547+
}
548+
476549
function sortPatterns(patternsArray) {
477550
return patternsArray.sort(function (a, b) {
478551

@@ -553,6 +626,14 @@ var ui_builder = function() {
553626
}
554627
writeFile(path.resolve(paths.public.root, 'index.html'), patternlabSiteHtml);
555628

629+
//write out the data to be read by the client
630+
exportData(patternlab);
631+
}
632+
633+
function exportData (patternlab) {
634+
var annotation_exporter = new ae(patternlab);
635+
var paths = patternlab.config.paths;
636+
556637
//write out the data
557638
var output = '';
558639

@@ -587,43 +668,69 @@ var ui_builder = function() {
587668
writeFile(path.resolve(paths.public.annotations, 'annotations.js'), annotations);
588669
}
589670

590-
function writeFile(filePath, data, callback) {
591-
if (callback) {
592-
fs.outputFile(filePath, data, callback);
593-
} else {
594-
fs.outputFile(filePath, data);
595-
}
596-
}
671+
597672

598673
function buildFrontend2(patternlab){
599674

675+
var paths = patternlab.config.paths;
676+
600677
//determine which patterns should be included in the front-end rendering
601678
var styleguidePatterns = groupPatterns(patternlab);
602679

603-
604680
//sort all the patterns explicitly
605-
681+
//TODO
606682

607683
//set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
608-
684+
var headerPartial = pattern_assembler.renderPattern(patternlab.header, {
685+
cacheBuster: patternlab.cacheBuster
686+
});
687+
var headerHTML = pattern_assembler.renderPattern(patternlab.userHead, {
688+
patternLabHead : headerPartial,
689+
cacheBuster: patternlab.cacheBuster
690+
});
609691

610692
//set the pattern-specific footer by compiling the general-footer with data, and then adding it to the meta footer
611-
693+
var footerPartial = pattern_assembler.renderPattern(patternlab.footer, {
694+
patternData: '{}',
695+
cacheBuster: patternlab.cacheBuster
696+
});
697+
var footerHTML = pattern_assembler.renderPattern(patternlab.userFoot, {
698+
patternLabFoot : footerPartial
699+
});
612700

613701
//build the viewall pages
614-
702+
//todo so close
703+
buildViewAllPages2(headerHTML, patternlab, styleguidePatterns);
615704

616705
//build the main styleguide page
706+
//todo broken
707+
var styleguideHtml = pattern_assembler.renderPattern(patternlab.viewAll,
708+
{
709+
partials: _.values(styleguidePatterns),
710+
cacheBuster: patternlab.cacheBuster
711+
}, {
712+
patternSection: patternlab.patternSection,
713+
patternSectionSubType: patternlab.patternSectionSubType
714+
});
617715

716+
//writeFile(path.resolve(paths.public.styleguide, 'html/styleguide.html'), headerHTML + styleguideHtml + footerHTML);
618717

619718
//build the patternlab navigation
620-
719+
//todo
621720

622721
//move the index file from its asset location into public root
722+
var patternlabSiteHtml;
723+
try {
724+
patternlabSiteHtml = fs.readFileSync(path.resolve(paths.source.styleguide, 'index.html'), 'utf8');
725+
} catch (error) {
726+
console.log(error);
727+
console.log("\nERROR: Could not load one or more styleguidekit assets from", paths.source.styleguide, '\n');
728+
process.exit(1);
729+
}
730+
//writeFile(path.resolve(paths.public.root, 'index.html'), patternlabSiteHtml);
623731

624-
625-
//write out patternlab.data object
626-
732+
//write out patternlab.data object to be read by the client
733+
//exportData(patternlab);
627734
}
628735

629736
return {
@@ -635,6 +742,9 @@ var ui_builder = function() {
635742
},
636743
isPatternExcluded: function (pattern, patternlab) {
637744
return isPatternExcluded(pattern, patternlab);
745+
},
746+
groupPatterns: function(patternlab) {
747+
return groupPatterns(patternlab);
638748
}
639749
};
640750

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
blue
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
red
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
yellow
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
black
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
grey
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
white

0 commit comments

Comments
 (0)