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

Commit e5e384a

Browse files
committed
spawn handlebars meta patterns if not found
part of pattern-lab/patternlab-node#611
1 parent 7ec9c27 commit e5e384a

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

_meta/_00-head.html

+16
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.html

+6
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_underscore.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
/*
24
* underscore pattern engine for patternlab-node - v0.15.1 - 2015
35
*
@@ -17,8 +19,8 @@
1719
*
1820
*/
1921

20-
21-
"use strict";
22+
const fs = require('fs-extra');
23+
const path = require('path');
2224

2325
var _ = require('underscore');
2426

@@ -171,7 +173,34 @@ var engine_underscore = {
171173
var partialID = partialIDWithQuotes.replace(edgeQuotesMatcher, '');
172174

173175
return partialID;
176+
},
177+
178+
spawnFile: function (config, fileName) {
179+
const paths = config.paths;
180+
const metaFilePath = path.resolve(paths.source.meta, fileName);
181+
try {
182+
fs.statSync(metaFilePath);
183+
} catch (err) {
184+
185+
//not a file, so spawn it from the included file
186+
const localMetaFilePath = path.resolve(__dirname, '_meta/', fileName);
187+
const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8');
188+
fs.outputFileSync(metaFilePath, metaFileContent);
189+
}
190+
},
191+
192+
/**
193+
* Checks to see if the _meta directory has engine-specific head and foot files,
194+
* spawning them if not found.
195+
*
196+
* @param {object} config - the global config object from core, since we won't
197+
* assume it's already present
198+
*/
199+
spawnMeta: function (config) {
200+
this.spawnFile(config, '_00-head.html');
201+
this.spawnFile(config, '_01-foot.html');
174202
}
203+
175204
};
176205

177206
module.exports = engine_underscore;

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"author": "Brian Muenzenmeyer & Geoffrey Pursell",
2525
"license": "MIT",
2626
"scripts": {
27-
"test": "grunt travis --verbose"
27+
"test": "grunt travis --verbose",
28+
"lint": "eslint **/*.js"
2829
},
2930
"engines": {
3031
"node": ">=4.0"

0 commit comments

Comments
 (0)