Skip to content

Commit be5c9c6

Browse files
author
Brian Muenzenmeyer
authored
Merge pull request #361 from pattern-lab/dev-2.0-core
2.0.0-alpha
2 parents 133d07c + 7c2d2fd commit be5c9c6

File tree

210 files changed

+3404
-19924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

210 files changed

+3404
-19924
lines changed

.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
"eqeqeq": [2, "allow-null"],
1515
"global-strict": [0, "never"],
1616
"guard-for-in": 2,
17-
"indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 1}],
18-
"lines-around-comment": [2, {
17+
"indent": [1, 2, {"SwitchCase": 1, "VariableDeclarator": 1}],
18+
"lines-around-comment": [1, {
1919
"beforeBlockComment": true,
2020
"beforeLineComment": true,
2121
"allowBlockStart": true,

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
node_modules/
2-
npm-debug.log
32
.DS_Store
43
latest-change.txt
54
patternlab.json

.travis.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
language: node_js
22

33
node_js:
4-
- stable
5-
- 4.0
6-
- 0.12
7-
- 0.11
4+
- node
5+
- 6
6+
- 5
7+
- 4
88

99
before_install:
1010
- phantomjs --version
@@ -16,3 +16,12 @@ branches:
1616
only:
1717
- master
1818
- dev
19+
- 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: 10 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,168 +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 + '**/*.mustache'),
88-
path.resolve(paths().source.patterns + '**/*.json'),
89-
path.resolve(paths().source.fonts + '/*'),
90-
path.resolve(paths().source.images + '/*'),
91-
path.resolve(paths().source.data + '*.json'),
92-
path.resolve(paths().source.js + '/*.js')
93-
],
94-
tasks: ['default', 'bsReload:css']
9517
}
9618
},
9719
nodeunit: {
9820
all: ['test/*_tests.js']
9921
},
100-
browserSync: {
101-
dev: {
102-
options: {
103-
server: path.resolve(paths().public.root),
104-
watchTask: true,
105-
watchOptions: {
106-
ignoreInitial: true,
107-
ignored: '*.html'
108-
},
109-
snippetOptions: {
110-
// Ignore all HTML files within the templates folder
111-
blacklist: ['/index.html', '/', '/?*']
112-
},
113-
plugins: [
114-
{
115-
module: 'bs-html-injector',
116-
options: {
117-
files: [path.resolve(paths().public.root + '/index.html'), path.resolve(paths().public.styleguide + '/styleguide.html')]
118-
}
119-
}
120-
],
121-
notify: {
122-
styles: [
123-
'display: none',
124-
'padding: 15px',
125-
'font-family: sans-serif',
126-
'position: fixed',
127-
'font-size: 1em',
128-
'z-index: 9999',
129-
'bottom: 0px',
130-
'right: 0px',
131-
'border-top-left-radius: 5px',
132-
'background-color: #1B2032',
133-
'opacity: 0.4',
134-
'margin: 0',
135-
'color: white',
136-
'text-align: center'
137-
]
138-
}
139-
}
140-
}
141-
},
14222
eslint: {
14323
options: {
14424
configFile: './.eslintrc'
14525
},
14626
target: ['./core/lib/*']
147-
},
148-
bsReload: {
149-
css: path.resolve(paths().public.root + '**/*.css')
15027
}
15128
});
15229

15330
// load all grunt tasks
154-
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
155-
156-
//load the patternlab task
157-
grunt.task.loadTasks('./core/lib/');
158-
159-
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');
16034

16135
//travis CI task
162-
grunt.registerTask('travis', ['nodeunit', 'eslint', 'patternlab']);
163-
164-
grunt.registerTask('serve', ['patternlab', 'copy:main', 'copy:styleguide', 'browserSync', 'watch:all']);
36+
grunt.registerTask('travis', ['nodeunit', 'eslint']);
16537

38+
//to be run prior to releasing a version
16639
grunt.registerTask('build', ['nodeunit', 'eslint', 'concat']);
16740

16841
};

