A script/template engine implemented in pure Java (Java 17+).
- Maven
<dependency>
<groupId>org.febit.wit</groupId>
<artifactId>wit-core</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>- Gradle
implementation 'org.febit.wit:wit-core:3.0.0-SNAPSHOT'
- Config Wit engine, load script and eval:
Wit wit = Wit.builder()
// set DispatchLoader with multiple rules.
.loader(Loaders.dispatch()
// Load script from string content.
.rule("code:", Loaders.string().build())
// Load script from FileSystem with a specific root.
.rule("file:", Loaders.fileSystem()
.root("path/to/local/scripts")
// Enable caching for file system loader.
.cacheEnabled(true)
.build())
// ... add more rules if needed
.build())
.build();
Script script = wit.script("""
code: echo "Hello Wit!";
""");
script.
eval(Vars.empty(),out);- What happens next:
Wit.builder()assembles the engine with a loader and extension points.wit.script(...)resolves the script source and returns aScript.- On first use, the script is parsed into executable IR.
script.eval(...)runs that IR with your inputs and output target.
%>Hello Wit!<%
var books;
{
for(book : books) {
%>
${for.iter.index + 1}.《${book.name}》 ¥${book.price}
<%
}
}
{
var func = function(a, b) {
return a + b + arguments[3];
};
echo func("a", "b", "c");
}
{
var map = {
books,
1: 1,
"key2": "value2",
3: 2 + 1
};
map[5] = 2 + 3;
map.~put("6", 2*3);
for(key, value : map) {
echo key + ":" +value + "\n";
}
}
%>Febit Wit 3 is released under the Apache-2.0 license. See the bundled LICENSE file for details.
- ASM under the BSD License.License file