# DomFor Helper for creating HTML wrappers ActiveRecord objects [![Build Status](https://travis-ci.org/mgrachev/dom_for.png?branch=master)](https://travis-ci.org/mgrachev/dom_for) [![Coverage Status](https://coveralls.io/repos/mgrachev/dom_for/badge.png?branch=master)](https://coveralls.io/r/mgrachev/dom_for?branch=master) [![Dependency Status](https://gemnasium.com/mgrachev/dom_for.svg)](https://gemnasium.com/mgrachev/dom_for) ## Installation Add this line to your application's Gemfile: gem 'dom_for' And then execute: $ bundle Or install it yourself as: $ gem install dom_for ## Usage ```erb <%= dom_for User, attribute_1: 'value_1', attribute_2: 'value_2', attribute_3: 'value_3' do %> <% @users.each do |user| %> <%= dom_for user, admin: user.admin, blocked: user.blocked do %> <%= content_tag(:span, user.name) %> <% end %> <% end %> <% end %> ``` ```html
Mikhail
Yulia
``` The first argument can be used as a model ActiveRecord: ```erb <%= dom_for User do %> <%= tag(:span) %> <% end %> ``` ```html
``` And record ActiveRecord: ```erb <%= dom_for @user do %> <%= tag(:span) %> <% end %> ``` ```html
``` The second argument passed to additional html-attributes (is optional): ```erb <%= dom_for User, attribute_1: 'value_1', attribute_2: 'value_2' do %> <%= tag(:span) %> <% end %> ``` ```html
``` The third argument, the helper `dom_for`, takes a block of code that will be wrapped in the tag `
` (is optional): ```erb <%= dom_for User %> ``` ```html
``` When defined instance variable with class name, the helper `dom_for` creates the additional html-attributes for this object: ```erb <% @user = User.last %> <%= dom_for User do %> <%= tag(:span) %> <% end %> ``` ```html
``` For each request, the helper `dom_for` creates additional attribute `data-action`, which will be equal to the method of the controller handling the request: ```erb <%= dom_for User do %> <%= tag(:span) %> <% end %> ``` ```html
``` ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create new Pull Request