core/lib/annotation_exporter.js

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
_ = require('lodash'),
8+
md = require('markdown-it')(),
9+
paths = pl.config.paths;
10+
11+
/*
12+
Returns the array of comments that used to be wrapped in raw JS.
13+
*/
14+
function parseAnnotationsJS() {
15+
//attempt to read the file
16+
try {
17+
var oldAnnotations = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.js'), 'utf8');
18+
} catch (ex) {
19+
console.log('annotations.js file missing from ' + paths.source.annotations + '. This may be expected.');
20+
return [];
21+
}
22+
23+
//parse as JSON by removing the old wrapping js syntax. comments and the trailing semi-colon
24+
oldAnnotations = oldAnnotations.replace('var comments = ', '');
25+
try {
26+
var oldAnnotationsJSON = JSON5.parse(oldAnnotations.trim().slice(0, -1));
27+
} catch (ex) {
28+
console.log('There was an error parsing JSON for ' + paths.source.annotations + 'annotations.js');
29+
console.log(ex);
30+
return [];
31+
}
32+
return oldAnnotationsJSON.comments;
33+
}
34+
35+
/*
36+
Converts the annotations.md file yaml list into an array of annotations
37+
*/
38+
function parseAnnotationsMD() {
39+
var annotations = [];
40+
41+
//attempt to read the file
42+
var annotationsMD = '';
43+
try {
44+
annotationsMD = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.md'), 'utf8');
45+
} catch (ex) {
46+
console.log('annotations.md file missing from ' + paths.source.annotations + '. This may be expected.');
47+
return [];
48+
}
49+
50+
//take the annotation snippets and split them on our custom delimiter
51+
var annotationsYAML = annotationsMD.split('~*~');
52+
for (var i = 0; i < annotationsYAML.length; i++) {
53+
var annotation = {};
54+
55+
//for each annotation process the yaml frontmatter and markdown
56+
var annotationSnippet = annotationsYAML[i];
57+
var annotationsRE = /---\r?\n{1}([\s\S]*)---\r?\n{1}([\s\S]*)+/gm;
58+
var chunks = annotationsRE.exec(annotationSnippet);
59+
if (chunks && chunks[1] && chunks[2]) {
60+
61+
//convert each yaml frontmatter key into an object key
62+
var frontmatter = chunks[1];
63+
var frontmatterLines = frontmatter.split(/\n/gm);
64+
for (var j = 0; j < frontmatterLines.length; j++) {
65+
var frontmatterLine = frontmatterLines[j];
66+
if (frontmatterLine.length > 0) {
67+
var frontmatterLineChunks = frontmatterLine.split(':'); //test this
68+
var frontmatterKey = frontmatterLineChunks[0].toLowerCase().trim();
69+
var frontmatterValueString = frontmatterLineChunks[1].trim();
70+
var frontmatterValue = frontmatterValueString.substring(1, frontmatterValueString.length - 1);
71+
if (frontmatterKey === 'el' || frontmatterKey === 'selector') {
72+
annotation.el = frontmatterValue;
73+
}
74+
if (frontmatterKey === 'title') {
75+
annotation.title = frontmatterValue;
76+
}
77+
}
78+
}
79+
80+
//set the comment to the parsed markdown
81+
var annotationMarkdown = chunks[2];
82+
annotation.comment = md.render(annotationMarkdown);
83+
84+
annotations.push(annotation);
85+
} else {
86+
console.log('annotations.md file not formatted as expected. Error parsing frontmatter and markdown out of ' + annotationSnippet);
87+
}
88+
}
89+
return annotations;
90+
}
91+
92+
function gatherAnnotations() {
93+
var annotationsJS = parseAnnotationsJS();
94+
var annotationsMD = parseAnnotationsMD();
95+
var mergedAnnotations = _.unionBy(annotationsJS, annotationsMD, 'el');
96+
return mergedAnnotations;
97+
}
98+
99+
return {
100+
gather: function () {
101+
return gatherAnnotations();
102+
},
103+
gatherJS: function () {
104+
return parseAnnotationsJS();
105+
},
106+
gatherMD: function () {
107+
return parseAnnotationsMD();
108+
}
109+
};
110+
111+
};
112+
113+
module.exports = annotations_exporter;

0 commit comments

Comments
 (0)