Skip to content

Commit

Permalink
Add simple parser
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Jan 15, 2015
1 parent c599588 commit 300c626
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -21,3 +21,5 @@ results/
learning/
coverage/
report/
_SpecRunner.html
.grunt
30 changes: 30 additions & 0 deletions dist/lettuce.js
Expand Up @@ -108,6 +108,36 @@ Parser.prototype.init = function () {

};

var DSLRunner = {
run: function(methods) {
this.ingredients = [];
this.methods = methods;

this.executeAndRemove('first');

for (var key in this.methods) {
if (key !== 'last' && key.match(/^bake/)) {
this.executeAndRemove(key);
}
}

this.executeAndRemove('last');
},

addIngredient: function(ingredient) {
this.ingredients.push(ingredient);
},

executeAndRemove: function(methodName) {
var output = this.methods[methodName]();
delete(this.methods[methodName]);
return output;
}
};

Parser.prototype = Lettuce.extend(Parser.prototype, DSLRunner);


var parser = {
Parser: Parser
};
Expand Down
4 changes: 2 additions & 2 deletions dist/lettuce.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions specs/parser-spec.js
@@ -1,13 +1,14 @@
'use strict';

describe("Parser", function () {
var L;
var L, Parser;

beforeEach(function() {
L = new lettuce();
Parser = new L.Parser();
});

it('it must be a function ot Lettuce', function () {

});
});
30 changes: 30 additions & 0 deletions src/parser.js
Expand Up @@ -6,6 +6,36 @@ Parser.prototype.init = function () {

};

var DSLRunner = {
run: function(methods) {
this.ingredients = [];
this.methods = methods;

this.executeAndRemove('first');

for (var key in this.methods) {
if (key !== 'last' && key.match(/^bake/)) {
this.executeAndRemove(key);
}
}

this.executeAndRemove('last');
},

addIngredient: function(ingredient) {
this.ingredients.push(ingredient);
},

executeAndRemove: function(methodName) {
var output = this.methods[methodName]();
delete(this.methods[methodName]);
return output;
}
};

Parser.prototype = Lettuce.extend(Parser.prototype, DSLRunner);


var parser = {
Parser: Parser
};
Expand Down

0 comments on commit 300c626

Please sign in to comment.