Sha256: b5a9743ce7994fe4424c42fbe803067b96c9c70080fc5fdf89fbd45ca1d1d371

Contents?: true

Size: 926 Bytes

Versions: 12

Compression:

Stored size: 926 Bytes

Contents

module Tramway::Core::Concerns::AttributesDecoratorHelper
  def date_view(value)
    I18n.l value.to_date if value
  end

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

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

  def image_view(value)
    content_tag(: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

  def enumerize_view(value)
    value.text
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
tramway-core-1.13.1.1 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.13.1 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.13.0.2 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.13.0.1 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.13 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.12.1 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.12.0.2 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.12.0.1 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.12 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.11.2.1 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.11.2 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb
tramway-core-1.11.1 app/decorators/tramway/core/concerns/attributes_decorator_helper.rb