[macro] add @:style macro
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
"license": "BSD",
|
"license": "BSD",
|
||||||
"tags": ["flash", "openfl"],
|
"tags": ["flash", "openfl"],
|
||||||
"description": "Framework.",
|
"description": "Framework.",
|
||||||
"version": "0.8.1",
|
"version": "0.8.2",
|
||||||
"releasenote": "Update.",
|
"releasenote": "Update.",
|
||||||
"contributors": ["shmyga"],
|
"contributors": ["shmyga"],
|
||||||
"classPath": "src/main",
|
"classPath": "src/main",
|
||||||
|
|||||||
45
src/main/haxework/macro/StyleMacro.hx
Normal file
45
src/main/haxework/macro/StyleMacro.hx
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
package haxework.macro;
|
||||||
|
|
||||||
|
import haxe.macro.Expr.MetadataEntry;
|
||||||
|
import haxe.macro.Context;
|
||||||
|
import haxe.macro.Type.ClassType;
|
||||||
|
|
||||||
|
class StyleMacro {
|
||||||
|
|
||||||
|
private static inline var metaName:String = ':style';
|
||||||
|
|
||||||
|
public static function has(classType:ClassType):Bool {
|
||||||
|
for (md in classType.meta.get()) if (md.name == metaName) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static var style:Dynamic;
|
||||||
|
|
||||||
|
|
||||||
|
private var classType:ClassType;
|
||||||
|
private var bindings:Map<String, String>;
|
||||||
|
|
||||||
|
private var meta(get, never):MetadataEntry;
|
||||||
|
private var styleFile:String;
|
||||||
|
|
||||||
|
private function get_meta():MetadataEntry {
|
||||||
|
for (md in classType.meta.get()) if (md.name == metaName) {
|
||||||
|
return md;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function new(classType:ClassType) {
|
||||||
|
this.classType = classType;
|
||||||
|
var params = Util.getMetaParams(meta);
|
||||||
|
var filePath = params[0];
|
||||||
|
if (filePath == null) {
|
||||||
|
filePath = classType.pack.join("/") + "/" + classType.name + ".yaml";
|
||||||
|
}
|
||||||
|
styleFile = Context.resolvePath(filePath);
|
||||||
|
style = FileUtil.loadFile(styleFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -39,11 +39,17 @@ class TemplateMacro {
|
|||||||
this.classType = classType;
|
this.classType = classType;
|
||||||
this.fields = fields;
|
this.fields = fields;
|
||||||
var params = Util.getMetaParams(meta);
|
var params = Util.getMetaParams(meta);
|
||||||
templateFile = Context.resolvePath(params[0]);
|
var filePath = params[0];
|
||||||
|
if (filePath == null) {
|
||||||
|
filePath = classType.pack.join("/") + "/" + classType.name + ".yaml";
|
||||||
|
}
|
||||||
|
templateFile = Context.resolvePath(filePath);
|
||||||
template = FileUtil.loadFile(templateFile);
|
template = FileUtil.loadFile(templateFile);
|
||||||
if (params.length > 1) {
|
if (params.length > 1) {
|
||||||
var styleFile = params.length > 1 ? Context.resolvePath(params[1]) : null;
|
var styleFile = params.length > 1 ? Context.resolvePath(params[1]) : null;
|
||||||
style = FileUtil.loadFile(styleFile);
|
style = FileUtil.loadFile(styleFile);
|
||||||
|
} else {
|
||||||
|
style = StyleMacro.style;
|
||||||
}
|
}
|
||||||
bindings = findViewsBindings(fields);
|
bindings = findViewsBindings(fields);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package haxework.parser;
|
package haxework.parser;
|
||||||
|
|
||||||
|
import haxework.macro.StyleMacro;
|
||||||
import haxe.macro.Context;
|
import haxe.macro.Context;
|
||||||
import haxe.macro.Expr;
|
import haxe.macro.Expr;
|
||||||
import haxe.macro.Type.ClassType;
|
import haxe.macro.Type.ClassType;
|
||||||
@@ -38,6 +39,9 @@ class Parser {
|
|||||||
fields = result;
|
fields = result;
|
||||||
}
|
}
|
||||||
// process class meta
|
// process class meta
|
||||||
|
if (StyleMacro.has(ct)) {
|
||||||
|
new StyleMacro(ct);
|
||||||
|
}
|
||||||
if (TemplateMacro.has(ct)) {
|
if (TemplateMacro.has(ct)) {
|
||||||
modify = true;
|
modify = true;
|
||||||
var template = new TemplateMacro(ct, fields);
|
var template = new TemplateMacro(ct, fields);
|
||||||
|
|||||||
Reference in New Issue
Block a user