Froze rails gems
[depot.git] / vendor / rails / actionpack / lib / action_view / helpers / record_tag_helper.rb
1 module ActionView
2 module Helpers
3 module RecordTagHelper
4 # Produces a wrapper DIV element with id and class parameters that
5 # relate to the specified Active Record object. Usage example:
6 #
7 # <% div_for(@person, :class => "foo") do %>
8 # <%=h @person.name %>
9 # <% end %>
10 #
11 # produces:
12 #
13 # <div id="person_123" class="person foo"> Joe Bloggs </div>
14 #
15 def div_for(record, *args, &block)
16 content_tag_for(:div, record, *args, &block)
17 end
18
19 # content_tag_for creates an HTML element with id and class parameters
20 # that relate to the specified Active Record object. For example:
21 #
22 # <% content_tag_for(:tr, @person) do %>
23 # <td><%=h @person.first_name %></td>
24 # <td><%=h @person.last_name %></td>
25 # <% end %>
26 #
27 # would produce the following HTML (assuming @person is an instance of
28 # a Person object, with an id value of 123):
29 #
30 # <tr id="person_123" class="person">....</tr>
31 #
32 # If you require the HTML id attribute to have a prefix, you can specify it:
33 #
34 # <% content_tag_for(:tr, @person, :foo) do %> ...
35 #
36 # produces:
37 #
38 # <tr id="foo_person_123" class="person">...
39 #
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:
43 #
44 # <% content_tag_for(:li, @person, :class => "bar") %>...
45 #
46 # produces:
47 #
48 # <li id="person_123" class="person bar">...
49 #
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)
55 end
56 end
57 end
58 end