Skip to content

Commit

Permalink
spawn twig meta files if not found
Browse files Browse the repository at this point in the history
part of #611
  • Loading branch information
bmuenzenmeyer authored and geoffp committed Feb 23, 2018
1 parent 415f2aa commit b44ec0b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 4 deletions.
16 changes: 16 additions & 0 deletions packages/patternengine-node-twig/_meta/_00-head.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html class="{{ htmlClass }}">
<head>
<title>{{ title }}</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width" />

<link rel="stylesheet" href="../../css/style.css?{{ cacheBuster }}" media="all" />
<link rel="stylesheet" href="../../css/pattern-scaffolding.css?{{ cacheBuster }}" media="all" />

<!-- Begin Pattern Lab (Required for Pattern Lab to run properly) -->
{{ patternLabHead | raw }}
<!-- End Pattern Lab -->

</head>
<body class="{{ bodyClass }}">
6 changes: 6 additions & 0 deletions packages/patternengine-node-twig/_meta/_01-foot.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

<!--DO NOT REMOVE-->
{{ patternLabFoot | raw }}

</body>
</html>
36 changes: 32 additions & 4 deletions packages/patternengine-node-twig/lib/engine_twig.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/*
* twig pattern engine for patternlab-node - v0.15.1 - 2015
*
Expand All @@ -18,10 +20,10 @@
*
*/

"use strict";

var Twig = require('twig');
var twig = Twig.twig;
const fs = require('fs-extra');
const path = require('path');
const Twig = require('twig');
const twig = Twig.twig;

var engine_twig = {
engine: Twig,
Expand Down Expand Up @@ -76,7 +78,33 @@ var engine_twig = {
partial = partial.replace(/"/g, '');

return partial;
},

spawnFile: function (config, fileName) {
const paths = config.paths;
const metaFilePath = path.resolve(paths.source.meta, fileName);
try {
fs.statSync(metaFilePath);
} catch (err) {

//not a file, so spawn it from the included file
const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8');
fs.outputFileSync(metaFilePath, metaFileContent);
}
},

/**
* Checks to see if the _meta directory has engine-specific head and foot files,
* spawning them if not found.
*
* @param {object} config - the global config object from core, since we won't
* assume it's already present
*/
spawnMeta: function (config) {
this.spawnFile(config, '_00-head.twig');
this.spawnFile(config, '_01-foot.twig');
}

};

module.exports = engine_twig;
1 change: 1 addition & 0 deletions packages/patternengine-node-twig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "0.1.0",
"main": "lib/engine_twig.js",
"dependencies": {
"fs-extra": "^0.30.0",
"twig": "^0.9.5"
},
"devDependencies": {},
Expand Down

0 comments on commit b44ec0b

Please sign in to comment.