Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 2b1fca4e08
Fetching contributors…

Cannot retrieve contributors at this time

100 lines (78 sloc) 3.532 kb
= Wunderbar: Common Gateway Interface for Single Page Applications
Wunder provides a number of globals, helper methods, and monkey patches which
simplify the development of single page applications in the form of CGI
Basic interface
A typical main program produces one or more of HTML, JSON, or plain text
output. This is accomplished by providing one or more of the following:
Wunderbar.html do
Wunderbar.json do
Wunderbar.text do
Arbitrary Ruby code can be placed in each.
== Methods provided to Wunderbar.html
Invoking methods that start with a Unicode "low line" character ("_") will
generate a HTML tag. As with builder on which this library is based, these
tags can have text content and attributes. Tags can also be nested. Logic
can be freely intermixed.
Wunderbar knows which HTML tags need to be explicitly closed with separate end
tags (example: textarea), and which should never be closed with separate end
tags (example: br). It also takes care of HTML quoting and escaping of
arguments and text.
The "_" method serves a number of purposes. Calling it with a single argument
produces text nodes. Inserting markup verbatim is done by "_ << text". A
number of other convenience methods are defined: -- was this invoked via HTTP POST?
_.system -- invokes a shell command, captures stdin, stdout, and stderr
== Globals provided
* $cgi - Common Gateway Interface
* $param - Access to parameters (read-only OpenStruct like interface)
* $env - Access to environment variables (read-only OpenStruct like interface)
* $USER - Host user id
* $HOME - Home directory
* $SERVER- Server name
* SELF - Request URI
* SELF? - Request URI with '?' appended (avoids spoiling the cache)
* $USER - user
* $HOME - user's home directory
* $HOST - server host
* $HTTP_GET - request is an HTTP GET
* $HTTP_POST - request is an HTTP POST
* $XHR_JSON - request is XmlHttpRequest for JSON
* $XHTML - user agent accepts XHTML responses
== HTML methods
* style! - argument is indented text/data
* system! - run command and capture output
* script! - argument is indented text/data
* body? - capture exceptions, and produce a stack traceback
== CGI methods
* json - produce JSON output using the block specified
* json! - produce JSON output using the block specified and exit
* html - produce HTML output using the block specified
* html! - produce HTML output using the block specified and exit
* post - execute block only if method is POST
* post! - if POST, produce HTML output using the block specified and exit
== Helper methods
* submit: runs command (or block) as a deamon process
== OpenStruct methods (for $params and $env)
* untaint_if_match: untaints value if it matches a regular expression
== Builder extensions
* indented_text: matches text indentation to markup
* indented_data: useful for script and styles in HTML syntax
* traceback!: formats an exception traceback
* method_missing: patched to ensure open tags are closed
== Command line options
When run from the command line, CGI name=value pairs can be specified.
Additionally, the following options are supported:
* --html: HTML (HTTP GET) output is expected
* --post: HTML (HTTP POST) output is expected
* --json: JSON (XML HTTP Request) output is expected
* --xhtml: XHTML output is expected
* --prompt: prompt for key/value pairs using stdin
* --install=path: produce an suexec-callable wrapper script
Jump to Line
Something went wrong with that request. Please try again.