4
# Produces a wrapper DIV element with id and class parameters that
5
# relate to the specified Active Record object. Usage example:
7
# <% div_for(@person, :class => "foo") do %>
13
# <div id="person_123" class="person foo"> Joe Bloggs </div>
15
def div_for(record, *args, &block)
16
content_tag_for(:div, record, *args, &block)
19
# content_tag_for creates an HTML element with id and class parameters
20
# that relate to the specified Active Record object. For example:
22
# <% content_tag_for(:tr, @person) do %>
23
# <td><%=h @person.first_name %></td>
24
# <td><%=h @person.last_name %></td>
27
# would produce the following HTML (assuming @person is an instance of
28
# a Person object, with an id value of 123):
30
# <tr id="person_123" class="person">....</tr>
32
# If you require the HTML id attribute to have a prefix, you can specify it:
34
# <% content_tag_for(:tr, @person, :foo) do %> ...
38
# <tr id="foo_person_123" class="person">...
40
# content_tag_for also accepts a hash of options, which will be converted to
41
# additional HTML attributes. If you specify a <tt>:class</tt> value, it will be combined
42
# with the default class name for your object. For example:
44
# <% content_tag_for(:li, @person, :class => "bar") %>...
48
# <li id="person_123" class="person bar">...
50
def content_tag_for(tag_name, record, *args, &block)
51
prefix = args.first.is_a?(Hash) ? nil : args.shift
52
options = args.extract_options!
53
options.merge!({ :class => "#{dom_class(record)} #{options[:class]}".strip, :id => dom_id(record, prefix) })
54
content_tag(tag_name, options, &block)