Skip to content

A Java template tool for separating logic from design completely.

License

Notifications You must be signed in to change notification settings

kawasima/moshas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Moshas

Moshas is a java template tool.

If you use moshas, you can separate logic from HTML completely.

A template is a pure HTML as follows:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Moshas tutorial!</title>
    </head>
    <body>
        <p>Hello world!</p>
        <p id="message">A message could go here.</p>
    </body>
</html>

And define the view logic as follows:

MoshasEngine engine = new MoshasEngine();
Template indexTemplate = engine.defineTemplate("index", t -> {
    t.select("p#message", text("message"));
});
Context context = new Context();
context.setVariable("message", "We changed the message!");
indexTemplate.render(context, System.out);

Manual

MoshasEngine

MoshasEngine processes rendering templates.

MoshasEngine moshas = new MoshasEngine();

Template

The template class represents a pure HTML template file and binds view logic.

HTML template file is very simple as follows:

<html>
<body>
  <p id="msg">Replace here!</p>
</body>
</html>

Describes view logic to MoshasEngine. select method defines a selector and a manipulation of the selected element.

moshas.describe("template", t -> {
    t.select("msg", (el, ctx) -> el.text(ctx.getString("msg")));
});

To render the template as follows:

Context ctx = new Context();
ctx.setVariable("msg", "Hello world!");
moshas.process("template", ctx);

And then moshas engine renders as follows:

<html>
<body>
  <p id="msg">Hello world!</p>
</body>
</html>

Snippet

About

A Java template tool for separating logic from design completely.

Resources

License

Stars

Watchers

Forks

Packages

No packages published