-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
compiler/src/main/java/com/github/mustachejava/codes/DynamicPartialCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.github.mustachejava.codes; | ||
|
||
import com.github.mustachejava.DefaultMustacheFactory; | ||
import com.github.mustachejava.TemplateContext; | ||
|
||
import java.io.Writer; | ||
import java.util.List; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
|
||
public class DynamicPartialCode extends DefaultCode { | ||
public DynamicPartialCode(TemplateContext tc, DefaultMustacheFactory df, String name) { | ||
super(tc, df, null, name, ">*"); | ||
} | ||
|
||
private final ConcurrentMap<String, PartialCode> partialCodeMap = new ConcurrentHashMap<>(); | ||
|
||
@Override | ||
public Writer execute(Writer writer, List<Object> scopes) { | ||
String partialName = (String) binding.get(scopes); | ||
if (partialName == null) { | ||
return appendText(writer); | ||
} | ||
PartialCode partialCode = partialCodeMap.computeIfAbsent(partialName, name -> { | ||
PartialCode pc = new PartialCode(tc, df, partialName); | ||
pc.append(appended); | ||
pc.init(); | ||
return pc; | ||
}); | ||
return partialCode.execute(writer, scopes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters