hmpo-template-mixins
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -329,2 +329,9 @@ 'use strict'; | ||
res.locals.url = function () { | ||
return function (url) { | ||
url = Hogan.compile(url).render(this); | ||
return path.resolve(req.baseUrl, url); | ||
}; | ||
}; | ||
next(); | ||
@@ -331,0 +338,0 @@ }; |
{ | ||
"name": "hmpo-template-mixins", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "A middleware that exposes a series of Mustache mixins on res.locals to ease usage of forms, translations, and some general needs.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -293,4 +293,32 @@ var mixins = require('../lib/template-mixins'); | ||
describe('url', function () { | ||
beforeEach(function () { | ||
middleware = mixins(translate, {}); | ||
}); | ||
it('prepends the baseUrl to relative paths', function () { | ||
req.baseUrl = '/base'; | ||
middleware(req, res, next); | ||
res.locals.url().call(res.locals, './path').should.equal('/base/path'); | ||
res.locals.url().call(res.locals, 'path').should.equal('/base/path'); | ||
}); | ||
it('does not prepend the baseUrl to absolute paths', function () { | ||
req.baseUrl = '/base'; | ||
middleware(req, res, next); | ||
res.locals.url().call(res.locals, '/path').should.equal('/path'); | ||
}); | ||
it('supports urls defined in template placeholders', function () { | ||
req.baseUrl = '/base'; | ||
res.locals.href = './link' | ||
middleware(req, res, next); | ||
res.locals.url().call(res.locals, '{{href}}').should.equal('/base/link'); | ||
}); | ||
}); | ||
}); | ||
}); |
31892
562