Skip to content

Commit 3ea5911

Browse files
committed
Merge remote-tracking branch 'refs/remotes/origin/dev-2.0-core' into load-engines
2 parents 9b8589c + 4b1edb4 commit 3ea5911

30 files changed

+571
-716
lines changed

.travis.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ language: node_js
22

33
node_js:
44
- stable
5+
- 5.0
56
- 4.0
6-
- 0.12
7-
- 0.11
87

98
before_install:
109
- phantomjs --version
@@ -18,3 +17,11 @@ branches:
1817
- dev
1918
- pattern-engines
2019
- dev-2.0-core
20+
21+
notifications:
22+
webhooks:
23+
urls:
24+
- https://webhooks.gitter.im/e/a14f537f16b0756d9470
25+
on_success: always
26+
on_failure: always
27+
on_start: never

Gruntfile.js

Lines changed: 9 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,167 +1,41 @@
11
module.exports = function (grunt) {
22

3-
var path = require('path');
4-
5-
function paths() {
6-
return require('./patternlab-config.json').paths;
7-
}
8-
9-
// Project configuration.
3+
/******************************
4+
* Project configuration.
5+
* Should only be needed if you are developing against core, running tests, linting and want to run tests or increment package numbers
6+
*****************************/
107
grunt.initConfig({
118
pkg: grunt.file.readJSON('package.json'),
129
concat: {
1310
options: {
1411
stripBanners: true,
15-
banner: '/* \n * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy") %> \n * \n * <%= pkg.author %>, and the web community.\n * Licensed under the <%= pkg.license %> license. \n * \n * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. \n *\n */\n\n',
12+
banner: '/* \n * <%= pkg.name %> - v<%= pkg.version %> - <%= grunt.template.today("yyyy") %> \n * \n * <%= pkg.author.name %>, <%= pkg.contributors[0].name %>, and the web community.\n * Licensed under the <%= pkg.license %> license. \n * \n * Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice. \n *\n */\n\n',
1613
},
1714
patternlab: {
1815
src: './core/lib/patternlab.js',
1916
dest: './core/lib/patternlab.js'
20-
},
21-
object_factory: {
22-
src: './core/lib/object_factory.js',
23-
dest: './core/lib/object_factory.js'
24-
},
25-
lineage: {
26-
src: './core/lib/lineage_hunter.js',
27-
dest: './core/lib/lineage_hunter.js'
28-
},
29-
media_hunter: {
30-
src: './core/lib/media_hunter.js',
31-
dest: './core/lib/media_hunter.js'
32-
},
33-
patternlab_grunt: {
34-
src: './core/lib/patternlab_grunt.js',
35-
dest: './core/lib/patternlab_grunt.js'
36-
},
37-
patternlab_gulp: {
38-
src: './core/lib/patternlab_gulp.js',
39-
dest: './core/lib/patternlab_gulp.js'
40-
},
41-
parameter_hunter: {
42-
src: './core/lib/parameter_hunter.js',
43-
dest: './core/lib/parameter_hunter.js'
44-
},
45-
pattern_exporter: {
46-
src: './core/lib/pattern_exporter.js',
47-
dest: './core/lib/pattern_exporter.js'
48-
},
49-
pattern_assembler: {
50-
src: './core/lib/pattern_assembler.js',
51-
dest: './core/lib/pattern_assembler.js'
52-
},
53-
pseudopattern_hunter: {
54-
src: './core/lib/pseudopattern_hunter.js',
55-
dest: './core/lib/pseudopattern_hunter.js'
56-
},
57-
list_item_hunter: {
58-
src: './core/lib/list_item_hunter.js',
59-
dest: './core/lib/list_item_hunter.js'
60-
},
61-
style_modifier_hunter: {
62-
src: './core/lib/style_modifier_hunter.js',
63-
dest: './core/lib/style_modifier_hunter.js'
64-
}
65-
},
66-
copy: {
67-
main: {
68-
files: [
69-
{ expand: true, cwd: path.resolve(paths().source.js), src: '*.js', dest: path.resolve(paths().public.js) },
70-
{ expand: true, cwd: path.resolve(paths().source.css), src: '*.css', dest: path.resolve(paths().public.css) },
71-
{ expand: true, cwd: path.resolve(paths().source.images), src: ['**/*.png', '**/*.jpg', '**/*.gif', '**/*.jpeg'], dest: path.resolve(paths().public.images) },
72-
{ expand: true, cwd: path.resolve(paths().source.fonts), src: '*', dest: path.resolve(paths().public.fonts) },
73-
{ expand: true, cwd: path.resolve(paths().source.data), src: 'annotations.js', dest: path.resolve(paths().public.data) }
74-
]
75-
},
76-
styleguide: {
77-
files: [
78-
{ expand: true, cwd: path.resolve(paths().source.styleguide), src: ['*.*', '**/*.*'], dest: path.resolve(paths().public.styleguide) }
79-
]
80-
}
81-
},
82-
watch: {
83-
all: {
84-
files: [
85-
path.resolve(paths().source.css + '**/*.css'),
86-
path.resolve(paths().source.styleguide + 'css/*.css'),
87-
path.resolve(paths().source.patterns + '**/*'),
88-
path.resolve(paths().source.fonts + '/*'),
89-
path.resolve(paths().source.images + '/*'),
90-
path.resolve(paths().source.data + '*.json'),
91-
path.resolve(paths().source.js + '/*.js')
92-
],
93-
tasks: ['default', 'bsReload:css']
9417
}
9518
},
9619
nodeunit: {
9720
all: ['test/*_tests.js']
9821
},
99-
browserSync: {
100-
dev: {
101-
options: {
102-
server: path.resolve(paths().public.root),
103-
watchTask: true,
104-
watchOptions: {
105-
ignoreInitial: true,
106-
ignored: '*.html'
107-
},
108-
snippetOptions: {
109-
// Ignore all HTML files within the templates folder
110-
blacklist: ['/index.html', '/', '/?*']
111-
},
112-
plugins: [
113-
{
114-
module: 'bs-html-injector',
115-
options: {
116-
files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')]
117-
}
118-
}
119-
],
120-
notify: {
121-
styles: [
122-
'display: none',
123-
'padding: 15px',
124-
'font-family: sans-serif',
125-
'position: fixed',
126-
'font-size: 1em',
127-
'z-index: 9999',
128-
'bottom: 0px',
129-
'right: 0px',
130-
'border-top-left-radius: 5px',
131-
'background-color: #1B2032',
132-
'opacity: 0.4',
133-
'margin: 0',
134-
'color: white',
135-
'text-align: center'
136-
]
137-
}
138-
}
139-
}
140-
},
14122
eslint: {
14223
options: {
14324
configFile: './.eslintrc'
14425
},
14526
target: ['./core/lib/*']
146-
},
147-
bsReload: {
148-
css: path.resolve(paths().public.root + '**/*.css')
14927
}
15028
});
15129

15230
// load all grunt tasks
153-
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
154-
155-
//load the patternlab task
156-
require('./core/lib/patternlab_grunt')(grunt);
157-
158-
grunt.registerTask('default', ['patternlab', 'copy:main', 'copy:styleguide']);
31+
grunt.loadNpmTasks('grunt-contrib-concat');
32+
grunt.loadNpmTasks('grunt-eslint');
33+
grunt.loadNpmTasks('grunt-contrib-nodeunit');
15934

16035
//travis CI task
16136
grunt.registerTask('travis', ['nodeunit', 'eslint']);
16237

163-
grunt.registerTask('serve', ['patternlab', 'copy:main', 'copy:styleguide', 'browserSync', 'watch:all']);
164-
38+
//to be run prior to releasing a version
16539
grunt.registerTask('build', ['nodeunit', 'eslint', 'concat']);
16640

16741
};

