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

Commit dbd7678

Browse files
Merge pull request #10 from pattern-lab/feature/spawnMeta
Feature/spawn meta
2 parents 765cc5a + fc67592 commit dbd7678

File tree

5 files changed

+68
-7
lines changed

5 files changed

+68
-7
lines changed

.eslintrc

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
{
22
"env": {
33
"node": true,
4-
"builtin": true
4+
"builtin": true,
5+
"es6": true
6+
},
7+
"parserOptions": {
8+
"ecmaVersion": 6,
9+
"sourceType": "module"
510
},
611
"globals": {},
712
"rules": {
@@ -67,7 +72,7 @@
6772
"no-with": 2,
6873
"quotes": [0, "single"],
6974
"radix": 2,
70-
"semi": [0, "never"],
75+
"semi": [1, "always"],
7176
"strict": 0,
7277
"space-before-blocks": 1,
7378
"space-before-function-paren": [1, {
@@ -78,6 +83,10 @@
7883
"space-infix-ops": 1,
7984
"valid-typeof": 2,
8085
"vars-on-top": 0,
81-
"wrap-iife": [2, "inside"]
86+
"wrap-iife": [2, "inside"],
87+
"prefer-const": ["error", {
88+
"destructuring": "any",
89+
"ignoreReadBeforeAssign": false
90+
}]
8291
}
8392
}

_meta/_00-head.mustache

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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 }}}
13+
<!-- End Pattern Lab -->
14+
15+
</head>
16+
<body class="{{ bodyClass }}">
17+

_meta/_01-foot.mustache

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
<!--DO NOT REMOVE-->
3+
{{{ patternLabFoot }}}
4+
5+
</body>
6+
</html>

lib/engine_mustache.js

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"use strict";
2+
13
/*
24
* mustache pattern engine for patternlab-node - v2.X.X - 2016
35
*
@@ -17,10 +19,10 @@
1719
*
1820
*/
1921

20-
"use strict";
21-
22-
var Mustache = require('mustache');
23-
var utilMustache = require('./util_mustache');
22+
const fs = require('fs-extra');
23+
const path = require('path');
24+
const Mustache = require('mustache');
25+
const utilMustache = require('./util_mustache');
2426

2527
// This holds the config from from core. The core has to call
2628
// usePatternLabConfig() at load time for this to be populated, which
@@ -73,6 +75,32 @@ var engine_mustache = {
7375
return matches;
7476
},
7577

78+
spawnFile: function (config, fileName) {
79+
const paths = config.paths;
80+
const metaFilePath = path.resolve(paths.source.meta, fileName);
81+
try {
82+
fs.statSync(metaFilePath);
83+
} catch (err) {
84+
85+
//not a file, so spawn it from the included file
86+
const localMetaFilePath = path.resolve(__dirname, '_meta/', fileName);
87+
const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8');
88+
fs.outputFileSync(metaFilePath, metaFileContent);
89+
}
90+
},
91+
92+
/**
93+
* Checks to see if the _meta directory has engine-specific head and foot files,
94+
* spawning them if not found.
95+
*
96+
* @param {object} config - the global config object from core, since we won't
97+
* assume it's already present
98+
*/
99+
spawnMeta: function (config) {
100+
this.spawnFile(config, '_00-head.mustache');
101+
this.spawnFile(config, '_01-foot.mustache');
102+
},
103+
76104
// find and return any {{> template-name }} within pattern
77105
findPartials: function findPartials(pattern) {
78106
var matches = this.patternMatcher(pattern, this.findPartialsRE);

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"version": "1.0.2",
55
"main": "lib/engine_mustache.js",
66
"dependencies": {
7+
"fs-extra": "^0.30.0",
78
"mustache": "^2.2.0"
89
},
910
"devDependencies": {

0 commit comments

Comments
 (0)