3 public abstract class NodeWriter : Object {
6 protected JsRender file;
10 protected string inpad; // the pad for the class outer
11 protected string pad; // the padd for the methods / properties.
12 protected string ipad;
14 protected Gee.ArrayList<Node> top_level_items; // top level items (was vitems)
15 protected int cur_line;
16 protected NodeWriter top;
23 GLib.error("set called on nodewriter ret");
27 string output = ""; // the result of outputing..
29 Gee.ArrayList<string> ignoreList;
30 static Gee.ArrayList<string>? globalIgnoreList = null;
32 globalIgnoreList = new Gee.ArrayList<string>();
36 * ctor - just initializes things
37 * - wraps a render node
39 protected NodeWriter( JsRender file, Node node, int depth, NodeWriter? parent)
45 this.var_name_count = 0;
47 this.top_level_items = new Gee.ArrayList<Node>();
48 this.cur_line = parent == null ? 0 : parent.cur_line;
49 this.top = parent == null ? this : parent.top;
51 // initialize line data..
52 node.line_start = this.cur_line;
53 node.line_end = this.cur_line;
54 node.lines = new Gee.ArrayList<int>();
55 node.line_map = new Gee.HashMap<int,string>();
57 node.node_lines = new Gee.ArrayList<int>();
58 node.node_lines_map = new Gee.HashMap<int,Node>();
61 this.ignoreList = new Gee.ArrayList<string>();
65 int var_name_count = 0; // was vcnt
67 string toValaNS(Node item)
69 return item.get("xns") + ".";
72 fills in all the xvala_cls names into the nodes
77 public void initPadding(char pad, int len)
80 var has_ns = this.file.xtype == "Gtk" && this.file.file_namespace.length > 0;
82 if (has_ns) { // namespaced..
83 this.inpad = string.nfill((depth > 0 ? 2 : 1)* len, pad);
85 this.inpad = string.nfill((depth > 0 ? 1 : 0) * len , pad);
87 this.pad = this.inpad + string.nfill(len, pad);
88 this.node.node_pad = this.inpad;
89 this.ipad = this.inpad + string.nfill(2* len, pad);;
94 public void toValaName(Node item, int depth =0)
96 this.var_name_count++;
98 var ns = this.toValaNS(item) ;
99 var cls = ns + item.get("xtype");
101 item.xvala_cls = cls;
103 string id = item.get("id").length > 0 ?
104 item.get("id") : "%s%d".printf(item.get("xtype"), this.var_name_count);
109 if (id[0] == '*' || id[0] == '+') {
110 item.xvala_xcls = "Xcls_" + id.substring(1);
112 item.xvala_xcls = "Xcls_" + id;
118 this.top_level_items.add(item);
120 // setting id on top level class changes it classname..
121 // oddly enough we havent really thought about namespacing here.
123 } else if (!item.props.has_key("id")) {
124 // use the file name..
125 item.xvala_xcls = this.file.file_without_namespace;
127 item.xvala_id = this.file.file_without_namespace;
132 if (item.readItems().size < 1) {
135 for(var i =0;i<item.readItems().size;i++) {
136 this.toValaName(item.readItems().get(i), depth+1);
141 protected void addLine(string str= "")
144 if (str.contains("\n")) {
145 this.addMultiLine(str);
150 //if (BuilderApplication.opt_bjs_compile != null) {
151 // this.output += "/*%d*/ ".printf(this.cur_line) + str + "\n";
153 this.output += str + "\n";
156 protected void addMultiLine(string str= "")
159 this.cur_line += str.split("\n").length;
160 //this.ret += "/*%d*/ ".printf(l) + str + "\n";
162 this.output += str + "\n";
164 protected string padMultiline(string pad, string str)
166 var ar = str.strip().split("\n");
167 return string.joinv("\n" + pad , ar);
169 protected static void globalIgnore(string i) {
170 if (globalIgnoreList == null) {
171 globalIgnoreList = new Gee.ArrayList<string>(); // should not happend.. but dont know about ctor process..
173 globalIgnoreList.add(i);
176 protected void ignore(string i) {
177 this.ignoreList.add(i);
181 protected bool shouldIgnore(string i)
183 return globalIgnoreList.contains(i) || ignoreList.contains(i);
188 public abstract string munge();