Skip to content

Instantly share code, notes, and snippets.

@RaycatWhoDat
Last active April 1, 2020 13:42
Show Gist options
  • Save RaycatWhoDat/ee6899f2c41d06af6e11c3cac7c48abc to your computer and use it in GitHub Desktop.
Save RaycatWhoDat/ee6899f2c41d06af6e11c3cac7c48abc to your computer and use it in GitHub Desktop.
Macro issues.
<div className="App">
<header className="App-header">
<img src=$logo className="App-logo" alt="logo" />
<p>
Edit <code>src/App.hx</code> and save to reload.
</p>
</header>
</div>
package;
import react.React;
import react.ReactDOM;
import react.ReactComponent;
import react.ReactMacro.jsx;
import AppTools;
/**
* This is the main entrypoint for the application.
*/
@:expose
class App extends ReactComponent {
public function new() {
super();
}
public static function main() {
ReactDOM.render(React.createElement(App), js.Browser.document.getElementById("root"));
trace("Application loaded.");
}
override function render() {
var logo = js.Lib.require("./assets/logo.svg");
return AppTools.insertTemplate("App");
}
}
/*
*/
package;
import haxe.macro.Expr;
#if macro
import sys.io.File;
#end
using haxe.macro.Tools;
class AppTools {
public macro static function insertTemplate(templateName: String) {
var template = "";
try {
template = File.getContent('./${templateName}.html');
} catch (error: String) {
trace("Error: " + error);
}
return macro react.ReactMacro.jsx($v{template});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment