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

co-nested-hbs

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

co-nested-hbs - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

test_instances/_p.hbs

22

index.js
var fs = require('fs');
var path = require('path');
var glob = require('glob');
var Handlebars = require('handlebars');
var handlebars = require('handlebars').create();
function read(filePath) {

@@ -19,3 +18,3 @@ return function(done) {

function* registerPartials(partialsPath) {
function *registerPartials(handlebars, partialsPath) {
var i, len, files, filePath, partialName, rawTemplate;

@@ -29,3 +28,2 @@

partialName = path.basename(filePath, '.hbs').substring(1);
handlebars.registerPartial(partialName, rawTemplate);

@@ -37,5 +35,5 @@ }

var registeredPartials = false;
var registeredPartialPaths = {};
function* renderTemplate(tmpl, locals) {
function *renderTemplate(handlebars, tmpl, locals) {
if (!tmpl.endsWith('.hbs')) {

@@ -54,2 +52,4 @@ tmpl = tmpl + '.hbs';

module.exports = function(viewPath, opts) {
var handlebars = Handlebars.create();
opts = opts || {};

@@ -75,8 +75,8 @@ opts.partialsPath = opts.partialsPath || viewPath;

hbs.render = function* () {
var buffer=null, lastArg, secondToLastArg, renderViewPath,
var buffer=null, lastArg, secondToLastArg,
renderOpts, locals, templates, i, len, tmpl;
if (!registeredPartials) {
yield registerPartials(opts.partialsPath);
registeredPartials = true;
if (opts.partialsPath && !registeredPartialPaths[opts.partialsPath]) {
yield registerPartials(handlebars, opts.partialsPath);
registeredPartialPaths[opts.partialsPath] = true;
}

@@ -121,3 +121,3 @@

buffer = yield renderTemplate(tmpl, locals);
buffer = yield renderTemplate(handlebars, tmpl, locals);
}

@@ -124,0 +124,0 @@

{
"name": "co-nested-hbs",
"version": "0.3.0",
"version": "1.0.0",
"repository": "speedmanly/co-nested-hbs",

@@ -5,0 +5,0 @@ "description": "Generator-based Handlebars templates for nested layouts.",

@@ -6,4 +6,16 @@ var assert = require('assert');

// preload
require('..')('test');
require('..')('test')
it('allows for different partials with the same name across different partialPaths', function(done) {
co(function *() {
var view1 = require('..')('test');
var view2 = require('..')('test_instances');
var html1 = yield view1.render('partial', {world: 'world'});
assert.equal(html1, 'hello partial world\n\n');
var html2 = yield view2.render('partial');
assert.equal(html2, 'hello partial with different view path\n\n');
})(done);
});
describe('view.render', function() {

@@ -10,0 +22,0 @@ it('nests output', function(done) {

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