view example update

This commit is contained in:
2015-07-18 00:02:21 +03:00
parent c532dc6e9f
commit 29b1b05441
4 changed files with 21 additions and 6 deletions

View File

@@ -15,7 +15,12 @@ class ViewExample {
}
public function new() {
new Root(new FormView({listener:this}));
var form = new FormView({listener:this});
Root.bind(form);
trace(form.panel);
trace(form.button1);
trace(form.button2);
trace(form.button3);
}
public function onPress(view:ButtonView):Void {

View File

@@ -10,6 +10,10 @@ import flash.display.Sprite;
class Root {
public static function bind(view:IView, autoSize:Bool = true) {
new Root(view, autoSize);
}
public static var instance(default, null):Root;
public var view(default, null):IView;

View File

@@ -25,12 +25,12 @@ class Builder {
templateFile = Context.resolvePath(templatePath[0]);
templateKey = templatePath[1];
template = BuilderUtil.loadFile(templateFile);
template = BuilderUtil.loadJsonFile(templateFile);
if (templateKey != null) template = Reflect.field(template, templateKey);
if (templateMeta[1] != null) {
styleFile = Context.resolvePath(templateMeta[1]);
style = BuilderUtil.loadFile(styleFile);
style = BuilderUtil.loadJsonFile(styleFile);
}
fields = Context.getBuildFields();
@@ -65,7 +65,7 @@ class Builder {
case "class":
a[1];
case "layout":
var template = BuilderUtil.loadFile(a[1]);
var template = BuilderUtil.loadJsonFile(a[1]);
return getValue(name, key, template, position);
case "link":
"(links == null) ? untyped this : Reflect.field(links, \"" + a[1] + "\")";

View File

@@ -7,11 +7,17 @@ import haxe.macro.Expr.ExprDef;
class BuilderUtil {
public static function loadFile(path:String, json:Bool = true) {
public static function loadJsonFile(path:String) {
Context.registerModuleDependency(Context.getLocalModule(), path);
var content = sys.io.File.getContent(path);
var json = null;
try {
json = PositionJsonParser.parse(content, path);
} catch(error:Dynamic) {
Context.error(error, Context.makePosition({min:0, max:0, file:path}));
}
Context.parse(content, Context.makePosition({min:0, max:0, file:path}));
return json ? PositionJsonParser.parse(content, path) : content;
return json;
}
public static function getMeta(key:String):Array<String> {