Class: Nemo::Examples::DatePicker::Root

Inherits:
Wee::Component
  • Object
show all
Defined in:
lib/nemo/examples/date_picker.rb

Overview

Set the value of a text field to a date string using a MiniCalendar.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(date = Date.today) ⇒ Root

Initialize with a Date object (defaults to today)



14
15
16
17
# File 'lib/nemo/examples/date_picker.rb', line 14

def initialize(date=Date.today)
  super()
  @date = date
end

Instance Attribute Details

#dateObject

Holds the currently chosen date



10
11
12
# File 'lib/nemo/examples/date_picker.rb', line 10

def date
  @date
end

Instance Method Details

#backtrack_state(snapshot) ⇒ Object

Backtrack state



21
22
23
24
# File 'lib/nemo/examples/date_picker.rb', line 21

def backtrack_state(snapshot)
  super
  snapshot.add(self)
end

#calendarObject

Call the calendar component



57
58
59
60
61
# File 'lib/nemo/examples/date_picker.rb', line 57

def calendar
  if date = call( Nemo::Components::MiniCalendar.new(@date) )
    @date = date
  end
end

#renderObject

Render date field, allow user to choose a Date using a MiniCalendar



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/nemo/examples/date_picker.rb', line 34

def render
  super
  r.html do
    r.head { r.title('Calendar Demo'); render_styles }
    r.body do
      r.form do
        r.table { r.table_row { r.table_header {
          r.table do
            r.table_row { r.table_header('Calendar Demo') }
            r.table_row { r.table_data {
              r.text_input.value(@date.strftime('%b %d, %Y')).callback { |input| @date = begin Date.parse(input) rescue Date.today end }
              r.space
              r.nemo_calendar_button.callback { calendar }
            }}
          end
        }}}
      end
    end
  end
end

#render_stylesObject

Render CSS styles



28
29
30
# File 'lib/nemo/examples/date_picker.rb', line 28

def render_styles
  r.link.type('text/css').rel('stylesheet').href('/nemo/calendar.css')
end