소스 검색

- added xml support (files .html, .mtt, .tpl are assumed xhtml)

Laurent Bedubourg 19 년 전
부모
커밋
b3ac014538
2개의 변경된 파일15개의 추가작업 그리고 8개의 파일을 삭제
  1. 11 5
      std/mtwin/templo/Parser.hx
  2. 4 3
      std/mtwin/templo/Template.hx

+ 11 - 5
std/mtwin/templo/Parser.hx

@@ -48,8 +48,10 @@ class Parser {
 	static var XHTML_ATTRS = ["compact","nowrap","ismap","declare","noshade","checked","disabled","readonly","multiple","selected","noresize","defer"];
 
 	var out : mtwin.templo.Generator;
+	var xhtmlMode : Bool;
 
-	public function new(){
+	public function new( ?isXhtml:Bool ){
+		xhtmlMode = (isXhtml == true);
 		out = new mtwin.templo.Generator();
 	}
 
@@ -164,10 +166,10 @@ class Parser {
 		var hasContent = (mtContent != null || xml.firstChild() != null);
 
 		var xhtmlEmpty = isXHTMLEmptyTag(xml.nodeName);
-		if (hasContent && xhtmlEmpty){
+		if (xhtmlMode && hasContent && xhtmlEmpty){
 			hasContent = false;
 		}
-		if (!hasContent && !xhtmlEmpty){
+		if (xhtmlMode && !hasContent && !xhtmlEmpty){
 			hasContent = true;
 		}
 		
@@ -320,14 +322,18 @@ class Parser {
 		out.writeHtml("]]>");
 	}
 
-	static function isBooleanAttribute( attName:String ) : Bool {
+	function isBooleanAttribute( attName:String ) : Bool {
+		if (!xhtmlMode)
+			return false;
 		for (f in XHTML_ATTRS){
 			if (f == attName) return true;
 		}
 		return false;
 	}
 
-	static function isXHTMLEmptyTag( tag:String ) : Bool {
+	function isXHTMLEmptyTag( tag:String ) : Bool {
+		if (!xhtmlMode)
+			return false;
 		for (f in XHTML_EMPTY){
 			if (f == tag) return true;
 		}

+ 4 - 3
std/mtwin/templo/Template.hx

@@ -72,10 +72,11 @@ class Template {
 		}
 		compiledFiles.set(path,true);
 		var content = neko.io.File.getContent(Loader.BASE_DIR+"/"+path);
-		return fromString(content, nekoId(path));
+		var isXhtml = StringTools.endsWith(path, ".mtt") || StringTools.endsWith(path,".html") || StringTools.endsWith(path,".tpl");
+		return fromString(content, nekoId(path), isXhtml);
 	}
 
-	public static function fromString( src:String, ?id:String ) : Dynamic -> String {
+	public static function fromString( src:String, ?id:String, ?isXhtml:Bool ) : Dynamic -> String {
 		if (id == null){
 			id = Md5.encode(src);
 		}
@@ -90,7 +91,7 @@ class Template {
 			throw { message:"Error in "+id+"\n"+Std.string(e), source:src };
 		}
 
-		var p = new mtwin.templo.Parser();
+		var p = new mtwin.templo.Parser(isXhtml == true);
 		var s = p.parse(x);
 
 		s = "// generated from " + id + "\n// temploc v"+mtwin.templo.Template.VERSION+"\n" + s;