Powered by SmartDoc

Managing resources

Resources directories manage resource files like image files or preference files. The directories are resources directory and web server resources directory setted for resourcesand web_server_resourcesattributes of CKApplication.

Resources and web server resources

Resources are files not sent to browsers, web server resources are files to send to browsers. Locate web server resources directory in document root of web server.

Accessing to resources

Use CKResourceManage to access to resources. You can get CKResourceManager object with CKApplication#resource_manager.

Main methods of CKResourceManager are url()and path(). url() returns URLs for resources, path() does absolute file paths. url() works only for resources in web server resources directory. You can?t get URLs for resources in resources directory.

Methods of CKResourceManager
Methods Description
url(name) Returns the public URL for the specified resource when it is under the web server resources directory. Otherwise returns nil.
path(name) Returns the file path of the specified resource.
bytedata(name) Returns a CKByteData object for the specified resource.
content_type(path) Finds the content type for extension of the specified path. If the path don't have extension, returns nil.

An example: displaying an image file

CKImage can display resource files as image. Do setting the following to display an image file (cgikit.png) in ImagePage of Examples.

move resourcesdirectory to path enables displaying images.

  1. set path of the resource directory for resourceattribute of CKAppication.
  2. set the image file name for file attribute of CKImage.

move resourcesdirectory

[localhost:/var/www/cgi-bin/Examples] user% mv resources ../../htdocs

set path of resourcesdirectory (Example.cgi)

app = CKApplication.new
app.web_server_resources = '../../htdocs/resources'
app.run

set an image file name of fileattribute (ImagePage.ckd)

FileInResource : CKImage {
  alt  = "File in resource direcory";
  file = "cgikit.png";
}

This is an example to display static an image file. CKImage can display dinamically using with dataattribute.