Wuby Documentation

Wuby = Ruby Web Server designed for light-weight Ruby web applications http://www.wuby.org

Copyright (C) 2007 Chris Matthieu

Portions of HTTPD version 1.8 were used thanks to contributions from:
Copyright (C) 2000-2004 Michel van de Ven
Copyright (C) 2004 Patric Mueller
Reference: http://www.xs4all.nl/~hipster/lib/ruby/httpd

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Wuby Start Command and Switches:

-h help
-v version
-d daemonize
-t threads followed by number of threads (-t 5) - Note: used with daemon and default is 4 threads
-a IP address for listening (-a 0.0.0.0) - Note: default is 0.0.0.0 which listens to all ip addresses
-p port number for listening (-p 80) - Note: default is port 8080 for development
-b allows directory browsing - Note: default is off
-k kills daemon process and stops wuby (Control C stops single threaded blocking instance run by ruby wuby.rb)
Usage: ruby wuby.rb -d -t 8 -p 80 -b = launches wuby as a daemon with 8 threads on all IP addresses and port 80 and also allowing directory browsing
Note: wuby defaults to index.rhtml as the start page; however, any rhtml file can be called from the URL. If directory browsing is turned on and no index.rhtml file exists, the directory is returned to the browser.

Wuby Commands:

IO.read - adds partial content including ruby syntax to an existing ruby.rhtml file like an include command in ASP or PHP - usage <%= IO.read('header.inc') %>

wrecordcount(table) - sets @recordcount variable with last record id in table

wrenew(table) - increments recordcount - used with wrequest create IOs

wrequest(crud, table, field, id, value) - Access database/table field values by ID
crud = actions such as "c"reate, "r"ead, "u"pdate, "d"elete - only first letter of crud gets passed to method
table = table name
field = field name
id / value = optional based on crud routine (id required for read, update, and delete) (value required create and update)
Note: Create wrequest calls requires that you manually increment the id using wrenew(table) - see blog demo add.rhtml
Note: All database values are stored as strings. Use .to_i to convert to integer if needed such as @id = db["id"].to_i


usage examples:
wrequest("c", "blog", "title", @params["title"])
wrequest("r", "blog", "title", id) (Note: no record found returns false)
wrequest("u", "blog", "title", id, @params["title"])
wrequest("d", "blog", "title", id)

Wuby Variables:

@params["form_element"] - Any form element can be accessed via the @params array. This works for both form GET and POST methods. @params["form_element"] will be nil if no such variable exists - usage <%= @params["title"] %>

ENV["server_variables"] - Environmental client/server variables - Usage <%= ENV["SERVER_SOFTWARE"] %> - Supported variables include:
ENV["SERVER_SOFTWARE"]
ENV["REMOTE_HOST"]
ENV["REQUEST_METHOD"]
ENV["SCRIPT_NAME"]
ENV["QUERY_STRING"]
ENV["CONTENT_LENGTH"]


@timing - time in seconds that Wuby receives the web request to the time it renders the ERB results - Usage: <%= page responded in #{@timing} seconds %>

@recordcount = last record id in table