mod_ruby is a module to embed Ruby interpreter in Apache web server. Some processes are needed to use CGIKit with it.
Using with mod_ruby is experimental.
If you don?t save name space of components in mod_ruby, CGIKit applications can affect each other. Then, create subclasses of CKApplication to save the name space.
Create a new file except a startup script and define a subclass of CKApplication in thi file (loaded in the startup script). Change the subclass name along with the application.
class Application < CKApplication end
Next, define each components inside the subclass.
class Application
class MainPage < CKComponent
...
end
end
You can use subclasses of CKApplication but for mod_ruby. If you collect methods related whole of an application into the subclass, you use effectively it because CKApplication objects are shared in each components.
CGIKit communicates with browsers using adapters
. By default, CGI and mod_ruby adapters are selected automatically. If you use customized adapter or adapters don?t be selected, specify an adapter for interfaceattribute of CKApplication.
#!/usr/local/bin/ruby require ?cgikit? require ?application? app = Application.new app.interface = CKAdapter::ModRuby app.run
WEBrick is a toolkit to builled web sesrver. To work CGIKit application with WEBrick, create an instance of the application and mount it as servlet.
Handlers for CGIKit are 3 types.
| Handler | Description |
|---|---|
WEBrick::CGIKitServlet::PathHandler |
Handler that receives component path in the second argument. |
WEBrick::CGIKitServlet::HashHandler |
Handler that receives a hash for accessors of CKApplication in the second argument. |
WEBrick::CGIKitServlet::ApplicationHandler |
Handler that receives a CKApplication object in the second argument. |
???ApplicationHandler?????????????????????HelloWorld???????????????????????????????????????????????
A startup script using with ApplicationHandleris the following (attached in HelloWorld an example application). Specify component path and port number to run.
% webrick-app.rb ?.? 8080
# webrick-app.rb [component_path [port]]
require 'webrick'
require 'cgikit'
path = ARGV.shift || Dir.pwd
port = (ARGV.shift || 8080).to_i
app = CKApplication.new
app.component_path = path
server = WEBrick::HTTPServer.new({:Port => port})
server.mount('/', WEBrick::CGIKitServlet::ApplicationHandler, app)
trap("INT"){ server.shutdown }
server.start