Class: Peek::Views::Select
- Inherits:
-
View
- Object
- View
- Peek::Views::Select
- Defined in:
- lib/peek/views/select.rb
Instance Attribute Summary collapse
-
#onchange ⇒ Object
readonly
Returns the value of attribute onchange.
Instance Method Summary collapse
- #collection ⇒ Object
- #name ⇒ Object
-
#parse_options ⇒ Object
A view to present a collection as a select list.
- #selected(controller) ⇒ Object
Instance Attribute Details
#onchange ⇒ Object (readonly)
Returns the value of attribute onchange.
37 38 39 |
# File 'lib/peek/views/select.rb', line 37 def onchange @onchange end |
Instance Method Details
#collection ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/peek/views/select.rb', line 23 def collection if @collection.respond_to?(:call) @collection.call else @collection end end |
#name ⇒ Object
19 20 21 |
# File 'lib/peek/views/select.rb', line 19 def name "peek-select-#{@name}" end |
#parse_options ⇒ Object
A view to present a collection as a select list.
name - Name inserted into the select element’s name collection - A collection of labels and values selected - A lambda returning the currently selected value onchange - JavaScript for the select list onchange attribute
Returns Peek::Views::Select
12 13 14 15 16 17 |
# File 'lib/peek/views/select.rb', line 12 def @name = @options.fetch(:name, "select") @collection = @options.fetch(:collection, []) @selected = @options.delete(:selected) @onchange = @options.delete(:onchange) end |
#selected(controller) ⇒ Object
31 32 33 34 35 |
# File 'lib/peek/views/select.rb', line 31 def selected(controller) if @selected.respond_to?(:call) @selected.call(controller) end end |