Class: Peek::Views::Select

Inherits:
View
  • Object
show all
Defined in:
lib/peek/views/select.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#onchangeObject (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

#collectionObject



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

#nameObject



19
20
21
# File 'lib/peek/views/select.rb', line 19

def name
  "peek-select-#{@name}"
end

#parse_optionsObject

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 parse_options
  @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