Skip to content

Commit c7ccacd

Browse files
Dan Whitebmuenzenmeyer
authored andcommitted
Merge branch 'release/0.1.3'
1 parent c09fc33 commit c7ccacd

File tree

5 files changed

+874
-9
lines changed

5 files changed

+874
-9
lines changed
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 | safe }}
13+
<!-- End Pattern Lab -->
14+
15+
</head>
16+
<body class="{{ bodyClass }}">
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 | safe }}
4+
5+
</body>
6+
</html>

packages/patternengine-node-nunjucks/lib/engine_nunjucks.js

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
"use strict";
2222

23-
var path = require('path'),
23+
var fs = require('fs-extra'),
24+
path = require('path'),
2425
plPath = process.cwd(),
2526
plConfig = require(path.join(plPath, 'patternlab-config.json')),
2627
nunjucks = require('nunjucks'),
@@ -36,10 +37,7 @@ try {
3637
if (typeof nunjucksConfig == 'function') {
3738
nunjucksConfig(nunjucks, env);
3839
}
39-
}
40-
catch (err) {
41-
console.log('Cannot find module \'patternlab-nunjucks-config.js\'');
42-
}
40+
} catch (err) { }
4341

4442

4543
////////////////////////////
@@ -76,7 +74,7 @@ var engine_nunjucks = {
7674
// replace pattern names with their full path so Nunjucks can find them.
7775
pattern.extendedTemplate = this.replacePartials(pattern);
7876
var result = nunjucks.renderString(pattern.extendedTemplate, data);
79-
return result;
77+
return Promise.resolve(result);
8078
}
8179
catch (err) {
8280
console.error('Failed to render pattern: ' + pattern.name);
@@ -141,6 +139,32 @@ var engine_nunjucks = {
141139
// handled by nunjucks. This is here to keep PL from erroring
142140
findPartialsWithPatternParameters: function () {
143141
return null;
142+
},
143+
144+
spawnFile: function (config, fileName) {
145+
const paths = config.paths;
146+
const metaFilePath = path.resolve(paths.source.meta, fileName);
147+
try {
148+
fs.statSync(metaFilePath);
149+
} catch (err) {
150+
151+
//not a file, so spawn it from the included file
152+
const localMetaFilePath = path.resolve(__dirname, '_meta/', fileName);
153+
const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8');
154+
fs.outputFileSync(metaFilePath, metaFileContent);
155+
}
156+
},
157+
158+
/**
159+
* Checks to see if the _meta directory has engine-specific head and foot files,
160+
* spawning them if not found.
161+
*
162+
* @param {object} config - the global config object from core, since we won't
163+
* assume it's already present
164+
*/
165+
spawnMeta: function (config) {
166+
this.spawnFile(config, '_00-head.njk');
167+
this.spawnFile(config, '_01-foot.njk');
144168
}
145169
};
146170

0 commit comments

Comments
 (0)