core/lib/annotation_exporter.js

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,19 @@ var annotations_exporter = function (pl) {
44
var path = require('path'),
55
fs = require('fs-extra'),
66
JSON5 = require('json5'),
7+
_ = require('lodash'),
8+
md = require('markdown-it')(),
79
paths = pl.config.paths;
810

9-
// HELPER FUNCTIONS
11+
/*
12+
Returns the array of comments that used to be wrapped in raw JS.
13+
*/
1014
function parseAnnotationsJS() {
1115
//attempt to read the file
1216
try {
1317
var oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
1418
} catch (ex) {
15-
console.log(ex, 'This may be expected.');
19+
console.log(ex, 'annotations.js file missing from ' + paths.source.annotations + '. This may be expected.');
1620
}
1721

1822
//parse as JSON by removing the old wrapping js syntax. comments and the trailing semi-colon
@@ -23,17 +27,81 @@ var annotations_exporter = function (pl) {
2327
console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js');
2428
console.log(ex);
2529
}
26-
return oldAnnotationsJSON;
30+
return oldAnnotationsJSON.comments;
31+
}
32+
33+
/*
34+
Converts the annotations.md file yaml list into an array of annotations
35+
*/
36+
function parseAnnotationsMD() {
37+
var annotations = [];
38+
39+
//attempt to read the file
40+
var annotationsMD = '';
41+
try {
42+
annotationsMD = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.md'), 'utf8');
43+
} catch (ex) {
44+
console.log(ex, 'annotations.md file missing from ' + paths.source.annotations + '. This may be expected.');
45+
}
46+
47+
//take the annotation snippets and split them on our custom delimiter
48+
var annotationsYAML = annotationsMD.split('~*~');
49+
for (var i = 0; i < annotationsYAML.length; i++) {
50+
var annotation = {};
51+
52+
//for each annotation process the yaml frontmatter and markdown
53+
var annotationSnippet = annotationsYAML[i];
54+
var annotationsRE = /---\r?\n{1}([\s\S]*)---\r?\n{1}([\s\S]*)+/gm;
55+
var chunks = annotationsRE.exec(annotationSnippet);
56+
if (chunks && chunks[1] && chunks[2]) {
57+
58+
//convert each yaml frontmatter key into an object key
59+
var frontmatter = chunks[1];
60+
var frontmatterLines = frontmatter.split(/\n/gm);
61+
for (var j = 0; j < frontmatterLines.length; j++) {
62+
var frontmatterLine = frontmatterLines[j];
63+
if (frontmatterLine.length > 0) {
64+
var frontmatterLineChunks = frontmatterLine.split(':'); //test this
65+
var frontmatterKey = frontmatterLineChunks[0].toLowerCase().trim();
66+
var frontmatterValueString = frontmatterLineChunks[1].trim();
67+
var frontmatterValue = frontmatterValueString.substring(1, frontmatterValueString.length - 1);
68+
if (frontmatterKey === 'el' || frontmatterKey === 'selector') {
69+
annotation.el = frontmatterValue;
70+
}
71+
if (frontmatterKey === 'title') {
72+
annotation.title = frontmatterValue;
73+
}
74+
}
75+
}
76+
77+
//set the comment to the parsed markdown
78+
var annotationMarkdown = chunks[2];
79+
annotation.comment = md.render(annotationMarkdown);
80+
81+
annotations.push(annotation);
82+
} else {
83+
console.log('annotations.md file not formatted as expected. Error parsing frontmatter and markdown out of ' + annotationSnippet);
84+
}
85+
}
86+
return annotations;
2787
}
2888

2989
function gatherAnnotations() {
30-
//todo: merge markdown too https://github.com/pattern-lab/patternlab-php-core/blob/c2c4bc6a8bda2b2f9c08b197669ebc94c025e7c6/src/PatternLab/Annotations.php
31-
return parseAnnotationsJS();
90+
var annotationsJS = parseAnnotationsJS();
91+
var annotationsMD = parseAnnotationsMD();
92+
var mergedAnnotations = _.unionBy(annotationsJS, annotationsMD, 'el');
93+
return mergedAnnotations;
3294
}
3395

3496
return {
3597
gather: function () {
3698
return gatherAnnotations();
99+
},
100+
gatherJS: function () {
101+
return parseAnnotationsJS();
102+
},
103+
gatherMD: function () {
104+
return parseAnnotationsMD();
37105
}
38106
};
39107

core/lib/lineage_hunter.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
/*
2-
* patternlab-node - v1.3.0 - 2016
3-
*
4-
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
8-
*
9-
*/
10-
111
"use strict";
122

133
var lineage_hunter = function () {
@@ -112,7 +102,7 @@ var lineage_hunter = function () {
112102
< patternlab.config.patternStateCascade.indexOf(lineageRPattern.patternState))) {
113103

114104
if (patternlab.config.debug) {
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));
105+
console.log('Found a lower common denominator pattern state: ' + pattern.patternState + ' on ' + pattern.patternPartial + '. Setting reverse lineage pattern ' + lineageRPattern.patternPartial + ' from ' + (lineageRPattern.patternState === '' ? '<<blank>>' : lineageRPattern.patternState));
116106
}
117107

