{{> valueDump}}{{/ifHasData}}",
- };
- var _compiledTemplates = {};
-
- function getTemplate(templateKey) {
- if (!_defaultsRegistered) {
- registerDefaults();
- _defaultsRegistered = true;
- }
-
- // if we cant find a template with the given key, use the default template.
- if (!templateKey || !_templates.hasOwnProperty(templateKey)) templateKey = "__default";
-
- // check to see if we already have a compiled version of this template
- if (_compiledTemplates.hasOwnProperty(templateKey)) return _compiledTemplates[templateKey];
-
- var source = _templates[templateKey];
- var template = Handlebars.compile(source);
-
- // add the compiled template to the cache
- _compiledTemplates[templateKey] = template;
- return _compiledTemplates[templateKey];
- }
-
- function isEmpty(value) {
- if (value === null) {
- return true;
- }
-
- if (typeof value === "object" || value instanceof Object) {
- if (Object.keys(value).length > 0) {
- return false;
- }
-
- return true;
- }
-
- if (Object.prototype.toString.call(value) === "[object Array]" || value instanceof Array) {
- if (value.length > 0) {
- return false;
- }
-
- return true;
- }
-
- return false;
- }
-
- function reflect(value) {
- return {
- value: value,
- type: typeof value,
- isString: typeof value === "string" || value instanceof String,
- isNumber: typeof value === "number" || value instanceof Number,
- isBoolean: typeof value === "boolean" || value instanceof Boolean,
- isArray: Object.prototype.toString.call(value) === "[object Array]" || value instanceof Array,
- isObject: (typeof value === "object" || value instanceof Object) && value !== null,
- isNull: value === null,
- isEmptyValue: isEmpty(value),
- isSimpleType:
- !(Object.prototype.toString.call(value) === "[object Array]" || value instanceof Array) &&
- !(typeof value === "object" || value instanceof Object),
- };
- }
-
- function registerDefaults() {
- registerPartials();
- registerHelpers();
- }
-
- function registerHelpers() {
- Handlebars.registerHelper("reflect", function (context, options) {
- return options.fn(reflect(context));
- });
-
- Handlebars.registerHelper("properties", function (context, options) {
- var fn = options.fn;
- var ret = "";
- var data;
- if (options.data) data = Handlebars.createFrame(options.data);
- if (context) {
- Object.keys(context || {}).forEach(function (key) {
- var info = reflect(context[key]);
- info.name = key;
- ret += fn(info, { data: data });
- });
- }
- return ret;
- });
-
- Handlebars.registerHelper("ifHasData", function (context, options) {
- if (isEmpty(context)) return options.inverse(this);
- return options.fn(this);
- });
- }
-
- function registerPartials() {
- Handlebars.registerPartial(
- "objectDump",
- "{{#ifHasData this}}" +
- '| {{name}} | \r\n" + - "\r\n" + - " {{#with value}}{{> valueDump}}{{/with}}" + - " | \r\n" + - "
|---|