Class: Campo::Select
Overview
Literal
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Attributes included from Childish
Instance Method Summary collapse
-
#initialize(name, params = {}) ⇒ Select
constructor
A new instance of Select.
- #option(*args) ⇒ Object
- #with_default(inner = "Choose one:") ⇒ Object
Methods inherited from Base
#labelled, #on_output, #output, output, quotable, unhash
Methods included from Convenience
#bit_of_ruby, #checkbox, #fieldset, #input, #literal, #radio, #select, #submit, #text, #textarea
Methods included from Iding
Methods included from Childish
Constructor Details
#initialize(name, params = {}) ⇒ Select
Returns a new instance of Select.
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 |
# File 'lib/campo.rb', line 337 def initialize( name, params={} ) opts = params[:opts] || [] attributes = params[:attributes] || {} haml_insert = params[:haml_insert] || nil super( name, { tabindex: %q!#{i += 1}! }.merge(attributes) ) self.on_output do |n=0, tab=2| %Q!#{" " * n * tab}%select{ atts[:#{name.gsub(/\W/, "_").downcase}], #{Base.unhash( @attributes )} }! end self.fields += Helpers.( name, opts ) unless opts.nil? || opts.empty? self.fields << Haml_Ruby_Insert.new( haml_insert ) unless haml_insert.nil? self end |
Instance Method Details
#option(*args) ⇒ Object
357 358 359 360 361 362 363 364 |
# File 'lib/campo.rb', line 357 def option( *args ) value = args.shift inner = args.shift selected, attributes = *args inner = value.capitalize if inner.nil? self << Campo::Option.new( @attributes[:name], value, inner, selected, attributes ) self end |