Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pattern Lab Node 2.0.2 #379

Merged
merged 7 commits into from
Jul 4, 2016
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
1 change: 1 addition & 0 deletions core/lib/object_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ var Pattern = function (relPath, data) {
// name of the pattern. UPDATE: this.key is now known as this.patternPartial
this.patternPartial = this.patternGroup + '-' + this.patternBaseName;

this.patternState = '';
this.template = '';
this.patternPartialCode = '';
this.lineage = [];
Expand Down
3 changes: 2 additions & 1 deletion core/lib/pattern_assembler.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,15 @@ var pattern_assembler = function () {
currentPattern.extendedTemplate = currentPattern.template;

//find how many partials there may be for the given pattern
var foundPatternPartials = currentPattern.findPartials(currentPattern);
var foundPatternPartials = currentPattern.findPartials();

//find any listItem blocks that within the pattern, even if there are no partials
list_item_hunter.process_list_item_partials(currentPattern, patternlab);

// expand any partials present in this pattern; that is, drill down into
// the template and replace their calls in this template with rendered
// results

if (currentPattern.engine.expandPartials && (foundPatternPartials !== null && foundPatternPartials.length > 0)) {
// eslint-disable-next-line
expandPartials(foundPatternPartials, list_item_hunter, patternlab, currentPattern);
Expand Down
2 changes: 1 addition & 1 deletion 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.0.1",
"version": "2.0.2",
"main": "./core/lib/patternlab.js",
"dependencies": {
"diveSync": "^0.3.0",
Expand Down
216 changes: 216 additions & 0 deletions test/engine_mustache_tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
"use strict";

var path = require('path');
var pa = require('../core/lib/pattern_assembler');
var Pattern = require('../core/lib/object_factory').Pattern;
var testPatternsPath = path.resolve(__dirname, 'files', '_patterns');
var eol = require('os').EOL;

// fake pattern lab constructor:
// sets up a fake patternlab object, which is needed by the pattern processing
// apparatus.
function fakePatternLab() {
var fpl = {
partials: {},
patterns: [],
footer: '',
header: '',
listitems: {},
listItemArray: [],
data: {
link: {}
},
config: require('../patternlab-config.json'),
package: {}
};

// patch the pattern source so the pattern assembler can correctly determine
// the "subdir"
fpl.config.paths.source.patterns = testPatternsPath;

return fpl;
}

// function for testing sets of partials
function testFindPartials(test, partialTests) {
test.expect(partialTests.length + 1);

// setup current pattern from what we would have during execution
// docs on partial syntax are here:
// http://patternlab.io/docs/pattern-including.html
var currentPattern = Pattern.create(
'01-molecules/00-testing/00-test-mol.mustache', // relative path now
null, // data
{
template: partialTests.join(eol)
}
);

// act
var results = currentPattern.findPartials();

// assert
test.equals(results.length, partialTests.length);
partialTests.forEach(function (testString, index) {
test.equals(results[index], testString);
});

test.done();
}

function testFindPartialsWithStyleModifiers(test, partialTests) {
test.expect(partialTests.length + 1);

// setup current pattern from what we would have during execution
// docs on partial syntax are here:
// http://patternlab.io/docs/pattern-including.html
var currentPattern = Pattern.create(
'01-molecules/00-testing/00-test-mol.mustache', // relative path now
null, // data
{
template: partialTests.join(eol)
}
);

// act
var results = currentPattern.findPartialsWithStyleModifiers();

// assert
test.equals(results.length, partialTests.length);
partialTests.forEach(function (testString, index) {
test.equals(results[index], testString);
});

test.done();
}

function testFindPartialsWithPatternParameters(test, partialTests) {
test.expect(partialTests.length + 1);

// setup current pattern from what we would have during execution
// docs on partial syntax are here:
// http://patternlab.io/docs/pattern-including.html
var currentPattern = Pattern.create(
'01-molecules/00-testing/00-test-mol.mustache', // relative path now
null, // data
{
template: partialTests.join(eol)
}
);

// act
var results = currentPattern.findPartialsWithPatternParameters();

// assert
test.equals(results.length, partialTests.length);
partialTests.forEach(function (testString, index) {
test.equals(results[index], testString);
});

test.done();
}

exports['engine_mustache'] = {
'find_pattern_partials finds one simple partial': function (test) {
testFindPartials(test, [
"{{> molecules-comment-header}}"
]);
},

'find_pattern_partials finds simple partials under stressed circumstances': function (test) {
testFindPartials(test, [
"{{>molecules-comment-header}}",
"{{> " + eol + " molecules-comment-header" + eol + "}}",
"{{> molecules-weird-spacing }}"
]);
},

'find_pattern_partials finds one simple verbose partial': function (test) {
testFindPartials(test, [
'{{> 00-atoms/00-global/06-test }}'
]);
},

'find_pattern_partials finds partials with parameters': function (test) {
testFindPartials(test, [
"{{> molecules-single-comment(description: true) }}",
"{{> molecules-single-comment(description: 42) }}",
"{{> molecules-single-comment(description: '42') }}",
"{{> molecules-single-comment(description: \"42\") }}",
"{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}",
"{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}",
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
]);
},

'find_pattern_partials finds simple partials with style modifiers': function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo }}',
'{{> molecules-single-comment:foo|bar }}'
]);
},
'find_pattern_partials finds mixed partials': function (test) {
testFindPartials(test, [
'{{> molecules-single-comment:foo(description: "test", anotherThing: true) }}',
'{{> molecules-single-comment:foo|bar(description: true) }}'
]);
},

