diff --git a/core/lib/markdown_parser.js b/core/lib/markdown_parser.js index 71b273456..9fd046a8f 100644 --- a/core/lib/markdown_parser.js +++ b/core/lib/markdown_parser.js @@ -11,7 +11,7 @@ var markdown_parser = function () { //for each block process the yaml frontmatter and markdown var frontmatterRE = /---\r?\n{1}([\s\S]*)---\r?\n{1}([\s\S]*)+/gm; var chunks = frontmatterRE.exec(block); - if (chunks && chunks[1] && chunks[2]) { + if (chunks && chunks[1]) { //convert each yaml frontmatter key / value into an object key var frontmatter = chunks[1]; @@ -25,17 +25,23 @@ var markdown_parser = function () { var frontmatterKey = frontmatterLineChunks[0].toLowerCase().trim(); var frontmatterValueString = frontmatterLineChunks[1].trim(); - returnObject[frontmatterKey] = frontmatterValueString.substring(1, frontmatterValueString.length - 1); + returnObject[frontmatterKey] = frontmatterValueString; } } + } + if (chunks && chunks[2]) { //parse the actual markdown returnObject.markdown = md.render(chunks[2]); + } else{ + //assume the passed in block is raw markdown + returnObject.markdown = md.render(block); } } catch (ex) { console.log(ex); console.log('error parsing markdown block', block); + return undefined; } //return the frontmatter keys and markdown for a consumer to decide what to do with diff --git a/core/lib/pattern_assembler.js b/core/lib/pattern_assembler.js index aa6926b0c..776b45da2 100644 --- a/core/lib/pattern_assembler.js +++ b/core/lib/pattern_assembler.js @@ -174,8 +174,12 @@ var pattern_assembler = function () { console.log('found pattern-specific markdown for ' + currentPattern.patternPartial); } } - catch (e) { - // do nothing + catch (err) { + // do nothing when file not found + if (err.errno !== -4058) { + console.log('there was an error setting pattern keys after markdown parsing of the companion file for pattern ' + currentPattern.patternPartial); + console.log(err); + } } } diff --git a/package.json b/package.json index 1cba62ce2..53992f55d 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.1.0", + "version": "2.1.1", "main": "./core/lib/patternlab.js", "dependencies": { "diveSync": "^0.3.0", diff --git a/test/files/_patterns/00-test/00-foo.md b/test/files/_patterns/00-test/00-foo.md new file mode 100644 index 000000000..4c8bbf296 --- /dev/null +++ b/test/files/_patterns/00-test/00-foo.md @@ -0,0 +1,3 @@ +## A Simple Include + +This pattern contains an include of `test-bar`. It also has this markdown file, which does not have frontmatter. diff --git a/test/files/_patterns/00-test/01-bar.md b/test/files/_patterns/00-test/01-bar.md new file mode 100644 index 000000000..d4fd865a2 --- /dev/null +++ b/test/files/_patterns/00-test/01-bar.md @@ -0,0 +1,6 @@ +--- +status: complete +--- +## A Simple Bit of Markup + +Foo cannot get simpler than bar, amiright? diff --git a/test/files/annotations.md b/test/files/annotations.md index caea14bab..7e2ad972a 100644 --- a/test/files/annotations.md +++ b/test/files/annotations.md @@ -1,18 +1,18 @@ --- -el: "header[role=banner]" -title: "Masthead" +el: header[role=banner] +title: Masthead --- The main header of the site doesn't take up *too much screen real estate* in order to keep the focus on the core content. It's using a linear CSS gradient instead of a background image to give greater design flexibility and reduce HTTP requests. ~*~ --- -selector: ".logo" -title: "Logo" +selector: .logo +title: Logo --- The _logo image_ is an SVG file. ~*~ --- -el: "#nav" -title : "Navigation" +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/markdown_parser_tests.js b/test/markdown_parser_tests.js new file mode 100644 index 000000000..9a9998818 --- /dev/null +++ b/test/markdown_parser_tests.js @@ -0,0 +1,35 @@ +"use strict"; + +var path = require('path'); +var fs = require('fs-extra'); +var eol = require('os').EOL; +var mp = require('../core/lib/markdown_parser'); +var markdown_parser = new mp(); + +exports['markdown_parser'] = { + 'parses pattern description block correctly when frontmatter not present' : function(test){ + //arrange + var markdownFileName = path.resolve("./test/files/_patterns/00-test/00-foo.md"); + var markdownFileContents = fs.readFileSync(markdownFileName, 'utf8'); + + //act + var returnObject = markdown_parser.parse(markdownFileContents) + + //assert + test.equals(returnObject.markdown, '
This pattern contains an include of test-bar
. It also has this markdown file, which does not have frontmatter.
Foo cannot get simpler than bar, amiright?
\n'); + test.equals(returnObject.status, 'complete'); + test.done(); + } +}; diff --git a/test/style_modifier_hunter_tests.js b/test/style_modifier_hunter_tests.js index 7a3562ad0..4e0d7ddf3 100644 --- a/test/style_modifier_hunter_tests.js +++ b/test/style_modifier_hunter_tests.js @@ -1,89 +1,86 @@ -(function () { - "use strict"; - - var smh = require('../core/lib/style_modifier_hunter'); - - exports['consume_style_modifier'] = { - 'uses the partial stylemodifer to modify the patterns extendedTemplate' : function(test){ - //arrange - var pl = {}; - pl.partials = {}; - pl.config = {}; - pl.config.debug = false; - - var pattern = { - extendedTemplate: '' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); - - //assert - test.equals(pattern.extendedTemplate, ''); - test.done(); - }, - 'replaces style modifiers with spaces in the syntax' : function(test){ - //arrange - var pl = {}; - pl.partials = {}; - pl.config = {}; - pl.config.debug = false; - - var pattern = { - extendedTemplate: '' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); - - //assert - test.equals(pattern.extendedTemplate, ''); - test.done(); - }, - 'replaces multiple style modifiers' : function(test){ - //arrange - var pl = {}; - pl.partials = {}; - pl.config = {}; - pl.config.debug = false; - - var pattern = { - extendedTemplate: '' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl); - - //assert - test.equals(pattern.extendedTemplate, ''); - test.done(); - }, - 'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){ - //arrange - var pl = {}; - pl.partials = {}; - pl.config = {}; - pl.config.debug = false; - - var pattern = { - extendedTemplate: '' - }; - - var style_modifier_hunter = new smh(); - - //act - style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl); - - //assert - test.equals(pattern.extendedTemplate, ''); - test.done(); - } - }; - -}()); +"use strict"; + +var smh = require('../core/lib/style_modifier_hunter'); + +exports['consume_style_modifier'] = { + 'uses the partial stylemodifer to modify the patterns extendedTemplate' : function(test){ + //arrange + var pl = {}; + pl.partials = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); + + //assert + test.equals(pattern.extendedTemplate, ''); + test.done(); + }, + 'replaces style modifiers with spaces in the syntax' : function(test){ + //arrange + var pl = {}; + pl.partials = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar}}', pl); + + //assert + test.equals(pattern.extendedTemplate, ''); + test.done(); + }, + 'replaces multiple style modifiers' : function(test){ + //arrange + var pl = {}; + pl.partials = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial:bar|baz|dum}}', pl); + + //assert + test.equals(pattern.extendedTemplate, ''); + test.done(); + }, + 'does not alter pattern extendedTemplate if styleModifier not found in partial' : function(test){ + //arrange + var pl = {}; + pl.partials = {}; + pl.config = {}; + pl.config.debug = false; + + var pattern = { + extendedTemplate: '' + }; + + var style_modifier_hunter = new smh(); + + //act + style_modifier_hunter.consume_style_modifier(pattern, '{{> partial}}', pl); + + //assert + test.equals(pattern.extendedTemplate, ''); + test.done(); + } +};