Skip to content

Commit 9b8589c

Browse files
committed
Merge branch 'dev-2.0-core' into load-engines
2 parents 7422b5b + fb3b240 commit 9b8589c

18 files changed

+638
-297
lines changed

core/lib/annotation_exporter.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use strict";
2+
3+
var annotations_exporter = function (pl) {
4+
var path = require('path'),
5+
fs = require('fs-extra'),
6+
JSON5 = require('json5'),
7+
paths = pl.config.paths;
8+
9+
// HELPER FUNCTIONS
10+
function parseAnnotationsJS() {
11+
//attempt to read the file
12+
try {
13+
var oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
14+
} catch (ex) {
15+
console.log(ex, 'This may be expected.');
16+
}
17+
18+
//parse as JSON by removing the old wrapping js syntax. comments and the trailing semi-colon
19+
oldAnnotations = oldAnnotations.replace('var comments = ', '');
20+
try {
21+
var oldAnnotationsJSON = JSON5.parse(oldAnnotations.trim().slice(0, -1));
22+
} catch (ex) {
23+
console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js');
24+
console.log(ex);
25+
}
26+
return oldAnnotationsJSON;
27+
}
28+
29+
function gatherAnnotations() {
30+
//todo: merge markdown too https://github.com/pattern-lab/patternlab-php-core/blob/c2c4bc6a8bda2b2f9c08b197669ebc94c025e7c6/src/PatternLab/Annotations.php
31+
return parseAnnotationsJS();
32+
}
33+
34+
return {
35+
gather: function () {
36+
return gatherAnnotations();
37+
}
38+
};
39+
40+
};
41+
42+
module.exports = annotations_exporter;

core/lib/lineage_hunter.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v1.2.0 - 2016
2+
* patternlab-node - v1.3.0 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -106,12 +106,13 @@ var lineage_hunter = function () {
106106
var lineageRPattern = pattern_assembler.findPartial(pattern.lineageRIndex[j], patternlab);
107107

108108
//only set patternState if pattern.patternState "is less than" the lineageRPattern.patternstate
109+
//or if lineageRPattern.patternstate (the consuming pattern) does not have a state
109110
//this makes patternlab apply the lowest common ancestor denominator
110-
if (patternlab.config.patternStateCascade.indexOf(pattern.patternState)
111-
< patternlab.config.patternStateCascade.indexOf(lineageRPattern.patternState)) {
111+
if (lineageRPattern.patternState === '' || (patternlab.config.patternStateCascade.indexOf(pattern.patternState)
112+
< patternlab.config.patternStateCascade.indexOf(lineageRPattern.patternState))) {
112113

113114
if (patternlab.config.debug) {
114-
console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.patternPartial + '. Setting reverse lineage pattern ' + lineageRPattern.patternPartial + ' from ' + lineageRPattern.patternState);
115+
console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.key + '. Setting reverse lineage pattern ' + lineageRPattern.patternPartial + ' from ' + (lineageRPattern.patternState === '' ? '<<blank>>' : lineageRPattern.patternState));
115116
}
116117

117118
lineageRPattern.patternState = pattern.patternState;

core/lib/list_item_hunter.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v1.2.1 - 2016
2+
* patternlab-node - v1.3.0 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.
@@ -13,6 +13,7 @@
1313
var list_item_hunter = function () {
1414

1515
var extend = require('util')._extend,
16+
JSON5 = require('json5'),
1617
pa = require('./pattern_assembler'),
1718
smh = require('./style_modifier_hunter'),
1819
plutils = require('./utilities'),
@@ -49,7 +50,13 @@ var list_item_hunter = function () {
4950
}
5051

5152
//check for a local listitems.json file
52-
var listData = JSON.parse(JSON.stringify(patternlab.listitems));
53+
var listData;
54+
try {
55+
listData = JSON5.parse(JSON5.stringify(patternlab.listitems));
56+
} catch (err) {
57+
console.log('There was an error parsing JSON for ' + pattern.abspath);
58+
console.log(err);
59+
}
5360
listData = plutils.mergeData(listData, pattern.listitems);
5461

5562
//iterate over each copied block, rendering its contents along with pattenlab.listitems[i]
@@ -60,8 +67,15 @@ var list_item_hunter = function () {
6067

6168
//combine listItem data with pattern data with global data
6269
var itemData = listData['' + items.indexOf(loopNumberString)]; //this is a property like "2"
63-
var globalData = JSON.parse(JSON.stringify(patternlab.data));
64-
var localData = JSON.parse(JSON.stringify(pattern.jsonFileData));
70+
var globalData;
71+
var localData;
72+
try {
73+
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
74+
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData));
75+
} catch (err) {
76+
console.log('There was an error parsing JSON for ' + pattern.abspath);
77+
console.log(err);
78+
}
6579

6680
var allData = plutils.mergeData(globalData, localData);
6781
allData = plutils.mergeData(allData, itemData !== undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup
@@ -78,8 +92,14 @@ var list_item_hunter = function () {
7892
var partialName = foundPartials[j].match(/([\w\-\.\/~]+)/g)[0];
7993
var partialPattern = pattern_assembler.findPartial(partialName, patternlab);
8094

81-
//create a copy of the partial so as to not pollute it after the findPartial call.
82-
var cleanPartialPattern = JSON.parse(JSON.stringify(partialPattern));
95+
//create a copy of the partial so as to not pollute it after the get_pattern_by_key call.
96+
var cleanPartialPattern;
97+
try {
98+
cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
99+
} catch (err) {
100+
console.log('There was an error parsing JSON for ' + pattern.abspath);
101+
console.log(err);
102+
}
83103

84104
//if partial has style modifier data, replace the styleModifier value
85105
if (foundPartials[j].indexOf(':') > -1) {

core/lib/media_hunter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v1.2.1 - 2016
2+
* patternlab-node - v1.3.0 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

core/lib/object_factory.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* patternlab-node - v1.2.1 - 2016
2+
* patternlab-node - v1.3.0 - 2016
33
*
44
* Brian Muenzenmeyer, and the web community.
55
* Licensed under the MIT license.

0 commit comments

Comments
 (0)