'find_pattern_partials finds one simple partial with styleModifier': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test}}"
]);
},
'find_pattern_partials finds partial with many styleModifiers': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3}}"
]);
},
'find_pattern_partials finds partials with differing styleModifiers': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3}}",
"{{> molecules-comment-header:foo-1}}",
"{{> molecules-comment-header:bar_1}}"
]);
},
'find_pattern_partials finds partials with styleModifiers when parameters present': function (test) {
testFindPartialsWithStyleModifiers(test, [
"{{> molecules-comment-header:test|test2|test3(description: true)}}",
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
]);
},

'find_pattern_partials_with_parameters finds one simple partial with parameters': function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-comment-header(description: 'test')}}"
]);
},
'find_pattern_partials_with_parameters finds partials with parameters': function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-single-comment(description: true) }}",
"{{> molecules-single-comment(description: 42) }}",
"{{> molecules-single-comment(description: '42') }}",
"{{> molecules-single-comment(description: \"42\") }}",
"{{> molecules-single-comment(description: 'test', anotherThing: 'retest') }}",
"{{> molecules-single-comment(description: false, anotherThing: \"retest\") }}",
'{{> molecules-single-comment(description:"A life is like a \"garden\". Perfect moments can be had, but not preserved, except in memory.") }}'
]);
},
'find_pattern_partials finds partials with parameters when styleModifiers present': function (test) {
testFindPartialsWithPatternParameters(test, [
"{{> molecules-comment-header:test|test2|test3(description: true)}}",
"{{> molecules-comment-header:foo-1(description: 'foo')}}",
"{{> molecules-comment-header:bar_1(descrition: 'bar', anotherThing: 10102010) }}"
]);
}

};


// don't run these tests unless mustache is installed
var engineLoader = require('../core/lib/pattern_engines');
if (!engineLoader.mustache) {
console.log("Mustache engine not installed, skipping tests.");
delete exports.engine_mustache;
}
1 change: 1 addition & 0 deletions test/object_factory_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
test.equals(p.lineageIndex.length, 0);
test.equals(p.lineageR.length, 0);
test.equals(p.lineageRIndex.length, 0);
test.equals(p.patternState, '');
test.done();
},
'test Pattern with one-directory subdir works as expected' : function (test) {
Expand Down
Loading