X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/7a654f8d43fdb43d78b63d90528bed6e86b608cc..3789b528d8dd8aad4558e38e22d775bcab1cbd36:/jsbuilder/src/Parser/Statement/If.js?ds=inline diff --git a/jsbuilder/src/Parser/Statement/If.js b/jsbuilder/src/Parser/Statement/If.js new file mode 100644 index 00000000..544b52b0 --- /dev/null +++ b/jsbuilder/src/Parser/Statement/If.js @@ -0,0 +1,57 @@ +Parser.Statement.If = Ext.extend(Parser.Statement, { + satisfied: false, + + evaluate: function() { + var ret = true, n; + + for (n in this.properties) { + if (!Parser.evaluate(n, this.properties[n])) { + ret = false; + break; + } + } + + return (this.isInverted ? !ret : ret); + }, + + parse: function(stream) { + if (this.evaluate()) { + this.satisfied = true; + } + + Parser.Statement.If.superclass.parse.apply(this, arguments); + + if (!this.satisfied) { + return ''; + } + + return this.buffer; + }, + + onSubStatement: function(statement, stream) { + var parsed = statement.parse(stream), + satisfied = false; + + if (statement.type === 'elseif') { + if (!this.satisfied) { + if (statement.evaluate()) { + this.satisfied = true; + satisfied = true; + } + } + } else if (statement.type === 'else') { + if (!this.satisfied) { + this.satisfied = true; + satisfied = true; + } + } else { + this.pushBuffer(parsed); + return; + } + + if (satisfied) { + this.resetBuffer(); + this.pushBuffer(parsed); + } + } +});