Class: CML::Tags::Select

Inherits:
CML::Tag show all
Defined in:
lib/cml/tags/select.rb

Constant Summary collapse

Template =
<<-HTML.freeze
{{label}}
<select name="{{name}}" class="{{classes}}">{% for option in options %}
  {{option}}{% endfor %}
</select>
HTML

Instance Attribute Summary

Attributes inherited from CML::Tag

#attrs, #cml, #tag

Instance Method Summary collapse

Methods inherited from CML::Tag

#classes, #convert, #gold=, #gold?, #initialize, #instructions, #label, #legend, #name, #prefix, #raw_label, #to_html, #to_liquid, #to_s, #validate?, #validations, #value, #wrapper, #wrapper_classes

Constructor Details

This class inherits a constructor from CML::Tag

Instance Method Details

#childrenObject



18
19
20
21
22
# File 'lib/cml/tags/select.rb', line 18

def children
  default + @cml.xpath("cml:option").map do |c|
    Option.new(c, @opts)
  end
end

#dataObject



24
25
26
# File 'lib/cml/tags/select.rb', line 24

def data
  super.merge({"options" => children})
end

#defaultObject

Auto magically prepend a default option if required



12
13
14
15
16
# File 'lib/cml/tags/select.rb', line 12

def default
  default = [Option.new("<cml:option value=\"\">#{@cml["default"]}</cml:option>", @opts)] if @cml["default"]
  default ||= [Option.new("<cml:option value=\"\">Select one</cml:option", @opts)] if validations.include?('validates-required')
  default || [] 
end