No-template: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
Line 18: | Line 18: | ||
public | public | ||
class MyTemplate extends NoTemplate { | class MyTemplate extends NoTemplate { | ||
public void | public void | ||
render(String firstName, String lastName, int age) { | render(String firstName, String lastName, int age) { | ||
Line 46: | Line 41: | ||
main(String[] args) { | main(String[] args) { | ||
NoTemplate.render(MyTemplate.class, new File("Output.html"), (MyTemplate t) -> { | |||
t.render("John", "Doe", 99); | |||
}); | |||
} | } | ||
} | } | ||
Line 54: | Line 51: | ||
== Resources == | == Resources == | ||
Find binaries [http://no-template.unkrig.de/download/ here]. | Find the binaries [http://no-template.unkrig.de/download/ here]. | ||
Find the source code [https://github.com/aunkrig/no-template here]. | Find the source code [https://github.com/aunkrig/no-template here]. | ||
Find the JAVADOC [http://no-template.unkrig.de/javadoc/index.html here]. | Find the JAVADOC [http://no-template.unkrig.de/javadoc/index.html here]. |
Revision as of 13:12, 2 June 2016
A super-small Java library for templating, i.e. generating text files (HTML, XML, whatever) from a "template" text file.
Working with the common templating frameworks (Freemarker, JSP, PHP, ...), you probably agree on the following inconveniences and problems:
- Each framework has its own syntax and semantics for implementing the dynamic part of a document (variables, control structures, in-source documentation, ...).
- Because the nesting of control structures and the indentation of the static content are generally not identical, it is very hard to write easily-readable code.
- Most templating frameworks have no static typing, i.e. you must always be careful when using (or worse: re-using) variables, because there is no "compile-time checking" of types.
- Powerful debuggers are not available in many cases, so you typcially revert to looking at log files.
- Because there are so many different templating engines, you favorite IDE possibly offers no advanced editor with code completion, refactoring, and the like.
- If the templating engine involves some kind of an "translation" step, then that must be executed on each and every code change - at worst manually.
The approach of no-template
is as simple as it could be:
package com.acme.notemplatedemo; import de.unkrig.notemplate.*; public class MyTemplate extends NoTemplate { public void render(String firstName, String lastName, int age) { l( "<!DOCTYPE html>", "", " ", "My first template ", " ", " ", " This is my very first template.", " <br />", " Hello " + firstName + " " + lastName + ",", " you must be " + age + " years old!", " ", "" ); } public static void main(String[] args) { NoTemplate.render(MyTemplate.class, new File("Output.html"), (MyTemplate t) -> { t.render("John", "Doe", 99); }); } }
And that would be it!
Resources
Find the binaries here.
Find the source code here.
Find the JAVADOC here.