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

Commit 79ee8f3

Browse files
Merge pull request #12 from pattern-lab/dev
v2.0.0-alpha.1
2 parents 4fa3eed + 0eea0b2 commit 79ee8f3

File tree

5 files changed

+66
-8
lines changed

5 files changed

+66
-8
lines changed

.eslintrc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"builtin": true,
55
"es6": true
66
},
7+
"parserOptions": {
8+
"ecmaVersion": 6,
9+
"sourceType": "module"
10+
},
711
"globals": {},
812
"rules": {
913
"block-scoped-var": 0,
@@ -68,7 +72,7 @@
6872
"no-with": 2,
6973
"quotes": [0, "single"],
7074
"radix": 2,
71-
"semi": [0, "never"],
75+
"semi": [1, "always"],
7276
"strict": 0,
7377
"space-before-blocks": 1,
7478
"space-before-function-paren": [1, {
@@ -79,6 +83,10 @@
7983
"space-infix-ops": 1,
8084
"valid-typeof": 2,
8185
"vars-on-top": 0,
82-
"wrap-iife": [2, "inside"]
86+
"wrap-iife": [2, "inside"],
87+
"prefer-const": ["error", {
88+
"destructuring": "any",
89+
"ignoreReadBeforeAssign": false
90+
}]
8391
}
8492
}

_meta/_00-head.hbs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html class="{{ htmlClass }}">
3+
<head>
4+
<title>{{ title }}</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width" />
7+
8+
<link rel="stylesheet" href="../../css/style.css?{{ cacheBuster }}" media="all" />
9+
<link rel="stylesheet" href="../../css/pattern-scaffolding.css?{{ cacheBuster }}" media="all" />
10+
11+
<!-- Begin Pattern Lab (Required for Pattern Lab to run properly) -->
12+
{{{ patternLabHead }}}
13+
<!-- End Pattern Lab -->
14+
15+
</head>
16+
<body class="{{ bodyClass }}">

_meta/_01-foot.hbs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
<!--DO NOT REMOVE-->
3+
{{{ patternLabFoot }}}
4+
5+
</body>
6+
</html>

lib/engine_handlebars.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
/*
24
* handlebars pattern engine for patternlab-node
35
*
@@ -20,9 +22,9 @@
2022
*
2123
*/
2224

23-
"use strict";
24-
25-
var Handlebars = require('handlebars');
25+
const fs = require('fs-extra');
26+
const path = require('path');
27+
const Handlebars = require('handlebars');
2628

2729
// regexes, stored here so they're only compiled once
2830
const findPartialsRE = /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/g;
@@ -37,7 +39,7 @@ function escapeAtPartialBlock(partialString) {
3739
var engine_handlebars = {
3840
engine: Handlebars,
3941
engineName: 'handlebars',
40-
engineFileExtension: '.hbs',
42+
engineFileExtension: ['.hbs', '.handlebars'],
4143

4244
// partial expansion is only necessary for Mustache templates that have
4345
// style modifiers or pattern parameters (I think)
@@ -91,6 +93,31 @@ var engine_handlebars = {
9193
findPartial: function (partialString) {
9294
var partial = partialString.replace(findPartialsRE, '$1');
9395
return partial;
96+
},
97+
98+
spawnFile: function (config, fileName) {
99+
const paths = config.paths;
100+
const metaFilePath = path.resolve(paths.source.meta, fileName);
101+
try {
102+
fs.statSync(metaFilePath);
103+
} catch (err) {
104+
105+
//not a file, so spawn it from the included file
106+
const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8');
107+
fs.outputFileSync(metaFilePath, metaFileContent);
108+
}
109+
},
110+
111+
/**
112+
* Checks to see if the _meta directory has engine-specific head and foot files,
113+
* spawning them if not found.
114+
*
115+
* @param {object} config - the global config object from core, since we won't
116+
* assume it's already present
117+
*/
118+
spawnMeta: function (config) {
119+
this.spawnFile(config, '_00-head.hbs');
120+
this.spawnFile(config, '_01-foot.hbs');
94121
}
95122
};
96123

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
{
2-
"name": "patternengine-node-handlebars",
2+
"name": "@pattern-lab/patternengine-node-handlebars",
33
"description": "The Handlebars engine for Pattern Lab / Node",
4-
"version": "1.0.3",
4+
"version": "2.0.0-alpha.1",
55
"main": "lib/engine_handlebars.js",
66
"dependencies": {
7+
"fs-extra": "^0.30.0",
78
"handlebars": "^4.0.5"
89
},
910
"devDependencies": {},

0 commit comments

Comments
 (0)