I’m working a bit on integrating the Fabulator engine into the Writing and Learning Communities software (source code is on github). WLC manages assignments as sequences of timed modules that manage student interaction. Except for the peer messaging, informational, and rubric modules, a module is a simple state machine with accompanying views and other metadata. This is exactly what the Fabulator engine is designed for. In fact, the WLC software was an early exploration of the idea in Ruby.
Using the Fabulator engine in WLC means we will have two application frameworks with different needs using the same engine and able to share the same extensions. Some framework-specific glue might be needed, but it should be minimal and behind the scenes. An extension that allows a DH project to access a remote resource, for example, will also allow that same resource to be used in designing an assignment.
One thing that the DH side of the shop has that the WLC doesn’t really have is a template engine. Since I envision a custom template system for DH as well someday as I explore the presentation layer design for long-term preservation of projects, I’m going ahead and building a template engine for the Fabulator system. I’ll use this to render the forms for assignment modules.
The logic elements of the template system is based on Radius, the XML-like template system used in Radiant. Right now, we have a element that passes our tests. The element is coded but hasn’t been tested yet.
The complete parsing process has several stages. The initial stage is to execute all of the tags. This is what is done in Radiant. Nothing new in this part. However, we have several additional steps available.
I use a form markup language that is not HTML. This allows me to focus on the logical structure of the form instead of how it is rendered in HTML. For example, the difference between radio buttons and checkboxes is a matter of how many choices can be made at once. The form language reflects this.
Once a template is parsed and run, additional methods allow the setting of default values for form elements (useful for rendering a form when editing an existing piece of information), set the captions for form elements (needed when using a module in an assignment), and set error messages/missing information markers.
After all of this information is added, the form can be output as html. The library uses an XSLT internally since the template is already parsed into a DOM.
A typical use of the template system might be:
parser = Fabulator::Template::Parser.new
parsed = parser.parse(context, text)
rendered = parsed.to_html
The ‘context’ here is a Fabulator::Expr::Context object. This would typically come from the state machine object. As a result, only the namespaces declared in the root element of the state machine definition will be available in any expressions run in the template.