diff --git a/analyzer2/Analyzer.js b/analyzer2/Analyzer.js index db0e88d..c5115c6 100644 --- a/analyzer2/Analyzer.js +++ b/analyzer2/Analyzer.js @@ -37,6 +37,7 @@ enyo.kind({ */ walk: function(inPaths, inPathResolver) { var modules = []; + var designs = []; var currentLabel; var next = function(inSender, inData) { if (inData) { @@ -45,6 +46,7 @@ enyo.kind({ inData.modules[i].label = currentLabel; } modules = modules.concat(inData.modules); + designs = designs.concat(inData.designs); } var path = inPaths.shift(), label = ''; if (path) { @@ -55,27 +57,32 @@ enyo.kind({ } new Walker().walk(path, inPathResolver).response(this, next); } else { - this.walkFinished(modules); + this.walkFinished(modules, designs); } }; next.call(this); }, //* @protected - walkFinished: function(inModules) { - this.read(inModules); + walkFinished: function(inModules, inDesigns) { + this.read(inModules, inDesigns); }, //* @protected - read: function(inModules) { + read: function(inModules, inDesigns) { new Reader() - .go({modules: inModules}) + .go({modules: inModules, designs: inDesigns}) .response(this, function(inSender, inData) { this.indexModules(inData.modules); + this.indexDesigns(inData.designs); + this.doIndexReady(); }) ; }, //* @protected indexModules: function(inModules) { this.index.addModules(inModules); - this.doIndexReady(); + }, + //* @protected + indexDesigns: function(inDesigns) { + this.index.addDesigns(inDesigns); } }); diff --git a/analyzer2/Indexer.js b/analyzer2/Indexer.js index c000a86..870ec2c 100644 --- a/analyzer2/Indexer.js +++ b/analyzer2/Indexer.js @@ -212,6 +212,73 @@ enyo.kind({ } return list; }, + /** + * Adds data from an array of "design" objects to the indexer, which were previously + * loaded by the Reader into each design object's `code` property. Design objects may + * specify palette or property meta-data. + * @param inDesigns Array of design objects with unparsed code string + * @protected + */ + addDesigns: function(inDesigns) { + enyo.forEach(inDesigns, this.addDesign, this); + enyo.forEach(this.palette, this.indexPalette, this); + enyo.forEach(this.propertyMetaData, this.indexPropertyMetaData, this); + }, + /** + * Adds a given "design" object to the indexer. + * @param inDesigns A design object with unparsed code string + * @protected + */ + addDesign: function(inDesign) { + try { + var design = enyo.json.parse(inDesign.code); + enyo.forEach(["palette", "propertyMetaData"], function(type) { + if (design[type]) { + var src = design[type]; + var dest = this[type] || []; + this[type] = dest.concat(src); + } + }, this); + } catch (err) { + enyo.warn("Error parsing designer meta-data (" + inDesign.path + "): " + err); + } + }, + /** + * Loops over all the palette entries in a given category and marks kinds in the indexer + * with a flag indicating it has a palette entry (useful for generating a catch-all palette + * later). Also fills in minimum palette information based on defaults if it is missing. + * @param inCategory A palette category (containing `items` array of palette entries) + * @protected + */ + indexPalette: function(inCategory) { + enyo.forEach(inCategory.items, function(item) { + var obj = this.findByName(item.kind); + if (obj) { + obj.hasPalette = true; + // Fill in defaults for missing data + item.name = item.name || obj.name; + item.config = item.config || { kind:obj.name }; + item.inline = item.inline || { kind:obj.name }; + item.description = item.description || obj.comment; + } else { + enyo.warn("Designer meta-data specifed palette entry for '" + (item.kind || item.name) + "' but no kind by that name found."); + } + }, this); + }, + /** + * Assigns a property meta-data item for a kind to its propertyMetaData entry + * @protected + */ + indexPropertyMetaData: function(inItem) { + if (inItem.type == "kind"){ + var obj = this.findByName(inItem.name); + if (obj) { + obj.propertyMetaData = inItem; + } else { + enyo.warn("Designer meta-data specifed property info for '" + inItem.name + "' but no kind by that name found."); + } + } + }, statics: { nameCompare: function(inA, inB) { var na = inA.name.toLowerCase(), @@ -225,4 +292,4 @@ enyo.kind({ return 0; } } -}); \ No newline at end of file +}); diff --git a/analyzer2/Reader.js b/analyzer2/Reader.js index 0014ac0..966761d 100644 --- a/analyzer2/Reader.js +++ b/analyzer2/Reader.js @@ -3,34 +3,35 @@ enyo.kind({ kind: enyo.Async, go: function(inData) { this.modules = inData.modules; - this.moduleIndex = 0; - enyo.asyncMethod(this, "nextModule"); + this.designs = inData.designs; + this.files = inData.modules.concat(inData.designs); + enyo.asyncMethod(this, "nextFile"); return this; }, - nextModule: function() { - var m = this.modules[this.moduleIndex++]; - if (m) { - this.loadModule(m); + nextFile: function() { + var f = this.files.shift(); + if (f) { + this.loadFile(f); } else { - this.modulesFinished(); + this.filesFinished(); } }, - loadModule: function(inModule) { + loadFile: function(inFile) { enyo.xhr.request({ - url: inModule.path, - callback: enyo.bind(this, "moduleLoaded", inModule) + url: inFile.path, + callback: enyo.bind(this, "fileLoaded", inFile) }); }, - moduleLoaded: function(inModule, inCode) { - this.addModule(inModule, inCode); - this.nextModule(); + fileLoaded: function(inFile, inCode) { + this.addFile(inFile, inCode); + this.nextFile(); }, - addModule: function(inModule, inCode) { + addFile: function(inFile, inCode) { if (inCode && inCode.length) { - inModule.code = inCode; + inFile.code = inCode; } }, - modulesFinished: function() { - this.respond({modules: this.modules}); + filesFinished: function() { + this.respond({modules: this.modules, designs: this.designs}); } }); \ No newline at end of file diff --git a/analyzer2/Walker.js b/analyzer2/Walker.js index 2073c75..cde05d7 100644 --- a/analyzer2/Walker.js +++ b/analyzer2/Walker.js @@ -50,7 +50,8 @@ enyo.kind({ walkFinish: function() { // we've read all the manifests and constructed our list of modules this.modules = this.loader.modules; - this.async.respond({modules: this.modules}); - this.doFinish({modules: this.modules}); + this.designs = this.loader.designs; + this.async.respond({modules: this.modules, designs: this.designs}); + this.doFinish({modules: this.modules, designs: this.designs}); } });