Powered by SmartDoc

Process of CGIKit

Startup

The startup of CGIKit is carried out by startup-program as cgi program. The startup-program is different from components. Normally, it is not neccessary to require components directly in startup-program.

The startup-program does three things.

Creates a CKApplication object.

  1. Sets parameters of the CKApplication object.
  2. Calls CKApplication#run.

Creates a CKApplication object

CKApplication is the central class in CGIKit. This class has the parameters, for example, CGI program's path, MainPage and component path. You can create a CKApplication object by calling CKApplication.new simply.

app = CKApplication.new

Sets parameters of the CKApplication object

CKApplication has many attributes. Here, two of them are introduced. The detail is explained in CKApplication's RDoc document.

Parameters of CKApplication objects
Parameter Description
element_id Component name which CGIKit shows.
main Component name which CGIKit shows if target is not set. The default value is "MainPage".

Calls CKApplication#run

Finally, you call CKApplication#run. By this method, CKApplication loads a component and initializes it.

When CKApplication#run is called, CKApplication decides what component is shown. CKApplication has two ways to decide the name of the top-level component to be shown. One way is CKApplication#element_id and another is query data. If CKApplication#element_id is set as CKElementID object in startup-program, CKApplication loads the component whose name is CKApplication#element_id. If CKApplication#element_id is not set, CKApplication tries to decide the component's name from query data. For example, when a client accesses "http://localhost/hello.cgi?element_id=FooBar" CKApplication loads FooBarcomponent. If both of ways fails, CKApplication load the component specified by CKApplication#main.

HelloWorld.cgi

This is one of the simplest startup-program.

#!/usr/local/bin/ruby

require 'cgikit'

app = CKApplication.new
app.run

After startup

Ordinally, you don't have to know the detail after startup. But, if you want to know about the process after startup, see the source and document of CKApplication. The document is provided in RDoc document.

Here, the process after startup is explained succinctly.

When CKApplication#run is called, the CKApplication object creates a CKAdapter object, which is an interface between CGIKit and a web server.

  1. The CKApplication object gets a request object from the CKAdapter object. Then, as explained above, the CKApplication object determines the component to be shown from the parameters of request object.
  2. The CKApplication object loads the specified component and converts it to HTML.
  3. The HTML is added to a response object created by the CKApplication object. The CKApplication object sends the response object to the CKAdapter object.
  4. The CKAdapter object receives the response object and shows it to the browser.