Permalink
Fetching contributors…
Cannot retrieve contributors at this time
54 lines (37 sloc) 1.55 KB
A little compiler compiling DOM fragments in XML to DOM-building JavaScript functions
To build this code, get and install SBT from
https://github.com/sbt/sbt
Get and install these library/libraries before building:
https://github.com/ritschwumm/xsbt-util
https://github.com/ritschwumm/xsbt-webapp
Use these commands to build:
git clone git@github.com:ritschwumm/xsbt-domc.git
cd xsbt-domc
sbt publish-local
What it does
If you compile an XML snippet like this
<div xid="Message">
<span xid="text"/>
<a xid="remove">x</a>
</div>
you get a JS function like this
function Message() {
... // create a DOM structure
return {
// the toplevel tag is always accessible under this name
"$": ... // the toplevel div
// if a tag has an xid, it is accessible under that name
"Message": ... // the toplevel div by its xid
"text": ... // the text-span by its xid
"remove": ... // the remove-link by its xid
};
}
There is no support for conditionals, looping or any logic.
These need to be done in JS code outside the template mechanism.
Sbt Plugin (package domc-sbt)
Add the plugin to your project in project/plugins.sbt:
addSbtPlugin("de.djini" % "xsbt-domc" % <version>)
Put dom files (named *.dom) sources into
src/main/webapp
Include domc in the webapp pipeline:
webappPipeline += domcProcessor