@trayio/threadneedle
Advanced tools
Comparing version 1.8.0 to 1.9.0
@@ -33,2 +33,8 @@ var Mustache = require('mustache'); | ||
//This is needed because Mustache has it's own behaviour for # parameters | ||
if (template.match(/{{(#[^{}]+)}}|{{{#([^{}]+)}}}/g)) { | ||
//Substitute hash paramters first, then continue with standard mustaching | ||
template = substituteHashParameters(template, params); | ||
} | ||
// If the above isn't the case, then template it with Mustache. | ||
@@ -41,2 +47,33 @@ var str = Mustache.render(template, params); | ||
//Mustache.render only the hash paramters seperately | ||
function substituteHashParameters (template, params) { | ||
var pathList = []; | ||
//Replace unsecape templating | ||
template = _.replace(template, /({{{#[^{}]+}}})/g, function (match, group) { | ||
var path = group.replace('}}}', '').replace('{{{#', ''); | ||
pathList.push(path); | ||
return '##{' + path + '}##'; | ||
}); | ||
//Replace all other templating | ||
template = _.replace(template, /({{#[^{}]+}})/g, function (match, group) { | ||
var path = group.replace('}}', '').replace('{{#', ''); | ||
pathList.push(path); | ||
return '##' + path + '##'; | ||
}); | ||
/* | ||
Create a substituted params including only hash parameters | ||
(but without the hash at the start of the key) | ||
*/ | ||
var hashParams = _.reduce(pathList, function (acc, path) { | ||
return _.set(acc, path, _.get(params, '#' + path)); | ||
}, {}); | ||
return Mustache.render(template, hashParams, {}, [ '##', '##' ]); | ||
} | ||
function substituteArray(template, params) { | ||
@@ -43,0 +80,0 @@ return _.map(template, function (value) { |
{ | ||
"name": "@trayio/threadneedle", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "A framework for simplifying working with HTTP-based APIs.", | ||
@@ -29,3 +29,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"lodash": "^4.17.11", | ||
"lodash": "^4.17.15", | ||
"mout": "^1.1.0", | ||
@@ -32,0 +32,0 @@ "mustache": "^3.0.1", |
65168
1261
Updatedlodash@^4.17.15