1 //<Script type="text/javascript">
4 public class JsRender.JsRender : Object {
6 * @cfg {Array} doubleStringProps list of properties that can be double quoted.
8 public Array<string> doubleStringProps;
11 public string name; // is the JS name of the file.
12 public string fullname;
13 public string path; // is the full path to the file.
14 public string parent; // JS parent.
16 public string title; // a title.. ?? nickname.. ??? -
17 public Project.Project project;
18 //Project : false, // link to container project!
20 public Node tree; // the tree of nodes.
22 public GLib.List<JsRender> cn; // child files.. (used by project ... should move code here..)
24 public bool hasParent;
26 JsRender(Project.Project project, string path) {
28 this.cn = new GLib.List<JsRender>();
30 this.project = project;
31 this.hasParent = false;
34 var ar = this.path.split("/");
35 // name is in theory filename without .bjs (or .js eventually...)
36 Regex regex = new Regex ("\\.(bjs|js)$");
38 this.name = regex.replace(ar[ar.length-1],ar[ar.length-1].length, 0 , "");
40 this.fullname = (this.parent.length > 0 ? (this.parent + ".") : "" ) + this.name;
45 public JsRender? factory(string xt, Project.Project project, string path)
50 return new Gtk(project, path);
52 return new Roo(project, path);
60 var write = this.toJsonArray();
61 var generator = new Json.Generator ();
63 generator.pretty = true;
64 var node = new Json.Node();
65 node.init_object(this.toJsonArray());
66 generator.set_root(node);
68 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
69 generator.to_file(this.path);
79 * load from a javascript file.. rather than bjs..
84 _loadItems : function(cb)
87 if (this.items !== false) {
93 var tr = new TokenReader( {
98 collapseWhite : false,
100 ignoreBadGrammer: true
103 var str = File.read(this.path);
104 var toks = tr.tokenize(new TextStream(str));
105 var rf = new JsParser(toks);
109 this.modOrder = cfg.modOrder || '001';
110 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
111 this.parent = cfg.parent;
112 this.permname = cfg.permname || '';
113 this.title = cfg.title || cfg.name;;
114 this.items = cfg.items || [];
116 //this.fixItems(_this, false);
124 * { success : , failure : , scope : }
131 print("File.getTree tree called on base object?!?!");
134 Json.Object toJsonArray ()
138 var ret = new Json.Object();
139 ret.set_string_member("id", this.id);
140 ret.set_string_member("name", this.name);
141 ret.set_string_member("parent", this.parent);
142 ret.set_string_member("title", this.title);
143 ret.set_string_member("path", this.path);
144 //ret.set_string_member("items", this.items);
145 ret.set_string_member("permname", this.permname);
146 ret.set_string_member("modOrder", this.modOrder);
155 if (this.title.length > 0) {
158 var a = this.path.split('/');
159 return a[a.length-1];
163 if (this.title.length > 0) {
164 return "<b>" + this.title + "</b> " + this.path;
171 this.cn.sort(function(a,b) {
172 return a.path > b.path;// ? 1 : -1;
176 // should be in palete provider really..
178 string guessName(Node ar) // turns the object into full name.
180 // eg. xns: Roo, xtype: XXX -> Roo.xxx
181 if (!ar.hasXnsType()) {
185 return ar.get("|xns") +'.' + ar.get("|xtype");
192 copyTo: function(path, cb)
195 this.loadItems(function() {
206 * munge JSON tree into Javascript code.
208 * NOTE - needs a deep copy of original tree, before starting..
209 * - so that it does not modify current..
211 * FIXME: + or / prefixes to properties hide it from renderer.
212 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
213 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
215 * @arg {object} obj the object or array to munge..
216 * @arg {boolean} isListener - is the array being sent a listener..
217 * @arg {string} pad - the padding to indent with.
220 public string mungeToString(string pad)
222 return this.tree.mungeToString(false, pad);