hmpo-template-mixins
Advanced tools
Comparing version 0.1.2 to 0.1.3
'use strict'; | ||
var _ = require('underscore'), | ||
var lookup = require('i18n-lookup'), | ||
Hogan = require('hogan.js'); | ||
@@ -10,24 +10,5 @@ | ||
module.exports = function (t) { | ||
/** | ||
* Given an array of keys and a context iterate through | ||
* each of the keys until (1) the translated key is different | ||
* from the non-translated key, and (2) a template containing the | ||
* data from the context compiles successfully. | ||
*/ | ||
return function (keys, context) { | ||
if (typeof keys === 'string') { | ||
keys = [keys]; | ||
} | ||
return _.reduce(keys, function (message, token) { | ||
if (!message && t(token) !== token) { | ||
try { | ||
message = Hogan.compile(t(token)).render(context || {}); | ||
} catch (e) {} | ||
} | ||
return message; | ||
}, null); | ||
}; | ||
return lookup(t, function (template, context) { | ||
return Hogan.compile(template).render(context); | ||
}); | ||
}; |
{ | ||
"name": "hmpo-template-mixins", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A middleware that exposes a series of Mustache mixins on res.locals to ease usage of forms, translations, and some general needs.", | ||
@@ -33,2 +33,3 @@ "main": "index.js", | ||
"hogan.js": "^3.0.2", | ||
"i18n-lookup": "^0.1.0", | ||
"moment": "^2.9.0", | ||
@@ -35,0 +36,0 @@ "underscore": "^1.7.0" |
25297
4
450
+ Addedi18n-lookup@^0.1.0
+ Addedi18n-lookup@0.1.0(transitive)