Json2html::Rails
Instead of writing HTML templates json2html relies on JSON transforms to convert a source JSON objects to html. The benefit of using a JSON transform is that they are already readable by the browser and DO NOT require any compilation before use. In addition, json2html allows the following
Short hand notation for mapping data objects to markup Event binding to DOM objects (exclusively with jquery.json2html) Use of inline functions to allow for complex logic during transformation Dynamic building of transform objects
Please checkout the original library: https://github.com/moappi/jquery.json2html
Installation
Add this line to your application's Gemfile:
gem 'json2html-rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install json2html-rails
include the following line to your javascript file:
//require json2html-rails
Usage
Example of a Transform?
var transform =
{tag:'li',id:'${id}',children:[
{tag:'span',html:'${name} ${year}'}
]};
Will render into the following html:
<li id=1123>
<span>Jack and Jill (2001)</span>
</li>
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request