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

multiplex-templates

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

multiplex-templates - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

22

index.js

@@ -1,2 +0,20 @@

module.exports = require('./lib/embed');
module.exports.engines = require('./lib/engines').engines;
'use strict';
var _ = require('lodash'),
embed = require('./lib/embed'),
engines = require('./lib/engines');
module.exports = function (instances) {
// if instances are passed through, use them
if (instances) {
_.forOwn(instances, function (instance, name) {
// add them to our engines
engines.set(name, instance);
});
}
// expose the renderer and the engines
return {
render: embed.render,
engines: engines.engines
};
};

21

lib/embed.test.js

@@ -51,7 +51,10 @@ 'use strict';

describe('render()', function () {
var sandbox,
html = '<strong>foo</strong>';
var sandbox, nunjucksMock, jadeMock,
string = 'foo',
obj = {text: 'foo'};
beforeEach(function () {
sandbox = sinon.sandbox.create();
nunjucksMock = sinon.mock(engines.nunjucks);
jadeMock = sinon.mock(engines.jade);
});

@@ -61,2 +64,4 @@

sandbox.restore();
nunjucksMock.restore();
jadeMock.restore();
});

@@ -66,5 +71,5 @@

sandbox.stub(glob, 'sync').returns(['foo.nunjucks']);
sandbox.stub(engines.nunjucks, 'render').returns(html);
expect(embed.render('foo', 'foo')).to.equal(html);
nunjucksMock.expects('render').withArgs('foo.nunjucks', obj);
embed.render(string, obj);
nunjucksMock.verify();
});

@@ -74,7 +79,7 @@

sandbox.stub(glob, 'sync').returns(['foo.jade']);
sandbox.stub(engines.jade, 'render').returns(html);
expect(embed.render('foo', 'foo')).to.equal(html);
jadeMock.expects('render').withArgs('foo.jade', obj);
embed.render(string, obj);
nunjucksMock.verify();
});
});
});

@@ -1,25 +0,38 @@

// todo: use consolidate.js when it exposes engines and
// allows you to add filters, globals, etc to engine instances before rendering
'use strict';
var nunjucks = require('nunjucks').configure('.', { autoescape: true }),
jade = require('jade');
var _ = require('lodash'),
engines = {},
supported = ['nunjucks', 'jade'];
// add nunjucks embed filter
nunjucks.addFilter('embed', require('./nunjucks').embedFilter);
// iterate through the supported engines, instantiating any that weren't passed in (or don't exist already)
_.map(supported, function(name) {
if (!engines[name]) {
if (name === 'nunjucks') {
engines.nunjucks = require('nunjucks').configure('.', { autoescape: true });
} else if (name === 'jade') {
engines.jade = require('jade');
}
}
});
// add embed filters and mixins
engines.nunjucks.addFilter('embed', require('./nunjucks').embedFilter);
module.exports = {
// expose engines
engines: {
nunjucks: nunjucks,
jade: jade
},
engines: engines,
// expose consolidated render methods for each engine
// expose consolidated render method for each engine
nunjucks: {
render: nunjucks.render.bind(nunjucks)
render: engines.nunjucks.render.bind(engines.nunjucks)
},
jade: {
render: jade.renderFile.bind(jade)
render: engines.jade.renderFile.bind(engines.jade)
}
};
module.exports.set = function (name, instance) {
// add them to our engines
if (_.contains(supported, name)) {
engines[name] = instance;
}
};
'use strict';
var expect = require('chai').expect;
var expect = require('chai').expect,
engines = require('./engines');
describe('Engines', function () {
it('should expose engines', function () {
var engines = require('./engines');
it('should expose nunjucks and jade engines', function () {
expect(engines.engines).to.have.keys(['nunjucks', 'jade']);
});
it('should use the same nunjucks instance', function () {
expect(require('./engines').engines.nunjucks).to.eql(require('./engines').engines.nunjucks);
it('should add nunjucks embed filter', function () {
expect(engines.engines.nunjucks.getFilter('embed')).to.be.a('function');
});
it('should use the same jade instance', function () {
expect(require('./engines').engines.jade).to.eql(require('./engines').engines.jade);
it('should use passed-in nunjucks instance', function () {
var env = require('nunjucks').configure('.');
// add a filter to this specific instance
env.addFilter('foo', function () {});
engines.set('nunjucks', env);
expect(engines.engines.nunjucks.getFilter('foo')).to.be.a('function');
});
it('should use passed-in jade instance', function () {
var env = require('jade');
engines.set('jade', env);
expect(engines.engines.jade).to.eql(env);
});
});
{
"name": "multiplex-templates",
"version": "0.2.0",
"version": "0.3.0",
"description": "Easy embedding for multiple template languages",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -18,3 +18,3 @@ # multiplex-templates

```js
var multiplex = require('multiplex-templates');
var multiplex = require('multiplex-templates')();

@@ -57,3 +57,3 @@ multiplex.render('component-name', data);

This module exposes the instances of the templating engines, so you can add mixins/filters/globals/etc into them:
This module exposes the instances of the templating engines, so you can add mixins/filters/globals/etc onto them:

@@ -66,2 +66,15 @@ ```js

You can also instantiate your own engines (and configure them however you like) and pass them into multiplex-templates.
```js
var env = require('nunjucks').configure('.', { watch: false }),
jadeEnv = require('jade'), // so cool, doesn't need config (⌐■_■)
multiplex = require('multiplex-templates')({
nunjucks: env,
jade: jadeEnv
});
// multiplex.engines.nunjucks === env
```
## Cross-engine Embedding

@@ -68,0 +81,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