Editing No-template

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
A super-small Java library for templating, i.e. generating text files (HTML, XML, whatever) from a "template" text file.
A super-small Java library for templating, i.e. generating text files (HTML, XML, whatever) from a "template" text file.


The project home page is [https://github.com/aunkrig/no-template here].
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 <code>no-template</code> is as simple as it could be:
 
package com.acme.notemplatedemo;
import de.unkrig.notemplate.*;
public
class MyTemplate extends NoTemplate {
    public
    MyTemplate(Writer out) {
        super(writer);
    }
    public void
    render(String firstName, String lastName, int age) {
        l(
"<!DOCTYPE html>",
"<html>",
"  <head>",
"    <title>My first template</title>",
"  </head>",
"  <body>",
"    This is my very first template.",
"    <br />",
"    Hello " + firstName + " " + lastName + ",",
"    you must be " + age + " years old!",
"  </body>",
"</html>"
        );
    }
    public static void
    main(String[] args) {
        new MyTemplate(new OutputStreamWriter(System.out)).render("John", "Doe", 99);
    }
}
 
And that would be it!
Please note that all contributions to unkrig.de may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see Unkrig.de:Copyrights for details). Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)