Chapter 7. Basics

Templates can be loaded using Web::load(filename). ruby-web loads .rb files as ruby, and assumes everything else is an erb template. Below is a short guide to erb templating:

<% ... %>
Evaluate ruby code.
<%= ... %>
Evaluate the enclosed ruby code and print the output.
<%%, %%>
Print out literal <%% or %%>.

The ruby-web interpreter will open a connection to the webserver and load the first command-line argument using Web::load. In a script, one can include additional files using Web::load.

In a ruby script, one can also open a Web::Connection using Web::open. This is not recommended, but is documented here for use in unsupported server environments.

Web::load( filename )
Given 'filename.ext' as filename, load using the handler Web::config[:load_suffix][:ext]. Returns value from handler.
Web::include( filename )
Loads filename, and returns output. Intended for use with Web::filter.
Web::connection
Return current Web::Connection.
Web::open(options)
Handle a web request. Use this method when running the ruby-web libraries outside of the ruby-web interpreter and outside of Web::load.
#!/usr/bin/ruby
require 'web'
Web::open do |connection|
  Web::write "Hello"
  cgi.write  "World"
end

Guide to options (defaults are in parenthesis):

:unbuffered
flag whether output should(n't) be buffered. (false)
:cgd
pass in a CGD driver
:out
set the output stream to the given IO ($stdout).
:raw_post_data
set the raw_post_data to the given IO ($stdin).
:request
pass in the request hash
:session
set the session to the given hash (Web::Session).
:env
pass in the ENV variables
:path_info
path_info is the part of the query that is after the script, i.e. the path_info.html in /script_name.rb/path_info.html (Web::env[:path_info])
:document_root
Document root of website. (Web::env[:document_root])
:script_name
Script name, ie /script_name.rb in /script_name.rb/path_info.html (Web::env[:script_name])