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:
- CKApplicaton#component_path
- ($LOAD_PATH)/cgikit/elements
- ($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.