Module: ShowFor::Content

Included in:
Builder
Defined in:
lib/show_for/content.rb

Instance Method Summary collapse

Instance Method Details

#content(value, options = {}, apply_options = true, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/show_for/content.rb', line 3

def content(value, options={}, apply_options=true, &block)

  # cache value for apply_wrapper_options!
  sample_value = value

  # We need to convert value to_a because when dealing with ActiveRecord
  # Array proxies, the follow statement Array# === value return false
  value = value.to_a if value.is_a?(Array)

  content = case value
    when Date, Time, DateTime
      I18n.l value, :format => options.delete(:format) || ShowFor.i18n_format
    when TrueClass
      I18n.t :"show_for.yes", :default => "Yes"
    when FalseClass
      I18n.t :"show_for.no", :default => "No"
    when Array, Hash
      collection_handler(value, options, &block)
    when Proc
      @template.capture(&value)
    when NilClass, Numeric
      value.to_s
    else
      if block
        template.capture(value, &block)
      else
        value
      end
  end

  if content.blank?
    content = blank_value(options)
  end

  options[:content_html] = options.except(:content_tag) if apply_options
  wrap_with(:content, content, apply_wrapper_options!(:content, options, sample_value) )
end