Skip to content

Commit 65c108c

Browse files
author
Brian Muenzenmeyer
authored
Merge pull request #398 from pattern-lab/dev
Pattern Lab Node 2.2.1
2 parents 7c7ff39 + b2242e5 commit 65c108c

File tree

8 files changed

+70
-54
lines changed

8 files changed

+70
-54
lines changed

core/lib/annotation_exporter.js

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22

33
var path = require('path'),
4+
glob = require('glob'),
45
fs = require('fs-extra'),
56
JSON5 = require('json5'),
67
_ = require('lodash'),
@@ -38,38 +39,42 @@ var annotations_exporter = function (pl) {
3839
return oldAnnotationsJSON.comments;
3940
}
4041

41-
/*
42-
Converts the annotations.md file yaml list into an array of annotations
43-
*/
44-
function parseAnnotationsMD() {
45-
var markdown_parser = new mp();
46-
var annotations = [];
42+
function buildAnnotationMD(annotationsYAML, markdown_parser) {
43+
var annotation = {};
44+
var markdownObj = markdown_parser.parse(annotationsYAML);
4745

48-
//attempt to read the file
49-
var annotationsMD = '';
50-
try {
51-
annotationsMD = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.md'), 'utf8');
52-
} catch (ex) {
53-
if (pl.config.debug) {
54-
console.log('annotations.md file missing from ' + paths.source.annotations + '. This may be expected.');
55-
}
56-
return [];
57-
}
46+
annotation.el = markdownObj.el || markdownObj.selector;
47+
annotation.title = markdownObj.title;
48+
annotation.comment = markdownObj.markdown;
49+
return annotation;
50+
}
5851

59-
//take the annotation snippets and split them on our custom delimiter
60-
var annotationsYAML = annotationsMD.split('~*~');
52+
function parseMDFile(annotations, parser) {
53+
var annotations = annotations;
54+
var markdown_parser = parser;
6155

62-
for (var i = 0; i < annotationsYAML.length; i++) {
63-
var annotation = {};
56+
return function (filePath) {
57+
var annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8');
6458

65-
var markdownObj = markdown_parser.parse(annotationsYAML[i]);
59+
//take the annotation snippets and split them on our custom delimiter
60+
var annotationsYAML = annotationsMD.split('~*~');
61+
for (var i = 0; i < annotationsYAML.length; i++) {
62+
var annotation = buildAnnotationMD(annotationsYAML[i], markdown_parser)
63+
annotations.push(annotation);
64+
}
65+
return false;
66+
}
67+
}
6668

67-
annotation.el = markdownObj.el || markdownObj.selector;
68-
annotation.title = markdownObj.title;
69-
annotation.comment = markdownObj.markdown;
69+
/*
70+
Converts the *.md file yaml list into an array of annotations
71+
*/
72+
function parseAnnotationsMD() {
73+
var markdown_parser = new mp();
74+
var annotations = [];
75+
var mdFiles = glob.sync(paths.source.annotations + '/*.md')
7076

71-
annotations.push(annotation);
72-
}
77+
mdFiles.forEach(parseMDFile(annotations, markdown_parser));
7378
return annotations;
7479
}
7580

core/lib/patternlab.js

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

core/lib/ui_builder.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,15 @@ function buildViewAllHTML(patternlab, patterns, patternPartial) {
299299
return viewAllHTML;
300300
}
301301

302-
function buildViewAllPages(mainPageHeadHtml, patternlab) {
302+
function buildViewAllPages(mainPageHeadHtml, patternlab, styleguidePatterns) {
303303
var paths = patternlab.config.paths;
304304
var prevSubdir = '';
305305
var prevGroup = '';
306306
var i;
307307

308-
for (i = 0; i < patternlab.patterns.length; i++) {
308+
for (i = 0; i < styleguidePatterns.length; i++) {
309309

310-
var pattern = patternlab.patterns[i];
310+
var pattern = styleguidePatterns[i];
311311

312312
// skip underscore-prefixed files
313313
if (isPatternExcluded(pattern)) {
@@ -336,29 +336,29 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) {
336336
var j;
337337

338338

339-
for (j = 0; j < patternlab.patterns.length; j++) {
339+
for (j = 0; j < styleguidePatterns.length; j++) {
340340

341341

342-
if (patternlab.patterns[j].patternGroup === pattern.patternGroup) {
342+
if (styleguidePatterns[j].patternGroup === pattern.patternGroup) {
343343
//again, skip any sibling patterns to the current one that may have underscores
344344

345-
if (isPatternExcluded(patternlab.patterns[j])) {
345+
if (isPatternExcluded(styleguidePatterns[j])) {
346346
if (patternlab.config.debug) {
347-
console.log('Omitting ' + patternlab.patterns[j].patternPartial + " from view all sibling rendering.");
347+
console.log('Omitting ' + styleguidePatterns[j].patternPartial + " from view all sibling rendering.");
348348
}
349349
continue;
350350
}
351351

352352
//this is meant to be a homepage that is not present anywhere else
353-
if (patternlab.patterns[j].patternPartial === patternlab.config.defaultPattern) {
353+
if (styleguidePatterns[j].patternPartial === patternlab.config.defaultPattern) {
354354
if (patternlab.config.debug) {
355355
console.log('Omitting ' + pattern.patternPartial + ' from view all sibling rendering because it is defined as a defaultPattern');
356356
}
357357
continue;
358358
}
359359

360360

361-
viewAllPatterns.push(patternlab.patterns[j]);
361+
viewAllPatterns.push(styleguidePatterns[j]);
362362
}
363363
}
364364

@@ -379,26 +379,26 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) {
379379
viewAllPatterns = [];
380380
patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup;
381381

382-
for (j = 0; j < patternlab.patterns.length; j++) {
382+
for (j = 0; j < styleguidePatterns.length; j++) {
383383

384-
if (patternlab.patterns[j].subdir === pattern.subdir) {
384+
if (styleguidePatterns[j].subdir === pattern.subdir) {
385385
//again, skip any sibling patterns to the current one that may have underscores
386-
if (isPatternExcluded(patternlab.patterns[j])) {
386+
if (isPatternExcluded(styleguidePatterns[j])) {
387387
if (patternlab.config.debug) {
388-
console.log('Omitting ' + patternlab.patterns[j].patternPartial + " from view all sibling rendering.");
388+
console.log('Omitting ' + styleguidePatterns[j].patternPartial + " from view all sibling rendering.");
389389
}
390390
continue;
391391
}
392392

393393
//this is meant to be a homepage that is not present anywhere else
394-
if (patternlab.patterns[j].patternPartial === patternlab.config.defaultPattern) {
394+
if (styleguidePatterns[j].patternPartial === patternlab.config.defaultPattern) {
395395
if (patternlab.config.debug) {
396396
console.log('Omitting ' + pattern.patternPartial + ' from view all sibling rendering because it is defined as a defaultPattern');
397397
}
398398
continue;
399399
}
400400

401-
viewAllPatterns.push(patternlab.patterns[j]);
401+
viewAllPatterns.push(styleguidePatterns[j]);
402402
}
403403

404404
}
@@ -446,7 +446,7 @@ function buildFrontEnd(patternlab) {
446446
styleguidePatterns = assembleStyleguidePatterns(patternlab);
447447

448448
//sort all patterns explicitly.
449-
patternlab.patterns = sortPatterns(styleguidePatterns);
449+
styleguidePatterns = sortPatterns(styleguidePatterns);
450450

451451
//set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header
452452
var headerPartial = pattern_assembler.renderPattern(patternlab.header, {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "patternlab-node",
33
"description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).",
4-
"version": "2.2.0",
4+
"version": "2.2.1",
55
"main": "./core/lib/patternlab.js",
66
"dependencies": {
77
"diveSync": "^0.3.0",
@@ -36,7 +36,7 @@
3636
},
3737
"contributors": [
3838
{
39-
"name" : "Geoff Pursell"
39+
"name": "Geoff Pursell"
4040
}
4141
],
4242
"license": "MIT",

test/annotation_exporter_tests.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
var eol = require('os').EOL;
44
var Pattern = require('../core/lib/object_factory').Pattern;
55
var extend = require('util')._extend;
6+
var anPath = './test/files/';
67

7-
function createFakePatternLab(customProps) {
8+
function createFakePatternLab(anPath, customProps) {
89
var pl = {
910
"config": {
1011
"paths": {
1112
"source": {
12-
"annotations": './test/files/'
13+
"annotations": anPath
1314
}
1415
}
1516
}
@@ -18,7 +19,7 @@ function createFakePatternLab(customProps) {
1819
return extend(pl, customProps);
1920
}
2021

21-
var patternlab = createFakePatternLab();
22+
var patternlab = createFakePatternLab(anPath);
2223
var ae = require('../core/lib/annotation_exporter')(patternlab);
2324

2425
exports['annotaton_exporter'] = {
@@ -65,5 +66,15 @@ exports['annotaton_exporter'] = {
6566

6667
test.done();
6768

69+
},
70+
71+
'when there are 0 annotation files' : function (test) {
72+
var emptyAnPath = './test/files/empty/';
73+
var patternlab2 = createFakePatternLab(emptyAnPath);
74+
var ae2 = require('../core/lib/annotation_exporter')(patternlab2);
75+
76+
var annotations = ae2.gather();
77+
test.equals(annotations.length, 0);
78+
test.done();
6879
}
6980
};

test/files/annotations.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,3 @@ selector: .logo
1010
title: Logo
1111
---
1212
The _logo image_ is an SVG file.
13-
~*~
14-
---
15-
el: #nav
16-
title : Navigation
17-
---
18-
Navigation for adaptive web experiences can be tricky. Refer to [these repsonsive patterns](https://bradfrost.github.io/this-is-responsive/patterns.html#navigation) when evaluating solutions.

test/files/empty/.gitkeep

Whitespace-only changes.

test/files/nav.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
el: #nav
3+
title : Navigation
4+
---
5+
Navigation for adaptive web experiences can be tricky. Refer to [these repsonsive patterns](https://bradfrost.github.io/this-is-responsive/patterns.html#navigation) when evaluating solutions.
6+

0 commit comments

Comments
 (0)