CKElement

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

Description

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.

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.

Programming Topics

Methods

bind_request
definition
each
element_id
fetch
instance
load_element_file
name_with_class
new
other_attributes_string
own_attributes
run
top_level?

Attributes

application [RW]
body [RW]
definition [W]
name [RW]
parent [RW]
repetition_index [RW]
Index in the last repetition.
repetitions [RW]
Array of repetitions.

Classes and Modules

Module CKElement::ElementAttribute
Module CKElement::ElementState
Class CKElement::AttributeError
Class CKElement::UnknownElementError

Public Class Methods

bind_request( component, definition, value )

Internal method that will be overridden in subclasses.

instance( element, app, parent, name, body )
load_element_file( component_path, element )

Internal method.

new( app, parent, name, body, path = nil )
own_attributes()

Return an array of names of the element’s own attributes. The value is used to generate optional HTML attributes. Subclasses must override this method.

Public Instance Methods

definition()

Return a definition hash of the element.

each() {|key, value| ...}

Calls block once for each attributes in definition passing the key and value as parameters.

element_id()

Returns the element ID.

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 .

name_with_class()

Return a definition name of the element with the class name.

other_attributes_string()

Return a string of values of optional attributes with "other" attribute string excepting the element’s own attributes.

run()

Internal method. This method will be overridden in subclasses.

top_level?()

Returns true if the element is a top level.