Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions core/lib/annotation_exporter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"use strict";

var path = require('path'),
glob = require('glob'),
fs = require('fs-extra'),
JSON5 = require('json5'),
_ = require('lodash'),
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/patternlab.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
32 changes: 16 additions & 16 deletions core/lib/ui_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -336,29 +336,29 @@ 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');
}
continue;
}


viewAllPatterns.push(patternlab.patterns[j]);
viewAllPatterns.push(styleguidePatterns[j]);
}
}

Expand All @@ -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]);
}

}
Expand Down Expand Up @@ -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, {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -36,7 +36,7 @@
},
"contributors": [
{
"name" : "Geoff Pursell"
"name": "Geoff Pursell"
}
],
"license": "MIT",
Expand Down
17 changes: 14 additions & 3 deletions test/annotation_exporter_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand All @@ -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'] = {
Expand Down Expand Up @@ -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();
}
};
6 changes: 0 additions & 6 deletions test/files/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Empty file added test/files/empty/.gitkeep
Empty file.
6 changes: 6 additions & 0 deletions test/files/nav.md
Original file line number Diff line number Diff line change
@@ -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.