118108
lineageRPattern.patternState = pattern.patternState;

core/lib/list_item_hunter.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
/*
2-
* patternlab-node - v1.3.0 - 2016
3-
*
4-
* Brian Muenzenmeyer, and the web community.
5-
* Licensed under the MIT license.
6-
*
7-
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
8-
*
9-
*/
10-
111
"use strict";
122

133
var list_item_hunter = function () {
@@ -17,7 +7,7 @@ var list_item_hunter = function () {
177
pa = require('./pattern_assembler'),
188
smh = require('./style_modifier_hunter'),
199
plutils = require('./utilities'),
20-
of = require('./object_factory');
10+
Pattern = require('./object_factory').Pattern;
2111

2212
var pattern_assembler = new pa(),
2313
style_modifier_hunter = new smh(),
@@ -54,7 +44,7 @@ var list_item_hunter = function () {
5444
try {
5545
listData = JSON5.parse(JSON5.stringify(patternlab.listitems));
5646
} catch (err) {
57-
console.log('There was an error parsing JSON for ' + pattern.abspath);
47+
console.log('There was an error parsing JSON for ' + pattern.relPath);
5848
console.log(err);
5949
}
6050
listData = plutils.mergeData(listData, pattern.listitems);
@@ -73,7 +63,7 @@ var list_item_hunter = function () {
7363
globalData = JSON5.parse(JSON5.stringify(patternlab.data));
7464
localData = JSON5.parse(JSON5.stringify(pattern.jsonFileData));
7565
} catch (err) {
76-
console.log('There was an error parsing JSON for ' + pattern.abspath);
66+
console.log('There was an error parsing JSON for ' + pattern.relPath);
7767
console.log(err);
7868
}
7969

@@ -82,7 +72,7 @@ var list_item_hunter = function () {
8272
allData.link = extend({}, patternlab.data.link);
8373

8474
//check for partials within the repeated block
85-
var foundPartials = of.oPattern.createEmpty({'template': thisBlockTemplate}).findPartials();
75+
var foundPartials = Pattern.createEmpty({'template': thisBlockTemplate}).findPartials();
8676

8777
if (foundPartials && foundPartials.length > 0) {
8878

@@ -97,7 +87,7 @@ var list_item_hunter = function () {
9787
try {
9888
cleanPartialPattern = JSON5.parse(JSON5.stringify(partialPattern));
9989
} catch (err) {
100-
console.log('There was an error parsing JSON for ' + pattern.abspath);
90+
console.log('There was an error parsing JSON for ' + pattern.relPath);
10191
console.log(err);
10292
}
10393

0 commit comments

Comments
 (0)