Open source templating engine for Java with the power of JavaScript. Incredibly small, quick, effective, easy!
- just one dependency, get it here: As-Libs-Core
- templates are fully scriptable, uses the Java builtin JavaScript engine
- Apache License 2.0
To insert the content of a variable:
this is the content of foo: §foo
hence the classic Hello World example:
String res=Cedilla.render("Hello, §what!", new String[]{"what", "World"});
System.out.println(res); // Hello, World!
to execute some javascript inside the template (one line way):
§ var foo="foo"; // this is JavaScript till the enf of line
another one line way:
§ var foo="I'm it!"; §This is foo: §foo
the multi-line way is possibile too, instead of § <javascript> § you just go with §| <javascript> |§
§|
var createdHere=
'This is made now!';
|§this is the content made now: §createdHere
expressions are easy too, you include them in §= <expression> §:
This is more then foo: §= foo+" and some more" §!
This means you can also do things like:
This is more then foo: §= (function()
{
var res="I do whatever I want in expressions too!!";
// do all you want !!!
return res;
})() §!"
also if you provide a CedillaHelper class you can do even more. For example you can load external files:
§= loadFile(".../path/to/external/file...", {also: "pass", what: "some keysValues", and: "Be very Happy! :-))"}); §
or import code from external files:
§ importFrom(".../path/to/external/file...", {also: "pass", what: "some keysValues", and: "Be very Happy! :-))"});
Cedilla is also configurable, you don't like "§" and "|"? No problem, provide your own:
String res=Cedilla.render(
new Configuration()
{{
delimiter="%";
multilineCodeDelimiters=new String[]{"%|", "|%"};
expressionDelimiters=new String[]{"%=", "%"};
internalVarPrefix="ȼ";
}},
"Hello, %what!", Cedilla.toValuesProvider(new String[]{"what", "World"}), null);
System.out.println(res); // Hello, World!
Cedilla can also be used without parameters, since you can create stuff inside the template itself:
String res=Cedilla.render(
"§ var lastPetalIsHeLovesMe=Math.random()>=0.5; §§= "+
"lastPetalIsHeLovesMe ? "+
"'He loves me! 😍' : "+
"'He loves me not! 😭' §"); // just the template, no parameters passed!
System.out.println(res);
// sometimes 'He loves me! 😍', sometimes 'He loves me not! 😭'
Cedilla can be used for whatever kind of file you want, probably even for binary files (not tested).
Compliments, it's a very good idea. 🤗
You can do so right here: Sponsor @ansorre on GitHub sponsors
Why it's a good idea? Read here.