class Makup::Decorator

Attributes

helpers[RW]

Public Class Methods

new(helpers = nil) click to toggle source
# File lib/makup/decorator.rb, line 6
def initialize(helpers = nil)
  @helpers = helpers
  @helpers ||= ApplicationController.helpers rescue nil
end

Public Instance Methods

decorate(value) click to toggle source
# File lib/makup/decorator.rb, line 11
def decorate(value)
  method = decorator_method(value)

  if respond_to?(method)
    send(method, value)
  else
    value
  end
end
decorate_ActiveSupport_TimeWithZone(value) click to toggle source
# File lib/makup/decorator.rb, line 30
def decorate_ActiveSupport_TimeWithZone(value)
  l(value)
end
decorate_Date(value) click to toggle source
# File lib/makup/decorator.rb, line 26
def decorate_Date(value)
  l(value)
end
decorate_FalseClass(value) click to toggle source
# File lib/makup/decorator.rb, line 42
def decorate_FalseClass(value)
  t(value.to_s)
end
decorate_Fixnum(value) click to toggle source
# File lib/makup/decorator.rb, line 50
def decorate_Fixnum(value)
  helpers.number_with_delimiter(value)
end
decorate_Float(value) click to toggle source
# File lib/makup/decorator.rb, line 46
def decorate_Float(value)
  helpers.number_with_delimiter(value)
end
decorate_Time(value) click to toggle source
# File lib/makup/decorator.rb, line 34
def decorate_Time(value)
  l(value)
end
decorate_TrueClass(value) click to toggle source
# File lib/makup/decorator.rb, line 38
def decorate_TrueClass(value)
  t(value.to_s)
end
decorator_method(value) click to toggle source
# File lib/makup/decorator.rb, line 21
def decorator_method(value)
  type = value.class.to_s.gsub('::', '_')
  "decorate_#{type}"
end
l(value, options = {}) click to toggle source
# File lib/makup/decorator.rb, line 54
def l(value, options = {})
  if helpers.present?
    helpers.l(value, options)
  else
    I18n.l(value, options)
  end
end
t(value, options = {}) click to toggle source
# File lib/makup/decorator.rb, line 62
def t(value, options = {})
  if helpers.present?
    helpers.t(value, options)
  else
    I18n.t(value, options)
  end
end