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

Commit

Permalink
spawn mustache meta patterns if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
bmuenzenmeyer committed May 16, 2017
1 parent cfae4d2 commit fc67592
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 5 deletions.
17 changes: 17 additions & 0 deletions _meta/_00-head.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!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 }}}
<!-- End Pattern Lab -->

</head>
<body class="{{ bodyClass }}">

6 changes: 6 additions & 0 deletions _meta/_01-foot.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

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

</body>
</html>
27 changes: 22 additions & 5 deletions lib/engine_mustache.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

/*
* mustache pattern engine for patternlab-node - v2.X.X - 2016
*
Expand All @@ -17,10 +19,10 @@
*
*/

"use strict";

var Mustache = require('mustache');
var utilMustache = require('./util_mustache');
const fs = require('fs-extra');
const path = require('path');
const Mustache = require('mustache');
const utilMustache = require('./util_mustache');

// This holds the config from from core. The core has to call
// usePatternLabConfig() at load time for this to be populated, which
Expand Down Expand Up @@ -73,6 +75,20 @@ var engine_mustache = {
return matches;
},

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 localMetaFilePath = path.resolve(__dirname, '_meta/', fileName);
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.
Expand All @@ -81,7 +97,8 @@ var engine_mustache = {
* assume it's already present
*/
spawnMeta: function (config) {

this.spawnFile(config, '_00-head.mustache');
this.spawnFile(config, '_01-foot.mustache');
},

// find and return any {{> template-name }} within pattern
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"version": "1.0.2",
"main": "lib/engine_mustache.js",
"dependencies": {
"fs-extra": "^0.30.0",
"mustache": "^2.2.0"
},
"devDependencies": {
Expand Down

0 comments on commit fc67592

Please sign in to comment.