Class CKElement
In: lib/cgikit.rb
Parent: Object

The super class of dynamic element classes.

Dynamic elements convert themselves to HTML. These are very important in development with CGIKit.

CKElement returns HTML when to_s() is called. In components development, you bind elements to component's methods. At runtime, the binding is executed by run(). These two methods are expected to be overrided in the subclasses of CKElement.

About CKElement#init_element

In initialize(), CKElement calls init_element(). You can hook the inialization of elements by this method. The reason why element classes have init_element() is for convenience. It may be better to override init_element() than initialize().

 class MainPage < CKComponent
   def initialize( app, parent, name, body )
     super( app, parent, name, body )

     # initializing code ...
   end
 end
 class MainPage < CKComponent
   def init_element

     # initializing code ...
   end
 end

Paths for searching elements and components

CKElement objects, including components, are usually instantiated by CKElement.instance. This method loads elements/components and creates element objects. In this method, some paths are searched to require files.

The searched paths:

  1. CKApplicaton#component_path
  2. ($LOAD_PATH)/cgikit/elements
  3. ($LOAD_PATH)/cgikit/components

The latter two paths are for extention elements or components. It is recommended that your own elements or components are installed in the 1st path.

Creation of custom elements

If you create custom elements, the class of the custom elements must inherit CKElement. Simple dynamic element can be created only by overriding to_s(). to_s() is called when CGIKit converts the dynamic elements to HTML. If you add new attributes to your custom elements, run() must be overrided.

Methods
check_required_attributes    check_undefined_attributes    definition    fetch    init_element    instance    name_with_class    new    oid    run   
Attributes
:application  [RW] 
:body  [RW] 
:definition  [RW] 
:name  [RW] 
:parent  [RW] 
Classes and Modules
Class CKElement::AttributeError
Class CKElement::UnknownElementError
Public Class methods
instance( element, app, parent, name, body )
new( app, parent, name, body )
Public Instance methods
init_element()
definition()
name_with_class()
oid()

Returns value of "name" attribute for form.

fetch( key, is_binding = true )

Fetches the result of the parent component's methods. When is_binding is true, fetch() returns String without binding from .

run()

This method will be overrided in subclasses.

check_undefined_attributes( *attrs )

Raises exception if an element has undefined attributes.

check_required_attributes( *patterns )

Raises exception if an element doesn't have required attributes.