Class: Formatic::Date

Inherits:
Base show all
Defined in:
app/components/formatic/date.rb

Overview

Date/calendar

Defined Under Namespace

Classes: Day

Instance Method Summary collapse

Methods inherited from Base

#data, #input_name, #param_key, #value, #wrapper

Methods inherited from ApplicationComponent

#initialize

Constructor Details

This class inherits a constructor from Formatic::ApplicationComponent

Instance Method Details

#calendar(now: ::Time.current) ⇒ Object



90
91
92
93
94
95
96
97
# File 'app/components/formatic/date.rb', line 90

def calendar(now: ::Time.current)
  from = skip_past ? now.to_date : (now.to_date - 5.days)
  till = now.beginning_of_month.advance(months: 2).end_of_month.to_date

  (from..till).map do |date|
    ::Formatic::Date::Day.new(date:)
  end
end

#calendar?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
# File 'app/components/formatic/date.rb', line 47

def calendar?
  return false if show_calendar == false
  return false if discard_day

  true
end

#css_classesObject



43
44
45
# File 'app/components/formatic/date.rb', line 43

def css_classes
  i[c-formatic-date__input]
end

#day_attribute_nameObject



66
67
68
# File 'app/components/formatic/date.rb', line 66

def day_attribute_name
  "#{f.object.model_name.param_key}[#{attribute_name}(3i)]"
end

#day_input_idObject



78
79
80
# File 'app/components/formatic/date.rb', line 78

def day_input_id
  "#{f.object.model_name.param_key}_#{attribute_name}_3i"
end

#month_attribute_nameObject



70
71
72
# File 'app/components/formatic/date.rb', line 70

def month_attribute_name
  "#{f.object.model_name.param_key}[#{attribute_name}(2i)]"
end

#month_input_idObject



82
83
84
# File 'app/components/formatic/date.rb', line 82

def month_input_id
  "#{f.object.model_name.param_key}_#{attribute_name}_2i"
end

#options_for_dayObject



54
55
56
# File 'app/components/formatic/date.rb', line 54

def options_for_day
  options_for_select collection_for_day, f.object.public_send(attribute_name)&.day
end

#options_for_monthObject



58
59
60
# File 'app/components/formatic/date.rb', line 58

def options_for_month
  options_for_select collection_for_month, f.object.public_send(attribute_name)&.month
end

#options_for_yearObject



62
63
64
# File 'app/components/formatic/date.rb', line 62

def options_for_year
  options_for_select collection_for_year, f.object.public_send(attribute_name)&.year
end

#year_attribute_nameObject



74
75
76
# File 'app/components/formatic/date.rb', line 74

def year_attribute_name
  "#{f.object.model_name.param_key}[#{attribute_name}(1i)]"
end

#year_input_idObject



86
87
88
# File 'app/components/formatic/date.rb', line 86

def year_input_id
  "#{f.object.model_name.param_key}_#{attribute_name}_1i"
end