1 //<Script type="text/javascript">
6 public errordomain Error {
10 public class JsRender : Object {
12 * @cfg {Array} doubleStringProps list of properties that can be double quoted.
14 public GLib.List<string> doubleStringProps;
17 public string name; // is the JS name of the file.
18 public string fullname;
19 public string path; // is the full path to the file.
20 public string parent; // JS parent.
22 public string title; // a title.. ?? nickname.. ??? -
24 public string permname;
25 public string modOrder;
29 public Project.Project project;
30 //Project : false, // link to container project!
32 public Node tree; // the tree of nodes.
34 public GLib.List<JsRender> cn; // child files.. (used by project ... should move code here..)
36 public bool hasParent;
38 public JsRender(Project.Project project, string path) {
40 this.cn = new GLib.List<JsRender>();
42 this.project = project;
43 this.hasParent = false;
47 var ar = this.path.split("/");
48 // name is in theory filename without .bjs (or .js eventually...)
50 Regex regex = new Regex ("\\.(bjs|js)$");
52 this.name = regex.replace(ar[ar.length-1],ar[ar.length-1].length, 0 , "");
56 this.fullname = (this.parent.length > 0 ? (this.parent + ".") : "" ) + this.name;
61 public static JsRender factory(string xt, Project.Project project, string path)
66 return new Gtk(project, path);
68 return new Roo(project, path);
70 throw new Error.INVALID_FORMAT("JsRender Factory called with xtype=%s", xt);
77 var generator = new Json.Generator ();
79 generator.pretty = true;
80 var node = new Json.Node(Json.NodeType.OBJECT);
81 node.set_object(this.toJsonArray());
82 generator.set_root(node);
84 print("WRITE: " + this.path);// + "\n" + JSON.stringify(write));
86 generator.to_file(this.path);
92 public void saveHTML ()
97 public void loadItems()
99 print("load items not handled..");
106 * load from a javascript file.. rather than bjs..
111 _loadItems : function(cb)
114 if (this.items !== false) {
120 var tr = new TokenReader( {
125 collapseWhite : false,
127 ignoreBadGrammer: true
130 var str = File.read(this.path);
131 var toks = tr.tokenize(new TextStream(str));
132 var rf = new JsParser(toks);
136 this.modOrder = cfg.modOrder || '001';
137 this.name = cfg.name.replace(/\.bjs/, ''); // BC!
138 this.parent = cfg.parent;
139 this.permname = cfg.permname || '';
140 this.title = cfg.title || cfg.name;;
141 this.items = cfg.items || [];
143 //this.fixItems(_this, false);
151 * { success : , failure : , scope : }
158 print("File.getTree tree called on base object?!?!");
161 public Json.Object toJsonArray ()
165 var ret = new Json.Object();
166 ret.set_string_member("id", this.id);
167 ret.set_string_member("name", this.name);
168 ret.set_string_member("parent", this.parent);
169 ret.set_string_member("title", this.title);
170 ret.set_string_member("path", this.path);
171 //ret.set_string_member("items", this.items);
172 ret.set_string_member("permname", this.permname);
173 ret.set_string_member("modOrder", this.modOrder);
180 public string getTitle ()
182 if (this.title.length > 0) {
185 var a = this.path.split("/");
186 return a[a.length-1];
188 public string getTitleTip()
190 if (this.title.length > 0) {
191 return "<b>" + this.title + "</b> " + this.path;
198 this.cn.sort(function(a,b) {
199 return a.path > b.path;// ? 1 : -1;
203 // should be in palete provider really..
205 public string guessName(Node ar) // turns the object into full name.
207 // eg. xns: Roo, xtype: XXX -> Roo.xxx
208 if (!ar.hasXnsType()) {
212 return ar.get("|xns") + "." + ar.get("|xtype");
219 copyTo: function(path, cb)
222 this.loadItems(function() {
233 * munge JSON tree into Javascript code.
235 * NOTE - needs a deep copy of original tree, before starting..
236 * - so that it does not modify current..
238 * FIXME: + or / prefixes to properties hide it from renderer.
239 * FIXME: '*props' - not supported by this.. ?? - upto rendering code..
240 * FIXME: needs to understand what properties might be translatable (eg. double quotes)
242 * @arg {object} obj the object or array to munge..
243 * @arg {boolean} isListener - is the array being sent a listener..
244 * @arg {string} pad - the padding to indent with.
247 public string mungeToString(string pad)
249 return this.tree.mungeToString(false, pad, this.doubleStringProps);
252 public string toSource() {