Stephen M. McKamey, 2008-08-03

JsonML Browser-Side Templating (JsonML+BST)

Architectural Goals:

All of these goals have been met with JsonML+BST.

High-Level Usage Overview

  1. At design-time, a *.jbst template is laid out in plain HTML with inline <% … %> code blocks for data binding.
    See an example *.jbst template.
  2. At build-time, this template is compiled into valid JavaScript.
    See an example pre-compiled template.
  3. At runtime, this template is requested by the browser using a <script src="…" /> tag.
    This template is requested only once and will be cached by the browser.
  4. At runtime, requests for raw JSON data are made which constitute the data to be bound to the template.
  5. At runtime, any combination of templates may be bound (and re-bound) to this same data without needing to request the template(s) or the data over again.
  6. At runtime, binding occurs by combining a UI template with JSON data to produce JsonML which is then built and inserted into the document.

Model-View-Controller (MVC) Pattern

To make an analogy to a familiar concept, this roughly follows the "Model-View-Controller" (MVP) pattern. The JSON data ("Model") is completely separate from the UI template ("View") until the point at which the webpage ("Controller") combines them. Behavioral events in the UI cause the Controller to affect either the Model or the View (or both) and update the display.

Advantages

The combination of separation of concern and leveraging existing standards produces a number of benefits, such as:

Implementation Notes

JsonML+BST Example

To see it in action, play with the live JsonML+BST Example.

Download

The run-time client scripts and a command line implementation of the template compiler are available below.

JsonML+BST template data-binding script:
Template Data Binder: JsonML_BST.js (2.13K)
JSMin'd version: JsonML_BST.js (679 bytes)
JsonML UI builder script:
UI Builder: JsonML2.js (5.62K)
JSMin'd version: JsonML2.js (2.08K)
JsonML+BST Template Compiler:
Compiled Binary for .NET Framework 2.0 (40.4K)
C# Source for .NET Framework 2.0 (80.9K)
Open source license