|
@@ -59,6 +59,9 @@ public class EngineConfig {
|
|
|
private Map<String, Class<? extends Directive>> directiveMap = new HashMap<String, Class<? extends Directive>>(64, 0.5F);
|
|
private Map<String, Class<? extends Directive>> directiveMap = new HashMap<String, Class<? extends Directive>>(64, 0.5F);
|
|
|
private SharedMethodKit sharedMethodKit = new SharedMethodKit();
|
|
private SharedMethodKit sharedMethodKit = new SharedMethodKit();
|
|
|
|
|
|
|
|
|
|
+ // 保留指令所在行空白字符的指令
|
|
|
|
|
+ private java.util.Set<String> keepLineBlankDirectives = new java.util.HashSet<>();
|
|
|
|
|
+
|
|
|
private boolean devMode = false;
|
|
private boolean devMode = false;
|
|
|
private boolean reloadModifiedSharedFunctionInDevMode = true;
|
|
private boolean reloadModifiedSharedFunctionInDevMode = true;
|
|
|
private String baseTemplatePath = null;
|
|
private String baseTemplatePath = null;
|
|
@@ -66,14 +69,19 @@ public class EngineConfig {
|
|
|
private String datePattern = "yyyy-MM-dd HH:mm";
|
|
private String datePattern = "yyyy-MM-dd HH:mm";
|
|
|
|
|
|
|
|
public EngineConfig() {
|
|
public EngineConfig() {
|
|
|
|
|
+ // #() 与 #include(...) 系统内置指令需要配置
|
|
|
|
|
+ setKeepLineBlank("output", true);
|
|
|
|
|
+ setKeepLineBlank("include", true);
|
|
|
|
|
+
|
|
|
// Add official directive of Template Engine
|
|
// Add official directive of Template Engine
|
|
|
- addDirective("render", RenderDirective.class);
|
|
|
|
|
- addDirective("date", DateDirective.class);
|
|
|
|
|
- addDirective("escape", EscapeDirective.class);
|
|
|
|
|
- addDirective("string", StringDirective.class);
|
|
|
|
|
- addDirective("random", RandomDirective.class);
|
|
|
|
|
- addDirective("number", NumberDirective.class);
|
|
|
|
|
- addDirective("call", CallDirective.class);
|
|
|
|
|
|
|
+ addDirective("render", RenderDirective.class, true);
|
|
|
|
|
+ addDirective("date", DateDirective.class, true);
|
|
|
|
|
+ addDirective("escape", EscapeDirective.class, true);
|
|
|
|
|
+ addDirective("random", RandomDirective.class, true);
|
|
|
|
|
+ addDirective("number", NumberDirective.class, true);
|
|
|
|
|
+ addDirective("call", CallDirective.class, true);
|
|
|
|
|
+
|
|
|
|
|
+ addDirective("string", StringDirective.class, false);
|
|
|
|
|
|
|
|
// Add official shared method of Template Engine
|
|
// Add official shared method of Template Engine
|
|
|
addSharedMethod(new SharedMethodLib());
|
|
addSharedMethod(new SharedMethodLib());
|
|
@@ -318,12 +326,7 @@ public class EngineConfig {
|
|
|
this.reloadModifiedSharedFunctionInDevMode = reloadModifiedSharedFunctionInDevMode;
|
|
this.reloadModifiedSharedFunctionInDevMode = reloadModifiedSharedFunctionInDevMode;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Deprecated
|
|
|
|
|
- public void addDirective(String directiveName, Directive directive) {
|
|
|
|
|
- addDirective(directiveName, directive.getClass());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- public synchronized void addDirective(String directiveName, Class<? extends Directive> directiveClass) {
|
|
|
|
|
|
|
+ public synchronized void addDirective(String directiveName, Class<? extends Directive> directiveClass, boolean keepLineBlank) {
|
|
|
if (StrKit.isBlank(directiveName)) {
|
|
if (StrKit.isBlank(directiveName)) {
|
|
|
throw new IllegalArgumentException("directive name can not be blank");
|
|
throw new IllegalArgumentException("directive name can not be blank");
|
|
|
}
|
|
}
|
|
@@ -333,7 +336,15 @@ public class EngineConfig {
|
|
|
if (directiveMap.containsKey(directiveName)) {
|
|
if (directiveMap.containsKey(directiveName)) {
|
|
|
throw new IllegalArgumentException("directive already exists : " + directiveName);
|
|
throw new IllegalArgumentException("directive already exists : " + directiveName);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
directiveMap.put(directiveName, directiveClass);
|
|
directiveMap.put(directiveName, directiveClass);
|
|
|
|
|
+ if (keepLineBlank) {
|
|
|
|
|
+ keepLineBlankDirectives.add(directiveName);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void addDirective(String directiveName, Class<? extends Directive> directiveClass) {
|
|
|
|
|
+ addDirective(directiveName, directiveClass, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public Class<? extends Directive> getDirective(String directiveName) {
|
|
public Class<? extends Directive> getDirective(String directiveName) {
|
|
@@ -342,6 +353,19 @@ public class EngineConfig {
|
|
|
|
|
|
|
|
public void removeDirective(String directiveName) {
|
|
public void removeDirective(String directiveName) {
|
|
|
directiveMap.remove(directiveName);
|
|
directiveMap.remove(directiveName);
|
|
|
|
|
+ keepLineBlankDirectives.remove(directiveName);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void setKeepLineBlank(String directiveName, boolean keepLineBlank) {
|
|
|
|
|
+ if (keepLineBlank) {
|
|
|
|
|
+ keepLineBlankDirectives.add(directiveName);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ keepLineBlankDirectives.remove(directiveName);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public boolean isKeepLineBlank(String directiveName) {
|
|
|
|
|
+ return keepLineBlankDirectives.contains(directiveName);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|