Module: Edgarj::CommonHelper

Included in:
EdgarjHelper
Defined in:
app/helpers/edgarj/common_helper.rb

Instance Method Summary collapse

Instance Method Details

#column_label(col_or_sym) ⇒ Object

column label with the following fallback order:

  1. t(‘view.CONTROLLER.MODEL.COLUMN’) if exists.

  2. model.human_attribute_name(col.name)

Parameters:

  • col_or_sym (Column, String, or Symbol)


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/helpers/edgarj/common_helper.rb', line 51

def column_label(col_or_sym)
  col_name =
      case col_or_sym
      when String, Symbol
        col_or_sym
      else
        col_or_sym.name
      end
  @controller_model ||= controller.send(:model)
  I18n.t(col_name,
      scope:    "view.#{controller_path}.#{@controller_model.name.underscore}",
      default:  @controller_model.human_attribute_name(col_name))
end

#date_fmt(dt) ⇒ Object

Edgarj standard date format



15
16
17
18
19
20
21
# File 'app/helpers/edgarj/common_helper.rb', line 15

def date_fmt(dt)
  if dt == nil then
    ''
  else
    dt.strftime(I18n.t('date.formats.default'))
  end
end

#datetime_fmt(dt) ⇒ Object

Edgarj standard datetime format



6
7
8
9
10
11
12
# File 'app/helpers/edgarj/common_helper.rb', line 6

def datetime_fmt(dt)
  if dt.blank? then
    ''
  else
    I18n.l(dt, format: I18n.t('edgarj.time.format'))
  end
end

#get_enum(model, col) ⇒ Object

get enum Module.

When Col(camelized argument col name) module exists, the Col is assumed enum definition.



27
28
29
30
31
32
33
34
35
# File 'app/helpers/edgarj/common_helper.rb', line 27

def get_enum(model, col)
  col_name  = col.name
  if model.const_defined?(col_name.camelize, false)
    enum = model.const_get(col_name.camelize)
    enum.is_a?(Module) ? enum : nil
  else
    nil
  end
end

#model_labelObject

model label with the following fallback order:

  1. t(‘view.CONTROLLER.model’) if exists.

  2. model.human_name



40
41
42
43
44
# File 'app/helpers/edgarj/common_helper.rb', line 40

def model_label
  @controller_model ||= controller.send(:model)
  I18n.t("view.#{controller_path}.model",
      default:  @controller_model.human_name)
end