Class: CML::Tags::Select
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
Instance Method Summary collapse
- #children ⇒ Object
- #data ⇒ Object
-
#default ⇒ Object
Auto magically prepend a default option if required.
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
#children ⇒ Object
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 |
#data ⇒ Object
24 25 26 |
# File 'lib/cml/tags/select.rb', line 24 def data super.merge({"options" => children}) end |
#default ⇒ Object
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 |