Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 523df6a

Browse files
committed
Support for patternlinks. Included these in the default nav templates to showcase how this works
closes #89
1 parent 631c703 commit 523df6a

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

builder/object_factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
this.template = '';
2020
this.patternPartial = '';
2121
this.patternName = ''; //this is the display name for the ui
22-
this.patternLink = '';
22+
this.patternLink = name + '/' + name + '.html';
2323
this.patternGroup = name.substring(name.indexOf('-') + 1, name.indexOf('-', 4) + 1 - name.indexOf('-') + 1);
2424
this.patternSubGroup = subdir.substring(subdir.indexOf('/') + 4);
2525
this.flatPatternPath = subdir.replace(/\//g, '-');

builder/patternlab.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
var patternlab_engine = function(){
1212
var path = require('path'),
1313
fs = require('fs-extra'),
14+
extend = require('util')._extend,
1415
diveSync = require('diveSync'),
1516
mustache = require('mustache'),
1617
of = require('./object_factory'),
@@ -59,6 +60,7 @@ var patternlab_engine = function(){
5960
patternlab.patterns = [];
6061
patternlab.patternIndex = [];
6162
patternlab.partials = {};
63+
patternlab.data.link = {};
6264

6365
diveSync('./source/_patterns', function(err, file){
6466

@@ -108,18 +110,8 @@ var patternlab_engine = function(){
108110
catch(e) {
109111

110112
}
111-
112113
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-
}
120114

121-
currentPattern.patternLink = currentPattern.name + '/' + currentPattern.name + '.html';;
122-
123115
//find pattern lineage
124116
var lineage_hunter = new lh();
125117
lineage_hunter.find_lineage(currentPattern, patternlab);
@@ -138,9 +130,10 @@ var patternlab_engine = function(){
138130
partialname = currentPattern.patternGroup + '-' + patternName.substring(patternName.indexOf('-') + 1);
139131
}
140132
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.
143135
patternlab.patternIndex.push(currentPattern.name);
136+
patternlab.data.link[currentPattern.patternGroup + '-' + currentPattern.patternName] = '/patterns/' + currentPattern.patternLink;
144137
patternlab.patterns.push(currentPattern);
145138
});
146139

@@ -149,6 +142,17 @@ var patternlab_engine = function(){
149142
//render all patterns last, so lineageR works
150143
patternlab.patterns.forEach(function(pattern, index, patterns){
151144

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+
152156
//add footer info before writing
153157
var patternFooter = renderPattern(patternlab.footer, pattern);
154158

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<nav id="nav" class="nav">
22
<ul>
3-
<li><a href="#">Home</a></li>
3+
<li><a href="{{ link.pages-homepage }}">Home</a></li>
44
<li><a href="#">About</a></li>
5-
<li><a href="#">Blog</a></li>
5+
<li><a href="{{ link.pages-blog }}">Blog</a></li>
66
<li><a href="#">Contact</a></li>
77
</ul>
88
</nav><!--end .nav-->
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<ul class="nav-footer">
2-
<li><a href="#">Home</a></li>
2+
<li><a href="{{ link.pages-homepage }}">Home</a></li>
33
<li><a href="#">About</a></li>
4-
<li><a href="#">Blog</a></li>
4+
<li><a href="{{ link.pages-blog }}">Blog</a></li>
55
<li><a href="#">Contact</a></li>
66
</ul>

0 commit comments

Comments
 (0)