NOT READY FOR PRODUCTION
This project is under heavy development, and the API has not solidfied yet. Don't use this for anything important...yet.
Synopsis
Bind data to DOM with zero configuration. Just call .fill(data)
.
Fill Fill Uses plain HTML with no extra templating markup Runs on the client or server (with jsdom) Render arrays without loops or partials Nested objects and collections Compatible (tested on IE6+, Chrome and Firefox)
Use it
Install with npm install fill
or get the
compiled and minified version
and include it to your application. jQuery is optional, but if you happen to
use it, fill registers itself as a plugin.
For server-side use, see spec
folder and the awesome
jsdom for the details.
Examples
Assigning values
fill binds JavaScript objects to DOM a element by id
, class
,element name
,
name
attribute and data-bind
attribute. Values are escaped before rendering.
Any keys that are prefixed with an underscore are treated as attributes (with
the exception of _text and _html).
Template:
Javascript:
var hello = _class: 'message' hello: 'Hello' goodbye: 'Goodbye!' span: '<i>See Ya!</i>' greeting: 'Howdy!' 'hi-label': 'Terve!' // Finnish i18n; // with jQuery; // ..or without;
Result:
Hello Goodbye! See Ya! Terve!
Iterating over a list
Template:
Javascript:
var activities = activity: 'Jogging' 'Gym' 'Sky Diving' ; ; // or;
Result:
Jogging Gym Sky Diving
Iterating over a list, using a css class to select the target
Template:
comment
Javascript:
var comments = body: "That rules" body: "Great post!" ;
Result:
commentThat rules commentGreat post!
Nested lists
Template:
Javascript:
var post = title: 'Hello World' post: 'Hi there it is me' comment: name: 'John' text: 'That rules' name: 'Arnold' text: 'Great post!' ; ;
Result:
Hello World Hi there it is me John That rules Arnold Great post!
Nested objects
Template:
Javascript:
var person = firstname: 'John' lastname: 'Wayne' address: street: '4th Street' city: 'San Francisco' zip: '94199' ; ;
Result:
John Wayne 4th Street 94199San Francisco
Global Match (find all matches)
Template:
Javascript:
// prefix with a dollar sign to find all matches// otherwise it will only find the first onevar post = $hello: 'hi'; ;
Result:
hi hi hi
Development environment
You need node.js 0.6.x and npm.
Install dependencies:
npm install
npm install -g uglify-js
Run tests
npm test
Run tests during development for more verbose assertion output
node_modules/jasmine-node/bin/jasmine-node --verbose spec
Generate Javascript libs
node build
Contributing
All the following are appreciated, in an asceding order of preference
- A feature request or a bug report
- Pull request with a failing unit test
- Pull request with unit tests and corresponding implementation
In case the contribution is going to change fill API, please create a ticket first in order to discuss and agree on design.
Origins and Alternatives
This project was forked from the very impressive Transparency project to attempt the following:
- allow the setting of attributes (without needing to use directives)
- eventually phasing out directives completely
- add support for manipulating strings of HTML (without jsdom)
- for superfast rendering of html on server (running node.js)
Similar projects:
- Transparency.js
- from which this project was spawned
- Plates.js
- successor of Weld.js