public class HelloWorld {
public String getMessage() {
return "Hello, World!";
}
public String generateHTML() {
String message = getMessage();
return "<html><body><h1>" + message + "</h1></body></html>";
}
}
html
<html>
<body>
<h1>${helloworld.getMessage()}</h1>
</body>
</html>
import org.webmacro.*;
public class HelloWorld {
private Context context;
public HelloWorld(Context context) {
this.context = context;
}
public String getMessage() {
return "Hello, World!";
}
public String generateHTML() throws Exception {
Template template = context.getTemplate("path/to/helloWorld.wm");
template.put("helloworld", this);
return template.toString();
}
}
import org.webmacro.*;
public class Main {
public static void main(String[] args) throws Exception {
Context context = createWebMacroContext();
HelloWorld helloWorld = new HelloWorld(context);
String html = helloWorld.generateHTML();
System.out.println(html);
}
private static Context createWebMacroContext() {
Context context = null;
// ...
return context;
}
}