Browse Source

新增 getDirectiveNames()、getSharedFunctionNames() 获取当前 engine 指令名与共享模板函数名

James 1 year ago
parent
commit
a29cc45058

+ 16 - 0
src/main/java/com/jfinal/template/Engine.java

@@ -18,7 +18,9 @@ package com.jfinal.template;
 
 import java.lang.reflect.Method;
 import java.math.RoundingMode;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.function.Consumer;
 import com.jfinal.kit.StrKit;
@@ -776,6 +778,20 @@ public class Engine {
         config.setStaticFieldExpression(enable);
         return this;
     }
+
+	/**
+	 * 获取当前 Engine 对象所有指令名称
+	 */
+	public List<String> getDirectiveNames() {
+		return new ArrayList<>(config.directiveMap.keySet());
+	}
+
+	/**
+	 * 获取当前 Engine 对象所有共享模板函数名称
+	 */
+	public List<String> getSharedFunctionNames() {
+		return new ArrayList<>(config.sharedFunctionMap.keySet());
+	}
 }
 
 

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

@@ -57,14 +57,14 @@ public class EngineConfig {
 
 	Compressor compressor = null;
 
-	private Map<String, Define> sharedFunctionMap = createSharedFunctionMap();		// new HashMap<String, Define>(512, 0.25F);
+	Map<String, Define> sharedFunctionMap = createSharedFunctionMap();		// new HashMap<String, Define>(512, 0.25F);
 	private List<ISource> sharedFunctionSourceList = new ArrayList<ISource>();		// for devMode only
 
 	Map<String, Object> sharedObjectMap = null;
 
 	private OutputDirectiveFactory outputDirectiveFactory = OutputDirectiveFactory.me;
 	private ISourceFactory sourceFactory = new FileSourceFactory();
-	private Map<String, Class<? extends Directive>> directiveMap = new HashMap<String, Class<? extends Directive>>(64, 0.5F);
+	Map<String, Class<? extends Directive>> directiveMap = new HashMap<String, Class<? extends Directive>>(64, 0.5F);
 	private SharedMethodKit sharedMethodKit = new SharedMethodKit();
 
 	// 保留指令所在行空白字符的指令