Module: Tramway::Core::Concerns::AttributesDecoratorHelper

Included in:
ApplicationDecorator
Defined in:
app/decorators/tramway/core/concerns/attributes_decorator_helper.rb

Instance Method Summary collapse

Instance Method Details

#date_view(value) ⇒ Object



4
5
6
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 4

def date_view(value)
  I18n.l value.to_date if value
end

#datetime_view(value) ⇒ Object



8
9
10
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 8

def datetime_view(value)
  I18n.l value if value
end

#enumerize_view(value) ⇒ Object



30
31
32
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 30

def enumerize_view(value)
  value.text
end

#image_view(value) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 16

def image_view(value)
  (:div) do
    begin
      if value.url.match(/jpg|JPG|png|PNG$/)
        concat image_tag value.try(:small) ? value.small.url : value.url
      end
    rescue NoMethodError => e
      error = Tramway::Error.new plugin: :core, method: :image_view, message: e.name == :url ? 'You should mount PhotoUploader to your model. Just add `mount_uploader #{attribute_name}, PhotoUploader` to your model' : e.message
      raise error.message
    end
    concat link_to(fa_icon(:download), value.url, class: 'btn btn-success')
  end
end

#state_machine_view(object, attribute_name) ⇒ Object



12
13
14
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 12

def state_machine_view(object, attribute_name)
  object.send "human_#{attribute_name}_name"
end