Skip to content

Commit

Permalink
pushing some cleanup relevant to #428
Browse files Browse the repository at this point in the history
  • Loading branch information
bmuenzenmeyer committed Aug 16, 2016
1 parent 25bbea0 commit cfee9ff
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
27 changes: 18 additions & 9 deletions core/lib/pattern_assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ var pattern_assembler = function () {
subTypePattern.isPattern = false;
subTypePattern.engine = null;

addSubtypePattern(subTypePattern, patternlab)
addSubtypePattern(subTypePattern, patternlab);
return subTypePattern;
}
} catch (err) {
Expand Down Expand Up @@ -410,21 +410,30 @@ var pattern_assembler = function () {
}

function parseDataLinksHelper(patternlab, obj, key) {
var linkRE, dataObjAsString, linkMatches, expandedLink;
var linkRE, dataObjAsString, linkMatches;

linkRE = /link\.[A-z0-9-_]+/g;
dataObjAsString = JSON5.stringify(obj);
linkMatches = dataObjAsString.match(linkRE);

if (linkMatches) {
for (var i = 0; i < linkMatches.length; i++) {
expandedLink = encodeURI(patternlab.data.link[linkMatches[i].split('.')[1]]);
if (expandedLink) {
expandedLink = expandedLink.replace('\\', '/');
if (patternlab.config.debug) {
console.log('expanded data link from ' + linkMatches[i] + ' to ' + expandedLink + ' inside ' + key);
var dataLink = linkMatches[i];
if (dataLink && dataLink.split('.').length >= 2) {
var linkPatternPartial = dataLink.split('.')[1];
var pattern = getPartial(linkPatternPartial, patternlab);
if (pattern !== undefined) {
var fullLink = patternlab.data.link[linkPatternPartial];
if (fullLink) {
fullLink = path.normalize(fullLink).replace(/\\/g, '/');
if (patternlab.config.debug) {
console.log('expanded data link from ' + dataLink + ' to ' + fullLink + ' inside ' + key);
}
dataObjAsString = dataObjAsString.replace(dataLink, fullLink);
}
} else {
console.log('pattern not found for', dataLink, 'inside', key);
}
dataObjAsString = dataObjAsString.replace(linkMatches[i], expandedLink);
}
}
}
Expand All @@ -449,7 +458,7 @@ var pattern_assembler = function () {

//loop through all patterns
for (var i = 0; i < patternlab.patterns.length; i++) {
patternlab.patterns[i].jsonFileData = parseDataLinksHelper(patternlab, patternlab.patterns[i].jsonFileData, patternlab.patterns[i].partial);
patternlab.patterns[i].jsonFileData = parseDataLinksHelper(patternlab, patternlab.patterns[i].jsonFileData, patternlab.patterns[i].patternPartial);
}
}

Expand Down
12 changes: 9 additions & 3 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,19 @@ var ui_builder = function () {
* @returns {{patternPartial: string, patternName: (*|string), patternState: string, patternSrcPath: string, patternPath: string}}
*/
function createPatternSubTypeItem(pattern) {
var patternPath = '';
if (pattern.isFlatPattern) {
patternPath = pattern.flatPatternPath + '-' + pattern.fileName + '/' + pattern.flatPatternPath + '-' + pattern.fileName + '.html';
} else {
patternPath = pattern.flatPatternPath + '/' + pattern.flatPatternPath + '.html';
}

return {
patternPartial: pattern.patternPartial,
patternName: pattern.patternName,
patternState: pattern.patternState,
patternSrcPath: encodeURI(pattern.subdir + pattern.filename),
patternPath: encodeURI(pattern.flatPatternPath + '/' + pattern.flatPatternPath + '.html')
patternSrcPath: encodeURI(pattern.subdir + '/' + pattern.fileName),
patternPath: patternPath
}
}

Expand Down Expand Up @@ -299,7 +306,6 @@ var ui_builder = function () {
patternType.patternItems.push({
patternPartial: 'viewall-' + pattern.patternGroup + '-all',
patternName: 'View All',
patternSrcPath: encodeURI(pattern.patternType + '/index.html'),
patternPath: encodeURI(pattern.patternType + '/index.html')
});
}
Expand Down

0 comments on commit cfee9ff

Please sign in to comment.