ruby-web 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +474 -0
- data/INSTALL.txt +9 -0
- data/InstalledFiles +180 -0
- data/LICENSE.txt +74 -0
- data/Rakefile +529 -0
- data/TODO +65 -0
- data/doc/additional.xml +149 -0
- data/doc/core.xml +652 -0
- data/doc/credits/index.xml +52 -0
- data/doc/credits/php.contributors.xml +118 -0
- data/doc/credits/php.language-snippets.ent +622 -0
- data/doc/install/index.xml +136 -0
- data/doc/install/mac/index.xml +21 -0
- data/doc/install/ruby-web.install.rb.instructions.xml +7 -0
- data/doc/install/unix/index.xml +46 -0
- data/doc/install/win/apache1.xml +166 -0
- data/doc/install/win/apache2.xml +141 -0
- data/doc/install/win/iis.xml +162 -0
- data/doc/install/win/index.xml +24 -0
- data/doc/install/win/installer.xml +31 -0
- data/doc/install/win/manual.xml +43 -0
- data/doc/manual.xml +69 -0
- data/doc/old/apache_cgi.txt +23 -0
- data/doc/old/fastcgi.txt +23 -0
- data/doc/old/mod_ruby.txt +21 -0
- data/doc/old/snippets.rdoc +183 -0
- data/doc/old/webrick.txt +23 -0
- data/doc/old/windows_cgi.txt +9 -0
- data/doc/tutorial.xml +14 -0
- data/doc/xsl/manual-multi.xsl +10 -0
- data/doc/xsl/manual-pdf.xsl +6 -0
- data/doc/xsl/manual-single.xsl +6 -0
- data/doc/xsl/manual.css +22 -0
- data/install.rb +1022 -0
- data/lib/formatter.rb +314 -0
- data/lib/html-parser.rb +429 -0
- data/lib/htmlrepair.rb +113 -0
- data/lib/htmlsplit.rb +842 -0
- data/lib/sgml-parser.rb +332 -0
- data/lib/web.rb +68 -0
- data/lib/web/assertinclude.rb +129 -0
- data/lib/web/config.rb +50 -0
- data/lib/web/connection.rb +1070 -0
- data/lib/web/convenience.rb +154 -0
- data/lib/web/formreader.rb +318 -0
- data/lib/web/htmlparser/html-parser.rb +429 -0
- data/lib/web/htmlparser/sgml-parser.rb +332 -0
- data/lib/web/htmltools/element.rb +296 -0
- data/lib/web/htmltools/stparser.rb +276 -0
- data/lib/web/htmltools/tags.rb +286 -0
- data/lib/web/htmltools/tree.rb +139 -0
- data/lib/web/htmltools/xmltree.rb +160 -0
- data/lib/web/htmltools/xpath.rb +71 -0
- data/lib/web/info.rb +63 -0
- data/lib/web/load.rb +210 -0
- data/lib/web/mime.rb +87 -0
- data/lib/web/phprb.rb +340 -0
- data/lib/web/resources/test/cookie.rb +33 -0
- data/lib/web/resources/test/counter.rb +20 -0
- data/lib/web/resources/test/multipart.rb +14 -0
- data/lib/web/resources/test/redirect.rb +8 -0
- data/lib/web/resources/test/stock.rb +33 -0
- data/lib/web/sapi/apache.rb +129 -0
- data/lib/web/sapi/fastcgi.rb +22 -0
- data/lib/web/sapi/install/apache.rb +180 -0
- data/lib/web/sapi/install/iis.rb +93 -0
- data/lib/web/sapi/install/macosx.rb +90 -0
- data/lib/web/sapi/webrick.rb +86 -0
- data/lib/web/session.rb +83 -0
- data/lib/web/shim/cgi.rb +129 -0
- data/lib/web/shim/rails.rb +175 -0
- data/lib/web/stringio.rb +78 -0
- data/lib/web/strscanparser.rb +24 -0
- data/lib/web/tagparser.rb +96 -0
- data/lib/web/testing.rb +666 -0
- data/lib/web/traceoutput.rb +75 -0
- data/lib/web/unit.rb +56 -0
- data/lib/web/upload.rb +59 -0
- data/lib/web/validate.rb +52 -0
- data/lib/web/wiki.rb +557 -0
- data/lib/web/wiki/linker.rb +72 -0
- data/lib/web/wiki/page.rb +201 -0
- data/lib/webunit.rb +27 -0
- data/lib/webunit/assert.rb +152 -0
- data/lib/webunit/converter.rb +154 -0
- data/lib/webunit/cookie.rb +118 -0
- data/lib/webunit/domwalker.rb +185 -0
- data/lib/webunit/exception.rb +14 -0
- data/lib/webunit/form.rb +116 -0
- data/lib/webunit/frame.rb +37 -0
- data/lib/webunit/htmlelem.rb +122 -0
- data/lib/webunit/image.rb +26 -0
- data/lib/webunit/jscript.rb +31 -0
- data/lib/webunit/link.rb +33 -0
- data/lib/webunit/params.rb +321 -0
- data/lib/webunit/parser.rb +229 -0
- data/lib/webunit/response.rb +464 -0
- data/lib/webunit/runtest.rb +41 -0
- data/lib/webunit/table.rb +148 -0
- data/lib/webunit/testcase.rb +45 -0
- data/lib/webunit/ui/cui/testrunner.rb +50 -0
- data/lib/webunit/utils.rb +68 -0
- data/lib/webunit/webunit.rb +28 -0
- data/test/dev/action.rb +83 -0
- data/test/dev/forms.rb +104 -0
- data/test/dev/forms2.rb +104 -0
- data/test/dev/parser.rb +17 -0
- data/test/dev/scripts/dump.rb +24 -0
- data/test/dev/scripts/makedist.rb +62 -0
- data/test/dev/scripts/uri.rb +41 -0
- data/test/dev/scripts/uri/common.rb +432 -0
- data/test/dev/scripts/uri/ftp.rb +149 -0
- data/test/dev/scripts/uri/generic.rb +1106 -0
- data/test/dev/scripts/uri/http.rb +76 -0
- data/test/dev/scripts/uri/https.rb +26 -0
- data/test/dev/scripts/uri/ldap.rb +238 -0
- data/test/dev/scripts/uri/mailto.rb +260 -0
- data/test/dev/scripts/urireg.rb +174 -0
- data/test/dev/simpledispatcher.rb +156 -0
- data/test/dev/test.action.rb +146 -0
- data/test/dev/test.formreader.rb +463 -0
- data/test/dev/test.simpledispatcher.rb +186 -0
- data/test/dev/webunit/conv/digit-0.rb +21 -0
- data/test/dev/webunit/conv/digit-1.rb +17 -0
- data/test/dev/webunit/conv/digit.rb +23 -0
- data/test/dev/webunit/conv/test_digit-0.rb +16 -0
- data/test/dev/webunit/conv/test_digit-1.rb +19 -0
- data/test/dev/webunit/conv/test_digit.rb +26 -0
- data/test/dev/webunit/conv/test_digit_view-0.rb +76 -0
- data/test/dev/webunit/conv/test_digit_view-1.rb +102 -0
- data/test/dev/webunit/conv/test_digit_view.rb +134 -0
- data/test/installation/htdocs/cgi_test.rb +296 -0
- data/test/installation/htdocs/test_install.rb +4 -0
- data/test/installation/runwebtest.rb +5 -0
- data/test/installation/test_cookie.rb +128 -0
- data/test/installation/test_form.rb +47 -0
- data/test/installation/test_multipart.rb +51 -0
- data/test/installation/test_request.rb +24 -0
- data/test/installation/test_response.rb +35 -0
- data/test/unit/htdocs/cookie.rb +32 -0
- data/test/unit/htdocs/multipart.rb +28 -0
- data/test/unit/htdocs/redirect.rb +12 -0
- data/test/unit/htdocs/simple.rb +13 -0
- data/test/unit/htdocs/stock.rb +33 -0
- data/test/unit/test_assert.rb +162 -0
- data/test/unit/test_cookie.rb +114 -0
- data/test/unit/test_domwalker.rb +77 -0
- data/test/unit/test_form.rb +42 -0
- data/test/unit/test_frame.rb +40 -0
- data/test/unit/test_htmlelem.rb +74 -0
- data/test/unit/test_image.rb +45 -0
- data/test/unit/test_jscript.rb +57 -0
- data/test/unit/test_link.rb +85 -0
- data/test/unit/test_multipart.rb +51 -0
- data/test/unit/test_params.rb +210 -0
- data/test/unit/test_parser.rb +53 -0
- data/test/unit/test_response.rb +150 -0
- data/test/unit/test_table.rb +70 -0
- data/test/unit/test_utils.rb +106 -0
- data/test/unit/test_webunit.rb +28 -0
- data/test/web/mod_ruby_stub.rb +39 -0
- data/test/web/test.assertinclude.rb +109 -0
- data/test/web/test.buffer.rb +182 -0
- data/test/web/test.code.loader.rb +78 -0
- data/test/web/test.config.rb +31 -0
- data/test/web/test.error.handling.rb +91 -0
- data/test/web/test.formreader-2.0.rb +352 -0
- data/test/web/test.load.rb +125 -0
- data/test/web/test.mime-type.rb +23 -0
- data/test/web/test.narf.cgi.rb +106 -0
- data/test/web/test.phprb.rb +239 -0
- data/test/web/test.request.rb +368 -0
- data/test/web/test.response.rb +637 -0
- data/test/web/test.ruby-web.rb +10 -0
- data/test/web/test.session.rb +50 -0
- data/test/web/test.shim.cgi.rb +96 -0
- data/test/web/test.tagparser.rb +65 -0
- data/test/web/test.template2.rb +297 -0
- data/test/web/test.testing2.rb +318 -0
- data/test/web/test.upload.rb +45 -0
- data/test/web/test.validate.rb +46 -0
- data/test/web/test.web.test.rb +495 -0
- data/test/wiki/test.history.rb +297 -0
- data/test/wiki/test.illustration_page.rb +287 -0
- data/test/wiki/test.linker.rb +197 -0
- data/test/wiki/test.tarpit.rb +56 -0
- data/test/wiki/test.wiki.rb +300 -0
- data/test/wikitestroot/admin.rb +7 -0
- data/test/wikitestroot/wiki.rb +6 -0
- metadata +234 -0
data/TODO
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
=== TODO:
|
2
|
+
|
3
|
+
Top Priorities:
|
4
|
+
|
5
|
+
* Installation
|
6
|
+
+ NSIS installer
|
7
|
+
+ Mac OS X pkg
|
8
|
+
|
9
|
+
* Manual
|
10
|
+
* More CGD and installation tests
|
11
|
+
* FastCGIServlet: modify resin servlet to do process management
|
12
|
+
* 'web/shim/rails'
|
13
|
+
|
14
|
+
Web
|
15
|
+
* Update Web::set_redirect() to use javascript if headers have been sent,
|
16
|
+
instead of throwing nasty error.
|
17
|
+
|
18
|
+
Templating
|
19
|
+
* Test tags in strange circumstances, i.e. <? Web::puts "?>" ?>
|
20
|
+
* Replace the Foreach syntax with the following:
|
21
|
+
<narf:foreach item="i" in="credits">
|
22
|
+
* Add support for RadioButtons
|
23
|
+
* pass through all values not depended on by the tag parser.
|
24
|
+
* Add support for links so that they correctly link to the current
|
25
|
+
cgi, or to a different one.
|
26
|
+
* Support form submits, and redirects to urls of the form "?foo=bar",
|
27
|
+
ie no script is mentioned.
|
28
|
+
* Provide a hook into test_unit to allow sessions to be automatically reset
|
29
|
+
before a setup
|
30
|
+
* Have the tag parser report which tag was not matched
|
31
|
+
* The following line produces an unhelpful error message:
|
32
|
+
<narf:foreach from"items" item="item">
|
33
|
+
* Make VarNotFoundException report a better error message, including
|
34
|
+
line number and what var was not found. Print out some context from
|
35
|
+
the template too.
|
36
|
+
* Add better error reporting (including line numbers and context) for
|
37
|
+
template parse errors.
|
38
|
+
* Add tests to test Web::Link
|
39
|
+
|
40
|
+
Web::Testing
|
41
|
+
* Allow clicking of links in a test.
|
42
|
+
* Add support for submitting a form to a CGI other than the current one.
|
43
|
+
* Have Values in textarea's and value attributes in other fields
|
44
|
+
correctly escaped so all escaping issues are handled.
|
45
|
+
* Add support for specific buttons to be submitted on a form.
|
46
|
+
* Provide a default form submit that submits any un-named form on the
|
47
|
+
page.
|
48
|
+
* Allow a request to be made directly to a form, passing in objects
|
49
|
+
(objects should be serialized, unserialized before passing)
|
50
|
+
* Add an assert that a particular template was used
|
51
|
+
assert_form_displayed MyTemplate
|
52
|
+
* Add a way to find out how long an array is in a test
|
53
|
+
* Add error reporting for when a template can not be found
|
54
|
+
* Report errors for unrecognized parameters for do_request
|
55
|
+
* Have assert_includes handle array fields to allow for parameters
|
56
|
+
with array types.
|
57
|
+
|
58
|
+
Web::SimpleDispatcher
|
59
|
+
* Support for useful data-binding might include
|
60
|
+
- Optionally, not having eveything written back to the form
|
61
|
+
- Automatic data type conversions, perhaps specified in a form tag.
|
62
|
+
* Submit could do with a more helpful error message. If a field is not
|
63
|
+
present, it could list out the fields that are present.
|
64
|
+
* Have do request automatically encode objects
|
65
|
+
* Make sure round trip object serialization works correctly
|
data/doc/additional.xml
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
<chapter id="reference-compatibility">
|
2
|
+
<title>Compatibility</title>
|
3
|
+
<para>
|
4
|
+
ruby-web ships with the cgi.rb interface, adapted to use the ruby-web infrastructure.
|
5
|
+
</para>
|
6
|
+
<programlisting
|
7
|
+
>require 'web/shim/cgi'
|
8
|
+
cgi = CGI.new
|
9
|
+
# ...</programlisting>
|
10
|
+
</chapter>
|
11
|
+
|
12
|
+
|
13
|
+
<chapter id="reference-custom_templates">
|
14
|
+
<title>Custom Templates</title>
|
15
|
+
<para>You can customize how ruby-web load templates:</para>
|
16
|
+
|
17
|
+
<programlisting
|
18
|
+
>require 'web/phprb'
|
19
|
+
|
20
|
+
Web::config['load_suffix']['rhtml'] = lambda do |scriptname|
|
21
|
+
PHPRB::load(scriptname)
|
22
|
+
end
|
23
|
+
|
24
|
+
# or, if you really really love your templating language:
|
25
|
+
Web::config['load_suffix'].default = lambda do |scriptname|
|
26
|
+
PHPRB::load(scriptname)
|
27
|
+
end
|
28
|
+
|
29
|
+
Web::load('template.rhtml') # <= will be processed by phprb</programlisting>
|
30
|
+
|
31
|
+
<para>phprb is an experimental template parser derived from erb, but not as inspired
|
32
|
+
by the systems invented by Sun and Microsoft. It has the following rules:</para>
|
33
|
+
|
34
|
+
<variablelist>
|
35
|
+
<varlistentry>
|
36
|
+
<term><? ... ?></term>
|
37
|
+
<listitem>
|
38
|
+
Evaluate ruby code.
|
39
|
+
</listitem>
|
40
|
+
</varlistentry>
|
41
|
+
|
42
|
+
<varlistentry>
|
43
|
+
<term><?= ... ?></term>
|
44
|
+
<listitem>
|
45
|
+
Evaluate the enclosed ruby code and print the output.
|
46
|
+
</listitem>
|
47
|
+
</varlistentry>
|
48
|
+
|
49
|
+
<varlistentry>
|
50
|
+
<term><!--- ... ---></term>
|
51
|
+
<listitem>
|
52
|
+
Comment out the enclosed code.
|
53
|
+
</listitem>
|
54
|
+
</varlistentry>
|
55
|
+
|
56
|
+
<varlistentry>
|
57
|
+
<term><??, ??></term>
|
58
|
+
<listitem>
|
59
|
+
Print out literal <?? or ??>.
|
60
|
+
</listitem>
|
61
|
+
</varlistentry>
|
62
|
+
</variablelist>
|
63
|
+
</chapter>
|
64
|
+
|
65
|
+
<chapter id="reference-testing">
|
66
|
+
<title>Testing Functions</title>
|
67
|
+
|
68
|
+
<para>To access these functions, include Web::Testing in your testcase</para>
|
69
|
+
|
70
|
+
<programlisting
|
71
|
+
>require 'web/testing'
|
72
|
+
require 'web/unit/testcase'
|
73
|
+
class MyWebTest << Test::Unit::TestCase
|
74
|
+
include Web::Testing
|
75
|
+
#...
|
76
|
+
end</programlisting>
|
77
|
+
|
78
|
+
<variablelist>
|
79
|
+
<varlistentry>
|
80
|
+
<term>do_request( scriptname, params={} )</term>
|
81
|
+
<listitem>
|
82
|
+
<para>Do a mock request to scriptname, passing in params.</para>
|
83
|
+
|
84
|
+
<para>
|
85
|
+
<emphasis>scriptname</emphasis> can be /absolute/scriptname.rb if you use set
|
86
|
+
the docroot using Web::docroot = "...".
|
87
|
+
Otherwise, use a relative path from the current directory.
|
88
|
+
</para>
|
89
|
+
|
90
|
+
<para>
|
91
|
+
<emphasis>params</emphasis> is a hash of request parameters. You can mock
|
92
|
+
enviroment parameters on an :env key.
|
93
|
+
</para>
|
94
|
+
</listitem>
|
95
|
+
</varlistentry>
|
96
|
+
|
97
|
+
<varlistentry>
|
98
|
+
<term>do_submit( formname, params={} )</term>
|
99
|
+
<listitem>
|
100
|
+
Once you've done a request, you can submit forms on the page.
|
101
|
+
You can "fill out" fields by passing in params.
|
102
|
+
</listitem>
|
103
|
+
</varlistentry>
|
104
|
+
|
105
|
+
<varlistentry>
|
106
|
+
<term>assert_content(expected, message="")</term>
|
107
|
+
<listitem>
|
108
|
+
fails if content is not set to the provided string.
|
109
|
+
</listitem>
|
110
|
+
</varlistentry>
|
111
|
+
|
112
|
+
<varlistentry>
|
113
|
+
<term>assert_form_includes(formname, vars)</term>
|
114
|
+
<listitem>
|
115
|
+
Assert output content contains a form that includes the given hash of values. ### this could sure use some more docs.
|
116
|
+
</listitem>
|
117
|
+
</varlistentry>
|
118
|
+
|
119
|
+
<varlistentry>
|
120
|
+
<term>Web::get_content()</term>
|
121
|
+
<listitem>
|
122
|
+
the body content of the response (sans headers)
|
123
|
+
</listitem>
|
124
|
+
</varlistentry>
|
125
|
+
|
126
|
+
<varlistentry>
|
127
|
+
<term>assert_header( name, values, message="" )</term>
|
128
|
+
<listitem>
|
129
|
+
Fails if the header has not been set to the provided value(s).
|
130
|
+
</listitem>
|
131
|
+
</varlistentry>
|
132
|
+
|
133
|
+
<varlistentry>
|
134
|
+
<term>assert_cookie( name, values, message="" )</term>
|
135
|
+
<listitem>
|
136
|
+
Fails if cookie values are not present.
|
137
|
+
</listitem>
|
138
|
+
</varlistentry>
|
139
|
+
|
140
|
+
</variablelist>
|
141
|
+
|
142
|
+
</chapter>
|
143
|
+
|
144
|
+
<!--para>
|
145
|
+
ruby-web also ships with a rails driver:
|
146
|
+
</para>
|
147
|
+
<programlisting>
|
148
|
+
require 'web/shim/rails'
|
149
|
+
...</programlisting-->
|
data/doc/core.xml
ADDED
@@ -0,0 +1,652 @@
|
|
1
|
+
<chapter id="reference-basics">
|
2
|
+
<title>Basics</title>
|
3
|
+
|
4
|
+
<para>
|
5
|
+
Templates are loaded using Web::load. ruby-web loads .rb files as ruby, and assumes everything else is an erb template. Below is a short guide to erb templating:</para>
|
6
|
+
<variablelist>
|
7
|
+
<varlistentry>
|
8
|
+
<term><% ... %></term>
|
9
|
+
<listitem>
|
10
|
+
Evaluate ruby code.
|
11
|
+
</listitem>
|
12
|
+
</varlistentry>
|
13
|
+
|
14
|
+
<varlistentry>
|
15
|
+
<term><%= ... %></term>
|
16
|
+
<listitem>
|
17
|
+
Evaluate the enclosed ruby code and print the output.
|
18
|
+
</listitem>
|
19
|
+
</varlistentry>
|
20
|
+
|
21
|
+
<!--varlistentry>
|
22
|
+
<term><!- - - ... - - -></term>
|
23
|
+
<listitem>
|
24
|
+
Comment out the enclosed code.
|
25
|
+
</listitem>
|
26
|
+
</varlistentry-->
|
27
|
+
|
28
|
+
<varlistentry>
|
29
|
+
<term><%%, %%></term>
|
30
|
+
<listitem>
|
31
|
+
Print out literal <%% or %%>.
|
32
|
+
</listitem>
|
33
|
+
</varlistentry>
|
34
|
+
</variablelist>
|
35
|
+
|
36
|
+
|
37
|
+
<para>
|
38
|
+
The ruby-web interpreter will open a connection to the webserver and load the first
|
39
|
+
command-line argument using Web::load. In a script, one can include additional files using Web::load.
|
40
|
+
</para>
|
41
|
+
|
42
|
+
<para>
|
43
|
+
In a ruby script, one can also open a Web::Connection using Web::open. This is not
|
44
|
+
recommended, but is documented here for use in unsupported server environments.
|
45
|
+
</para>
|
46
|
+
|
47
|
+
<variablelist>
|
48
|
+
<varlistentry>
|
49
|
+
<term>Web::load( filename )</term>
|
50
|
+
<listitem>
|
51
|
+
Given 'filename.ext' as filename, load using the handler Web::config[:load_suffix][:ext].
|
52
|
+
</listitem>
|
53
|
+
</varlistentry>
|
54
|
+
|
55
|
+
<varlistentry>
|
56
|
+
<term>Web::connection</term>
|
57
|
+
<listitem>
|
58
|
+
Return current Web::Connection.
|
59
|
+
</listitem>
|
60
|
+
</varlistentry>
|
61
|
+
|
62
|
+
<varlistentry>
|
63
|
+
<term>Web::open(options)</term>
|
64
|
+
<listitem>
|
65
|
+
Handle a web request. Use this method when running the ruby-web libraries
|
66
|
+
outside of the ruby-web interpreter and outside of Web::load.
|
67
|
+
<programlisting>
|
68
|
+
#!/usr/bin/ruby
|
69
|
+
require 'web'
|
70
|
+
Web::open do |connection|
|
71
|
+
Web::write "Hello"
|
72
|
+
cgi.write "World"
|
73
|
+
end</programlisting>
|
74
|
+
|
75
|
+
<para>Guide to options <emphasis>(defaults are in parenthesis)</emphasis>:</para>
|
76
|
+
|
77
|
+
<variablelist>
|
78
|
+
<varlistentry>
|
79
|
+
<term>:unbuffered</term>
|
80
|
+
<listitem>
|
81
|
+
flag whether output should(n't) be buffered. <emphasis>(false)</emphasis>
|
82
|
+
</listitem>
|
83
|
+
</varlistentry>
|
84
|
+
|
85
|
+
<varlistentry>
|
86
|
+
<term>:cgd</term>
|
87
|
+
<listitem>
|
88
|
+
pass in a CGD driver
|
89
|
+
</listitem>
|
90
|
+
</varlistentry>
|
91
|
+
|
92
|
+
<varlistentry>
|
93
|
+
<term>:out</term>
|
94
|
+
<listitem>
|
95
|
+
set the output stream to the given IO <emphasis>($stdout)</emphasis>.
|
96
|
+
</listitem>
|
97
|
+
</varlistentry>
|
98
|
+
|
99
|
+
<varlistentry>
|
100
|
+
<term>:raw_post_data</term>
|
101
|
+
<listitem>
|
102
|
+
set the raw_post_data to the given IO <emphasis>($stdin)</emphasis>.
|
103
|
+
</listitem>
|
104
|
+
</varlistentry>
|
105
|
+
|
106
|
+
<varlistentry>
|
107
|
+
<term>:request</term>
|
108
|
+
<listitem>
|
109
|
+
pass in the request hash
|
110
|
+
</listitem>
|
111
|
+
</varlistentry>
|
112
|
+
|
113
|
+
<varlistentry>
|
114
|
+
<term>:session</term>
|
115
|
+
<listitem>
|
116
|
+
set the session to the given hash <emphasis>(Web::Session)</emphasis>.
|
117
|
+
</listitem>
|
118
|
+
</varlistentry>
|
119
|
+
|
120
|
+
<varlistentry>
|
121
|
+
<term>:env</term>
|
122
|
+
<listitem>
|
123
|
+
pass in the ENV variables
|
124
|
+
</listitem>
|
125
|
+
</varlistentry>
|
126
|
+
|
127
|
+
<varlistentry>
|
128
|
+
<term>:path_info</term>
|
129
|
+
<listitem>
|
130
|
+
path_info is the part of the query that is after the script,
|
131
|
+
i.e. the path_info.html in /script_name.rb/path_info.html <emphasis>(Web::env[:path_info])</emphasis>
|
132
|
+
</listitem>
|
133
|
+
</varlistentry>
|
134
|
+
|
135
|
+
<varlistentry>
|
136
|
+
<term>:document_root</term>
|
137
|
+
<listitem>
|
138
|
+
Document root of website. <emphasis>(Web::env[:document_root])</emphasis>
|
139
|
+
</listitem>
|
140
|
+
</varlistentry>
|
141
|
+
|
142
|
+
<varlistentry>
|
143
|
+
<term>:script_name</term>
|
144
|
+
<listitem>
|
145
|
+
Script name, ie /script_name.rb in /script_name.rb/path_info.html <emphasis>(Web::env[:script_name])</emphasis>
|
146
|
+
</listitem>
|
147
|
+
</varlistentry>
|
148
|
+
</variablelist>
|
149
|
+
</listitem>
|
150
|
+
</varlistentry>
|
151
|
+
</variablelist>
|
152
|
+
|
153
|
+
</chapter>
|
154
|
+
|
155
|
+
<chapter id="reference-variables">
|
156
|
+
<title>Web Variables</title>
|
157
|
+
<variablelist>
|
158
|
+
<varlistentry>
|
159
|
+
<term>Web[key]</term>
|
160
|
+
<listitem>
|
161
|
+
Convenience method to access values within Web::request.
|
162
|
+
If the key is array-style, aka 'param[]', the value is
|
163
|
+
returned as an array. Otherwise, value is joined with ","
|
164
|
+
and returned as a string.
|
165
|
+
</listitem>
|
166
|
+
</varlistentry>
|
167
|
+
|
168
|
+
<varlistentry>
|
169
|
+
<term>Web[key] = value</term>
|
170
|
+
<listitem>
|
171
|
+
Convenience method to set values within Web::request.
|
172
|
+
If value is not an array, sets key to [value].
|
173
|
+
</listitem>
|
174
|
+
</varlistentry>
|
175
|
+
|
176
|
+
<varlistentry>
|
177
|
+
<term>Web::cookie</term>
|
178
|
+
<listitem>
|
179
|
+
Access cookies sent by the client.
|
180
|
+
</listitem>
|
181
|
+
</varlistentry>
|
182
|
+
|
183
|
+
<varlistentry>
|
184
|
+
<term>Web::env</term>
|
185
|
+
<listitem>
|
186
|
+
ENV variables, scoped to the request, returned in a case-insensitive hash
|
187
|
+
</listitem>
|
188
|
+
</varlistentry>
|
189
|
+
|
190
|
+
<varlistentry>
|
191
|
+
<term>Web::get</term>
|
192
|
+
<listitem>
|
193
|
+
Access parameters passed on the url.
|
194
|
+
</listitem>
|
195
|
+
</varlistentry>
|
196
|
+
|
197
|
+
<varlistentry>
|
198
|
+
<term>Web::info</term>
|
199
|
+
<listitem>
|
200
|
+
Display information about the execution enviroment to the client.
|
201
|
+
</listitem>
|
202
|
+
</varlistentry>
|
203
|
+
|
204
|
+
<varlistentry>
|
205
|
+
<term>Web::key?(key)</term>
|
206
|
+
<listitem>
|
207
|
+
Test whether Web::cookie, Web::get, or Web::post contain the given key.
|
208
|
+
</listitem>
|
209
|
+
</varlistentry>
|
210
|
+
|
211
|
+
<varlistentry>
|
212
|
+
<term>Web::keys</term>
|
213
|
+
<listitem>
|
214
|
+
Return set of the keys of Web::cookie, Web::get, and Web::post.
|
215
|
+
</listitem>
|
216
|
+
</varlistentry>
|
217
|
+
|
218
|
+
<varlistentry>
|
219
|
+
<term>Web::local</term>
|
220
|
+
<listitem>
|
221
|
+
A hash scoped to the current web connection.
|
222
|
+
Similar to Request scope in the Java Servlet API.
|
223
|
+
</listitem>
|
224
|
+
</varlistentry>
|
225
|
+
|
226
|
+
<varlistentry>
|
227
|
+
<term>Web::post</term>
|
228
|
+
<listitem>
|
229
|
+
Access parameters submitted via a form posting.
|
230
|
+
</listitem>
|
231
|
+
</varlistentry>
|
232
|
+
|
233
|
+
<varlistentry>
|
234
|
+
<term>Web::request</term>
|
235
|
+
<listitem>
|
236
|
+
Convenience array. Combines Web::get, Web::post, and Web::cookie into one hash. If the same key is passed in Web::get and Web::post, Web::env['request_method'] is used to choose which takes priority.
|
237
|
+
</listitem>
|
238
|
+
</varlistentry>
|
239
|
+
|
240
|
+
<varlistentry>
|
241
|
+
<term>Web::raw_post_data</term>
|
242
|
+
<listitem>
|
243
|
+
An IO object containing the raw post data from the request.
|
244
|
+
</listitem>
|
245
|
+
</varlistentry>
|
246
|
+
|
247
|
+
<varlistentry>
|
248
|
+
<term>Web::session</term>
|
249
|
+
<listitem>
|
250
|
+
Session values.
|
251
|
+
</listitem>
|
252
|
+
</varlistentry>
|
253
|
+
|
254
|
+
</variablelist>
|
255
|
+
</chapter>
|
256
|
+
|
257
|
+
<chapter id="reference-output">
|
258
|
+
<title>Output Functions</title>
|
259
|
+
<variablelist>
|
260
|
+
<varlistentry>
|
261
|
+
<term>Web << output</term>
|
262
|
+
<listitem>
|
263
|
+
Write output to the browser.
|
264
|
+
</listitem>
|
265
|
+
</varlistentry>
|
266
|
+
|
267
|
+
<varlistentry>
|
268
|
+
<term>Web::clear</term>
|
269
|
+
<listitem>
|
270
|
+
Reset output buffer. Fails if headers have been sent.
|
271
|
+
</listitem>
|
272
|
+
</varlistentry>
|
273
|
+
|
274
|
+
<varlistentry>
|
275
|
+
<term>Web::close</term>
|
276
|
+
<listitem>
|
277
|
+
Flushes the output and, if applicable, saves the session.
|
278
|
+
</listitem>
|
279
|
+
</varlistentry>
|
280
|
+
|
281
|
+
<varlistentry>
|
282
|
+
<term>Web::flush</term>
|
283
|
+
<listitem>
|
284
|
+
Send header to the client, and flush any buffered output
|
285
|
+
</listitem>
|
286
|
+
</varlistentry>
|
287
|
+
|
288
|
+
<varlistentry>
|
289
|
+
<term>Web::puts(output)</term>
|
290
|
+
<listitem>
|
291
|
+
Write output to the browser with line breaks.
|
292
|
+
</listitem>
|
293
|
+
</varlistentry>
|
294
|
+
|
295
|
+
<varlistentry>
|
296
|
+
<term>Web::write(output)</term>
|
297
|
+
<listitem>
|
298
|
+
Write output to the browser.
|
299
|
+
</listitem>
|
300
|
+
</varlistentry>
|
301
|
+
|
302
|
+
<varlistentry>
|
303
|
+
<term>Web::send_file( filename )</term>
|
304
|
+
<listitem>
|
305
|
+
This method will replace the contents of the output buffer
|
306
|
+
with the content read from the given filename.
|
307
|
+
If the Content-Type header has not already been set,
|
308
|
+
it will guess an appropriate mime-type from the extension of the file.
|
309
|
+
</listitem>
|
310
|
+
</varlistentry>
|
311
|
+
|
312
|
+
<varlistentry>
|
313
|
+
<term>Web::send_lib_file( relative_filename )</term>
|
314
|
+
<listitem>
|
315
|
+
Using Web::send_file(filename), sends the contents of a file
|
316
|
+
from the ruby lib to the client. Filename is relative to the file of Kernel::caller.
|
317
|
+
This method is intended to help the distribution of web applications as normal ruby libraries.
|
318
|
+
<programlisting>
|
319
|
+
# sends ".../ruby/site_lib/1.8/web/resources/logo.gif" to the client
|
320
|
+
Web::send_lib_file( 'resources/logo.gif' )</programlisting>
|
321
|
+
</listitem>
|
322
|
+
</varlistentry>
|
323
|
+
|
324
|
+
<varlistentry>
|
325
|
+
<term>Web::unbuffered?</term>
|
326
|
+
<listitem>
|
327
|
+
Returns whether output buffering is being used. By default, output is buffered.
|
328
|
+
</listitem>
|
329
|
+
</varlistentry>
|
330
|
+
|
331
|
+
<varlistentry>
|
332
|
+
<term>Web::filter</term>
|
333
|
+
<listitem>
|
334
|
+
Start an output buffer. aka Web::ob_start. Yields content for filtering before being written out:
|
335
|
+
<programlisting>
|
336
|
+
Web::filter do |content|
|
337
|
+
# ... filter content
|
338
|
+
end</programlisting>
|
339
|
+
|
340
|
+
</listitem>
|
341
|
+
</varlistentry>
|
342
|
+
|
343
|
+
<varlistentry>
|
344
|
+
<term>Web::ob_flush</term>
|
345
|
+
<listitem>
|
346
|
+
Flush (send) the output buffer
|
347
|
+
</listitem>
|
348
|
+
</varlistentry>
|
349
|
+
|
350
|
+
<varlistentry>
|
351
|
+
<term>Web::ob_clean</term>
|
352
|
+
<listitem>
|
353
|
+
Erase and discard contents of the output buffer
|
354
|
+
</listitem>
|
355
|
+
</varlistentry>
|
356
|
+
|
357
|
+
<varlistentry>
|
358
|
+
<term>Web::ob_end_clean</term>
|
359
|
+
<listitem>
|
360
|
+
Erase contents of output buffer, and discard the buffer itself
|
361
|
+
</listitem>
|
362
|
+
</varlistentry>
|
363
|
+
|
364
|
+
<varlistentry>
|
365
|
+
<term>Web::ob_end_flush</term>
|
366
|
+
<listitem>
|
367
|
+
Flush (send) the output buffer and discard the buffer itself
|
368
|
+
</listitem>
|
369
|
+
</varlistentry>
|
370
|
+
|
371
|
+
<varlistentry>
|
372
|
+
<term>Web::ob_get_clean</term>
|
373
|
+
<listitem>
|
374
|
+
Get current buffer contents and delete current output buffer
|
375
|
+
</listitem>
|
376
|
+
</varlistentry>
|
377
|
+
|
378
|
+
<varlistentry>
|
379
|
+
<term>Web::ob_get_contents</term>
|
380
|
+
<listitem>
|
381
|
+
Return the contents of the output buffer
|
382
|
+
</listitem>
|
383
|
+
</varlistentry>
|
384
|
+
|
385
|
+
<varlistentry>
|
386
|
+
<term>Web::ob_get_flush</term>
|
387
|
+
<listitem>
|
388
|
+
Flush the output buffer, return it as a string and turn off output buffering
|
389
|
+
</listitem>
|
390
|
+
</varlistentry>
|
391
|
+
|
392
|
+
<varlistentry>
|
393
|
+
<term>Web::ob_get_length</term>
|
394
|
+
<listitem>Return the length of the output buffer</listitem>
|
395
|
+
</varlistentry>
|
396
|
+
|
397
|
+
<varlistentry>
|
398
|
+
<term>Web::ob_get_level</term>
|
399
|
+
<listitem>Return the nesting level of the output buffering mechanism</listitem>
|
400
|
+
</varlistentry>
|
401
|
+
|
402
|
+
<varlistentry>
|
403
|
+
<term>Web::ob_list_handlers</term>
|
404
|
+
<listitem>List all output handlers in use</listitem>
|
405
|
+
</varlistentry>
|
406
|
+
|
407
|
+
<!--# ob_get_contents Return the contents of the output buffer-->
|
408
|
+
|
409
|
+
</variablelist>
|
410
|
+
</chapter>
|
411
|
+
|
412
|
+
<chapter id="reference-header">
|
413
|
+
<title>Header Functions</title>
|
414
|
+
<varlistentry>
|
415
|
+
<term>Web::charset / Web::charset=(new_charset)</term>
|
416
|
+
<listitem>
|
417
|
+
Get / set charset.
|
418
|
+
</listitem>
|
419
|
+
</varlistentry>
|
420
|
+
|
421
|
+
<variablelist>
|
422
|
+
<varlistentry>
|
423
|
+
<term>Web::cookies_sent</term>
|
424
|
+
<listitem>
|
425
|
+
Returns a hash of all the cookie name/value pairs that have been set on the server.
|
426
|
+
</listitem>
|
427
|
+
</varlistentry>
|
428
|
+
|
429
|
+
<varlistentry>
|
430
|
+
<term>Web::content_type() / Web::content_type=(new_content_type)</term>
|
431
|
+
<listitem>
|
432
|
+
Get / set content type. The default content-type is "text/html".
|
433
|
+
</listitem>
|
434
|
+
</varlistentry>
|
435
|
+
|
436
|
+
<varlistentry>
|
437
|
+
<term>Web::encoding / Web::encoding=( new_encoding )</term>
|
438
|
+
<listitem>
|
439
|
+
Get / set character encoding.a
|
440
|
+
</listitem>
|
441
|
+
</varlistentry>
|
442
|
+
|
443
|
+
<varlistentry>
|
444
|
+
<term>Web::get_cookie(key)</term>
|
445
|
+
<listitem>
|
446
|
+
Returns an array of cookie values that have been set. Path / Expires / etc. info is currently not returned. Note that this is different from the cookies that the browser submitted to the server.
|
447
|
+
</listitem>
|
448
|
+
</varlistentry>
|
449
|
+
|
450
|
+
<varlistentry>
|
451
|
+
<term>Web::status / Web::status=(new_status)</term>
|
452
|
+
<listitem>
|
453
|
+
Get / Set new status, as in:
|
454
|
+
<programlisting>Web::status = 200</programlisting>
|
455
|
+
</listitem>
|
456
|
+
</varlistentry>
|
457
|
+
|
458
|
+
<varlistentry>
|
459
|
+
<term>Web::set_cookie( name, value, options={} )</term>
|
460
|
+
<listitem>
|
461
|
+
<para>Sends client a cookie with the given name and a value, and these optional keyword arguments:</para>
|
462
|
+
|
463
|
+
<variablelist>
|
464
|
+
<varlistentry>
|
465
|
+
<term>:path</term>
|
466
|
+
<listitem>
|
467
|
+
Path string
|
468
|
+
</listitem>
|
469
|
+
</varlistentry>
|
470
|
+
<varlistentry>
|
471
|
+
<term>:domain</term>
|
472
|
+
<listitem>
|
473
|
+
Domain string
|
474
|
+
</listitem>
|
475
|
+
</varlistentry>
|
476
|
+
<varlistentry>
|
477
|
+
<term>:expires</term>
|
478
|
+
<listitem>
|
479
|
+
Date this cookie should expire
|
480
|
+
</listitem>
|
481
|
+
</varlistentry>
|
482
|
+
<varlistentry>
|
483
|
+
<term>:secure</term>
|
484
|
+
<listitem>
|
485
|
+
Whether this cookie should be tagged as secure or not.
|
486
|
+
</listitem>
|
487
|
+
</varlistentry>
|
488
|
+
</variablelist>
|
489
|
+
</listitem>
|
490
|
+
</varlistentry>
|
491
|
+
|
492
|
+
<varlistentry>
|
493
|
+
<term>Web::set_redirect( new_location )</term>
|
494
|
+
<listitem>
|
495
|
+
Sets the status and the location appropriately.
|
496
|
+
</listitem>
|
497
|
+
</varlistentry>
|
498
|
+
|
499
|
+
</variablelist>
|
500
|
+
|
501
|
+
</chapter>
|
502
|
+
|
503
|
+
<chapter id="reference-utility">
|
504
|
+
<title>Utility Functions</title>
|
505
|
+
<variablelist>
|
506
|
+
<varlistentry>
|
507
|
+
<term>Web::escape(string)</term>
|
508
|
+
<listitem>
|
509
|
+
URL-encode a string. (from cgi.rb)
|
510
|
+
<programlisting>
|
511
|
+
url_encoded_string = Web::escape("'Stop!' said Fred")
|
512
|
+
# => "%27Stop%21%27+said+Fred"</programlisting>
|
513
|
+
</listitem>
|
514
|
+
</varlistentry>
|
515
|
+
|
516
|
+
<varlistentry>
|
517
|
+
<term>Web::escape_element(string, *elements)</term>
|
518
|
+
<listitem>
|
519
|
+
Escape only the tags of certain HTML elements in string. Takes an element or elements or array of elements. Each element is specified by the name of the element, without angle brackets. This matches both the start and the end tag of that element. The attribute list of the open tag will also be escaped (for instance, the double-quotes surrounding attribute values). (from cgi.rb)
|
520
|
+
<programlisting>
|
521
|
+
print Web::escape_element('<BR><A HREF="url"></A>', "A", "IMG")
|
522
|
+
# "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt;"
|
523
|
+
|
524
|
+
print Web::escape_element('<BR><A HREF="url"></A>', ["A", "IMG"])
|
525
|
+
# "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt;"</programlisting>
|
526
|
+
</listitem>
|
527
|
+
</varlistentry>
|
528
|
+
|
529
|
+
<varlistentry>
|
530
|
+
<term>Web::escape_html(string)</term>
|
531
|
+
<listitem>
|
532
|
+
Escape special characters in HTML, namely &\"<> (from cgi.rb)
|
533
|
+
<programlisting>
|
534
|
+
Web::escape_html('Usage: foo "bar" <baz>')
|
535
|
+
# => "Usage: foo &quot;bar&quot; &lt;baz&gt;"</programlisting>
|
536
|
+
</listitem>
|
537
|
+
</varlistentry>
|
538
|
+
|
539
|
+
<varlistentry>
|
540
|
+
<term>Web::get_mime_type(filename)</term>
|
541
|
+
<listitem>
|
542
|
+
Guess the mimetype for the filename from the file extension.
|
543
|
+
</listitem>
|
544
|
+
</varlistentry>
|
545
|
+
|
546
|
+
<varlistentry>
|
547
|
+
<term>Web::lib_file_contents( filename )</term>
|
548
|
+
<listitem>
|
549
|
+
Get the contents of a file in the ruby libraries. Filename is relative to Kernel::caller
|
550
|
+
<programlisting>
|
551
|
+
template = Web::lib_file_contents('resources/template.html')</programlisting>
|
552
|
+
</listitem>
|
553
|
+
</varlistentry>
|
554
|
+
|
555
|
+
<varlistentry>
|
556
|
+
<term>Web::lib_filename( resource )</term>
|
557
|
+
<listitem>
|
558
|
+
This function is for apps that want to store resources with the source files in the ruby lib directories. Filename is relative to Kernel::caller
|
559
|
+
<programlisting>
|
560
|
+
Web::lib_filename('resources/logo.gif')
|
561
|
+
# => ".../ruby/site_lib/1.8/web/resources/logo.gif"</programlisting>
|
562
|
+
</listitem>
|
563
|
+
</varlistentry>
|
564
|
+
|
565
|
+
<varlistentry>
|
566
|
+
<term>Web::rfc1123_date(time)</term>
|
567
|
+
<listitem>
|
568
|
+
Make RFC1123 date string
|
569
|
+
<programlisting>Web::rfc1123_date(Time.now) # => Sat, 01 Jan 2000 00:00:00 GMT</programlisting>
|
570
|
+
</listitem>
|
571
|
+
</varlistentry>
|
572
|
+
|
573
|
+
<varlistentry>
|
574
|
+
<term>Web::unescape(string)</term>
|
575
|
+
<listitem>
|
576
|
+
URL-decode a string. (from cgi.rb)
|
577
|
+
<programlisting>
|
578
|
+
string = Web::unescape("%27Stop%21%27+said+Fred")
|
579
|
+
# => "'Stop!' said Fred"</programlisting>
|
580
|
+
</listitem>
|
581
|
+
</varlistentry>
|
582
|
+
|
583
|
+
<varlistentry>
|
584
|
+
<term>Web::unescape_element(string, *elements)</term>
|
585
|
+
<listitem>
|
586
|
+
Undo escaping such as that done by Web::escape_element. (from cgi.rb)
|
587
|
+
<programlisting>
|
588
|
+
print Web::unescape_element(
|
589
|
+
Web::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
|
590
|
+
# "&lt;BR&gt;<A HREF="url"></A>"
|
591
|
+
|
592
|
+
print Web::unescape_element(
|
593
|
+
Web::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
|
594
|
+
# "&lt;BR&gt;<A HREF="url"></A>"</programlisting>
|
595
|
+
</listitem>
|
596
|
+
</varlistentry>
|
597
|
+
|
598
|
+
<varlistentry>
|
599
|
+
<term>Web::unescape_html(string)</term>
|
600
|
+
<listitem>
|
601
|
+
Unescape a string that has been HTML-escaped (from cgi.rb)
|
602
|
+
<programlisting>
|
603
|
+
Web::unescape_html("Usage: foo &quot;bar&quot; &lt;baz&gt;")
|
604
|
+
# => "Usage: foo \"bar\" <baz>"</programlisting>
|
605
|
+
</listitem>
|
606
|
+
</varlistentry>
|
607
|
+
|
608
|
+
</variablelist>
|
609
|
+
</chapter>
|
610
|
+
|
611
|
+
<chapter id="reference-configuration">
|
612
|
+
<title>Configuration</title>
|
613
|
+
<para>Config directives are set using Web::config[:directive] = value. If desired, config directives can be set within 'site_lib/x.x/web/site-config.rb'.</para>
|
614
|
+
<para>Below is a list of available config directives:</para>
|
615
|
+
<variablelist>
|
616
|
+
<varlistentry>
|
617
|
+
<term>:load_suffix</term>
|
618
|
+
<listitem>
|
619
|
+
<para>:load_suffix contains a hash of handlers for different file extensions. You can then control the behavior of Web::load:</para>
|
620
|
+
<programlisting
|
621
|
+
>Web::config[:load_suffix][:amrita] = lambda do |scriptname|
|
622
|
+
#...handle amrita templates...
|
623
|
+
end</programlisting>
|
624
|
+
<para>
|
625
|
+
:load_suffix by default will load .rb and .erb files appropriately.
|
626
|
+
Everything else is loaded using ruby-web's default templating.
|
627
|
+
</para>
|
628
|
+
</listitem>
|
629
|
+
</varlistentry>
|
630
|
+
|
631
|
+
<varlistentry>
|
632
|
+
<term>:load_path</term>
|
633
|
+
<listitem>
|
634
|
+
:load_path is an array of directories, searched by Web::load when it has been given a relative path to load.
|
635
|
+
</listitem>
|
636
|
+
</varlistentry>
|
637
|
+
|
638
|
+
<varlistentry>
|
639
|
+
<term>:error_style</term>
|
640
|
+
<listitem>
|
641
|
+
Controls how exceptions are handled. Valid values include :development, :production, or :custom. :development prints a full stacktrace, :production prints a more abbreviated message. :custom allows one to defined their own handler using Web::config[:error_handler]
|
642
|
+
</listitem>
|
643
|
+
</varlistentry>
|
644
|
+
|
645
|
+
<varlistentry>
|
646
|
+
<term>:multipart_progress_hook</term>
|
647
|
+
<listitem>
|
648
|
+
Allows one to pass a lambda that will be called as a multipart upload is read. The lambda is called with 2 arguments: the total number of bytes, and the number of bytes read so far. Probably only useful to AJAX implementations.
|
649
|
+
</listitem>
|
650
|
+
</varlistentry>
|
651
|
+
</variablelist>
|
652
|
+
</chapter>
|