Class: Alchemy::Ingredients::DatetimeView

Inherits:
BaseView
  • Object
show all
Defined in:
app/components/alchemy/ingredients/datetime_view.rb

Instance Attribute Summary collapse

Attributes inherited from BaseView

#html_options, #ingredient

Instance Method Summary collapse

Methods inherited from BaseView

#render?

Constructor Details

#initialize(ingredient, date_format: :"alchemy.default", html_options: {}) ⇒ DatetimeView

Returns a new instance of DatetimeView.

Parameters:

  • ingredient (Alchemy::Ingredient)
  • date_format (String) (defaults to: :"alchemy.default")

    The date format to use. Use either a strftime format string, a I18n format symbol or “rfc822”. Defaults to “time.formats.alchemy.default”.



8
9
10
11
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 8

def initialize(ingredient, date_format: :"alchemy.default", html_options: {})
  super(ingredient)
  @date_format = settings_value(:date_format, value: date_format)
end

Instance Attribute Details

#date_formatObject (readonly)

Returns the value of attribute date_format.



4
5
6
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 4

def date_format
  @date_format
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
# File 'app/components/alchemy/ingredients/datetime_view.rb', line 13

def call
  datetime = ingredient.value.in_time_zone(Rails.application.config.time_zone)
  if date_format == "rfc822"
    datetime.to_fs(:rfc822)
  else
    ::I18n.l(datetime, format: date_format)
  end.html_safe
end