Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

metalsmith-layouts

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

metalsmith-layouts - npm Package Compare versions

Comparing version 2.2.0 to 2.3.0

3

CHANGELOG.md

@@ -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

28

lib/index.js

@@ -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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc