Class: Nemo::Examples::DatePicker::Root
- Inherits:
-
Wee::Component
- Object
- Wee::Component
- Nemo::Examples::DatePicker::Root
- 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
-
#date ⇒ Object
Holds the currently chosen date.
Instance Method Summary collapse
-
#backtrack_state(snapshot) ⇒ Object
Backtrack state.
-
#calendar ⇒ Object
Call the calendar component.
-
#initialize(date = Date.today) ⇒ Root
constructor
Initialize with a Date object (defaults to today).
-
#render ⇒ Object
Render date field, allow user to choose a Date using a MiniCalendar.
-
#render_styles ⇒ Object
Render CSS styles.
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
#date ⇒ Object
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 |
#calendar ⇒ Object
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 |
#render ⇒ Object
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..callback { calendar } }} end }}} end end end end |
#render_styles ⇒ Object
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 |