Browse Source

jfinal 4.4

James 6 years ago
parent
commit
e1c44e64ab

+ 3 - 3
src/main/java/com/jfinal/template/EngineConfig.java

@@ -71,7 +71,7 @@ public class EngineConfig {
 	private String datePattern = "yyyy-MM-dd HH:mm";
 	
 	public EngineConfig() {
-		// #() 与 #include(...) 系统内置指令需要配置
+		// 内置指令 #() 与 #include() 需要配置,保留指令所在行前后空白字符以及行尾换行字符 '\n'
 		setKeepLineBlank("output", true);
 		setKeepLineBlank("include", true);
 		
@@ -366,8 +366,8 @@ public class EngineConfig {
 		}
 	}
 	
-	public boolean isKeepLineBlank(String directiveName) {
-		return keepLineBlankDirectives.contains(directiveName);
+	public Set<String> getKeepLineBlankDirectives() {
+		return keepLineBlankDirectives;
 	}
 	
 	/**

+ 5 - 5
src/main/java/com/jfinal/template/stat/Lexer.java

@@ -18,7 +18,7 @@ package com.jfinal.template.stat;
 
 import java.util.ArrayList;
 import java.util.List;
-import com.jfinal.template.EngineConfig;
+import java.util.Set;
 
 /**
  * DKFF(Dynamic Key Feature Forward) Lexer
@@ -28,7 +28,7 @@ class Lexer {
 	static final char EOF = (char)-1;
 	static final int TEXT_STATE_DIAGRAM = 999;
 	
-	EngineConfig config;
+	Set<String> keepLineBlankDirectives;
 	
 	char[] buf;
 	int state = 0;
@@ -41,8 +41,8 @@ class Lexer {
 	List<Token> tokens = new ArrayList<Token>();
 	String fileName;
 	
-	public Lexer(EngineConfig config, StringBuilder content, String fileName) {
-		this.config = config;
+	public Lexer(StringBuilder content, String fileName, Set<String> keepLineBlankDirectives) {
+		this.keepLineBlankDirectives = keepLineBlankDirectives;
 		
 		int len = content.length();
 		buf = new char[len + 1];
@@ -490,7 +490,7 @@ class Lexer {
 		tokens.add(paraToken);
 		
 		// 保留指令所在行空白字符
-		if (config.isKeepLineBlank(idToken.value())) {
+		if (keepLineBlankDirectives.contains(idToken.value())) {
 			prepareNextScan(0);
 		} else {
 			trimLineBlank();

+ 1 - 1
src/main/java/com/jfinal/template/stat/Parser.java

@@ -71,7 +71,7 @@ public class Parser {
 	}
 	
 	public StatList parse() {
-		tokenList = new Lexer(env.getEngineConfig(), content, fileName).scan();
+		tokenList = new Lexer(content, fileName, env.getEngineConfig().getKeepLineBlankDirectives()).scan();
 		tokenList.add(EOF);
 		StatList statList = statList();
 		if (peek() != EOF) {