Skip to content

Commit a168ab8

Browse files
committed
Have the constructor for Pattern take a patternlab object as its third
parameter so it can construct correct pattern links based on the configure outputFilePaths in the user config
1 parent e885524 commit a168ab8

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

core/lib/object_factory.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var extend = require('util')._extend;
66

77
// Pattern properties
88

9-
var Pattern = function (relPath, data) {
9+
var Pattern = function (relPath, data, patternlab) {
1010
// We expect relPath to be the path of the pattern template, relative to the
1111
// root of the pattern tree. Parse out the path parts and save the useful ones.
1212
var pathObj = path.parse(path.normalize(relPath));
@@ -44,6 +44,10 @@ var Pattern = function (relPath, data) {
4444
// the joined pattern group and subgroup directory
4545
this.flatPatternPath = this.subdir.replace(/[\/\\]/g, '-'); // '00-atoms-00-global'
4646

47+
// calculated path from the root of the public directory to the generated
48+
// (rendered!) html file for this pattern, to be shown in the iframe
49+
this.patternLink = patternlab ? this.getPatternLink(patternlab, 'rendered') : null;
50+
4751
// The canonical "key" by which this pattern is known. This is the callable
4852
// name of the pattern. UPDATE: this.key is now known as this.patternPartial
4953
this.patternPartial = this.patternGroup + '-' + this.patternBaseName;
@@ -88,11 +92,6 @@ Pattern.prototype = {
8892
var suffixConfig = patternlab.config.outputFileSuffixes;
8993
var suffix = suffixType ? suffixConfig[suffixType] : suffixConfig.rendered;
9094

91-
if (this.patternLink) {
92-
// Someone or something has explicitly set a patternLink on this pattern.
93-
// We had better respect that.
94-
return this.patternLink;
95-
}
9695
return this.name + path.sep + this.name + suffix + '.html';
9796
},
9897

@@ -123,16 +122,16 @@ Pattern.prototype = {
123122

124123
// factory: creates an empty Pattern for miscellaneous internal use, such as
125124
// by list_item_hunter
126-
Pattern.createEmpty = function (customProps) {
127-
var pattern = new Pattern('', null);
125+
Pattern.createEmpty = function (customProps, patternlab) {
126+
var pattern = new Pattern('', null, patternlab);
128127
return extend(pattern, customProps);
129128
};
130129

131130
// factory: creates an Pattern object on-demand from a hash; the hash accepts
132131
// parameters that replace the positional parameters that the Pattern
133132
// constructor takes.
134-
Pattern.create = function (relPath, data, customProps) {
135-
var newPattern = new Pattern(relPath || '', data || null);
133+
Pattern.create = function (relPath, data, customProps, patternlab) {
134+
var newPattern = new Pattern(relPath || '', data || null, patternlab);
136135
return extend(newPattern, customProps);
137136
};
138137

core/lib/pattern_assembler.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ var pattern_assembler = function () {
213213
if (proposedDirectoryStats.isDirectory()) {
214214
var subTypeMarkdownFileContents = fs.readFileSync(proposedDirectory + '.md', 'utf8');
215215
var subTypeMarkdown = markdown_parser.parse(subTypeMarkdownFileContents);
216-
var subTypePattern = new Pattern(relPath);
216+
var subTypePattern = new Pattern(relPath, null, patternlab);
217217
subTypePattern.patternSectionSubtype = true;
218218
subTypePattern.patternLink = subTypePattern.name + '/index.html';
219219
subTypePattern.patternDesc = subTypeMarkdown.markdown;
@@ -244,7 +244,7 @@ var pattern_assembler = function () {
244244
if (!patternEngines.isPatternFile(filename, patternlab)) { return null; }
245245

246246
//make a new Pattern Object
247-
var currentPattern = new Pattern(relPath);
247+
var currentPattern = new Pattern(relPath, null, patternlab);
248248

249249
//if file is named in the syntax for variants
250250
if (patternEngines.isPseudoPatternJSON(filename)) {

core/lib/ui_builder.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ var ui_builder = function () {
154154
engine: null,
155155
flatPatternPath: pattern.flatPatternPath,
156156
isDocPattern: true
157-
}
157+
},
158+
patternlab
158159
);
159160
return docPattern;
160161
}

test/ui_builder_tests.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ function createFakePatternLab(customProps) {
1616
}
1717
},
1818
styleGuideExcludes: [ 'templates' ],
19-
debug: false
19+
debug: false,
20+
outputFileSuffixes: {
21+
rendered: '.rendered',
22+
rawTemplate: '',
23+
markupOnly: '.markup-only'
24+
}
2025
}
2126
};
2227
return extend(pl, customProps);

0 commit comments

Comments
 (0)