Class: Aurita::GUI::Widget

Inherits:
Element
  • Object
show all
Includes:
Aurita::GUI
Defined in:
lib/aurita-gui/widget.rb

Overview

Widget is a proxy / factory for an actual Aurita::GUI::Element. Method #element has to be overloaded that defines the Element instance the class is delegating to.

A simple widget could look like this:

class Annotated_Image < Aurita::GUI::Widget

  attr_accessor :src, :title, :description

  def initialize(params={})
     @src         = params[:src]
     @title       = params[:title]
     @description = params[:description]
  end

  def element
     HTML.div.annotated_image {
       HTML.img(:src => @src, :title => @title, :alt => @title) + 
       HTML.p { @description }
     }
  end

end # class

It then can be used like a regular Element instance:

image = Annotated_Image.new(:src         => '/images/wombat.jpg', 
                            :title       => 'wombat', 
                            :description => 'A cute wombat')
image.add_css_class(:active)
puts image.string

-->

<div class="annotated_image active">
  <img src="/images/wombat.jpg" title="wombat" alt="wombat" />
  <p>A cute wombat</p>
</div>

Instance Attribute Summary

Attributes inherited from Element

#attrib, #force_closing_tag, #gui_element_id, #parent, #tag

Instance Method Summary collapse

Methods inherited from Element

#+, #<<, #[], #[]=, #add_class, #aurita_gui_element, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #inspect, #js_init_code, #length, #method_missing, #recurse, #remove_class, #set_content, #string, #swap, #to_ary, #touch, #touched?, #type=, #untouch

Methods included from Marshal_Helper_Class_Methods

#marshal_load

Methods included from Marshal_Helper

#marshal_dump

Constructor Details

#initializeWidget

Returns a new instance of Widget.



51
52
53
# File 'lib/aurita-gui/widget.rb', line 51

def initialize()
  super(element())
end

Dynamic Method Handling

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

Instance Method Details

#elementObject

Raises:

  • (::Exception)


55
56
57
# File 'lib/aurita-gui/widget.rb', line 55

def element
  raise ::Exception.new('Missing method #element for ' << self.class.to_s)
end

#js_initializeObject



59
60
61
# File 'lib/aurita-gui/widget.rb', line 59

def js_initialize
  ''
end