1. Damon Oehlman
  2. recipe

Commits

Damon Oehlman  committed 3257750

Updated recipes to include variant definitions for variable sections

  • Participants
  • Parent commits 453916e
  • Branches master

Comments (0)

Files changed (7)

File dist/amd/recipe.js

View file
         reLocalFile = /^[\/\\\.]/,
         reSection = /\s*\[(\w+)\]/;
     
+    /* Recipe definition */
+    
     function Recipe(opts) {
         // if opts is a string, then map this to opts.text
         if (typeof opts == 'string' || (opts instanceof String)) {
                     match = reSection.exec(line);
                     if (match) {
                         // create the active section
-                        activeSection = this.sections[match[1]] = {};
+                        activeSection = this.sections[match[1]] = new RecipeSection(this, match[1]);
                     }
                     else {
-                        // check for a download match
-                        downloadMatch = reDownload.exec(line);
-    
-                        // if we have a download match, then add it to the active section
-                        if (downloadMatch) {
-                            var fileType = downloadMatch[1] || 'js';
-    
-                            // if the active section is currently undefined, then create the core section
-                            if (! activeSection) {
-                                activeSection = this.sections.core = {};
-                            }
-    
-                            // if the file type is not in the active section then add it
-                            if (! activeSection[fileType]) {
-                                activeSection[fileType] = [];
-                            }
-    
-                            // add the download to the file types in the active section
-                            activeSection[fileType].push(formatter(downloadMatch[2])(this));
+                        // if we don't have an active section, then create the core section
+                        if (! activeSection) {
+                            activeSection = this.sections.core = new RecipeSection(this, 'core');
                         }
+    
+                        activeSection.parse(line, opts);
                     }
                 }
             }
         }
     });
     
+    /* Recipe Section Definition */
+    
+    function RecipeSection(recipe, name) {
+        this.recipe = recipe;
+        this.name = name;
+        this.targets = {};
+        this._variants = [];
+    }
+    
+    RecipeSection.prototype = {
+        parse: function(line, opts) {
+            // check for a download match
+            var downloadMatch = reDownload.exec(line);
+    
+            // if we have a download match, then add it to the active section
+            if (downloadMatch) {
+                var fileType = downloadMatch[1] || 'js';
+    
+                // if the file type is not in the active section then add it
+                if (! this.targets[fileType]) {
+                    this.targets[fileType] = [];
+                }
+    
+                // add the download to the file types in the active section
+                this.targets[fileType].push(formatter(downloadMatch[2])(this.recipe));
+            }
+            else {
+                var fieldMatch = reField.exec(line);
+    
+                // if this was a field match, then apply the field
+                if (fieldMatch) {
+                    this[fieldMatch[1]] = fieldMatch[2];
+                }
+            }
+        },
+    
+        toJSON: function() {
+            return {
+                targets: this.targets,
+                variants: this._variants
+            };
+        }
+    };
+    
+    // define a `req` property to deal with parsing the string requirements into an array
+    Object.defineProperty(RecipeSection.prototype, 'variants', {
+        get: function() {
+            return [].concat(this._variants);
+        },
+    
+        set: function(value) {
+            if (typeof value == 'string' || (value instanceof String)) {
+                this._variants = this._variants.concat(value.split(reCommaDelim));
+            }
+        }
+    });
+    
     // no extensions available for the targeted build platform
     
     exports.define = function(opts) {

File dist/commonjs/recipe.js

View file
     reLocalFile = /^[\/\\\.]/,
     reSection = /\s*\[(\w+)\]/;
 
+/* Recipe definition */
+
 function Recipe(opts) {
     // if opts is a string, then map this to opts.text
     if (typeof opts == 'string' || (opts instanceof String)) {
                 match = reSection.exec(line);
                 if (match) {
                     // create the active section
-                    activeSection = this.sections[match[1]] = {};
+                    activeSection = this.sections[match[1]] = new RecipeSection(this, match[1]);
                 }
                 else {
-                    // check for a download match
-                    downloadMatch = reDownload.exec(line);
-
-                    // if we have a download match, then add it to the active section
-                    if (downloadMatch) {
-                        var fileType = downloadMatch[1] || 'js';
-
-                        // if the active section is currently undefined, then create the core section
-                        if (! activeSection) {
-                            activeSection = this.sections.core = {};
-                        }
-
-                        // if the file type is not in the active section then add it
-                        if (! activeSection[fileType]) {
-                            activeSection[fileType] = [];
-                        }
-
-                        // add the download to the file types in the active section
-                        activeSection[fileType].push(formatter(downloadMatch[2])(this));
+                    // if we don't have an active section, then create the core section
+                    if (! activeSection) {
+                        activeSection = this.sections.core = new RecipeSection(this, 'core');
                     }
+
+                    activeSection.parse(line, opts);
                 }
             }
         }
     }
 });
 
