view builder update
This commit is contained in:
@@ -41,10 +41,11 @@ class Builder {
|
|||||||
private function getPosition(?position:JsonKeyPosition):Position {
|
private function getPosition(?position:JsonKeyPosition):Position {
|
||||||
var min = position == null ? 1 : position.min + 32; // :-(
|
var min = position == null ? 1 : position.min + 32; // :-(
|
||||||
var max = position == null ? 1 : position.max + 32;
|
var max = position == null ? 1 : position.max + 32;
|
||||||
return Context.makePosition({min:min, max:max, file:templateFile});
|
var file = position == null || position.file == null ? templateFile : position.file;
|
||||||
|
return Context.makePosition({min:min, max:max, file:file});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function specialValue(name:String, key:String, a:Array<String>):Dynamic {
|
private function specialValue(name:String, key:String, a:Array<String>, position:JsonKeyPosition):Dynamic {
|
||||||
return switch (a[0]) {
|
return switch (a[0]) {
|
||||||
case "asset":
|
case "asset":
|
||||||
switch (a[1]) {
|
switch (a[1]) {
|
||||||
@@ -56,7 +57,7 @@ class Builder {
|
|||||||
case "res":
|
case "res":
|
||||||
var res = "haxework.provider.Provider.get(haxework.resources.IResources)." + a[1];
|
var res = "haxework.provider.Provider.get(haxework.resources.IResources)." + a[1];
|
||||||
var bindExpr = res + ".bind(\"" + a[2] + "\", " + name + ", \"" + key + "\")";
|
var bindExpr = res + ".bind(\"" + a[2] + "\", " + name + ", \"" + key + "\")";
|
||||||
exprs.push(Context.parse(bindExpr, getPosition()));
|
exprs.push(Context.parse(bindExpr, getPosition(position)));
|
||||||
//res + ".get(\"" + a[2] + "\")";
|
//res + ".get(\"" + a[2] + "\")";
|
||||||
null;
|
null;
|
||||||
case "locale":
|
case "locale":
|
||||||
@@ -65,7 +66,7 @@ class Builder {
|
|||||||
a[1];
|
a[1];
|
||||||
case "layout":
|
case "layout":
|
||||||
var template = BuilderUtil.loadFile(a[1]);
|
var template = BuilderUtil.loadFile(a[1]);
|
||||||
return getValue(name, key, template);
|
return getValue(name, key, template, position);
|
||||||
case "link":
|
case "link":
|
||||||
"(links == null) ? untyped this : Reflect.field(links, \"" + a[1] + "\")";
|
"(links == null) ? untyped this : Reflect.field(links, \"" + a[1] + "\")";
|
||||||
case _:
|
case _:
|
||||||
@@ -73,12 +74,14 @@ class Builder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getValue(name:String, key:String, value:Dynamic):Dynamic {
|
private function getValue(name:String, key:String, value:Dynamic, position:JsonKeyPosition):Dynamic {
|
||||||
return if (Std.is(value, Array)) {
|
return if (Std.is(value, Array)) {
|
||||||
value.map(function(v) { return getValue(null, null, v); });
|
value.map(function(v) {
|
||||||
|
return getValue(null, null, v, position);
|
||||||
|
});
|
||||||
} else if (Std.is(value, String)) {
|
} else if (Std.is(value, String)) {
|
||||||
if (value.charAt(0) == "@") {
|
if (value.charAt(0) == "@") {
|
||||||
specialValue(name, key, value.substring(1, value.length).split(":"));
|
specialValue(name, key, value.substring(1, value.length).split(":"), position);
|
||||||
} else if (~/(0x|#)[A-Fa-f\d]{6}/.match(value)) {
|
} else if (~/(0x|#)[A-Fa-f\d]{6}/.match(value)) {
|
||||||
Std.parseInt(StringTools.replace(Std.string(value), "#", "0x"));
|
Std.parseInt(StringTools.replace(Std.string(value), "#", "0x"));
|
||||||
} else {
|
} else {
|
||||||
@@ -90,11 +93,12 @@ class Builder {
|
|||||||
if (Reflect.hasField(value, "type")) {
|
if (Reflect.hasField(value, "type")) {
|
||||||
var n = "a" + i++;
|
var n = "a" + i++;
|
||||||
var type = Reflect.field(value, "type");
|
var type = Reflect.field(value, "type");
|
||||||
exprs.push(Context.parse("var " + n + " = new " + type + "()", getPosition()));
|
exprs.push(Context.parse("var " + n + " = new " + type + "()", getPosition(position)));
|
||||||
createElement(value, n);
|
createElement(value, n);
|
||||||
n;
|
n;
|
||||||
} else {
|
} else {
|
||||||
value;
|
Context.error("Need type field", getPosition(position));
|
||||||
|
null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
value;
|
value;
|
||||||
@@ -104,8 +108,11 @@ class Builder {
|
|||||||
private function createElement(template:Dynamic, name:String):String {
|
private function createElement(template:Dynamic, name:String):String {
|
||||||
if (Reflect.hasField(template, "style")) {
|
if (Reflect.hasField(template, "style")) {
|
||||||
var s = Reflect.field(style, Reflect.field(template, "style"));
|
var s = Reflect.field(style, Reflect.field(template, "style"));
|
||||||
for (key in Reflect.fields(s)) if (!Reflect.hasField(template, key)) {
|
for (key in Reflect.fields(s)) {
|
||||||
Reflect.setField(template, key, Reflect.field(s, key));
|
if (key.charAt(0) != "$" && !Reflect.hasField(template, key)) {
|
||||||
|
Reflect.setField(template, key, Reflect.field(s, key));
|
||||||
|
Reflect.setField(template, "$" + key, Reflect.field(s, "$" + key));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +136,7 @@ class Builder {
|
|||||||
for (key in Reflect.fields(template)) {
|
for (key in Reflect.fields(template)) {
|
||||||
if (key.charAt(0) == "$" || ["type", "style"].indexOf(key) > -1) continue;
|
if (key.charAt(0) == "$" || ["type", "style"].indexOf(key) > -1) continue;
|
||||||
var position = Reflect.field(template, "$" + key);
|
var position = Reflect.field(template, "$" + key);
|
||||||
var value = getValue(name, key, Reflect.field(template, key));
|
var value = getValue(name, key, Reflect.field(template, key), position);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
exprs.push(Context.parse(name + "." + key + " = " + value, getPosition(position)));
|
exprs.push(Context.parse(name + "." + key + " = " + value, getPosition(position)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class BuilderUtil {
|
|||||||
Context.registerModuleDependency(Context.getLocalModule(), path);
|
Context.registerModuleDependency(Context.getLocalModule(), path);
|
||||||
var content = sys.io.File.getContent(path);
|
var content = sys.io.File.getContent(path);
|
||||||
Context.parse(content, Context.makePosition({min:0, max:0, file:path}));
|
Context.parse(content, Context.makePosition({min:0, max:0, file:path}));
|
||||||
return json ? PositionJsonParser.parse(content) : content;
|
return json ? PositionJsonParser.parse(content, path) : content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getMeta(key:String):Array<String> {
|
public static function getMeta(key:String):Array<String> {
|
||||||
|
|||||||
@@ -3,26 +3,30 @@ package haxework.gui.build;
|
|||||||
typedef JsonKeyPosition = {
|
typedef JsonKeyPosition = {
|
||||||
var min:Int;
|
var min:Int;
|
||||||
var max:Int;
|
var max:Int;
|
||||||
|
var file:String;
|
||||||
}
|
}
|
||||||
|
|
||||||
class PositionJsonParser {
|
class PositionJsonParser {
|
||||||
|
|
||||||
static public inline function parse(str : String) : Dynamic {
|
static public inline function parse(str : String, file : String) : Dynamic {
|
||||||
return new PositionJsonParser(str).parseRec();
|
return new PositionJsonParser(str, file).parseRec();
|
||||||
}
|
}
|
||||||
|
|
||||||
var str : String;
|
var str : String;
|
||||||
var pos : Int;
|
var pos : Int;
|
||||||
|
var file : String;
|
||||||
|
|
||||||
function new( str : String ) {
|
function new( str : String, file:String ) {
|
||||||
this.str = str;
|
this.str = str;
|
||||||
this.pos = 0;
|
this.pos = 0;
|
||||||
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getKeyPosition():JsonKeyPosition {
|
function getKeyPosition():JsonKeyPosition {
|
||||||
return {
|
return {
|
||||||
min: pos,
|
min: pos,
|
||||||
max: pos
|
max: pos,
|
||||||
|
file: file
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user