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.. ??? -
18 public string permname;
19 public string modOrder;
22 public Project.Project project;
23 //Project : false, // link to container project!
25 public Node tree; // the tree of nodes.
27 public GLib.List<JsRender> cn; // child files.. (used by project ... should move code here..)
29 public bool hasParent;
31 JsRender(Project.Project project, string path) {
33 this.cn = new GLib.List<JsRender>();
35 this.project = project;
36 this.hasParent = false;
39 var ar = this.path.split("/");
40 // name is in theory filename without .bjs (or .js eventually...)
41 Regex regex = new Regex ("\\.(bjs|js)$");
43 this.name = regex.replace(ar[ar.length-1],ar[ar.length-1].length, 0 , "");
45 this.fullname = (this.parent.length > 0 ? (this.parent + ".") : "" ) + this.name;
50 public JsRender? factory(string xt, Project.Project project, string path)
55 return new Gtk(project, path);
57 return new Roo(project, path);
65 var write = this.toJsonArray();
66 var generator = new Json.Generator ();
68 generator.pretty = true;
69 var node = new Json.Node(Json.NodeType.OBJECT);
70 node.init_object(this.toJsonArray());
71 generator.set_root(node);
73 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
74 generator.to_file(this.path);
84 * load from a javascript file.. rather than bjs..
89 _loadItems : function(cb)
92 if (this.items !== false) {
98 var tr = new TokenReader( {
103 collapseWhite : false,
105 ignoreBadGrammer: true
108 var str = File.read(this.path);
109 var toks = tr.tokenize(new TextStream(str));
110 var rf = new JsParser(toks);
114 this.modOrder = cfg.modOrder || '001';
115 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
116 this.parent = cfg.parent;
117 this.permname = cfg.permname || '';
118 this.title = cfg.title || cfg.name;;
119 this.items = cfg.items || [];
121 //this.fixItems(_this, false);
129 * { success : , failure : , scope : }
136 print("File.getTree tree called on base object?!?!");
139 Json.Object toJsonArray ()
143 var ret = new Json.Object();
144 ret.set_string_member("id", this.id);
145 ret.set_string_member("name", this.name);
146 ret.set_string_member("parent", this.parent);
147 ret.set_string_member("title", this.title);
148 ret.set_string_member("path", this.path);
149 //ret.set_string_member("items", this.items);
150 ret.set_string_member("permname", this.permname);
151 ret.set_string_member("modOrder", this.modOrder);
160 if (this.title.length > 0) {
163 var a = this.path.split("/");
164 return a[a.length-1];
168 if (this.title.length > 0) {
169 return "<b>" + this.title + "</b> " + this.path;
176 this.cn.sort(function(a,b) {
177 return a.path > b.path;// ? 1 : -1;
181 // should be in palete provider really..
183 string guessName(Node ar) // turns the object into full name.
185 // eg. xns: Roo, xtype: XXX -> Roo.xxx
186 if (!ar.hasXnsType()) {
190 return ar.get("|xns") + "." + ar.get("|xtype");
197 copyTo: function(path, cb)
200 this.loadItems(function() {
211 * munge JSON tree into Javascript code.
213 * NOTE - needs a deep copy of original tree, before starting..
214 * - so that it does not modify current..
216 * FIXME: + or / prefixes to properties hide it from renderer.
217 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
218 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
220 * @arg {object} obj the object or array to munge..
221 * @arg {boolean} isListener - is the array being sent a listener..
222 * @arg {string} pad - the padding to indent with.
225 public string mungeToString(string pad)
227 return this.tree.mungeToString(false, pad, this.doubleStringProps);