Class: Campo::Input

Inherits:
Base
  • Object
show all
Defined in:
lib/campo.rb

Overview

form << Campo::Input.new( “submit”, :submit )

Constant Summary

Constants inherited from Base

Base::DEFAULT

Instance Attribute Summary

Attributes inherited from Base

#attributes, #fields

Attributes included from Childish

#parent

Instance Method Summary collapse

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

#id_tag

Methods included from Childish

#push=

Constructor Details

#initialize(name, type = :text, attributes = {}) ⇒ Input

{ type: nil, value: nil, name: nil } { size: nil, maxlength: nil, type: “text” } { size: nil, maxlength: nil, type: “hidden” } { type: “submit” }



440
441
442
443
444
445
446
447
448
449
450
451
452
453
# File 'lib/campo.rb', line 440

def initialize( name, type=:text, attributes={} )
  super( name, 
        { type: type.to_s, 
          id: "#{name}#{id_tag(attributes[:value]).gsub(/\W/, "_")}",
          tabindex: %q!#{i += 1}!, 
        }.merge( attributes ) )
        
           
  @attributes.delete(:name) if type == :submit
        
  self.on_output do |n=0, tab=2|
    %Q!#{" " * n * tab}%input{ atts[:#{name.gsub(/\W/, "_")}#{id_tag(attributes[:value]).gsub(/\W/, "_")}], #{Base.unhash( @attributes )} }! 
  end
end