Skip to content
This repository was archived by the owner on Dec 10, 2019. It is now read-only.

Commit 913119a

Browse files
committed
First commit!
1 parent ed35de6 commit 913119a

File tree

4 files changed

+242
-0
lines changed

4 files changed

+242
-0
lines changed

.editorconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
tab_width = 2
8+
end_of_line = lf
9+
charset = utf-8
10+
trim_trailing_whitespace = true
11+
insert_final_newline = true

.eslintrc

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"env": {
3+
"node": true,
4+
"builtin": true
5+
},
6+
"globals": {},
7+
"rules": {
8+
"block-scoped-var": 0,
9+
"camelcase": 0,
10+
"comma-spacing": [1, {"before": false, "after": true}],
11+
"consistent-return": 2,
12+
"curly": [2, "all"],
13+
"dot-notation": [1, { "allowKeywords": true }],
14+
"eqeqeq": [2, "allow-null"],
15+
"global-strict": [0, "never"],
16+
"guard-for-in": 2,
17+
"indent": [1, 2, {"SwitchCase": 1, "VariableDeclarator": 1}],
18+
"lines-around-comment": [1, {
19+
"beforeBlockComment": true,
20+
"beforeLineComment": true,
21+
"allowBlockStart": true,
22+
"allowObjectStart": true,
23+
"allowArrayStart": true
24+
}],
25+
"key-spacing": 0,
26+
"keyword-spacing": 1,
27+
"new-cap": 0,
28+
"no-alert": 2,
29+
"no-bitwise": 2,
30+
"no-caller": 2,
31+
"no-cond-assign": [2, "except-parens"],
32+
"no-debugger": 2,
33+
"no-dupe-args": 2,
34+
"no-dupe-keys": 2,
35+
"no-empty": 2,
36+
"no-eval": 2,
37+
"no-extend-native": 2,
38+
"no-extra-bind": 2,
39+
"no-extra-parens": 0,
40+
"no-extra-semi": 2,
41+
"no-func-assign": 2,
42+
"no-implied-eval": 2,
43+
"no-invalid-regexp": 2,
44+
"no-irregular-whitespace": 1,
45+
"no-iterator": 2,
46+
"no-loop-func": 2,
47+
"no-mixed-requires": 0,
48+
"no-multi-str": 2,
49+
"no-multi-spaces": 1,
50+
"no-native-reassign": 2,
51+
"no-new": 2,
52+
"no-param-reassign": 1,
53+
"no-proto": 2,
54+
"no-redeclare": 0,
55+
"no-script-url": 2,
56+
"no-self-assign": 2,
57+
"no-self-compare": 2,
58+
"no-sequences": 2,
59+
"no-shadow": 2,
60+
"no-undef": 2,
61+
"no-underscore-dangle": 0,
62+
"no-unreachable": 1,
63+
"no-unused-vars": 1,
64+
"no-use-before-define": 1,
65+
"no-useless-call": 2,
66+
"no-useless-concat": 2,
67+
"no-with": 2,
68+
"quotes": [0, "single"],
69+
"radix": 2,
70+
"semi": [0, "never"],
71+
"strict": 0,
72+
"space-before-blocks": 1,
73+
"space-before-function-paren": [1, {
74+
"anonymous": "always",
75+
"named": "never"
76+
}],
77+
"space-in-parens": [1, "never"],
78+
"space-infix-ops": 1,
79+
"valid-typeof": 2,
80+
"vars-on-top": 0,
81+
"wrap-iife": [2, "inside"]
82+
}
83+
}

