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

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

Constant Summary collapse

BASE64_REGEXP =
%r{^(?:[a-zA-Z0-9+/]{4})*(?:|(?:[a-zA-Z0-9+/]{3}=)|
(?:[a-zA-Z0-9+/]{2}==)|(?:[a-zA-Z0-9+/]{1}===))$}x.freeze

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



42
43
44
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 42

def enumerize_view(value)
  value.text
end

#file_view(original, filename: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 31

def file_view(original, filename: nil)
  return unless original.present?

  filename ||= build_filename(original)
  (:div) do
    concat filename
    concat ' '
    concat download_button(filename: filename, original: original) if filename
  end
end

#image_view(original, thumb: nil, filename: nil) ⇒ Object



22
23
24
25
26
27
28
29
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 22

def image_view(original, thumb: nil, filename: nil)
  return unless original.present?

  filename ||= build_filename(original)
  (:div) do
    build_div_content src_original(original), src_thumb(original, thumb), filename || build_filename(original)
  end
end

#state_machine_view(object, attribute_name) ⇒ Object



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

def state_machine_view(object, attribute_name)
  state = object.send(attribute_name)
  I18n.t("state_machines.#{object.class.model_name.to_s.underscore}.#{attribute_name}.states.#{state}")
rescue StandardError
  object.aasm.human_state
end

#yaml_view(value) ⇒ Object



46
47
48
# File 'app/decorators/tramway/core/concerns/attributes_decorator_helper.rb', line 46

def yaml_view(value)
  (:pre) { value.to_yaml }
end