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 GLib.List<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 static JsRender? factory(string xt, Project.Project project, string path)
55 return new Gtk(project, path);
57 return new Roo(project, path);
65 var generator = new Json.Generator ();
67 generator.pretty = true;
68 var node = new Json.Node(Json.NodeType.OBJECT);
69 node.init_object(this.toJsonArray());
70 generator.set_root(node);
72 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
74 generator.to_file(this.path);
80 public void saveHTML ()
87 * load from a javascript file.. rather than bjs..
92 _loadItems : function(cb)
95 if (this.items !== false) {
101 var tr = new TokenReader( {
106 collapseWhite : false,
108 ignoreBadGrammer: true
111 var str = File.read(this.path);
112 var toks = tr.tokenize(new TextStream(str));
113 var rf = new JsParser(toks);
117 this.modOrder = cfg.modOrder || '001';
118 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
119 this.parent = cfg.parent;
120 this.permname = cfg.permname || '';
121 this.title = cfg.title || cfg.name;;
122 this.items = cfg.items || [];
124 //this.fixItems(_this, false);
132 * { success : , failure : , scope : }
139 print("File.getTree tree called on base object?!?!");
142 public Json.Object toJsonArray ()
146 var ret = new Json.Object();
147 ret.set_string_member("id", this.id);
148 ret.set_string_member("name", this.name);
149 ret.set_string_member("parent", this.parent);
150 ret.set_string_member("title", this.title);
151 ret.set_string_member("path", this.path);
152 //ret.set_string_member("items", this.items);
153 ret.set_string_member("permname", this.permname);
154 ret.set_string_member("modOrder", this.modOrder);
161 public string getTitle ()
163 if (this.title.length > 0) {
166 var a = this.path.split("/");
167 return a[a.length-1];
169 public string getTitleTip()
171 if (this.title.length > 0) {
172 return "<b>" + this.title + "</b> " + this.path;
179 this.cn.sort(function(a,b) {
180 return a.path > b.path;// ? 1 : -1;
184 // should be in palete provider really..
186 public string guessName(Node ar) // turns the object into full name.
188 // eg. xns: Roo, xtype: XXX -> Roo.xxx
189 if (!ar.hasXnsType()) {
193 return ar.get("|xns") + "." + ar.get("|xtype");
200 copyTo: function(path, cb)
203 this.loadItems(function() {
214 * munge JSON tree into Javascript code.
216 * NOTE - needs a deep copy of original tree, before starting..
217 * - so that it does not modify current..
219 * FIXME: + or / prefixes to properties hide it from renderer.
220 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
221 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
223 * @arg {object} obj the object or array to munge..
224 * @arg {boolean} isListener - is the array being sent a listener..
225 * @arg {string} pad - the padding to indent with.
228 public string mungeToString(string pad)
230 return this.tree.mungeToString(false, pad, this.doubleStringProps);