+/* Recipe Section Definition */
+
+function RecipeSection(recipe, name) {
+    this.recipe = recipe;
+    this.name = name;
+    this.targets = {};
+    this._variants = [];
+}
+
+RecipeSection.prototype = {
+    parse: function(line, opts) {
+        // check for a download match
+        var downloadMatch = reDownload.exec(line);
+
+        // if we have a download match, then add it to the active section
+        if (downloadMatch) {
+            var fileType = downloadMatch[1] || 'js';
+
+            // if the file type is not in the active section then add it
+            if (! this.targets[fileType]) {
+                this.targets[fileType] = [];
+            }
+
+            // add the download to the file types in the active section
+            this.targets[fileType].push(formatter(downloadMatch[2])(this.recipe));
+        }
+        else {
+            var fieldMatch = reField.exec(line);
+
+            // if this was a field match, then apply the field
+            if (fieldMatch) {
+                this[fieldMatch[1]] = fieldMatch[2];
+            }
+        }
+    },
+
+    toJSON: function() {
+        return {
+            targets: this.targets,
+            variants: this._variants
+        };
+    }
+};
+
+// define a `req` property to deal with parsing the string requirements into an array
+Object.defineProperty(RecipeSection.prototype, 'variants', {
+    get: function() {
+        return [].concat(this._variants);
+    },
+
+    set: function(value) {
+        if (typeof value == 'string' || (value instanceof String)) {
+            this._variants = this._variants.concat(value.split(reCommaDelim));
+        }
+    }
+});
+
 Recipe.prototype.resolve = function(callback) {
     
 };

File dist/glob/recipe.js

View file
         reLocalFile = /^[\/\\\.]/,
         reSection = /\s*\[(\w+)\]/;
     
+    /* Recipe definition */
+    
     function Recipe(opts) {
         // if opts is a string, then map this to opts.text
         if (typeof opts == 'string' || (opts instanceof String)) {
                     match = reSection.exec(line);
                     if (match) {
                         // create the active section
-                        activeSection = this.sections[match[1]] = {};
+                        activeSection = this.sections[match[1]] = new RecipeSection(this, match[1]);
                     }
                     else {
-                        // check for a download match
-                        downloadMatch = reDownload.exec(line);
-    
-                        // if we have a download match, then add it to the active section
-                        if (downloadMatch) {
-                            var fileType = downloadMatch[1] || 'js';
-    
-                            // if the active section is currently undefined, then create the core section
-                            if (! activeSection) {
-                                activeSection = this.sections.core = {};
-                            }
-    
-                            // if the file type is not in the active section then add it
-                            if (! activeSection[fileType]) {
-                                activeSection[fileType] = [];
-                            }
-    
-                            // add the download to the file types in the active section
-                            activeSection[fileType].push(formatter(downloadMatch[2])(this));
+                        // if we don't have an active section, then create the core section
+                        if (! activeSection) {
+                            activeSection = this.sections.core = new RecipeSection(this, 'core');
                         }
+    
+                        activeSection.parse(line, opts);
                     }
                 }
             }
         }
     });
     
