|
| 1 | +"use strict"; |
| 2 | + |
1 | 3 | /* |
2 | 4 | * underscore pattern engine for patternlab-node - v0.15.1 - 2015 |
3 | 5 | * |
|
17 | 19 | * |
18 | 20 | */ |
19 | 21 |
|
20 | | - |
21 | | -"use strict"; |
| 22 | +const fs = require('fs-extra'); |
| 23 | +const path = require('path'); |
22 | 24 |
|
23 | 25 | var _ = require('underscore'); |
24 | 26 |
|
@@ -85,7 +87,7 @@ _.mixin({ |
85 | 87 | var engine_underscore = { |
86 | 88 | engine: _, |
87 | 89 | engineName: 'underscore', |
88 | | - engineFileExtension: '.html', |
| 90 | + engineFileExtension: ['.html', '.underscore'], |
89 | 91 |
|
90 | 92 | // partial expansion is only necessary for Mustache templates that have |
91 | 93 | // style modifiers or pattern parameters (I think) |
@@ -171,7 +173,34 @@ var engine_underscore = { |
171 | 173 | var partialID = partialIDWithQuotes.replace(edgeQuotesMatcher, ''); |
172 | 174 |
|
173 | 175 | return partialID; |
| 176 | + }, |
| 177 | + |
| 178 | + spawnFile: function (config, fileName) { |
| 179 | + const paths = config.paths; |
| 180 | + const metaFilePath = path.resolve(paths.source.meta, fileName); |
| 181 | + try { |
| 182 | + fs.statSync(metaFilePath); |
| 183 | + } catch (err) { |
| 184 | + |
| 185 | + //not a file, so spawn it from the included file |
| 186 | + const localMetaFilePath = path.resolve(__dirname, '_meta/', fileName); |
| 187 | + const metaFileContent = fs.readFileSync(path.resolve(__dirname, '..', '_meta/', fileName), 'utf8'); |
| 188 | + fs.outputFileSync(metaFilePath, metaFileContent); |
| 189 | + } |
| 190 | + }, |
| 191 | + |
| 192 | + /** |
| 193 | + * Checks to see if the _meta directory has engine-specific head and foot files, |
| 194 | + * spawning them if not found. |
| 195 | + * |
| 196 | + * @param {object} config - the global config object from core, since we won't |
| 197 | + * assume it's already present |
| 198 | + */ |
| 199 | + spawnMeta: function (config) { |
| 200 | + this.spawnFile(config, '_00-head.html'); |
| 201 | + this.spawnFile(config, '_01-foot.html'); |
174 | 202 | } |
| 203 | + |
175 | 204 | }; |
176 | 205 |
|
177 | 206 | module.exports = engine_underscore; |
0 commit comments