|
@@ -27,19 +27,10 @@ package mtwin.templo;
|
|
|
|
|
|
class Template {
|
|
|
|
|
|
- /** Enable production mode (no file check). */
|
|
|
- public static var OPTIMIZED = false;
|
|
|
- /** Destination of .neko and .n files */
|
|
|
- public static var TMP_DIR = "/tmp/";
|
|
|
- /** Templates repository */
|
|
|
- public static var BASE_DIR = null;
|
|
|
- /** Macros file */
|
|
|
- public static var MACROS = "macros.mtt";
|
|
|
-
|
|
|
public var execute : Dynamic -> String;
|
|
|
|
|
|
public function new( file:String ){
|
|
|
- execute = if (OPTIMIZED) loadTemplate(nekoBin(file)) else fromFile(file);
|
|
|
+ execute = if (File.OPTIMIZED) loadTemplate(nekoBin(file)) else fromFile(file);
|
|
|
}
|
|
|
|
|
|
static function nekoId( path:String ) : String {
|
|
@@ -54,28 +45,28 @@ class Template {
|
|
|
}
|
|
|
|
|
|
static function nekoBin( path:String ) : String {
|
|
|
- return TMP_DIR + nekoId(path) + ".n";
|
|
|
+ return File.TMP_DIR + nekoId(path) + ".n";
|
|
|
}
|
|
|
|
|
|
static function nekoSrc( path:String ) : String {
|
|
|
- return TMP_DIR + nekoId(path) + ".neko";
|
|
|
+ return File.TMP_DIR + nekoId(path) + ".neko";
|
|
|
}
|
|
|
|
|
|
public static function fromFile( path:String ) : Dynamic -> String {
|
|
|
- if (OPTIMIZED)
|
|
|
+ if (File.OPTIMIZED)
|
|
|
return loadTemplate(nekoBin(path));
|
|
|
- if (MACROS != null && mtwin.templo.Preprocessor.macroFileStamp == null)
|
|
|
- mtwin.templo.Preprocessor.registerMacroFile(BASE_DIR+MACROS);
|
|
|
+ if (File.MACROS != null && mtwin.templo.Preprocessor.macroFileStamp == null)
|
|
|
+ mtwin.templo.Preprocessor.registerMacroFile(File.BASE_DIR+File.MACROS);
|
|
|
var binPath = nekoBin(path);
|
|
|
if (neko.FileSystem.exists(binPath)){
|
|
|
var macroStamp = mtwin.templo.Preprocessor.macroFileStamp;
|
|
|
- var sourceStamp = neko.FileSystem.stat(BASE_DIR+"/"+path).mtime.getTime();
|
|
|
+ var sourceStamp = neko.FileSystem.stat(File.BASE_DIR+"/"+path).mtime.getTime();
|
|
|
var stamp = neko.FileSystem.stat(binPath).mtime.getTime();
|
|
|
if ((stamp >= sourceStamp) && (macroStamp == null || macroStamp < stamp)){
|
|
|
return loadTemplate(binPath);
|
|
|
}
|
|
|
}
|
|
|
- var content = neko.File.getContent(BASE_DIR+"/"+path);
|
|
|
+ var content = neko.File.getContent(File.BASE_DIR+"/"+path);
|
|
|
return fromString(content, nekoId(path));
|
|
|
}
|
|
|
|
|
@@ -103,10 +94,10 @@ class Template {
|
|
|
f.write(s);
|
|
|
f.close();
|
|
|
|
|
|
- var r = neko.Sys.command("nekoc -o "+TMP_DIR+" "+path+" 2> "+TMP_DIR+"/nekoc.out");
|
|
|
+ var r = neko.Sys.command("nekoc -o "+File.TMP_DIR+" "+path+" 2> "+File.TMP_DIR+"/nekoc.out");
|
|
|
if (r != 0){
|
|
|
- if (neko.FileSystem.exists(TMP_DIR+"/nekoc.out")){
|
|
|
- throw "nekoc compilation of "+path+" failed ("+r+") : "+neko.File.getContent(TMP_DIR+"/nekoc.out");
|
|
|
+ if (neko.FileSystem.exists(File.TMP_DIR+"/nekoc.out")){
|
|
|
+ throw "nekoc compilation of "+path+" failed ("+r+") : "+neko.File.getContent(File.TMP_DIR+"/nekoc.out");
|
|
|
}
|
|
|
else {
|
|
|
throw "nekoc compilation of "+path+" failed ("+r+") -- no nekoc.out available";
|