[Helma-dev] MarkupLib
Hannes Wallnoefer
hannes at helma.at
Tue May 11 17:22:40 CEST 2004
I uploaded some initial code that hopefully will soon result in a Helma
Markup Library:
http://adele.helma.org/download/helma/contrib/hannes/markuplib/
For a short description of what I'm planning to do:
http://gobble.helma.org/Brainstorming/markup+objects/
The advantage of this approach compared to using AntvilleLib Html.* or
verbatim HTML forms in skins is that you get an object representation of
your forms that lets you do value manipulation, validation and caching
in a very smooth way. Here's a snipped of code that illustrates its
features:
function getForm() {
// create form structure
var form = HtmlForm("form", {method: "post"}, [
HtmlInput("name", {size: 40}),
HtmlTextarea("body", {rows: 10, cols: 50}),
HtmlInput("counter", {size: 5}),
HtmlInput("save", {type: "submit", value: "go"})
]);
// populate form from this
form.populate(this);
// set up validation hooks
form.all.name.validate = function() {
this.value = this.value.toUpperCase();
}
form.all.body.validate = function() {
this.value = this.value.toLowerCase();
}
form.all.counter.validate = function() {
var value = parseInt(this.value);
this.value = isNaN(value) ? 0 : ++value;
}
return form;
}
function form_test_action() {
var form = this.getForm();
// if form submitted, read request and validate
if (req.isPost()) {
form.populate(req.data);
form.validate();
}
// render form
form.render();
}
One big missing part is skin interoperability. It's currently not
possible to embed Markup objects in skins, i.e. there is no way to place
markup elements within a skin using macros. There's no trivial way of
doing this (short of setting up macros or macro properties dynamically),
which led me to the conclusion that the Helma macro lookup code is too
rigid. I'm currently considering adding macro resolutino via a
renderMacro(name) function. Let me know if you have any ideas/opinions
on this.
BTW, I think this might be destined to become part of HelmaLib.
Currently, everything is implemented as HopObjects, but we don't really
use any HopObject features, so it might as well be implemented as
vanilla JS objects in Global.
Hannes
More information about the Helma-dev
mailing list