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

Dev #12

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"builtin": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"globals": {},
"rules": {
"block-scoped-var": 0,
Expand Down Expand Up @@ -68,7 +72,7 @@
"no-with": 2,
"quotes": [0, "single"],
"radix": 2,
"semi": [0, "never"],
"semi": [1, "always"],
"strict": 0,
"space-before-blocks": 1,
"space-before-function-paren": [1, {
Expand All @@ -79,6 +83,10 @@
"space-infix-ops": 1,
"valid-typeof": 2,
"vars-on-top": 0,
"wrap-iife": [2, "inside"]
"wrap-iife": [2, "inside"],
"prefer-const": ["error", {
"destructuring": "any",
"ignoreReadBeforeAssign": false
}]
}
}
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>
35 changes: 31 additions & 4 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
*
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 All @@ -37,7 +39,7 @@ function escapeAtPartialBlock(partialString) {
var engine_handlebars = {
engine: Handlebars,
engineName: 'handlebars',
engineFileExtension: '.hbs',
engineFileExtension: ['.hbs', '.handlebars'],

// partial expansion is only necessary for Mustache templates that have
// style modifiers or pattern parameters (I think)
Expand Down Expand Up @@ -91,6 +93,31 @@ 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 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
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "patternengine-node-handlebars",
"name": "@pattern-lab/patternengine-node-handlebars",
"description": "The Handlebars engine for Pattern Lab / Node",
"version": "1.0.3",
"version": "2.0.0-alpha.1",
"main": "lib/engine_handlebars.js",
"dependencies": {
"fs-extra": "^0.30.0",
"handlebars": "^4.0.5"
},
"devDependencies": {},
Expand Down