Skip to content

Commit

Permalink
Export the helpers in the public API for inheritance purpose
Browse files Browse the repository at this point in the history
Signed-off-by: Loïc Mahieu <mahieuloic@gmail.com>
  • Loading branch information
LoicMahieu committed Jun 5, 2013
1 parent eaa42be commit 0c8f7fd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
16 changes: 16 additions & 0 deletions spec/handlebars.form-helpers.spec.js
Expand Up @@ -8,6 +8,22 @@ describe('Handlebars form helpers', function() {
expect(typeof HandlebarsFormHelpers.namespace).toBe('function');
});

it('Has \'helpers\' object and it contains all the helpers', function() {
expect(typeof HandlebarsFormHelpers.helpers).toBe('object');

var helpers = [
'form', 'input', 'label', 'button', 'submit', 'select',
'checkbox', 'radio', 'file', 'hidden', 'password', 'textarea',
'label_validation', 'input_validation', 'select_validation',
'checkbox_validation', 'radio_validation', 'file_validation',
'password_validation', 'textarea_validation', 'field_errors'
];

for (var i = 0, l = helpers.length; i < l; i++) {
expect(typeof HandlebarsFormHelpers.helpers[helpers[i]]).toBe('function');
}
});

it('Sets or gets the namespace', function() {
HandlebarsFormHelpers.namespace('test');
expect(HandlebarsFormHelpers.namespace()).toBe('test-');
Expand Down
63 changes: 35 additions & 28 deletions src/handlebars.form-helpers.js
Expand Up @@ -323,40 +323,47 @@
}

// Register all helpers
function register(HandlebarsSrc) {
var allHelpers = [
// Form helpers
[form, helperForm],
[input, helperInput],
[label, helperLabel],
[button, helperButton],
[submit, helperSubmit],
[select, helperSelect],
[checkbox, helperCheckbox],
[radio, helperRadio],
[file, helperFile],
[hidden, helperHidden],
[password, helperPassword],
[textarea, helperTextarea],
// Form validation helpers
[label+validationSufffix, helperLabelValidation],
[input+validationSufffix, helperInputValidation],
[select+validationSufffix, helperSelectValidation],
[checkbox+validationSufffix, helperCheckboxValidation],
[radio+validationSufffix, helperRadioValidation],
[file+validationSufffix, helperFileValidation],
[password+validationSufffix, helperPasswordValidation],
[textarea+validationSufffix, helperTextareaValidation],
[field_errors, helperFieldErrors]
];

function register(HandlebarsSrc) {
Handlebars = HandlebarsSrc;

registerHelpers([
// Form helpers
[form, helperForm],
[input, helperInput],
[label, helperLabel],
[button, helperButton],
[submit, helperSubmit],
[select, helperSelect],
[checkbox, helperCheckbox],
[radio, helperRadio],
[file, helperFile],
[hidden, helperHidden],
[password, helperPassword],
[textarea, helperTextarea],
// Form validation helpers
[label+validationSufffix, helperLabelValidation],
[input+validationSufffix, helperInputValidation],
[select+validationSufffix, helperSelectValidation],
[checkbox+validationSufffix, helperCheckboxValidation],
[radio+validationSufffix, helperRadioValidation],
[file+validationSufffix, helperFileValidation],
[password+validationSufffix, helperPasswordValidation],
[textarea+validationSufffix, helperTextareaValidation],
[field_errors, helperFieldErrors]
]);
registerHelpers(allHelpers);
}

// public API
return {
namespace: namespace,
register: register
register: register,

// Export all helpers for inheritance purpose
helpers: (function () {
var helpers = {};
for (var i = 0, l = allHelpers.length; i < l; i++) helpers[allHelpers[i][0]] = allHelpers[i][1];
return helpers;
})()
};
}));

0 comments on commit 0c8f7fd

Please sign in to comment.