lib/engine_react.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* mustache pattern engine for patternlab-node - v2.X.X - 2016
3+
*
4+
* Geoffrey Pursell, Brian Muenzenmeyer, and the web community.
5+
* Licensed under the MIT license.
6+
*
7+
* Many thanks to Brad Frost and Dave Olsen for inspiration, encouragement, and advice.
8+
*
9+
*/
10+
11+
/*
12+
* ENGINE SUPPORT LEVEL:
13+
*
14+
* Full + extensions. Partial calls and lineage hunting are supported. Style
15+
* modifiers and pattern parameters are used to extend the core feature set of
16+
* Mustache templates.
17+
*
18+
*/
19+
20+
"use strict";
21+
22+
var Mustache = require('mustache');
23+
var utilMustache = require('./util_mustache');
24+
25+
var engine_mustache = {
26+
engine: Mustache,
27+
engineName: 'mustache',
28+
engineFileExtension: '.mustache',
29+
30+
// partial expansion is only necessary for Mustache templates that have
31+
// style modifiers or pattern parameters (I think)
32+
expandPartials: true,
33+
34+
// regexes, stored here so they're only compiled once
35+
findPartialsRE: utilMustache.partialsRE,
36+
findPartialsWithStyleModifiersRE: utilMustache.partialsWithStyleModifiersRE,
37+
findPartialsWithPatternParametersRE: utilMustache.partialsWithPatternParametersRE,
38+
findListItemsRE: utilMustache.listItemsRE,
39+
findPartialRE: utilMustache.partialRE,
40+
41+
// render it
42+
renderPattern: function renderPattern(pattern, data, partials) {
43+
try {
44+
if (partials) {
45+
return Mustache.render(pattern.extendedTemplate, data, partials);
46+
}
47+
return Mustache.render(pattern.extendedTemplate, data);
48+
} catch (e) {
49+
debugger;
50+
console.log("e = ", e);
51+
}
52+
},
53+
54+
/**
55+
* Find regex matches within both pattern strings and pattern objects.
56+
*
57+
* @param {string|object} pattern Either a string or a pattern object.
58+
* @param {object} regex A JavaScript RegExp object.
59+
* @returns {array|null} An array if a match is found, null if not.
60+
*/
61+
patternMatcher: function patternMatcher(pattern, regex) {
62+
var matches;
63+
if (typeof pattern === 'string') {
64+
matches = pattern.match(regex);
65+
} else if (typeof pattern === 'object' && typeof pattern.template === 'string') {
66+
matches = pattern.template.match(regex);
67+
}
68+
return matches;
69+
},
70+
71+
// find and return any {{> template-name }} within pattern
72+
findPartials: function findPartials(pattern) {
73+
var matches = this.patternMatcher(pattern, this.findPartialsRE);
74+
return matches;
75+
},
76+
findPartialsWithStyleModifiers: function (pattern) {
77+
var matches = this.patternMatcher(pattern, this.findPartialsWithStyleModifiersRE);
78+
return matches;
79+
},
80+
81+
// returns any patterns that match {{> value(foo:"bar") }} or {{>
82+
// value:mod(foo:"bar") }} within the pattern
83+
findPartialsWithPatternParameters: function (pattern) {
84+
var matches = this.patternMatcher(pattern, this.findPartialsWithPatternParametersRE);
85+
return matches;
86+
},
87+
findListItems: function (pattern) {
88+
var matches = this.patternMatcher(pattern, this.findListItemsRE);
89+
return matches;
90+
},
91+
92+
// given a pattern, and a partial string, tease out the "pattern key" and
93+
// return it.
94+
findPartial_new: function (partialString) {
95+
var partial = partialString.replace(this.findPartialRE, '$1');
96+
return partial;
97+
},
98+
99+
// GTP: the old implementation works better. We might not need
100+
// this.findPartialRE anymore if it works in all cases!
101+
findPartial: function (partialString) {
102+
//strip out the template cruft
103+
var foundPatternPartial = partialString.replace("{{> ", "").replace(" }}", "").replace("{{>", "").replace("}}", "");
104+
105+
// remove any potential pattern parameters. this and the above are rather brutish but I didn't want to do a regex at the time
106+
if (foundPatternPartial.indexOf('(') > 0) {
107+
foundPatternPartial = foundPatternPartial.substring(0, foundPatternPartial.indexOf('('));
108+
}
109+
110+
//remove any potential stylemodifiers.
111+
foundPatternPartial = foundPatternPartial.split(':')[0];
112+
113+
return foundPatternPartial;
114+
}
115+
};
116+
117+
module.exports = engine_mustache;

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "patternengine-node-react",
3+
"description": "The React engine for Pattern Lab / Node",
4+
"version": "0.1.0",
5+
"main": "lib/engine_react.js",
6+
"dependencies": {
7+
},
8+
"devDependencies": {
9+
},
10+
"keywords": [
11+
"Pattern Lab",
12+
"Atomic Web Design",
13+
"Node",
14+
"Gulp",
15+
"Javascript",
16+
"React"
17+
],
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/pattern-lab/patternengine-node-react.git"
21+
},
22+
"bugs": "https://github.com/pattern-lab/patternlab-node/issues",
23+
"author": "Brian Muenzenmeyer & Geoffrey Pursell",
24+
"license": "MIT",
25+
"scripts": {
26+
"test": "grunt travis --verbose"
27+
},
28+
"engines": {
29+
"node": ">=4.4"
30+
}
31+
}

0 commit comments

Comments
 (0)