+    /* Recipe Section Definition */
+    
+    function RecipeSection(recipe, name) {
+        this.recipe = recipe;
+        this.name = name;
+        this.targets = {};
+        this._variants = [];
+    }
+    
+    RecipeSection.prototype = {
+        parse: function(line, opts) {
+            // check for a download match
+            var downloadMatch = reDownload.exec(line);
+    
+            // if we have a download match, then add it to the active section
+            if (downloadMatch) {
+                var fileType = downloadMatch[1] || 'js';
+    
+                // if the file type is not in the active section then add it
+                if (! this.targets[fileType]) {
+                    this.targets[fileType] = [];
+                }
+    
+                // add the download to the file types in the active section
+                this.targets[fileType].push(formatter(downloadMatch[2])(this.recipe));
+            }
+            else {
+                var fieldMatch = reField.exec(line);
+    
+                // if this was a field match, then apply the field
+                if (fieldMatch) {
+                    this[fieldMatch[1]] = fieldMatch[2];
+                }
+            }
+        },
+    
+        toJSON: function() {
+            return {
+                targets: this.targets,
+                variants: this._variants
+            };
+        }
+    };
+    
+    // define a `req` property to deal with parsing the string requirements into an array
+    Object.defineProperty(RecipeSection.prototype, 'variants', {
+        get: function() {
+            return [].concat(this._variants);
+        },
+    
+        set: function(value) {
+            if (typeof value == 'string' || (value instanceof String)) {
+                this._variants = this._variants.concat(value.split(reCommaDelim));
+            }
+        }
+    });
+    
     // no extensions available for the targeted build platform
     
     exports.define = function(opts) {

File src/core/recipe.js

View file
     reLocalFile = /^[\/\\\.]/,
     reSection = /\s*\[(\w+)\]/;
 
+/* Recipe definition */
+
 function Recipe(opts) {
     // if opts is a string, then map this to opts.text
     if (typeof opts == 'string' || (opts instanceof String)) {
                 match = reSection.exec(line);
                 if (match) {
                     // create the active section
-                    activeSection = this.sections[match[1]] = {};
+                    activeSection = this.sections[match[1]] = new RecipeSection(this, match[1]);
                 }
                 else {
-                    // check for a download match
-                    downloadMatch = reDownload.exec(line);
-
-                    // if we have a download match, then add it to the active section
-                    if (downloadMatch) {
-                        var fileType = downloadMatch[1] || 'js';
-
-                        // if the active section is currently undefined, then create the core section
-                        if (! activeSection) {
-                            activeSection = this.sections.core = {};
-                        }
-
-                        // if the file type is not in the active section then add it
-                        if (! activeSection[fileType]) {
-                            activeSection[fileType] = [];
-                        }
-
-                        // add the download to the file types in the active section
-                        activeSection[fileType].push(formatter(downloadMatch[2])(this));
+                    // if we don't have an active section, then create the core section
+                    if (! activeSection) {
+                        activeSection = this.sections.core = new RecipeSection(this, 'core');
                     }
+
+                    activeSection.parse(line, opts);
                 }
             }
         }
     set: function(value) {
         this.requirements = value.split(reCommaDelim);
     }
+});
+
+/* Recipe Section Definition */
+
+function RecipeSection(recipe, name) {
+    this.recipe = recipe;
+    this.name = name;
+    this.targets = {};
+    this._variants = [];
+}
+
+RecipeSection.prototype = {
+    parse: function(line, opts) {
+        // check for a download match
+        var downloadMatch = reDownload.exec(line);
+
+        // if we have a download match, then add it to the active section
+        if (downloadMatch) {
+            var fileType = downloadMatch[1] || 'js';
+
+            // if the file type is not in the active section then add it
+            if (! this.targets[fileType]) {
+                this.targets[fileType] = [];
+            }
+
+            // add the download to the file types in the active section
+            this.targets[fileType].push(formatter(downloadMatch[2])(this.recipe));
+        }
+        else {
+            var fieldMatch = reField.exec(line);
+
+            // if this was a field match, then apply the field
+            if (fieldMatch) {
+                this[fieldMatch[1]] = fieldMatch[2];
+            }
+        }
+    },
+
+    toJSON: function() {
+        return {
+            targets: this.targets,
+            variants: this._variants
+        };
+    }
+};
+
+// define a `req` property to deal with parsing the string requirements into an array
+Object.defineProperty(RecipeSection.prototype, 'variants', {
+    get: function() {
+        return [].concat(this._variants);
+    },
+
+    set: function(value) {
+        if (typeof value == 'string' || (value instanceof String)) {
+            this._variants = this._variants.concat(value.split(reCommaDelim));
+        }
+    }
 });

File test/metadata.js

View file
         var testRecipe = recipe.define(samples.simple),
             core = testRecipe.sections.core;
         
-        expect(core.js).to.be.ok();
-        expect(sniff(core.js)).to.equal('array');
-        expect(core.js.length).to.equal(1);
-        expect(core.js[0]).to.equal('github://DamonOehlman/classtweak/classtweak.js');
+        expect(core.targets.js).to.be.ok();
+        expect(sniff(core.targets.js)).to.equal('array');
+        expect(core.targets.js.length).to.equal(1);
+        expect(core.targets.js[0]).to.equal('github://DamonOehlman/classtweak/classtweak.js');
     });
 });

File test/recipe-validators/core.js

View file
 		});
 	}
 
-	// console.log(recipe);
+	console.log(JSON.stringify(recipe, false, 2));
 };

File test/recipes/bootstrap.recipe

View file
 css <= http://twitter.github.com/bootstrap/assets/css/bootstrap.css
 
 [addin]
+# variants: modal, dropdown, scrollspy, tab, tooltip
+# variants: popover[req: tooltip], alert, button
+# variants: collapse[req: transition], transition, carousel, typeahead
 js <= github://twitter/bootstrap/js/bootstrap-$addin.js