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

Commit

Permalink
spawn handlebars 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 6bfb650 commit 3dd846b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
16 changes: 16 additions & 0 deletions _meta/_00-head.hbs
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 }}}
<!-- End Pattern Lab -->

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

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

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

/*
* handlebars pattern engine for patternlab-node - v0.15.1 - 2015
*
Expand All @@ -20,9 +22,9 @@
*
*/

"use strict";

var Handlebars = require('handlebars');
const fs = require('fs-extra');
const path = require('path');
const Handlebars = require('handlebars');

// regexes, stored here so they're only compiled once
const findPartialsRE = /{{#?>\s*([\w-\/.]+)(?:.|\s+)*?}}/g;
Expand Down Expand Up @@ -92,6 +94,32 @@ var engine_handlebars = {
findPartial: function (partialString) {
var partial = partialString.replace(findPartialsRE, '$1');
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 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.
*
* @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.hbs');
this.spawnFile(config, '_01-foot.hbs');
}
};

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_handlebars.js",
"dependencies": {
"fs-extra": "^0.30.0",
"handlebars": "^4.0.5"
},
"devDependencies": {},
Expand Down

0 comments on commit 3dd846b

Please sign in to comment.