Class: Aurita::GUI::Button

Inherits:
Element
  • Object
show all
Defined in:
lib/aurita-gui/button.rb

Overview

Specialization of Aurita::GUI::Element, extending it by @icon to display in the button.

Usage:

b = Button.new(:type => :submit,             # default is :button
               :icon => '/path/to/icon.png', # default is no icon
               :onclick => 'alert('button clicked'); ") { 
      'click me' 
    }

Change button text:

b.content = 'Custom button text'

Disable icon again:

b.icon   = false

Instance Attribute Summary collapse

Attributes inherited from Element

#attrib, #parent, #tag, #type

Instance Method Summary collapse

Methods inherited from Element

#+, #[], #[]=, #clear_floating, #dom_id, #dom_id=, #each, #empty?, #id, #id=, #length, #method_missing, #string, #to_ary

Constructor Details

#initialize(params, &block) ⇒ Button

Returns a new instance of Button.



29
30
31
32
33
34
35
# File 'lib/aurita-gui/button.rb', line 29

def initialize(params, &block)
  params[:tag]  = :button
  params[:type] = :button unless params[:type]
  @icon         = params[:icon]
  params.delete(:icon)
  super(params, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element

Instance Attribute Details

#iconObject

Returns the value of attribute icon.



27
28
29
# File 'lib/aurita-gui/button.rb', line 27

def icon
  @icon
end

Instance Method Details

#contentObject



37
38
39
40
41
42
# File 'lib/aurita-gui/button.rb', line 37

def content
  if @icon then
    return [ HTML.img(:src => @icon), @content ]
  end
  return @content
end