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
@@ -0,0 +1,174 @@
|
|
1
|
+
# urireg.rb: generates Regexps for uri.rb
|
2
|
+
# $Id: urireg.rb,v 1.1.1.1 2002/11/29 04:34:24 patsplat Exp $
|
3
|
+
|
4
|
+
# CAUTION: Some regexps generated by this cannot be compiled.
|
5
|
+
# In ruby v1.4.3, /\//.source() generates "/".
|
6
|
+
|
7
|
+
=begin
|
8
|
+
rfc2396
|
9
|
+
URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]
|
10
|
+
absoluteURI = scheme ":" ( hier_part | opaque_part )
|
11
|
+
relativeURI = ( net_path | abs_path | rel_path ) [ "?" query ]
|
12
|
+
|
13
|
+
hier_part = ( net_path | abs_path ) [ "?" query ]
|
14
|
+
opaque_part = uric_no_slash *uric
|
15
|
+
|
16
|
+
uric_no_slash = unreserved | escaped | ";" | "?" | ":" | "@" |
|
17
|
+
"&" | "=" | "+" | "$" | ","
|
18
|
+
|
19
|
+
net_path = "//" authority [ abs_path ]
|
20
|
+
abs_path = "/" path_segments
|
21
|
+
rel_path = rel_segment [ abs_path ]
|
22
|
+
|
23
|
+
rel_segment = 1*( unreserved | escaped |
|
24
|
+
";" | "@" | "&" | "=" | "+" | "$" | "," )
|
25
|
+
|
26
|
+
scheme = alpha *( alpha | digit | "+" | "-" | "." )
|
27
|
+
|
28
|
+
authority = server | reg_name
|
29
|
+
|
30
|
+
reg_name = 1*( unreserved | escaped | "$" | "," |
|
31
|
+
";" | ":" | "@" | "&" | "=" | "+" )
|
32
|
+
|
33
|
+
server = [ [ userinfo "@" ] hostport ]
|
34
|
+
userinfo = *( unreserved | escaped |
|
35
|
+
";" | ":" | "&" | "=" | "+" | "$" | "," )
|
36
|
+
|
37
|
+
hostport = host [ ":" port ]
|
38
|
+
host = hostname | IPv4address
|
39
|
+
hostname = *( domainlabel "." ) toplabel [ "." ]
|
40
|
+
domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
|
41
|
+
toplabel = alpha | alpha *( alphanum | "-" ) alphanum
|
42
|
+
IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
|
43
|
+
port = *digit
|
44
|
+
|
45
|
+
path = [ abs_path | opaque_part ] # path is dangling
|
46
|
+
path_segments = segment *( "/" segment )
|
47
|
+
segment = *pchar *( ";" param )
|
48
|
+
param = *pchar
|
49
|
+
pchar = unreserved | escaped |
|
50
|
+
":" | "@" | "&" | "=" | "+" | "$" | ","
|
51
|
+
|
52
|
+
query = *uric
|
53
|
+
|
54
|
+
fragment = *uric
|
55
|
+
|
56
|
+
uric = reserved | unreserved | escaped
|
57
|
+
reserved = ";" | "/" | "?" | ":" | "@" | "&" | "=" | "+" |
|
58
|
+
"$" | ","
|
59
|
+
unreserved = alphanum | mark
|
60
|
+
mark = "-" | "_" | "." | "!" | "~" | "*" | "'" |
|
61
|
+
"(" | ")"
|
62
|
+
|
63
|
+
escaped = "%" hex hex
|
64
|
+
hex = digit | "A" | "B" | "C" | "D" | "E" | "F" |
|
65
|
+
"a" | "b" | "c" | "d" | "e" | "f"
|
66
|
+
|
67
|
+
alphanum = alpha | digit
|
68
|
+
alpha = lowalpha | upalpha
|
69
|
+
|
70
|
+
lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" |
|
71
|
+
"j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" |
|
72
|
+
"s" | "t" | "u" | "v" | "w" | "x" | "y" | "z"
|
73
|
+
upalpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" |
|
74
|
+
"J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" |
|
75
|
+
"S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z"
|
76
|
+
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" |
|
77
|
+
"8" | "9"
|
78
|
+
=end
|
79
|
+
|
80
|
+
require 'regman'
|
81
|
+
|
82
|
+
# pchar = unreserved | escaped | ":" | "@" | "&" | "=" | "+" | "$" | ","
|
83
|
+
PCHAR = /[0-9A-Za-z\-_.!~*'():@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f]/
|
84
|
+
|
85
|
+
# param = *pchar
|
86
|
+
PARAM = /(?:[0-9A-Za-z\-_.!~*'():@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*/
|
87
|
+
|
88
|
+
# segment = *pchar *( ";" param )
|
89
|
+
SEGMENT = /(?:[0-9A-Za-z\-_.!~*'():@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*(?:;(?:[0-9A-Za-z\-_.!~*'():@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*)*/
|
90
|
+
|
91
|
+
# IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
|
92
|
+
IPV4ADDRESS = /\d+\.\d+\.\d+\.\d+/
|
93
|
+
|
94
|
+
# toplabel = alpha | alpha *( alphanum | "-" ) alphanum
|
95
|
+
TOPLABEL = /[A-Za-z]|[A-Za-z][0-9A-Za-z\-]*[0-9A-Za-z]/
|
96
|
+
|
97
|
+
# domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
|
98
|
+
DOMAINLABEL = /[0-9A-Za-z]|[0-9A-Za-z][0-9A-Za-z\-]*[0-9A-Za-z]/
|
99
|
+
|
100
|
+
# hostname = *( domainlabel "." ) toplabel [ "." ]
|
101
|
+
HOSTNAME = RM.cat(RM.star(RM.cat(DOMAINLABEL, /\./)), TOPLABEL, /\.?/)
|
102
|
+
|
103
|
+
# path_segments = segment *( "/" segment )
|
104
|
+
tmp = RM.cat(SEGMENT, RM.star(RM.cat(/\//, SEGMENT)))
|
105
|
+
PATH_SEGMENTS = /\A#{tmp.source}\z/
|
106
|
+
|
107
|
+
# abs_path = "/" path_segments
|
108
|
+
# equals
|
109
|
+
# abs_path = "/" segment *( "/" segment )
|
110
|
+
# equals
|
111
|
+
# abs_path = 1*( "/" segment )
|
112
|
+
tmp = RM.plus(RM.cat(/\//, SEGMENT))
|
113
|
+
ABS_PATH = /\A#{tmp.source}\z/
|
114
|
+
|
115
|
+
# rel_segment = 1*( unreserved | escaped |
|
116
|
+
# ";" | "@" | "&" | "=" | "+" | "$" | "," )
|
117
|
+
REL_SEGMENT = /\A(?:[0-9A-Za-z\-_.!~*'();@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])+\z/
|
118
|
+
|
119
|
+
# host = hostname | IPv4address
|
120
|
+
tmp = RM.bar(HOSTNAME, /\d+\.\d+\.\d+\.\d+/)
|
121
|
+
HOST = /\A(?:#{tmp.source})\z/
|
122
|
+
|
123
|
+
# userinfo = *( unreserved | escaped |
|
124
|
+
# ";" | ":" | "&" | "=" | "+" | "$" | "," )
|
125
|
+
USERINFO = /\A(?:[0-9A-Za-z\-_.!~*'();:&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*\z/
|
126
|
+
|
127
|
+
# reg_name = 1*( unreserved | escaped | "$" | "," |
|
128
|
+
# ";" | ":" | "@" | "&" | "=" | "+" )
|
129
|
+
REG_NAME = /\A(?:[0-9A-Za-z\-_.!~*'()$,;:@&=+]|%[0-9A-Fa-f][0-9A-Fa-f])+\z/
|
130
|
+
|
131
|
+
# query = *uric
|
132
|
+
# uric = reserved | unreserved | escaped
|
133
|
+
QUERY = /\A(?:[0-9A-Za-z\-_.!~*'();\/?:@&=+$,]|%[0-9A-Fa-f][0-9A-Fa-f])*\z/
|
134
|
+
|
135
|
+
# scheme = alpha *( alpha | digit | "+" | "-" | "." )
|
136
|
+
SCHEME = /\A[A-Za-z][0-9A-Za-z+\-.]*\z/
|
137
|
+
|
138
|
+
# fragment = *uric
|
139
|
+
FRAGMENT = QUERY
|
140
|
+
|
141
|
+
puts 'FRAGMENT (invalid source)'
|
142
|
+
puts FRAGMENT.source
|
143
|
+
puts
|
144
|
+
|
145
|
+
puts 'SCHEME'
|
146
|
+
puts SCHEME.source
|
147
|
+
puts
|
148
|
+
|
149
|
+
puts 'QUERY (invalid source)'
|
150
|
+
puts QUERY.source
|
151
|
+
puts
|
152
|
+
|
153
|
+
puts 'REG_NAME'
|
154
|
+
puts REG_NAME.source
|
155
|
+
puts
|
156
|
+
|
157
|
+
puts 'USERINFO'
|
158
|
+
puts USERINFO.source
|
159
|
+
puts
|
160
|
+
|
161
|
+
puts 'HOST'
|
162
|
+
puts HOST.source
|
163
|
+
puts
|
164
|
+
|
165
|
+
puts 'REL_SEGMENT'
|
166
|
+
puts REL_SEGMENT.source
|
167
|
+
puts
|
168
|
+
|
169
|
+
puts 'PATH_SEGMENTS (invalid source)'
|
170
|
+
puts PATH_SEGMENTS.source
|
171
|
+
puts
|
172
|
+
|
173
|
+
puts 'ABS_PATH (invalid source)'
|
174
|
+
puts ABS_PATH.source
|
@@ -0,0 +1,156 @@
|
|
1
|
+
module Web
|
2
|
+
# Web::SimpleDispatcher provides a simple framework for organizing
|
3
|
+
# Web applications, combining them with forms and handling forms.
|
4
|
+
#
|
5
|
+
# The following is an example form template
|
6
|
+
# '/myappdir/html/templates/my_app.html
|
7
|
+
#
|
8
|
+
# <html>
|
9
|
+
# <body>
|
10
|
+
# <narf:form name="my_form" method="post">
|
11
|
+
# <narf:text name="field1">
|
12
|
+
# <narf:textarea name="field2">
|
13
|
+
# </narf:form>
|
14
|
+
# </body>
|
15
|
+
# </html>
|
16
|
+
#
|
17
|
+
# Patrick notes: simple dispatcher might not be simple.
|
18
|
+
# view as promising alpha
|
19
|
+
module SimpleDispatcher #:nodoc: all
|
20
|
+
def SimpleDispatcher.trace_dispatcher text
|
21
|
+
if $ADD_TEST_OUTPUT
|
22
|
+
Kernel.puts text
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Link
|
27
|
+
attr_reader :page, :query
|
28
|
+
|
29
|
+
def initialize page, query
|
30
|
+
@page = page
|
31
|
+
@query = query
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_link
|
35
|
+
"#{SimpleDispatcher.template_from_class(@page)}?#{Link.make_query_string(Web.encode_objects(@query))}"
|
36
|
+
end
|
37
|
+
|
38
|
+
def encode
|
39
|
+
encode64(Marshal.dump(self))
|
40
|
+
end
|
41
|
+
|
42
|
+
class << self
|
43
|
+
def make_query_string query
|
44
|
+
query.collect do |k,v|
|
45
|
+
"#{k}=#{Web.escape(v)}"
|
46
|
+
end.join("&")
|
47
|
+
end
|
48
|
+
|
49
|
+
def Link.unencode string
|
50
|
+
Marshal.load(decode64(string))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
module TemplateMixin
|
56
|
+
def redirect_to_template templateClass, params
|
57
|
+
Web.reset_headers
|
58
|
+
Web.set_redirect File.join(Web.script_name, "#{templateClass.template}?#{Web.make_query_string(Web.encode_objects(params))}")
|
59
|
+
end
|
60
|
+
|
61
|
+
def assign_params
|
62
|
+
params = {}
|
63
|
+
Web.keys.each do |k|
|
64
|
+
if k
|
65
|
+
params[k] = Web[k]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
Scope.new(self).update( params )
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
module TemplateClassMixin
|
74
|
+
def template
|
75
|
+
SimpleDispatcher::template_from_class self
|
76
|
+
end
|
77
|
+
|
78
|
+
def redirect_to params
|
79
|
+
Web.reset_headers
|
80
|
+
Web.set_redirect File.join(Web.script_name, "#{template}?#{Web.make_query_string(Web.encode_objects(params))}")
|
81
|
+
end
|
82
|
+
|
83
|
+
def template_filename
|
84
|
+
template + ".html"
|
85
|
+
end
|
86
|
+
|
87
|
+
def format_description
|
88
|
+
"Template: #{template_filename}, formclass #{name}"
|
89
|
+
end
|
90
|
+
|
91
|
+
def was_not_a_submit
|
92
|
+
Web["__submitted"] == ""
|
93
|
+
end
|
94
|
+
|
95
|
+
def handle aTemplate
|
96
|
+
if was_not_a_submit
|
97
|
+
# trace_dispatcher format_description
|
98
|
+
else
|
99
|
+
# trace_dispatcher "Submit to: #{name}"
|
100
|
+
aTemplate.assign_params
|
101
|
+
aTemplate.on_submit({})
|
102
|
+
end
|
103
|
+
|
104
|
+
Web::load template_filename
|
105
|
+
|
106
|
+
#aTemplate, Web.encode_objects(Web.query)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
class Template
|
111
|
+
include TemplateMixin
|
112
|
+
|
113
|
+
class << self
|
114
|
+
include TemplateClassMixin
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class << self
|
119
|
+
def class_from_template template
|
120
|
+
template.gsub(/(^|_)([a-z])/) { |m| m.gsub('_','').upcase }
|
121
|
+
end
|
122
|
+
|
123
|
+
def template_from_class aClass
|
124
|
+
first = true
|
125
|
+
aClass.name.gsub(/([A-Z])/) do |m|
|
126
|
+
value = m.downcase
|
127
|
+
if first
|
128
|
+
first = false
|
129
|
+
value
|
130
|
+
else
|
131
|
+
"_" + value
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def template_from_path_info
|
137
|
+
if (Web.get_cgi.path_info != "/")
|
138
|
+
if (m = /\/?(.+)\/?/.match(Web.get_cgi.path_info))
|
139
|
+
eval(class_from_template(m[1]))
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def handle_request options
|
145
|
+
unless formclass = template_from_path_info
|
146
|
+
options[:default].redirect_to Web.query
|
147
|
+
return
|
148
|
+
end
|
149
|
+
|
150
|
+
aTemplate = formclass.new(Web.query)
|
151
|
+
|
152
|
+
formclass.handle aTemplate
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
module Web
|
2
|
+
class Action
|
3
|
+
def Action.clear_actions
|
4
|
+
Thread::current[:actions] = [ ]
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class TestAction < Test::Unit::TestCase
|
10
|
+
def set_up
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown
|
14
|
+
@output = @cgi = @action = @stored_pattern = nil
|
15
|
+
Web::Action.clear_actions
|
16
|
+
end
|
17
|
+
|
18
|
+
def output
|
19
|
+
@output ||= ""
|
20
|
+
end
|
21
|
+
|
22
|
+
def cgi params={}
|
23
|
+
Web::CGI.new( :out => output, :params => params )
|
24
|
+
end
|
25
|
+
|
26
|
+
def stored_pattern pattern={}
|
27
|
+
@stored_pattern ||= pattern
|
28
|
+
end
|
29
|
+
|
30
|
+
def action( pattern=stored_pattern, &function )
|
31
|
+
@action ||= Web::Action.new( pattern, &function )
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_failed_match_on_blank_cgi
|
35
|
+
action( "name" => // )
|
36
|
+
assert_equal( false, action.applies?(cgi) )
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_fails_with_different_params
|
40
|
+
action "name" => //
|
41
|
+
assert_equal( false, action.applies?(cgi( {"not" => "me"} )) )
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_matchs_by_param_present
|
45
|
+
action "name" => //
|
46
|
+
assert action.applies?(cgi( {"name" => "something"}) )
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_matches_exact_param
|
50
|
+
action "name" => "patrick"
|
51
|
+
assert action.applies?(cgi( {"name" => "patrick" } ))
|
52
|
+
assert_equal( false, action.applies?(cgi( {"name" => "patrick.may"} ) ))
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_matches_pattern
|
56
|
+
action "name" => /patrick|tom/
|
57
|
+
assert action.applies?(cgi( {"name" => "patrick the great" } ))
|
58
|
+
assert action.applies?(cgi( {"name" => "tom the silly" } ))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_match_is_not_anal
|
62
|
+
action "name" => //
|
63
|
+
assert action.applies?(cgi( {"name" => "something", "ignore" => "me"} ))
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_runs_block
|
67
|
+
action_ran_flag = false
|
68
|
+
action( "name" => // ) {
|
69
|
+
action_ran_flag = true
|
70
|
+
}
|
71
|
+
|
72
|
+
action.run
|
73
|
+
|
74
|
+
assert action_ran_flag
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_guards_block
|
78
|
+
Web::Action.new.run
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_passes_cgi_in_with_run
|
82
|
+
action_ran_flag = false
|
83
|
+
action( "name" => // ){ |cgi|
|
84
|
+
action_ran_flag = cgi.key? "flag"
|
85
|
+
}
|
86
|
+
|
87
|
+
action.run cgi( "flag" => "it ran" )
|
88
|
+
|
89
|
+
assert action_ran_flag
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_pick_action_picks_the_most_specific_action
|
93
|
+
one = Web::Action.new( "name" => // ) { assert false }
|
94
|
+
second = Web::Action.new( "name" => "patrick" ) { assert true }
|
95
|
+
third = Web::Action.new( "name" => /patrick|tom/ ) { assert false }
|
96
|
+
|
97
|
+
# for some reason, object ids change with thread local variables
|
98
|
+
# assert_equal( second, Web::Action.pick( cgi({ "name" => "patrick"}) ) )
|
99
|
+
|
100
|
+
Web::Action.pick( cgi({ "name" => "patrick"}) ).run
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_set_default_action
|
104
|
+
default = Web::Action.new
|
105
|
+
another = Web::Action.new( "this" => "that", "here" => "there" )
|
106
|
+
assert_equal( default, Web::Action.pick( cgi ) )
|
107
|
+
end
|
108
|
+
|
109
|
+
# this test causes no initial default action
|
110
|
+
# def test_raises_exception_if_no_action_is_found
|
111
|
+
# assert_raises(Web::Exception){
|
112
|
+
# Web::Action.pick cgi
|
113
|
+
# }
|
114
|
+
# end
|
115
|
+
|
116
|
+
def test_doesnt_raise_exception_if_no_exception_is_found
|
117
|
+
Web::Action.pick(cgi).run
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_blank_action_doesnt_mask_default
|
121
|
+
Web::Action.pick(cgi).run
|
122
|
+
|
123
|
+
default = Web::Action.new
|
124
|
+
|
125
|
+
assert_equal( default, Web::Action.pick(cgi) )
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_run
|
129
|
+
cgi_params = { "name" => "patrick" }
|
130
|
+
test_params = {}
|
131
|
+
|
132
|
+
Web::Action.new { |cgi|
|
133
|
+
test_params = cgi.multiple_params
|
134
|
+
}
|
135
|
+
|
136
|
+
Web::set_cgi nil
|
137
|
+
Web::Action.run :params => cgi_params, :out => ""
|
138
|
+
|
139
|
+
assert_equal( cgi_params, test_params )
|
140
|
+
end
|
141
|
+
|
142
|
+
def todo_test_subclassing_action
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|