dotfiles/plugins/tampermonkey-mzte/src/Macro.hx

34 lines
953 B
Haxe
Raw Normal View History

2023-08-19 16:03:22 +02:00
#if macro
import haxe.macro.Compiler;
import haxe.macro.Context;
import sys.FileSystem;
2023-08-19 16:03:22 +02:00
import sys.io.File;
#end
using StringTools;
var assetRoot = "../../cgout/cgassets/tampermonkey-mzte";
2023-08-19 16:03:22 +02:00
macro function init() {
var oldHeader = Context.definedValue("source-header");
var header = Std.string(File.read('$assetRoot/header.txt').readAll());
2023-08-19 16:03:22 +02:00
Compiler.define("source-header", '$header\n//$oldHeader');
return macro {};
}
macro function fileContent(path:String):haxe.macro.Expr.ExprOf<String> {
return macro $v{Std.string(File.read('$assetRoot/$path').readAll())};
2023-08-19 16:03:22 +02:00
}
macro function siteStyles():haxe.macro.Expr.ExprOf<Map<String, String>> {
var map:Array<haxe.macro.Expr> = [];
for (f in FileSystem.readDirectory('$assetRoot/site_styles')) {
if (f.endsWith(".css")) {
map.push(macro $v{f.substr(0, f.length - 4)} => Macro.fileContent($v{'site_styles/$f'}));
}
}
return macro $a{map};
}