summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorkpdecker <kpdecker@gmail.com>2015-08-19 06:35:32 -0700
committerkpdecker <kpdecker@gmail.com>2015-08-22 10:59:34 -0700
commit2a4a5447f560723a2c898e0a4d97cd929131bba6 (patch)
tree7f5ae1fa298d7878835ff4d957a8becd7e8207eb /lib
parent1c274088c1ea9969f7a676fd5bebd11698f73116 (diff)
downloadhandlebars.js-2a4a5447f560723a2c898e0a4d97cd929131bba6.zip
handlebars.js-2a4a5447f560723a2c898e0a4d97cd929131bba6.tar.gz
handlebars.js-2a4a5447f560723a2c898e0a4d97cd929131bba6.tar.bz2
Implement decorator environment and registration
Diffstat (limited to 'lib')
-rw-r--r--lib/handlebars/base.js17
-rw-r--r--lib/handlebars/decorators.js5
-rw-r--r--lib/handlebars/runtime.js4
3 files changed, 25 insertions, 1 deletions
diff --git a/lib/handlebars/base.js b/lib/handlebars/base.js
index 41bb98d..e59f5e7 100644
--- a/lib/handlebars/base.js
+++ b/lib/handlebars/base.js
@@ -1,6 +1,7 @@
import {createFrame, extend, toString} from './utils';
import Exception from './exception';
import {registerDefaultHelpers} from './helpers';
+import {registerDefaultDecorators} from './decorators';
import logger from './logger';
export const VERSION = '3.0.1';
@@ -17,11 +18,13 @@ export const REVISION_CHANGES = {
const objectType = '[object Object]';
-export function HandlebarsEnvironment(helpers, partials) {
+export function HandlebarsEnvironment(helpers, partials, decorators) {
this.helpers = helpers || {};
this.partials = partials || {};
+ this.decorators = decorators || {};
registerDefaultHelpers(this);
+ registerDefaultDecorators(this);
}
HandlebarsEnvironment.prototype = {
@@ -54,6 +57,18 @@ HandlebarsEnvironment.prototype = {
},
unregisterPartial: function(name) {
delete this.partials[name];
+ },
+
+ registerDecorator: function(name, fn) {
+ if (toString.call(name) === objectType) {
+ if (fn) { throw new Exception('Arg not supported with multiple decorators'); }
+ extend(this.decorators, name);
+ } else {
+ this.decorators[name] = fn;
+ }
+ },
+ unregisterDecorator: function(name) {
+ delete this.decorators[name];
}
};
diff --git a/lib/handlebars/decorators.js b/lib/handlebars/decorators.js
new file mode 100644
index 0000000..d5caefb
--- /dev/null
+++ b/lib/handlebars/decorators.js
@@ -0,0 +1,5 @@
+import registerInline from './decorators/inline';
+
+export function registerDefaultDecorators(instance) {
+}
+
diff --git a/lib/handlebars/runtime.js b/lib/handlebars/runtime.js
index de42752..2300439 100644
--- a/lib/handlebars/runtime.js
+++ b/lib/handlebars/runtime.js
@@ -153,9 +153,13 @@ export function template(templateSpec, env) {
if (templateSpec.usePartial) {
container.partials = container.merge(options.partials, env.partials);
}
+ if (templateSpec.useDecorators) {
+ container.decorators = container.merge(options.decorators, env.decorators);
+ }
} else {
container.helpers = options.helpers;
container.partials = options.partials;
+ container.decorators = options.decorators;
}
};