Class: EasyDl::DefinitionListBuilder

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/easy_dl/definition_list_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(obj, template) ⇒ DefinitionListBuilder

Returns a new instance of DefinitionListBuilder.



6
7
8
9
10
# File 'lib/easy_dl/definition_list_builder.rb', line 6

def initialize(obj, template)
  @obj = obj
  @template = template
  @is_active_record = obj.respond_to?(:to_model)
end

Instance Method Details

#item(name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/easy_dl/definition_list_builder.rb', line 12

def item(name)
  concat tag(:dt, nil, true, true)
  concat try_translate(name)
  concat '</dt>'

  concat tag(:dd, nil, true, true)
  if block_given?
    yield @obj
  else
    if val = @obj.send(name)
      concat @template.html_escape( @obj.send(name) )
    end
  end
  concat '</dd>'

end