Sha256: e7536d65e3edf37e9ed9922ffb07020bf8f43f5958475079946629cfa9ccec8f

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# coding: UTF-8

module Edgarj
  module CommonHelper
    # Edgarj standard datetime format
    def datetime_fmt(dt)
      if dt.blank? then
        ''
      else
        I18n.l(dt, format: I18n.t('edgarj.time.format'))
      end
    end

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

    # get enum Module.
    #
    # When Col(camelized argument col name) module exists, the Col is
    # assumed enum definition.
    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

    # column label with the following fallback order:
    # 1. t('view.CONTROLLER.label.MODEL.COLUMN') if exists.
    # 1. model.human_attribute_name(col.name)
    def column_label(col)
      @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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
edgarj-0.01.27 app/helpers/edgarj/common_helper.rb