1 //<Script type="text/javascript">
4 class JsRender.JsRender : Object {
6 * @cfg {Array} doubleStringProps list of properties that can be double quoted.
8 Array<string> doubleStringProps;
11 string name; // is the JS name of the file.
12 string path; // is the full path to the file.
13 string parent; // JS parent.
15 string title; // a title.. ?? nickname.. ??? -
16 Project.Project project;
17 //Project : false, // link to container project!
19 Node tree; // the tree of nodes.
21 GLib.List<JsRender> cn; // child files.. (used by project ... should move code here..)
24 void JsRender(Project.Project project, string path) {
26 this.cn = new GLib.List<JsRender>();
28 this.project = project;
32 .JsRender? factory(string xt, Project.Project project, string path)
37 return new JsRender.Gtk(project, path);
39 return new JsRender.Roo(project, path);
47 var write = this.toJsonArray();
48 var generator = new Json.Generator ();
50 generator.pretty = true;
51 var node = new Json.Node();
52 node.init_object(this.toJsonArray());
53 generator.set_root(node);
55 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
56 generator.to_file(this.path);
66 * load from a javascript file.. rather than bjs..
71 _loadItems : function(cb)
74 if (this.items !== false) {
80 var tr = new TokenReader( {
85 collapseWhite : false,
87 ignoreBadGrammer: true
90 var str = File.read(this.path);
91 var toks = tr.tokenize(new TextStream(str));
92 var rf = new JsParser(toks);
96 this.modOrder = cfg.modOrder || '001';
97 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
98 this.parent = cfg.parent;
99 this.permname = cfg.permname || '';
100 this.title = cfg.title || cfg.name;;
101 this.items = cfg.items || [];
103 //this.fixItems(_this, false);
111 * { success : , failure : , scope : }
118 print("File.getTree tree called on base object?!?!");
121 Json.Object toJsonArray ()
125 var ret = new Json.Object();
126 ret.set_string_member("id", this.id);
127 ret.set_string_member("name", this.name);
128 ret.set_string_member("parent", this.parent);
129 ret.set_string_member("title", this.title);
130 ret.set_string_member("path", this.path);
131 //ret.set_string_member("items", this.items);
132 ret.set_string_member("permname", this.permname);
133 ret.set_string_member("modOrder", this.modOrder);
142 if (this.title.length > 0) {
145 var a = this.path.split('/');
146 return a[a.length-1];
150 if (this.title.length > 0) {
151 return "<b>" + this.title + "</b> " + this.path;
158 this.cn.sort(function(a,b) {
159 return a.path > b.path;// ? 1 : -1;
163 // should be in palete provider really..
165 string guessName(JsRender.Node ar) // turns the object into full name.
167 // eg. xns: Roo, xtype: XXX -> Roo.xxx
168 if (!ar.hasXnsType()) {
172 return ar.get("|xns") +'.' + ar.get("|xtype");
179 copyTo: function(path, cb)
182 this.loadItems(function() {
193 * munge JSON tree into Javascript code.
195 * NOTE - needs a deep copy of original tree, before starting..
196 * - so that it does not modify current..
198 * FIXME: + or / prefixes to properties hide it from renderer.
199 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
200 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
202 * @arg {object} obj the object or array to munge..
203 * @arg {boolean} isListener - is the array being sent a listener..
204 * @arg {string} pad - the padding to indent with.
207 function mungeToString(string pad)
209 return this.tree.mungeToString(false, pad);