hmpo-template-mixins
Advanced tools
Comparing version 0.5.0 to 0.6.0
@@ -41,3 +41,4 @@ 'use strict'; | ||
'partials/forms/select', | ||
'partials/forms/checkbox' | ||
'partials/forms/checkbox', | ||
'partials/forms/textarea-group' | ||
]; | ||
@@ -209,2 +210,8 @@ var compiled = _.chain(PARTIALS).map(function (relativeTemplatePath) { | ||
res.locals.textarea = function () { | ||
return function (key) { | ||
return compiled['partials/forms/textarea-group'].render(inputText.call(this, key)); | ||
}; | ||
}; | ||
res.locals['radio-group'] = function () { | ||
@@ -211,0 +218,0 @@ return function (key) { |
{ | ||
"name": "hmpo-template-mixins", | ||
"version": "0.5.0", | ||
"version": "0.6.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", |
@@ -54,2 +54,3 @@ # passports-template-mixins | ||
input-submit | ||
textarea | ||
``` |
@@ -245,2 +245,78 @@ var mixins = require('../lib/template-mixins'); | ||
describe('textarea', function () { | ||
beforeEach(function () { | ||
middleware = mixins(translate, {}); | ||
}); | ||
it('adds a function to res.locals', function () { | ||
middleware(req, res, next); | ||
res.locals.textarea.should.be.a('function'); | ||
}); | ||
it('returns a function', function () { | ||
middleware(req, res, next); | ||
res.locals.textarea().should.be.a('function'); | ||
}); | ||
it('looks up field label', function () { | ||
middleware(req, res, next); | ||
res.locals.textarea().call(res.locals, 'field-name'); | ||
render.should.have.been.calledWith(sinon.match({ | ||
label: 'fields.field-name.label' | ||
})); | ||
}); | ||
it('prefixes translation lookup with namespace if provided', function () { | ||
middleware = mixins(translate, {}, { sharedTranslationsKey: 'name.space' }); | ||
middleware(req, res, next); | ||
res.locals.textarea().call(res.locals, 'field-name'); | ||
render.should.have.been.calledWith(sinon.match({ | ||
label: 'name.space.fields.field-name.label' | ||
})); | ||
}); | ||
it('should have classes if one or more were specified against the field', function () { | ||
middleware = mixins(translate, { | ||
'field-name': { | ||
'className': ['abc', 'def'] | ||
} | ||
}); | ||
middleware(req, res, next); | ||
res.locals.textarea().call(res.locals, 'field-name'); | ||
render.should.have.been.calledWith(sinon.match({ | ||
className: 'abc def' | ||
})); | ||
}); | ||
it('uses maxlength property set at a field level over default option', function () { | ||
middleware = mixins(translate, { | ||
'field-name': { | ||
'validate': [ | ||
{ type: 'maxlength', arguments: 10 } | ||
] | ||
} | ||
}); | ||
middleware(req, res, next); | ||
res.locals.textarea().call(res.locals, 'field-name'); | ||
render.should.have.been.calledWith(sinon.match({ | ||
maxlength: 10 | ||
})); | ||
}); | ||
it('uses locales translation property', function () { | ||
middleware = mixins(sinon.stub().withArgs({'label': 'field-name.label'}).returns('Field name'), { | ||
'field-name': { | ||
'label': 'field-name.label' | ||
} | ||
}); | ||
middleware(req, res, next); | ||
res.locals.textarea().call(res.locals, 'field-name'); | ||
render.should.have.been.calledWith(sinon.match({ | ||
label: 'Field name' | ||
})); | ||
}); | ||
}); | ||
describe('checkbox', function () { | ||
@@ -247,0 +323,0 @@ |
40793
18
735
56