Manifests
A library that wants to expose new tags to MXHX may create an XML manifest that maps tag names to fully-qualified class names.
The following example manifest creates two new tags.
<componentPackage>
<component id="MyComponent" class="com.example.MyComponent"/>
<component id="AnotherComponent" class="com.example.AnotherComponent"/>
</componentPackage>
A manifest may be registered with mxhx.macros.MXHXComponent
in a Haxe initialization macro.
The following example creates a class with a static initialize()
method that may be used as an initialization macro. If this class is located at ./src/com/example/macros/MXHXMacro.hx, it assumes that the manifest may be found at ./mxhx-manifest.xml (in the parent directory of src).
package com.example.macros;
#if macro
import haxe.io.Path;
import haxe.macro.Context;
import haxe.macro.Expr;
class MXHXMacro {
private static final NS_URI = "https://ns.example.com/mxhx";
private static final MANIFEST_FILE_NAME = "mxhx-manifest.xml";
public static function initialize():Void {
var libraryPath = getLibraryPath();
if (libraryPath == null) {
return;
}
var manifestPath = Path.join([libraryPath, MANIFEST_FILE_NAME]);
mxhx.macros.MXHXComponent.registerManifest(NS_URI, manifestPath);
}
private static function getLibraryPath():String {
var t = Context.getModule("com.example.macros.MXHXMacro");
var filePath:String = null;
switch (t[0]) {
case TInst(t, params):
filePath = Context.getPosInfos(t.get().pos).file;
default:
return null;
}
return Path.join([Path.directory(filePath), "..", "..", ".."]);
}
}
To use this initialization macro, specify the --macro
compiler option.
In an .hxml file:
--macro com.example.macros.MXHXMacro.initialize()
In an OpenFL project.xml file:
<haxeflag name="--macro" value="com.example.macros.MXHXMacro.initialize()"/>