Skip to content

Commit

Permalink
Merge pull request #199 from geoffp/pattern-engines
Browse files Browse the repository at this point in the history
PatternEngines ongoing work, round 3
  • Loading branch information
Brian Muenzenmeyer authored and geoffp committed Feb 23, 2018
1 parent 570bfef commit 204ddc4
Show file tree
Hide file tree
Showing 35 changed files with 748 additions and 530 deletions.
4 changes: 3 additions & 1 deletion packages/patternengine-node-mustache/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"all"
],
"dot-notation": [
2,
1,
{
"allowKeywords": true
}
Expand All @@ -29,6 +29,7 @@
"never"
],
"guard-for-in": 2,
"key-spacing": 1,
"new-cap": 0,
"no-bitwise": 2,
"no-caller": 2,
Expand All @@ -52,6 +53,7 @@
"no-sequences": 2,
"no-shadow": 2,
"no-undef": 2,
"no-underscore-dangle": 1,
"no-unused-vars": 2,
"no-with": 2,
"quotes": [
Expand Down
2 changes: 2 additions & 0 deletions packages/patternengine-node-mustache/.travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: node_js

node_js:
- stable
- 4.0
- 0.12
- 0.11

Expand Down
10 changes: 10 additions & 0 deletions packages/patternengine-node-mustache/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
THIS CHANGELOG IS AN ATTEMPT TO DOCUMENT CHANGES TO THIS PROJECT.

PL-node-v0.15.1
- FIX: Resolve issue with styleModifiers not being replaced when the partial has spaces in it.
- ADD: Support multiple styleModifier classes using the | pipe syntax
- FIX: Resolve issue with styleModifiers not being applied correctly when mixed with pattern parameters
- THX: Thanks @theorise for the issue reports!

PL-node-v0.15.0
- CHG: Updated package.json devDependencies for Node 4.X and 5.X support.
- CHG: Updated package.gulp.json devDependencies for Node 4.X and 5.X support.

PL-node-v0.14.0
- ADD: Support for style modifiers
- ADD: Support for styleGuideExcludes
Expand Down
2 changes: 1 addition & 1 deletion packages/patternengine-node-mustache/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Contributing to Patternlab - Node
If you'd like to contribute to patternlab - node, please do so! There is always a lot of ground to cover, with patternlab - php being so feature-rich.

No pull request is too small.
No pull request is too small. Check out any [up for grabs issues](https://github.com/pattern-lab/patternlab-node/labels/up%20for%20grabs) as a good way to get your feet wet.

##Guidelines
1. Please keep your pull requests concise and limited to **ONE** substantive change at a time.
Expand Down
13 changes: 8 additions & 5 deletions packages/patternengine-node-mustache/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,12 @@ This repository contains the vanilla builder logic, grunt and gulp configuration

* Download the [latest release of patternlab-node](https://github.com/pattern-lab/patternlab-node/releases/latest) from Github
* Via npm, run `npm install patternlab-node` (Note this will auto install the grunt version currently. see below)
* **NOTE** Node version 4.X is not officially supported yet, citing [a lot of Windows issues](https://github.com/nodejs/node-gyp/issues/629), including [mine](https://github.com/pattern-lab/patternlab-node/issues/162). Upgrade node at your own risk until otherwise stated.
* **NOTE** Node version 4.X and 5.X have tentative support, citing [a lot of Windows issues](https://github.com/nodejs/node-gyp/issues/629), including [mine](https://github.com/pattern-lab/patternlab-node/issues/162). Upgrade node at your own risk until otherwise stated. I've tried to catalog some issues and troubleshooting steps on the [wiki](https://github.com/pattern-lab/patternlab-node/wiki/Windows-Issues).

### Choose Your Adventure! Now Vanilla, Grunt & Gulp

This repository ships with two `package.json` files, a `Gruntfile.js`, and a `gulpfile.js`. The default is grunt currently. The core builder is not dependent on either.

**HELP WANTED** Please help me test both of the configurations by [reporting](https://github.com/pattern-lab/patternlab-node/blob/dev/CONTRIBUTING.md) any issues encountered.

### Getting Started - Grunt

To run patternlab-node using grunt, do the following in the directory you downloaded and extracted the zipped release:
Expand All @@ -27,7 +25,7 @@ To run patternlab-node using grunt, do the following in the directory you downlo
* Not deleting `builder/patternlab_gulp.js` may cause a harmless error when running grunt. Delete it.
3. Run `grunt` or `grunt serve` from the command line

This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `grunt serve` to see have BrowserSync spin up and serve the files to you.
This creates all patterns, the styleguide, and the pattern lab site. It's strongly recommended to run `grunt serve` to have BrowserSync spin up and serve the files to you.

### Getting Started - Gulp

Expand All @@ -51,7 +49,7 @@ It's not expected to toggle between the two build systems, but for those migrati

### Upgrading

You can find some simple upgrade documenation in it's current home here (unreleased but confirmed to work): [https://github.com/pattern-lab/website/blob/dev/patternlabsite/docs/node/upgrading.md](https://github.com/pattern-lab/website/blob/dev/patternlabsite/docs/node/upgrading.md)
You can find instructions on how to upgrade from version to version of Pattern Lab Node here: [https://github.com/pattern-lab/patternlab-node/wiki/Upgrading](https://github.com/pattern-lab/patternlab-node/wiki/Upgrading)

### Command Line Interface

Expand Down Expand Up @@ -214,6 +212,11 @@ Once rendered, it looks like this:
</div>
```

You may also specify multiple classes using a pipe character (|).

```
{{> atoms-message:error|is-on }}
```



Expand Down
11 changes: 7 additions & 4 deletions packages/patternengine-node-mustache/builder/lineage_hunter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* patternlab-node - v0.14.0 - 2015
*
/*
* patternlab-node - v0.15.1 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
Expand All @@ -17,9 +17,12 @@

var pa = require('./pattern_assembler');
var pattern_assembler = new pa();
var config = require('../config.json');

//find the {{> template-name }} within patterns
console.log('===\n', pattern, '\n===');
if (config.debug) {
console.log('===\n', pattern, '\n===');
}
var matches = pattern.findPartials();
if(matches !== null){
matches.forEach(function(match, index, matches){
Expand Down
17 changes: 10 additions & 7 deletions packages/patternengine-node-mustache/builder/list_item_hunter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* patternlab-node - v0.14.0 - 2015
*
/*
* patternlab-node - v0.15.1 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
Expand All @@ -16,6 +16,7 @@
var extend = require('util')._extend,
pa = require('./pattern_assembler'),
smh = require('./style_modifier_hunter'),
plutils = require('./utilities'),
config = require('../config.json'),
of = require('./object_factory');

Expand All @@ -42,13 +43,15 @@
var repeatedBlockTemplate = [];
var repeatedBlockHtml = '';
for(var i = 0; i < items.indexOf(loopNumberString); i++){
console.log('adding', patternBlock, 'to repeatedBlockTemplate');
if (config.debug) {
console.log('list item(s) in pattern', pattern.patternName, 'adding', patternBlock, 'to repeatedBlockTemplate');
}
repeatedBlockTemplate.push(patternBlock);
}

//check for a local listitems.json file
var listData = JSON.parse(JSON.stringify(patternlab.listitems));
listData = pattern_assembler.merge_data(listData, pattern.listitems);
listData = plutils.mergeData(listData, pattern.listitems);

//iterate over each copied block, rendering its contents along with pattenlab.listitems[i]
for(var i = 0; i < repeatedBlockTemplate.length; i++){
Expand All @@ -61,8 +64,8 @@
var globalData = JSON.parse(JSON.stringify(patternlab.data));
var localData = JSON.parse(JSON.stringify(pattern.jsonFileData));

var allData = pattern_assembler.merge_data(globalData, localData);
allData = pattern_assembler.merge_data(allData, itemData != undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup
var allData = plutils.mergeData(globalData, localData);
allData = plutils.mergeData(allData, itemData != undefined ? itemData[i] : {}); //itemData could be undefined if the listblock contains no partial, just markup
allData.link = extend({}, patternlab.data.link);

//check for partials within the repeated block
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.14.0 - 2015
* patternlab-node - v0.15.1 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand Down
55 changes: 33 additions & 22 deletions packages/patternengine-node-mustache/builder/object_factory.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* patternlab-node - v0.14.0 - 2015
* patternlab-node - v0.15.1 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
Expand All @@ -19,7 +19,7 @@

// oPattern properties

var oPattern = function(abspath, subdir, filename, data){
var oPattern = function(abspath, subdir, filename, data) {
if (config.debug) {
console.log('=== NEW OPATTERN.', '\nabsPath:', abspath, '\nsubdir:', subdir, '\nfilename:', filename, '\ndata:\n', data);
}
Expand Down Expand Up @@ -50,27 +50,38 @@

// oPattern methods

// render method on oPatterns; this acts as a proxy for the PatternEngine's
// render function
oPattern.prototype.render = function (data, partials) {
if (config.debug && this.isPseudoPattern) {
console.log('===', this.name + ' IS A PSEUDO-PATTERN ===');
oPattern.prototype = {

// render method on oPatterns; this acts as a proxy for the PatternEngine's
// render function
render: function (data, partials) {
if (config.debug && this.isPseudoPattern) {
console.log('===', this.name + ' IS A PSEUDO-PATTERN ===');
}
return this.engine.renderPattern(this.extendedTemplate, data, partials);
},

// the finders all delegate to the PatternEngine, which also encapsulates all
// appropriate regexes
findPartials: function () {
return this.engine.findPartials(this);
},

findPartialsWithStyleModifiers: function () {
return this.engine.findPartialsWithStyleModifiers(this);
},

findPartialsWithPatternParameters: function () {
return this.engine.findPartialsWithPatternParameters(this);
},

findListItems: function () {
return this.engine.findListItems(this);
},

getPartialKey: function (partialString) {
return this.engine.getPartialKey(this, partialString);
}
return this.engine.renderPattern(this.extendedTemplate, data, partials);
};
// the finders all delegate to the PatternEngine, which also encapsulates all
// appropriate regexes
oPattern.prototype.findPartials = function () {
return this.engine.findPartials(this);
};
oPattern.prototype.findPartialsWithStyleModifiers = function () {
return this.engine.findPartialsWithStyleModifiers(this);
};
oPattern.prototype.findPartialsWithPatternParameters = function () {
return this.engine.findPartialsWithPatternParameters(this);
};
oPattern.prototype.findListItems = function () {
return this.engine.findListItems(this);
};

// oPattern static methods
Expand Down
14 changes: 8 additions & 6 deletions packages/patternengine-node-mustache/builder/parameter_hunter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* patternlab-node - v0.14.0 - 2015
*
/*
* patternlab-node - v0.15.1 - 2015
*
* Brian Muenzenmeyer, and the web community.
* Licensed under the MIT license.
*
Expand All @@ -15,8 +15,8 @@

var extend = require('util')._extend,
pa = require('./pattern_assembler'),
mustache = require('mustache'),
smh = require('./style_modifier_hunter'),
plutils = require('./utilities'),
style_modifier_hunter = new smh(),
pattern_assembler = new pa();

Expand All @@ -28,6 +28,8 @@
//find the partial's name and retrieve it
var partialName = pMatch.match(/([\w\-\.\/~]+)/g)[0];
var partialPattern = pattern_assembler.get_pattern_by_key(partialName, patternlab);
//if we retrieved a pattern we should make sure that its extendedTemplate is reset. looks to fix #190
partialPattern.extendedTemplate = partialPattern.template;

if(patternlab.config.debug){
console.log('found patternParameters for ' + partialName);
Expand All @@ -44,8 +46,8 @@
var globalData = JSON.parse(JSON.stringify(patternlab.data));
var localData = JSON.parse(JSON.stringify(pattern.jsonFileData || {}));

var allData = pattern_assembler.merge_data(globalData, localData);
allData = pattern_assembler.merge_data(allData, paramData);
var allData = plutils.mergeData(globalData, localData);
allData = plutils.mergeData(allData, paramData);

//if partial has style modifier data, replace the styleModifier value
if(pattern.stylePartials && pattern.stylePartials.length > 0){
Expand Down
Loading

0 comments on commit 204ddc4

Please sign in to comment.