Class: Campo::Option
Overview
Options for your Selectas!
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#attributes, #attributes The element's html attributes., #fields, #fields The element's child elements.
Attributes included from Childish
Instance Method Summary collapse
-
#initialize(name, value, inner = nil, selected = nil, attributes = {}) ⇒ Option
constructor
A new instance of Option.
Methods inherited from Base
#each, #labelled, #on_output, #output, output, quotable, unhash
Methods included from Convenience
#bit_of_ruby, #checkbox, #fieldset, #hidden, #input, #literal, #password, #radio, #select, #submit, #text, #textarea
Methods included from Iding
Methods included from Childish
Constructor Details
#initialize(name, value, inner = nil, selected = nil, attributes = {}) ⇒ Option
Returns a new instance of Option.
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 |
# File 'lib/campo/campo.rb', line 569 def initialize( name, value, inner=nil, selected=nil, attributes={} ) unless inner.nil? || inner.kind_of?( String ) attributes = selected selected = inner inner = nil end unless selected.nil? || selected.kind_of?( TrueClass ) if selected.respond_to? :each_pair attributes = selected selected = nil else selected = true @selected = true end end attributes ||= {} @inner = (inner || value.gsub("_"," ").capitalize) attributes = { id: "#{(name.gsub(/\W/, "_") + id_tag(value).gsub(/\W/, "_")).downcase}" }.merge(attributes) unless value.nil? || value.to_s.empty? super( name, { value: value, selected: (selected ? "selected" : nil) }.merge( attributes ) ) atts_string = "atts[:#{@attributes[:id]}]," unless @attributes[:id].nil? self.on_output do |n=0, tab=2| %Q!#{" " * n * tab}%option{ #{atts_string} #{Base.unhash( @attributes )} }#{@inner}! end end |