wesleytodd / Universal-Forms

A set of libraries based on a universal JSON representation of a form
9 stars 0 forks source link

Template rendering in the Javascript library #1

Open wesleytodd opened 12 years ago

wesleytodd commented 12 years ago

I think this should be an optional package that just has a well documented interface so people can use, or re-implement as needed.

I was thinking a file called renderer.js which provides an interface you can use like:

// Returns an Underscore like template function
UniversalForms.Renderer.getTemplate();

// Renders the template
UniversalForms.Renderer.render(options);

// Use decorator pattern to add methods to object prototype
for (var prop in UniversalForms.Renderer) {
    Field.prototype[prop] = UniversalForms.Renderer[prop];
    Form.prototype[prop] = UniversalForms.Renderer[prop];
}

// Usage
var f = new Form();
$('body').append(f.render());
wesleytodd commented 12 years ago

https://github.com/wesleytodd/Universal-Forms/commit/007fe49dd636aaee2efe79c59ce0b6ad41ea6bcd