+35
-35
@@ -26,12 +26,19 @@ 'use strict' | ||
| var handleObjectTemplate = function (tmpl) { | ||
| for (var key in tmpl) break | ||
| var key = Object.keys(tmpl)[0] | ||
| var template = {} | ||
| template[key] = {} | ||
| if (typeof tmpl !== 'object') { | ||
| throw new Error('generator.template should be an object') | ||
| } | ||
| if (typeof tmpl[key] === 'object') { | ||
| tmpl[key].tmpl = compileTemplate(tmpl[key].tmpl) | ||
| template[key].tmpl = compileTemplate(tmpl[key].tmpl) | ||
| template[key].parser = tmpl[key].parser | ||
| } else if (typeof tmpl[key] === 'string') { | ||
| tmpl[key] = {tmpl: compileTemplate(tmpl[key])} | ||
| template[key].tmpl = compileTemplate(tmpl[key]) | ||
| } else if (typeof tmpl[key] === 'function') { | ||
| template[key].tmpl = tmpl[key] | ||
| } | ||
| return tmpl | ||
| return template | ||
| } | ||
@@ -46,11 +53,4 @@ | ||
| if (Array.isArray(tmpls)) { | ||
| tmpls.forEach(function (def) { | ||
| for (var key in def) break | ||
| if (typeof def[key] === 'object') { | ||
| def[key].tmpl = compileTemplate(def[key].tmpl) | ||
| } else if (typeof def[key] === 'string') { | ||
| def[key] = {tmpl: compileTemplate(def[key])} | ||
| } | ||
| templates.push(def) | ||
| tmpls.forEach(function (tmpl) { | ||
| templates.push(handleObjectTemplate(tmpl)) | ||
| }) | ||
@@ -73,27 +73,27 @@ } else { | ||
| var templates = [] | ||
| if (gen.template !== undefined) { | ||
| templates = templates.concat(handleObjectTemplate(gen.template)) | ||
| var templates = [] | ||
| if (gen.template !== undefined) { | ||
| templates = templates.concat(handleObjectTemplate(gen.template)) | ||
| } | ||
| templates = templates.concat(handleTemplates(gen.templates)) | ||
| var options = { | ||
| helpers: gen.helpers, | ||
| partials: gen.partials | ||
| } | ||
| var results = [] | ||
| templates.forEach(function (template) { | ||
| var key = Object.keys(template)[0] | ||
| var dataParsed = processParsers(template[key], gen, data) | ||
| if (Array.isArray(dataParsed)) { | ||
| dataParsed.forEach(function (element) { | ||
| results.push(bindTemplate(key, template, element, options)) | ||
| }) | ||
| } else { | ||
| results.push(bindTemplate(key, template, dataParsed, options)) | ||
| } | ||
| templates = templates.concat(handleTemplates(gen.templates)) | ||
| var options = { | ||
| helpers: gen.helpers, | ||
| partials: gen.partials | ||
| } | ||
| }) | ||
| var results = [] | ||
| templates.forEach(function (template) { | ||
| for (var key in template) break | ||
| var dataParsed = processParsers(template[key], gen, data) | ||
| if (Array.isArray(dataParsed)) { | ||
| dataParsed.forEach(function (element) { | ||
| results.push(bindTemplate(key, template, element, options)) | ||
| }) | ||
| } else { | ||
| results.push(bindTemplate(key, template, dataParsed, options)) | ||
| } | ||
| }) | ||
| return results | ||
| return results | ||
| } |
+1
-1
| { | ||
| "name": "data2code", | ||
| "version": "0.0.6", | ||
| "version": "0.0.7", | ||
| "description": "Codegenerator for data", | ||
@@ -5,0 +5,0 @@ "main": "lib/data2code.js", |
6762
-1.11%109
-0.91%