metalsmith-layouts
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -0,1 +1,4 @@ | ||
### 2.3.0 - November 1, 2018 | ||
* add support for async rendering | ||
### 2.2.0 - September 4, 2018 | ||
@@ -2,0 +5,0 @@ * add suppressNoFilesError feature |
@@ -45,25 +45,21 @@ const debug = require('debug')('metalsmith-layouts'); | ||
function render({ filename, files, metadata, settings, metalsmith }) { | ||
return new Promise(resolve => { | ||
const file = files[filename]; | ||
const layout = getLayout({ file, settings }); | ||
const extension = layout.split('.').pop(); | ||
const file = files[filename]; | ||
const layout = getLayout({ file, settings }); | ||
const extension = layout.split('.').pop(); | ||
debug(`rendering ${filename} with layout ${layout}`); | ||
debug(`rendering ${filename} with layout ${layout}`); | ||
// Stringify file contents | ||
let contents = file.contents.toString(); | ||
// Stringify file contents | ||
const contents = file.contents.toString(); | ||
const transform = getTransformer(extension); | ||
const locals = Object.assign({}, metadata, file, { contents }); | ||
const layoutPath = path.join(metalsmith.path(settings.directory), layout); | ||
const transform = getTransformer(extension); | ||
const locals = Object.assign({}, metadata, file, { contents }); | ||
const layoutPath = path.join(metalsmith.path(settings.directory), layout); | ||
// Transform the contents | ||
contents = transform.renderFile(layoutPath, settings.engineOptions, locals).body; | ||
// Transform the contents | ||
return transform.renderFileAsync(layoutPath, settings.engineOptions, locals).then(rendered => { | ||
// Update file with results | ||
// eslint-disable-next-line no-param-reassign | ||
file.contents = Buffer.from(contents); | ||
file.contents = Buffer.from(rendered.body); | ||
debug(`done rendering ${filename}`); | ||
return resolve(); | ||
}); | ||
@@ -70,0 +66,0 @@ } |
@@ -27,2 +27,19 @@ /* eslint-env jest */ | ||
it('should apply a single layout to a single file with an async jstransformer', done => { | ||
const base = path.join(process.cwd(), 'test', 'fixtures', 'single-file-async'); | ||
const actual = path.join(base, 'build'); | ||
const expected = path.join(base, 'expected'); | ||
const metalsmith = new Metalsmith(base); | ||
rimraf.sync(actual); | ||
return metalsmith.use(plugin()).build(err => { | ||
if (err) { | ||
return done(err); | ||
} | ||
expect(() => equal(actual, expected)).not.toThrow(); | ||
return done(); | ||
}); | ||
}); | ||
it('should apply a single layout to multiple files', done => { | ||
@@ -29,0 +46,0 @@ const base = path.join(process.cwd(), 'test', 'fixtures', 'multiple-files'); |
@@ -8,3 +8,3 @@ { | ||
"repository": "git://github.com/metalsmith/metalsmith-layouts.git", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"scripts": { | ||
@@ -49,2 +49,3 @@ "precommit": "lint-staged", | ||
"jstransformer-handlebars": "^1.0.0", | ||
"jstransformer-qejs": "^0.2.0", | ||
"lint-staged": "^7.0.0", | ||
@@ -51,0 +52,0 @@ "metalsmith": "^2.3.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29099
398
14