diff --git a/core/lib/annotation_exporter.js b/core/lib/annotation_exporter.js index 240c2f755..8d4ebc3bb 100644 --- a/core/lib/annotation_exporter.js +++ b/core/lib/annotation_exporter.js @@ -1,6 +1,7 @@ "use strict"; var path = require('path'), + glob = require('glob'), fs = require('fs-extra'), JSON5 = require('json5'), _ = require('lodash'), @@ -38,38 +39,42 @@ var annotations_exporter = function (pl) { return oldAnnotationsJSON.comments; } - /* - Converts the annotations.md file yaml list into an array of annotations - */ - function parseAnnotationsMD() { - var markdown_parser = new mp(); - var annotations = []; + function buildAnnotationMD(annotationsYAML, markdown_parser) { + var annotation = {}; + var markdownObj = markdown_parser.parse(annotationsYAML); - //attempt to read the file - var annotationsMD = ''; - try { - annotationsMD = fs.readFileSync(path.resolve(paths.source.annotations, 'annotations.md'), 'utf8'); - } catch (ex) { - if (pl.config.debug) { - console.log('annotations.md file missing from ' + paths.source.annotations + '. This may be expected.'); - } - return []; - } + annotation.el = markdownObj.el || markdownObj.selector; + annotation.title = markdownObj.title; + annotation.comment = markdownObj.markdown; + return annotation; + } - //take the annotation snippets and split them on our custom delimiter - var annotationsYAML = annotationsMD.split('~*~'); + function parseMDFile(annotations, parser) { + var annotations = annotations; + var markdown_parser = parser; - for (var i = 0; i < annotationsYAML.length; i++) { - var annotation = {}; + return function (filePath) { + var annotationsMD = fs.readFileSync(path.resolve(filePath), 'utf8'); - var markdownObj = markdown_parser.parse(annotationsYAML[i]); + //take the annotation snippets and split them on our custom delimiter + var annotationsYAML = annotationsMD.split('~*~'); + for (var i = 0; i < annotationsYAML.length; i++) { + var annotation = buildAnnotationMD(annotationsYAML[i], markdown_parser) + annotations.push(annotation); + } + return false; + } + } - annotation.el = markdownObj.el || markdownObj.selector; - annotation.title = markdownObj.title; - annotation.comment = markdownObj.markdown; + /* + Converts the *.md file yaml list into an array of annotations + */ + function parseAnnotationsMD() { + var markdown_parser = new mp(); + var annotations = []; + var mdFiles = glob.sync(paths.source.annotations + '/*.md') - annotations.push(annotation); - } + mdFiles.forEach(parseMDFile(annotations, markdown_parser)); return annotations; } diff --git a/core/lib/patternlab.js b/core/lib/patternlab.js index 809646ee0..d0518ab77 100644 --- a/core/lib/patternlab.js +++ b/core/lib/patternlab.js @@ -1,5 +1,5 @@ /* - * patternlab-node - v2.2.0 - 2016 + * patternlab-node - v2.2.1 - 2016 * * Brian Muenzenmeyer, Geoff Pursell, and the web community. * Licensed under the MIT license. diff --git a/core/lib/ui_builder.js b/core/lib/ui_builder.js index eb3c33170..6e17fcd35 100644 --- a/core/lib/ui_builder.js +++ b/core/lib/ui_builder.js @@ -299,15 +299,15 @@ function buildViewAllHTML(patternlab, patterns, patternPartial) { return viewAllHTML; } -function buildViewAllPages(mainPageHeadHtml, patternlab) { +function buildViewAllPages(mainPageHeadHtml, patternlab, styleguidePatterns) { var paths = patternlab.config.paths; var prevSubdir = ''; var prevGroup = ''; var i; - for (i = 0; i < patternlab.patterns.length; i++) { + for (i = 0; i < styleguidePatterns.length; i++) { - var pattern = patternlab.patterns[i]; + var pattern = styleguidePatterns[i]; // skip underscore-prefixed files if (isPatternExcluded(pattern)) { @@ -336,21 +336,21 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) { var j; - for (j = 0; j < patternlab.patterns.length; j++) { + for (j = 0; j < styleguidePatterns.length; j++) { - if (patternlab.patterns[j].patternGroup === pattern.patternGroup) { + if (styleguidePatterns[j].patternGroup === pattern.patternGroup) { //again, skip any sibling patterns to the current one that may have underscores - if (isPatternExcluded(patternlab.patterns[j])) { + if (isPatternExcluded(styleguidePatterns[j])) { if (patternlab.config.debug) { - console.log('Omitting ' + patternlab.patterns[j].patternPartial + " from view all sibling rendering."); + console.log('Omitting ' + styleguidePatterns[j].patternPartial + " from view all sibling rendering."); } continue; } //this is meant to be a homepage that is not present anywhere else - if (patternlab.patterns[j].patternPartial === patternlab.config.defaultPattern) { + if (styleguidePatterns[j].patternPartial === patternlab.config.defaultPattern) { if (patternlab.config.debug) { console.log('Omitting ' + pattern.patternPartial + ' from view all sibling rendering because it is defined as a defaultPattern'); } @@ -358,7 +358,7 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) { } - viewAllPatterns.push(patternlab.patterns[j]); + viewAllPatterns.push(styleguidePatterns[j]); } } @@ -379,26 +379,26 @@ function buildViewAllPages(mainPageHeadHtml, patternlab) { viewAllPatterns = []; patternPartial = "viewall-" + pattern.patternGroup + "-" + pattern.patternSubGroup; - for (j = 0; j < patternlab.patterns.length; j++) { + for (j = 0; j < styleguidePatterns.length; j++) { - if (patternlab.patterns[j].subdir === pattern.subdir) { + if (styleguidePatterns[j].subdir === pattern.subdir) { //again, skip any sibling patterns to the current one that may have underscores - if (isPatternExcluded(patternlab.patterns[j])) { + if (isPatternExcluded(styleguidePatterns[j])) { if (patternlab.config.debug) { - console.log('Omitting ' + patternlab.patterns[j].patternPartial + " from view all sibling rendering."); + console.log('Omitting ' + styleguidePatterns[j].patternPartial + " from view all sibling rendering."); } continue; } //this is meant to be a homepage that is not present anywhere else - if (patternlab.patterns[j].patternPartial === patternlab.config.defaultPattern) { + if (styleguidePatterns[j].patternPartial === patternlab.config.defaultPattern) { if (patternlab.config.debug) { console.log('Omitting ' + pattern.patternPartial + ' from view all sibling rendering because it is defined as a defaultPattern'); } continue; } - viewAllPatterns.push(patternlab.patterns[j]); + viewAllPatterns.push(styleguidePatterns[j]); } } @@ -446,7 +446,7 @@ function buildFrontEnd(patternlab) { styleguidePatterns = assembleStyleguidePatterns(patternlab); //sort all patterns explicitly. - patternlab.patterns = sortPatterns(styleguidePatterns); + styleguidePatterns = sortPatterns(styleguidePatterns); //set the pattern-specific header by compiling the general-header with data, and then adding it to the meta header var headerPartial = pattern_assembler.renderPattern(patternlab.header, { diff --git a/package.json b/package.json index 8aea62ad0..c48a2821d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "patternlab-node", "description": "Pattern Lab is a collection of tools to help you create atomic design systems. This is the node command line interface (CLI).", - "version": "2.2.0", + "version": "2.2.1", "main": "./core/lib/patternlab.js", "dependencies": { "diveSync": "^0.3.0", @@ -36,7 +36,7 @@ }, "contributors": [ { - "name" : "Geoff Pursell" + "name": "Geoff Pursell" } ], "license": "MIT", diff --git a/test/annotation_exporter_tests.js b/test/annotation_exporter_tests.js index 70bbfec06..49ae049c8 100644 --- a/test/annotation_exporter_tests.js +++ b/test/annotation_exporter_tests.js @@ -3,13 +3,14 @@ var eol = require('os').EOL; var Pattern = require('../core/lib/object_factory').Pattern; var extend = require('util')._extend; +var anPath = './test/files/'; -function createFakePatternLab(customProps) { +function createFakePatternLab(anPath, customProps) { var pl = { "config": { "paths": { "source": { - "annotations": './test/files/' + "annotations": anPath } } } @@ -18,7 +19,7 @@ function createFakePatternLab(customProps) { return extend(pl, customProps); } -var patternlab = createFakePatternLab(); +var patternlab = createFakePatternLab(anPath); var ae = require('../core/lib/annotation_exporter')(patternlab); exports['annotaton_exporter'] = { @@ -65,5 +66,15 @@ exports['annotaton_exporter'] = { test.done(); + }, + + 'when there are 0 annotation files' : function (test) { + var emptyAnPath = './test/files/empty/'; + var patternlab2 = createFakePatternLab(emptyAnPath); + var ae2 = require('../core/lib/annotation_exporter')(patternlab2); + + var annotations = ae2.gather(); + test.equals(annotations.length, 0); + test.done(); } }; diff --git a/test/files/annotations.md b/test/files/annotations.md index 7e2ad972a..cf895f081 100644 --- a/test/files/annotations.md +++ b/test/files/annotations.md @@ -10,9 +10,3 @@ selector: .logo title: Logo --- The _logo image_ is an SVG file. -~*~ ---- -el: #nav -title : Navigation ---- -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. diff --git a/test/files/empty/.gitkeep b/test/files/empty/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/test/files/nav.md b/test/files/nav.md new file mode 100644 index 000000000..00de05203 --- /dev/null +++ b/test/files/nav.md @@ -0,0 +1,6 @@ +--- +el: #nav +title : Navigation +--- +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. +