dust-usecontent-helper
Advanced tools
Comparing version 4.0.0-2 to 4.0.0-3
32
index.js
@@ -28,3 +28,2 @@ "use strict"; | ||
ctx = ctx.push({ intl: { messages: content, bundle: params.bundle } }); | ||
hackGibson(ctx, content, params.bundle); | ||
bodies.block(chunk, ctx).end(); | ||
@@ -37,33 +36,2 @@ } | ||
function hackGibson(ctx, content, bundle) { | ||
var oldShiftBlocks = ctx.shiftBlocks; | ||
var oldPush = ctx.push; | ||
ctx.shiftBlocks = function(locals) { | ||
return oldShiftBlocks.call(this, objMap(locals, function (l) { | ||
return wrapBlock(l, content, bundle); | ||
})); | ||
}; | ||
ctx.push = function(head, idx, len) { | ||
var newCtx = oldPush.apply(this, arguments); | ||
hackGibson(newCtx, content, bundle); | ||
return newCtx; | ||
}; | ||
} | ||
function wrapBlock(block, content, bundle) { | ||
return function (chunk, ctx) { | ||
ctx = ctx.push({intl: { messages: content, bundle: bundle }}); | ||
return block(chunk, ctx); | ||
} | ||
} | ||
function objMap(obj, fn) { | ||
var n = {}; | ||
Object.keys(obj).forEach(function (e) { | ||
n[e] = fn(obj[e]); | ||
}); | ||
return n; | ||
} | ||
module.exports.withLoader = module.exports; |
{ | ||
"name": "dust-usecontent-helper", | ||
"version": "4.0.0-2", | ||
"version": "4.0.0-3", | ||
"description": "A dust helper to load i18n content at render time", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tape test/*.js" | ||
"test": "nyc tap test/*.js && nyc report", | ||
"cover": "nyc report --reporter=lcov" | ||
}, | ||
@@ -14,4 +15,5 @@ "author": "Aria Stewart <ariastewart@paypal.com>", | ||
"dustjs-linkedin": "~2.7.1", | ||
"tape": "^3.0.0" | ||
"nyc": "^2.3.0", | ||
"tap": "^1.2.0" | ||
} | ||
} |
"use strict"; | ||
var test = require('tape'); | ||
var test = require('tap').test; | ||
var dustjs = require('dustjs-linkedin'); | ||
var messages = require('dust-message-helper'); | ||
var helper = require('../'); | ||
test('Does helper load?', function (t) { | ||
require('../index')(function(locality, bundle, cont) { | ||
helper(function(locality, bundle, cont) { | ||
}).registerWith(dustjs); | ||
@@ -16,3 +17,3 @@ | ||
test('Does loader work?', function (t) { | ||
require('../index')(function(context, bundle, cont) { | ||
helper(function(context, bundle, cont) { | ||
t.same(context.options.option, true); | ||
@@ -45,6 +46,15 @@ t.pass('loader got called'); | ||
}); | ||
t.test('do empty helpers work?', function (t) { | ||
var tmpl = dustjs.loadSource(dustjs.compile('!{@useContent bundle="test" /}!')); | ||
dustjs.render(tmpl, dustjs.context({}, { option: true }), function (err, out) { | ||
t.equal(out, "!!"); | ||
t.end(); | ||
}); | ||
}); | ||
}); | ||
test('bundle annotation', function (t) { | ||
require('../index')(function(context, bundle, cont) { | ||
helper(function(context, bundle, cont) { | ||
t.same(context.options.option, true); | ||
@@ -67,10 +77,8 @@ t.pass('loader got called'); | ||
t.test('does loader get called?', function (t) { | ||
dustjs.loadSource(dustjs.compile('{@useContent bundle="test"}{@wompwomp/}{/useContent}', 'test')); | ||
dustjs.render('test', dustjs.context({}, { option: true }), function (err, out) { | ||
t.error(err); | ||
t.equal(out, "test"); | ||
t.end(); | ||
}); | ||
dustjs.loadSource(dustjs.compile('{@useContent bundle="test"}{@wompwomp/}{/useContent}', 'test')); | ||
dustjs.render('test', dustjs.context({}, { option: true }), function (err, out) { | ||
t.error(err); | ||
t.equal(out, "test"); | ||
t.end(); | ||
}); | ||
}); |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
12614
192
11
1
46
4
112