4 To init the Loader, assuming PATH points to the root folder
6 load(PATH + 'src/Loader.js');
7 Loader.setBasePath(PATH + 'src');
9 After that, simply include other classes at will. The behaviour should be similar to require_once in PHP. It is specially useful when you need to include dynamic components during run-time without having to specify all of them at the beginning. For example:
12 Loader.require('Filesystem');
13 Fiesystem.readFile('some/file/here.js');
16 Loader.require(['Filesystem', 'Logger', 'Parser']);
19 Loader.require('Some.Thing.Here'); // Will load Some/Thing/Here.js within the basePath set above
21 This is beautifully utilized by the Parser below to dynamically load Statement classes on demand.
26 The new Parser allows fully customizable build, to be consumed by all of our products. It combines the syntax of inline JavaScript comments & HTML for high readablity. As a quick example, let say we have this chunk of code:
28 alert('Some code here');
30 //<if browser="ie" browserVersion="6">
32 alert("Some ugly hacks just to target IE 6 only");
40 During build time, if we supply the following params:
47 alert('Some code here');
52 Nested conditions / tags are fully supported without sacrificing much build performance. We can mix and match complex conditions when necessary:
53 //<if condition="here">
64 //<deprecated since="1.0">
73 Currently all these are supported:
86 Auto casting during evaluation
87 Boolean: "true" => true, "false" => false
91 Parser package is designed to be highly extensible. All custom tag names have their own corresponding class, extending from Parser.Statement (Parser/Statement.js). Currently we have the following:
99 Debug and Deprecated extends from If, and they make typing more convenient:
102 alert("Stuff in here are strictly for debugging, shouldn't appear during production");
105 Which is equivalent to:
117 Deprecated has a required "since" attribute:
119 //<deprecated since="2.0">
120 alert("Old stuff for backwards compatibility");
123 If the param name "minVersion" (minimum supported version) is set to 3.0 (>2.0) during build, the above will disappear for good.
125 Unknown tags (no equivalent classes that the Loader can find) will be ignored
127 alert("Nothing special")
130 Furture tags can be added with ease based on our needs. This is how Parser.Statement.Debug looks like:
131 Loader.require('Parser.Statement.If');
133 Parser.Statement.Debug = Ext.extend(Parser.Statement.If, {
134 constructor: function() {
135 Parser.Statement.Debug.superclass.constructor.apply(this, arguments);
137 this.setProperty('debug', true);
142 For convenience, conditional inversion can be done like this:
154 Parser is a singleton and does not depend on anything else other than Loader.js and Ext.js. It's unittest-able too. Usage is straight-forward:
163 // Returns the parsed content of the given file, based on the params supplied above
164 var parsed = Parser.parse("path/to/file.js");
166 ###Integration with building process
167 Parser will automatically process final target files right before compression. It takes the "options" property inside jsb3 file as the params, merged with the old "debug" property. For example, currently in ext-touch.jsb3:
171 "name": "Sencha Touch",
172 "target": "ext-touch.js",
179 To supply more params for Parser:
183 "name": "Sencha Touch",
184 "target": "ext-touch.js",
195 From which the Parser will process with the following params:
203 /path/to/jsdb tests/run.js --name parser