ruby_on_ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (493) hide show
  1. data/.gitignore +18 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE +22 -0
  5. data/README.md +66 -0
  6. data/Rakefile +1 -0
  7. data/lib/ruby_on_ruby.rb +5 -0
  8. data/lib/ruby_on_ruby/console.rb +7 -0
  9. data/lib/ruby_on_ruby/context.rb +33 -0
  10. data/lib/ruby_on_ruby/file_loader.rb +31 -0
  11. data/lib/ruby_on_ruby/ruby_stream.rb +27 -0
  12. data/lib/ruby_on_ruby/version.rb +3 -0
  13. data/lib/rubyonruby.rb +1 -0
  14. data/ruby_in_ruby.gemspec +19 -0
  15. data/vendor/javascripts/emscripted-ruby/lib/.document +106 -0
  16. data/vendor/javascripts/emscripted-ruby/lib/English.rb +155 -0
  17. data/vendor/javascripts/emscripted-ruby/lib/Env.rb +18 -0
  18. data/vendor/javascripts/emscripted-ruby/lib/README +96 -0
  19. data/vendor/javascripts/emscripted-ruby/lib/abbrev.rb +103 -0
  20. data/vendor/javascripts/emscripted-ruby/lib/base64.rb +133 -0
  21. data/vendor/javascripts/emscripted-ruby/lib/benchmark.rb +572 -0
  22. data/vendor/javascripts/emscripted-ruby/lib/cgi-lib.rb +272 -0
  23. data/vendor/javascripts/emscripted-ruby/lib/cgi.rb +2308 -0
  24. data/vendor/javascripts/emscripted-ruby/lib/cgi/.document +2 -0
  25. data/vendor/javascripts/emscripted-ruby/lib/cgi/session.rb +498 -0
  26. data/vendor/javascripts/emscripted-ruby/lib/cgi/session/pstore.rb +111 -0
  27. data/vendor/javascripts/emscripted-ruby/lib/complex.rb +663 -0
  28. data/vendor/javascripts/emscripted-ruby/lib/csv.rb +992 -0
  29. data/vendor/javascripts/emscripted-ruby/lib/date.rb +1767 -0
  30. data/vendor/javascripts/emscripted-ruby/lib/date/format.rb +1190 -0
  31. data/vendor/javascripts/emscripted-ruby/lib/date2.rb +5 -0
  32. data/vendor/javascripts/emscripted-ruby/lib/debug.rb +947 -0
  33. data/vendor/javascripts/emscripted-ruby/lib/delegate.rb +337 -0
  34. data/vendor/javascripts/emscripted-ruby/lib/drb.rb +2 -0
  35. data/vendor/javascripts/emscripted-ruby/lib/drb/acl.rb +146 -0
  36. data/vendor/javascripts/emscripted-ruby/lib/drb/drb.rb +1782 -0
  37. data/vendor/javascripts/emscripted-ruby/lib/drb/eq.rb +16 -0
  38. data/vendor/javascripts/emscripted-ruby/lib/drb/extserv.rb +64 -0
  39. data/vendor/javascripts/emscripted-ruby/lib/drb/extservm.rb +89 -0
  40. data/vendor/javascripts/emscripted-ruby/lib/drb/gw.rb +122 -0
  41. data/vendor/javascripts/emscripted-ruby/lib/drb/invokemethod.rb +36 -0
  42. data/vendor/javascripts/emscripted-ruby/lib/drb/observer.rb +22 -0
  43. data/vendor/javascripts/emscripted-ruby/lib/drb/ssl.rb +190 -0
  44. data/vendor/javascripts/emscripted-ruby/lib/drb/timeridconv.rb +91 -0
  45. data/vendor/javascripts/emscripted-ruby/lib/drb/unix.rb +108 -0
  46. data/vendor/javascripts/emscripted-ruby/lib/e2mmap.rb +195 -0
  47. data/vendor/javascripts/emscripted-ruby/lib/erb.rb +880 -0
  48. data/vendor/javascripts/emscripted-ruby/lib/eregex.rb +37 -0
  49. data/vendor/javascripts/emscripted-ruby/lib/fileutils.rb +1591 -0
  50. data/vendor/javascripts/emscripted-ruby/lib/finalize.rb +193 -0
  51. data/vendor/javascripts/emscripted-ruby/lib/find.rb +79 -0
  52. data/vendor/javascripts/emscripted-ruby/lib/forwardable.rb +218 -0
  53. data/vendor/javascripts/emscripted-ruby/lib/ftools.rb +261 -0
  54. data/vendor/javascripts/emscripted-ruby/lib/generator.rb +418 -0
  55. data/vendor/javascripts/emscripted-ruby/lib/getoptlong.rb +621 -0
  56. data/vendor/javascripts/emscripted-ruby/lib/getopts.rb +127 -0
  57. data/vendor/javascripts/emscripted-ruby/lib/gserver.rb +253 -0
  58. data/vendor/javascripts/emscripted-ruby/lib/importenv.rb +33 -0
  59. data/vendor/javascripts/emscripted-ruby/lib/ipaddr.rb +814 -0
  60. data/vendor/javascripts/emscripted-ruby/lib/irb.rb +346 -0
  61. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/chws.rb +33 -0
  62. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/fork.rb +39 -0
  63. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/help.rb +34 -0
  64. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/load.rb +67 -0
  65. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/nop.rb +39 -0
  66. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/pushws.rb +39 -0
  67. data/vendor/javascripts/emscripted-ruby/lib/irb/cmd/subirb.rb +43 -0
  68. data/vendor/javascripts/emscripted-ruby/lib/irb/completion.rb +205 -0
  69. data/vendor/javascripts/emscripted-ruby/lib/irb/context.rb +255 -0
  70. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/change-ws.rb +62 -0
  71. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/history.rb +110 -0
  72. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/loader.rb +120 -0
  73. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/math-mode.rb +37 -0
  74. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/multi-irb.rb +241 -0
  75. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/save-history.rb +85 -0
  76. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/tracer.rb +61 -0
  77. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/use-loader.rb +65 -0
  78. data/vendor/javascripts/emscripted-ruby/lib/irb/ext/workspaces.rb +56 -0
  79. data/vendor/javascripts/emscripted-ruby/lib/irb/extend-command.rb +264 -0
  80. data/vendor/javascripts/emscripted-ruby/lib/irb/frame.rb +67 -0
  81. data/vendor/javascripts/emscripted-ruby/lib/irb/help.rb +33 -0
  82. data/vendor/javascripts/emscripted-ruby/lib/irb/init.rb +259 -0
  83. data/vendor/javascripts/emscripted-ruby/lib/irb/input-method.rb +120 -0
  84. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/error.rb +30 -0
  85. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/help-message +35 -0
  86. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/error.rb +27 -0
  87. data/vendor/javascripts/emscripted-ruby/lib/irb/lc/ja/help-message +36 -0
  88. data/vendor/javascripts/emscripted-ruby/lib/irb/locale.rb +184 -0
  89. data/vendor/javascripts/emscripted-ruby/lib/irb/notifier.rb +145 -0
  90. data/vendor/javascripts/emscripted-ruby/lib/irb/output-method.rb +85 -0
  91. data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-lex.rb +1149 -0
  92. data/vendor/javascripts/emscripted-ruby/lib/irb/ruby-token.rb +273 -0
  93. data/vendor/javascripts/emscripted-ruby/lib/irb/slex.rb +285 -0
  94. data/vendor/javascripts/emscripted-ruby/lib/irb/version.rb +16 -0
  95. data/vendor/javascripts/emscripted-ruby/lib/irb/workspace.rb +107 -0
  96. data/vendor/javascripts/emscripted-ruby/lib/irb/ws-for-case-2.rb +15 -0
  97. data/vendor/javascripts/emscripted-ruby/lib/irb/xmp.rb +86 -0
  98. data/vendor/javascripts/emscripted-ruby/lib/jcode.rb +220 -0
  99. data/vendor/javascripts/emscripted-ruby/lib/logger.rb +703 -0
  100. data/vendor/javascripts/emscripted-ruby/lib/mailread.rb +62 -0
  101. data/vendor/javascripts/emscripted-ruby/lib/mathn.rb +308 -0
  102. data/vendor/javascripts/emscripted-ruby/lib/matrix.rb +1278 -0
  103. data/vendor/javascripts/emscripted-ruby/lib/mkmf.rb +1811 -0
  104. data/vendor/javascripts/emscripted-ruby/lib/monitor.rb +352 -0
  105. data/vendor/javascripts/emscripted-ruby/lib/mutex_m.rb +122 -0
  106. data/vendor/javascripts/emscripted-ruby/lib/net/ftp.rb +927 -0
  107. data/vendor/javascripts/emscripted-ruby/lib/net/http.rb +2277 -0
  108. data/vendor/javascripts/emscripted-ruby/lib/net/https.rb +173 -0
  109. data/vendor/javascripts/emscripted-ruby/lib/net/imap.rb +3371 -0
  110. data/vendor/javascripts/emscripted-ruby/lib/net/pop.rb +999 -0
  111. data/vendor/javascripts/emscripted-ruby/lib/net/protocol.rb +392 -0
  112. data/vendor/javascripts/emscripted-ruby/lib/net/smtp.rb +1014 -0
  113. data/vendor/javascripts/emscripted-ruby/lib/net/telnet.rb +756 -0
  114. data/vendor/javascripts/emscripted-ruby/lib/observer.rb +192 -0
  115. data/vendor/javascripts/emscripted-ruby/lib/open-uri.rb +678 -0
  116. data/vendor/javascripts/emscripted-ruby/lib/open3.rb +101 -0
  117. data/vendor/javascripts/emscripted-ruby/lib/optparse.rb +1790 -0
  118. data/vendor/javascripts/emscripted-ruby/lib/optparse/date.rb +17 -0
  119. data/vendor/javascripts/emscripted-ruby/lib/optparse/shellwords.rb +6 -0
  120. data/vendor/javascripts/emscripted-ruby/lib/optparse/time.rb +10 -0
  121. data/vendor/javascripts/emscripted-ruby/lib/optparse/uri.rb +6 -0
  122. data/vendor/javascripts/emscripted-ruby/lib/optparse/version.rb +70 -0
  123. data/vendor/javascripts/emscripted-ruby/lib/ostruct.rb +146 -0
  124. data/vendor/javascripts/emscripted-ruby/lib/parsearg.rb +87 -0
  125. data/vendor/javascripts/emscripted-ruby/lib/parsedate.rb +53 -0
  126. data/vendor/javascripts/emscripted-ruby/lib/pathname.rb +1062 -0
  127. data/vendor/javascripts/emscripted-ruby/lib/ping.rb +64 -0
  128. data/vendor/javascripts/emscripted-ruby/lib/pp.rb +654 -0
  129. data/vendor/javascripts/emscripted-ruby/lib/prettyprint.rb +896 -0
  130. data/vendor/javascripts/emscripted-ruby/lib/profile.rb +6 -0
  131. data/vendor/javascripts/emscripted-ruby/lib/profiler.rb +59 -0
  132. data/vendor/javascripts/emscripted-ruby/lib/pstore.rb +395 -0
  133. data/vendor/javascripts/emscripted-ruby/lib/racc/parser.rb +442 -0
  134. data/vendor/javascripts/emscripted-ruby/lib/rational.rb +564 -0
  135. data/vendor/javascripts/emscripted-ruby/lib/readbytes.rb +41 -0
  136. data/vendor/javascripts/emscripted-ruby/lib/resolv-replace.rb +62 -0
  137. data/vendor/javascripts/emscripted-ruby/lib/resolv.rb +2210 -0
  138. data/vendor/javascripts/emscripted-ruby/lib/rexml/attlistdecl.rb +62 -0
  139. data/vendor/javascripts/emscripted-ruby/lib/rexml/attribute.rb +185 -0
  140. data/vendor/javascripts/emscripted-ruby/lib/rexml/cdata.rb +67 -0
  141. data/vendor/javascripts/emscripted-ruby/lib/rexml/child.rb +96 -0
  142. data/vendor/javascripts/emscripted-ruby/lib/rexml/comment.rb +80 -0
  143. data/vendor/javascripts/emscripted-ruby/lib/rexml/doctype.rb +271 -0
  144. data/vendor/javascripts/emscripted-ruby/lib/rexml/document.rb +208 -0
  145. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/attlistdecl.rb +10 -0
  146. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/dtd.rb +51 -0
  147. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/elementdecl.rb +17 -0
  148. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/entitydecl.rb +56 -0
  149. data/vendor/javascripts/emscripted-ruby/lib/rexml/dtd/notationdecl.rb +39 -0
  150. data/vendor/javascripts/emscripted-ruby/lib/rexml/element.rb +1227 -0
  151. data/vendor/javascripts/emscripted-ruby/lib/rexml/encoding.rb +71 -0
  152. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/CP-1252.rb +103 -0
  153. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/EUC-JP.rb +35 -0
  154. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ICONV.rb +22 -0
  155. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-1.rb +7 -0
  156. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/ISO-8859-15.rb +72 -0
  157. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT-JIS.rb +37 -0
  158. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/SHIFT_JIS.rb +1 -0
  159. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UNILE.rb +34 -0
  160. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/US-ASCII.rb +30 -0
  161. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-16.rb +35 -0
  162. data/vendor/javascripts/emscripted-ruby/lib/rexml/encodings/UTF-8.rb +18 -0
  163. data/vendor/javascripts/emscripted-ruby/lib/rexml/entity.rb +165 -0
  164. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/default.rb +109 -0
  165. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/pretty.rb +137 -0
  166. data/vendor/javascripts/emscripted-ruby/lib/rexml/formatters/transitive.rb +56 -0
  167. data/vendor/javascripts/emscripted-ruby/lib/rexml/functions.rb +382 -0
  168. data/vendor/javascripts/emscripted-ruby/lib/rexml/instruction.rb +70 -0
  169. data/vendor/javascripts/emscripted-ruby/lib/rexml/light/node.rb +196 -0
  170. data/vendor/javascripts/emscripted-ruby/lib/rexml/namespace.rb +47 -0
  171. data/vendor/javascripts/emscripted-ruby/lib/rexml/node.rb +75 -0
  172. data/vendor/javascripts/emscripted-ruby/lib/rexml/output.rb +24 -0
  173. data/vendor/javascripts/emscripted-ruby/lib/rexml/parent.rb +166 -0
  174. data/vendor/javascripts/emscripted-ruby/lib/rexml/parseexception.rb +51 -0
  175. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/baseparser.rb +503 -0
  176. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/lightparser.rb +60 -0
  177. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/pullparser.rb +196 -0
  178. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/sax2parser.rb +238 -0
  179. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/streamparser.rb +46 -0
  180. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/treeparser.rb +97 -0
  181. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/ultralightparser.rb +56 -0
  182. data/vendor/javascripts/emscripted-ruby/lib/rexml/parsers/xpathparser.rb +698 -0
  183. data/vendor/javascripts/emscripted-ruby/lib/rexml/quickpath.rb +266 -0
  184. data/vendor/javascripts/emscripted-ruby/lib/rexml/rexml.rb +32 -0
  185. data/vendor/javascripts/emscripted-ruby/lib/rexml/sax2listener.rb +97 -0
  186. data/vendor/javascripts/emscripted-ruby/lib/rexml/source.rb +251 -0
  187. data/vendor/javascripts/emscripted-ruby/lib/rexml/streamlistener.rb +92 -0
  188. data/vendor/javascripts/emscripted-ruby/lib/rexml/syncenumerator.rb +33 -0
  189. data/vendor/javascripts/emscripted-ruby/lib/rexml/text.rb +344 -0
  190. data/vendor/javascripts/emscripted-ruby/lib/rexml/undefinednamespaceexception.rb +8 -0
  191. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/relaxng.rb +559 -0
  192. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validation.rb +155 -0
  193. data/vendor/javascripts/emscripted-ruby/lib/rexml/validation/validationexception.rb +9 -0
  194. data/vendor/javascripts/emscripted-ruby/lib/rexml/xmldecl.rb +119 -0
  195. data/vendor/javascripts/emscripted-ruby/lib/rexml/xmltokens.rb +18 -0
  196. data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath.rb +66 -0
  197. data/vendor/javascripts/emscripted-ruby/lib/rexml/xpath_parser.rb +792 -0
  198. data/vendor/javascripts/emscripted-ruby/lib/rinda/rinda.rb +283 -0
  199. data/vendor/javascripts/emscripted-ruby/lib/rinda/ring.rb +271 -0
  200. data/vendor/javascripts/emscripted-ruby/lib/rinda/tuplespace.rb +642 -0
  201. data/vendor/javascripts/emscripted-ruby/lib/rss.rb +19 -0
  202. data/vendor/javascripts/emscripted-ruby/lib/rss/0.9.rb +428 -0
  203. data/vendor/javascripts/emscripted-ruby/lib/rss/1.0.rb +452 -0
  204. data/vendor/javascripts/emscripted-ruby/lib/rss/2.0.rb +111 -0
  205. data/vendor/javascripts/emscripted-ruby/lib/rss/atom.rb +749 -0
  206. data/vendor/javascripts/emscripted-ruby/lib/rss/content.rb +31 -0
  207. data/vendor/javascripts/emscripted-ruby/lib/rss/content/1.0.rb +10 -0
  208. data/vendor/javascripts/emscripted-ruby/lib/rss/content/2.0.rb +12 -0
  209. data/vendor/javascripts/emscripted-ruby/lib/rss/converter.rb +162 -0
  210. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore.rb +161 -0
  211. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/1.0.rb +13 -0
  212. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/2.0.rb +13 -0
  213. data/vendor/javascripts/emscripted-ruby/lib/rss/dublincore/atom.rb +17 -0
  214. data/vendor/javascripts/emscripted-ruby/lib/rss/image.rb +193 -0
  215. data/vendor/javascripts/emscripted-ruby/lib/rss/itunes.rb +410 -0
  216. data/vendor/javascripts/emscripted-ruby/lib/rss/maker.rb +44 -0
  217. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/0.9.rb +467 -0
  218. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/1.0.rb +434 -0
  219. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/2.0.rb +223 -0
  220. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/atom.rb +172 -0
  221. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/base.rb +868 -0
  222. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/content.rb +21 -0
  223. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/dublincore.rb +124 -0
  224. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/entry.rb +163 -0
  225. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/feed.rb +429 -0
  226. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/image.rb +111 -0
  227. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/itunes.rb +242 -0
  228. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/slash.rb +33 -0
  229. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/syndication.rb +18 -0
  230. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/taxonomy.rb +118 -0
  231. data/vendor/javascripts/emscripted-ruby/lib/rss/maker/trackback.rb +61 -0
  232. data/vendor/javascripts/emscripted-ruby/lib/rss/parser.rb +541 -0
  233. data/vendor/javascripts/emscripted-ruby/lib/rss/rexmlparser.rb +54 -0
  234. data/vendor/javascripts/emscripted-ruby/lib/rss/rss.rb +1312 -0
  235. data/vendor/javascripts/emscripted-ruby/lib/rss/slash.rb +49 -0
  236. data/vendor/javascripts/emscripted-ruby/lib/rss/syndication.rb +67 -0
  237. data/vendor/javascripts/emscripted-ruby/lib/rss/taxonomy.rb +145 -0
  238. data/vendor/javascripts/emscripted-ruby/lib/rss/trackback.rb +288 -0
  239. data/vendor/javascripts/emscripted-ruby/lib/rss/utils.rb +111 -0
  240. data/vendor/javascripts/emscripted-ruby/lib/rss/xml-stylesheet.rb +105 -0
  241. data/vendor/javascripts/emscripted-ruby/lib/rss/xml.rb +71 -0
  242. data/vendor/javascripts/emscripted-ruby/lib/rss/xmlparser.rb +93 -0
  243. data/vendor/javascripts/emscripted-ruby/lib/rss/xmlscanner.rb +121 -0
  244. data/vendor/javascripts/emscripted-ruby/lib/rubyunit.rb +6 -0
  245. data/vendor/javascripts/emscripted-ruby/lib/runit/assert.rb +73 -0
  246. data/vendor/javascripts/emscripted-ruby/lib/runit/cui/testrunner.rb +51 -0
  247. data/vendor/javascripts/emscripted-ruby/lib/runit/error.rb +9 -0
  248. data/vendor/javascripts/emscripted-ruby/lib/runit/testcase.rb +45 -0
  249. data/vendor/javascripts/emscripted-ruby/lib/runit/testresult.rb +44 -0
  250. data/vendor/javascripts/emscripted-ruby/lib/runit/testsuite.rb +26 -0
  251. data/vendor/javascripts/emscripted-ruby/lib/runit/topublic.rb +8 -0
  252. data/vendor/javascripts/emscripted-ruby/lib/scanf.rb +702 -0
  253. data/vendor/javascripts/emscripted-ruby/lib/securerandom.rb +137 -0
  254. data/vendor/javascripts/emscripted-ruby/lib/set.rb +1233 -0
  255. data/vendor/javascripts/emscripted-ruby/lib/shell.rb +269 -0
  256. data/vendor/javascripts/emscripted-ruby/lib/shell/builtin-command.rb +154 -0
  257. data/vendor/javascripts/emscripted-ruby/lib/shell/command-processor.rb +592 -0
  258. data/vendor/javascripts/emscripted-ruby/lib/shell/error.rb +26 -0
  259. data/vendor/javascripts/emscripted-ruby/lib/shell/filter.rb +110 -0
  260. data/vendor/javascripts/emscripted-ruby/lib/shell/process-controller.rb +260 -0
  261. data/vendor/javascripts/emscripted-ruby/lib/shell/system-command.rb +168 -0
  262. data/vendor/javascripts/emscripted-ruby/lib/shell/version.rb +16 -0
  263. data/vendor/javascripts/emscripted-ruby/lib/shellwords.rb +172 -0
  264. data/vendor/javascripts/emscripted-ruby/lib/singleton.rb +360 -0
  265. data/vendor/javascripts/emscripted-ruby/lib/soap/attachment.rb +107 -0
  266. data/vendor/javascripts/emscripted-ruby/lib/soap/baseData.rb +942 -0
  267. data/vendor/javascripts/emscripted-ruby/lib/soap/element.rb +258 -0
  268. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/aspDotNetHandler.rb +213 -0
  269. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/handler.rb +100 -0
  270. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/literalHandler.rb +226 -0
  271. data/vendor/javascripts/emscripted-ruby/lib/soap/encodingstyle/soapHandler.rb +582 -0
  272. data/vendor/javascripts/emscripted-ruby/lib/soap/generator.rb +268 -0
  273. data/vendor/javascripts/emscripted-ruby/lib/soap/header/handler.rb +57 -0
  274. data/vendor/javascripts/emscripted-ruby/lib/soap/header/handlerset.rb +70 -0
  275. data/vendor/javascripts/emscripted-ruby/lib/soap/header/simplehandler.rb +44 -0
  276. data/vendor/javascripts/emscripted-ruby/lib/soap/httpconfigloader.rb +119 -0
  277. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping.rb +10 -0
  278. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/factory.rb +355 -0
  279. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/mapping.rb +381 -0
  280. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/registry.rb +541 -0
  281. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/rubytypeFactory.rb +475 -0
  282. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/typeMap.rb +50 -0
  283. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlencodedregistry.rb +280 -0
  284. data/vendor/javascripts/emscripted-ruby/lib/soap/mapping/wsdlliteralregistry.rb +418 -0
  285. data/vendor/javascripts/emscripted-ruby/lib/soap/marshal.rb +59 -0
  286. data/vendor/javascripts/emscripted-ruby/lib/soap/mimemessage.rb +240 -0
  287. data/vendor/javascripts/emscripted-ruby/lib/soap/netHttpClient.rb +190 -0
  288. data/vendor/javascripts/emscripted-ruby/lib/soap/parser.rb +251 -0
  289. data/vendor/javascripts/emscripted-ruby/lib/soap/processor.rb +66 -0
  290. data/vendor/javascripts/emscripted-ruby/lib/soap/property.rb +333 -0
  291. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/cgistub.rb +206 -0
  292. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/driver.rb +254 -0
  293. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/element.rb +325 -0
  294. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/httpserver.rb +129 -0
  295. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/proxy.rb +497 -0
  296. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/router.rb +594 -0
  297. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/rpc.rb +25 -0
  298. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/soaplet.rb +162 -0
  299. data/vendor/javascripts/emscripted-ruby/lib/soap/rpc/standaloneServer.rb +43 -0
  300. data/vendor/javascripts/emscripted-ruby/lib/soap/soap.rb +140 -0
  301. data/vendor/javascripts/emscripted-ruby/lib/soap/streamHandler.rb +229 -0
  302. data/vendor/javascripts/emscripted-ruby/lib/soap/wsdlDriver.rb +575 -0
  303. data/vendor/javascripts/emscripted-ruby/lib/sync.rb +311 -0
  304. data/vendor/javascripts/emscripted-ruby/lib/tempfile.rb +209 -0
  305. data/vendor/javascripts/emscripted-ruby/lib/test/unit.rb +280 -0
  306. data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertionfailederror.rb +14 -0
  307. data/vendor/javascripts/emscripted-ruby/lib/test/unit/assertions.rb +622 -0
  308. data/vendor/javascripts/emscripted-ruby/lib/test/unit/autorunner.rb +220 -0
  309. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector.rb +43 -0
  310. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/dir.rb +107 -0
  311. data/vendor/javascripts/emscripted-ruby/lib/test/unit/collector/objectspace.rb +34 -0
  312. data/vendor/javascripts/emscripted-ruby/lib/test/unit/error.rb +56 -0
  313. data/vendor/javascripts/emscripted-ruby/lib/test/unit/failure.rb +51 -0
  314. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testcase.rb +160 -0
  315. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testresult.rb +80 -0
  316. data/vendor/javascripts/emscripted-ruby/lib/test/unit/testsuite.rb +76 -0
  317. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/console/testrunner.rb +127 -0
  318. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/fox/testrunner.rb +268 -0
  319. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk/testrunner.rb +416 -0
  320. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/gtk2/testrunner.rb +465 -0
  321. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnermediator.rb +68 -0
  322. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/testrunnerutilities.rb +46 -0
  323. data/vendor/javascripts/emscripted-ruby/lib/test/unit/ui/tk/testrunner.rb +260 -0
  324. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/backtracefilter.rb +40 -0
  325. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/observable.rb +90 -0
  326. data/vendor/javascripts/emscripted-ruby/lib/test/unit/util/procwrapper.rb +48 -0
  327. data/vendor/javascripts/emscripted-ruby/lib/thread.rb +479 -0
  328. data/vendor/javascripts/emscripted-ruby/lib/thwait.rb +169 -0
  329. data/vendor/javascripts/emscripted-ruby/lib/time.rb +797 -0
  330. data/vendor/javascripts/emscripted-ruby/lib/timeout.rb +122 -0
  331. data/vendor/javascripts/emscripted-ruby/lib/tmpdir.rb +130 -0
  332. data/vendor/javascripts/emscripted-ruby/lib/tracer.rb +167 -0
  333. data/vendor/javascripts/emscripted-ruby/lib/tsort.rb +290 -0
  334. data/vendor/javascripts/emscripted-ruby/lib/un.rb +235 -0
  335. data/vendor/javascripts/emscripted-ruby/lib/uri.rb +29 -0
  336. data/vendor/javascripts/emscripted-ruby/lib/uri/common.rb +611 -0
  337. data/vendor/javascripts/emscripted-ruby/lib/uri/ftp.rb +198 -0
  338. data/vendor/javascripts/emscripted-ruby/lib/uri/generic.rb +1122 -0
  339. data/vendor/javascripts/emscripted-ruby/lib/uri/http.rb +100 -0
  340. data/vendor/javascripts/emscripted-ruby/lib/uri/https.rb +20 -0
  341. data/vendor/javascripts/emscripted-ruby/lib/uri/ldap.rb +190 -0
  342. data/vendor/javascripts/emscripted-ruby/lib/uri/ldaps.rb +12 -0
  343. data/vendor/javascripts/emscripted-ruby/lib/uri/mailto.rb +266 -0
  344. data/vendor/javascripts/emscripted-ruby/lib/weakref.rb +100 -0
  345. data/vendor/javascripts/emscripted-ruby/lib/webrick.rb +29 -0
  346. data/vendor/javascripts/emscripted-ruby/lib/webrick/accesslog.rb +67 -0
  347. data/vendor/javascripts/emscripted-ruby/lib/webrick/cgi.rb +257 -0
  348. data/vendor/javascripts/emscripted-ruby/lib/webrick/compat.rb +15 -0
  349. data/vendor/javascripts/emscripted-ruby/lib/webrick/config.rb +97 -0
  350. data/vendor/javascripts/emscripted-ruby/lib/webrick/cookie.rb +110 -0
  351. data/vendor/javascripts/emscripted-ruby/lib/webrick/htmlutils.rb +25 -0
  352. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth.rb +45 -0
  353. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/authenticator.rb +79 -0
  354. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/basicauth.rb +65 -0
  355. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/digestauth.rb +343 -0
  356. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htdigest.rb +91 -0
  357. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htgroup.rb +61 -0
  358. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/htpasswd.rb +83 -0
  359. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpauth/userdb.rb +29 -0
  360. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpproxy.rb +254 -0
  361. data/vendor/javascripts/emscripted-ruby/lib/webrick/httprequest.rb +365 -0
  362. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpresponse.rb +327 -0
  363. data/vendor/javascripts/emscripted-ruby/lib/webrick/https.rb +63 -0
  364. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpserver.rb +210 -0
  365. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet.rb +22 -0
  366. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/abstract.rb +71 -0
  367. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgi_runner.rb +47 -0
  368. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/cgihandler.rb +108 -0
  369. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/erbhandler.rb +54 -0
  370. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/filehandler.rb +435 -0
  371. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpservlet/prochandler.rb +33 -0
  372. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpstatus.rb +126 -0
  373. data/vendor/javascripts/emscripted-ruby/lib/webrick/httputils.rb +399 -0
  374. data/vendor/javascripts/emscripted-ruby/lib/webrick/httpversion.rb +49 -0
  375. data/vendor/javascripts/emscripted-ruby/lib/webrick/log.rb +88 -0
  376. data/vendor/javascripts/emscripted-ruby/lib/webrick/server.rb +200 -0
  377. data/vendor/javascripts/emscripted-ruby/lib/webrick/ssl.rb +126 -0
  378. data/vendor/javascripts/emscripted-ruby/lib/webrick/utils.rb +100 -0
  379. data/vendor/javascripts/emscripted-ruby/lib/webrick/version.rb +13 -0
  380. data/vendor/javascripts/emscripted-ruby/lib/wsdl/binding.rb +65 -0
  381. data/vendor/javascripts/emscripted-ruby/lib/wsdl/data.rb +64 -0
  382. data/vendor/javascripts/emscripted-ruby/lib/wsdl/definitions.rb +250 -0
  383. data/vendor/javascripts/emscripted-ruby/lib/wsdl/documentation.rb +32 -0
  384. data/vendor/javascripts/emscripted-ruby/lib/wsdl/import.rb +80 -0
  385. data/vendor/javascripts/emscripted-ruby/lib/wsdl/importer.rb +38 -0
  386. data/vendor/javascripts/emscripted-ruby/lib/wsdl/info.rb +39 -0
  387. data/vendor/javascripts/emscripted-ruby/lib/wsdl/message.rb +54 -0
  388. data/vendor/javascripts/emscripted-ruby/lib/wsdl/operation.rb +130 -0
  389. data/vendor/javascripts/emscripted-ruby/lib/wsdl/operationBinding.rb +108 -0
  390. data/vendor/javascripts/emscripted-ruby/lib/wsdl/param.rb +85 -0
  391. data/vendor/javascripts/emscripted-ruby/lib/wsdl/parser.rb +163 -0
  392. data/vendor/javascripts/emscripted-ruby/lib/wsdl/part.rb +52 -0
  393. data/vendor/javascripts/emscripted-ruby/lib/wsdl/port.rb +84 -0
  394. data/vendor/javascripts/emscripted-ruby/lib/wsdl/portType.rb +73 -0
  395. data/vendor/javascripts/emscripted-ruby/lib/wsdl/service.rb +61 -0
  396. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/address.rb +40 -0
  397. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/binding.rb +49 -0
  398. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/body.rb +56 -0
  399. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/cgiStubCreator.rb +76 -0
  400. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreator.rb +314 -0
  401. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/classDefCreatorSupport.rb +126 -0
  402. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/clientSkeltonCreator.rb +78 -0
  403. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/complexType.rb +161 -0
  404. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/data.rb +42 -0
  405. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/definitions.rb +149 -0
  406. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/driverCreator.rb +95 -0
  407. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/element.rb +28 -0
  408. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/fault.rb +56 -0
  409. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/header.rb +86 -0
  410. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/headerfault.rb +56 -0
  411. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/mappingRegistryCreator.rb +92 -0
  412. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/methodDefCreator.rb +228 -0
  413. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/operation.rb +122 -0
  414. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/servantSkeltonCreator.rb +67 -0
  415. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/standaloneServerStubCreator.rb +85 -0
  416. data/vendor/javascripts/emscripted-ruby/lib/wsdl/soap/wsdl2ruby.rb +176 -0
  417. data/vendor/javascripts/emscripted-ruby/lib/wsdl/types.rb +43 -0
  418. data/vendor/javascripts/emscripted-ruby/lib/wsdl/wsdl.rb +23 -0
  419. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/all.rb +69 -0
  420. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/annotation.rb +34 -0
  421. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/any.rb +56 -0
  422. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/attribute.rb +127 -0
  423. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/choice.rb +69 -0
  424. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexContent.rb +92 -0
  425. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/complexType.rb +139 -0
  426. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/content.rb +96 -0
  427. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/data.rb +80 -0
  428. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/element.rb +154 -0
  429. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/enumeration.rb +36 -0
  430. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/import.rb +65 -0
  431. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/importer.rb +87 -0
  432. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/include.rb +54 -0
  433. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/length.rb +35 -0
  434. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/parser.rb +166 -0
  435. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/pattern.rb +36 -0
  436. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/schema.rb +143 -0
  437. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/sequence.rb +69 -0
  438. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleContent.rb +65 -0
  439. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleExtension.rb +54 -0
  440. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleRestriction.rb +73 -0
  441. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/simpleType.rb +73 -0
  442. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/unique.rb +34 -0
  443. data/vendor/javascripts/emscripted-ruby/lib/wsdl/xmlSchema/xsd2ruby.rb +107 -0
  444. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/.document +1 -0
  445. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/README.txt +31 -0
  446. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/base64.rb +81 -0
  447. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/client.rb +624 -0
  448. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/config.rb +40 -0
  449. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/create.rb +290 -0
  450. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/datetime.rb +142 -0
  451. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/httpserver.rb +178 -0
  452. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/marshal.rb +76 -0
  453. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/parser.rb +813 -0
  454. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/server.rb +780 -0
  455. data/vendor/javascripts/emscripted-ruby/lib/xmlrpc/utils.rb +165 -0
  456. data/vendor/javascripts/emscripted-ruby/lib/xsd/charset.rb +187 -0
  457. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen.rb +12 -0
  458. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/classdef.rb +203 -0
  459. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/commentdef.rb +34 -0
  460. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/gensupport.rb +166 -0
  461. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/methoddef.rb +63 -0
  462. data/vendor/javascripts/emscripted-ruby/lib/xsd/codegen/moduledef.rb +191 -0
  463. data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes.rb +1269 -0
  464. data/vendor/javascripts/emscripted-ruby/lib/xsd/datatypes1999.rb +20 -0
  465. data/vendor/javascripts/emscripted-ruby/lib/xsd/iconvcharset.rb +33 -0
  466. data/vendor/javascripts/emscripted-ruby/lib/xsd/mapping.rb +42 -0
  467. data/vendor/javascripts/emscripted-ruby/lib/xsd/namedelements.rb +95 -0
  468. data/vendor/javascripts/emscripted-ruby/lib/xsd/ns.rb +140 -0
  469. data/vendor/javascripts/emscripted-ruby/lib/xsd/qname.rb +78 -0
  470. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser.rb +61 -0
  471. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/parser.rb +96 -0
  472. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/rexmlparser.rb +54 -0
  473. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlparser.rb +50 -0
  474. data/vendor/javascripts/emscripted-ruby/lib/xsd/xmlparser/xmlscanner.rb +147 -0
  475. data/vendor/javascripts/emscripted-ruby/lib/yaml.rb +440 -0
  476. data/vendor/javascripts/emscripted-ruby/lib/yaml/baseemitter.rb +247 -0
  477. data/vendor/javascripts/emscripted-ruby/lib/yaml/basenode.rb +216 -0
  478. data/vendor/javascripts/emscripted-ruby/lib/yaml/constants.rb +45 -0
  479. data/vendor/javascripts/emscripted-ruby/lib/yaml/dbm.rb +111 -0
  480. data/vendor/javascripts/emscripted-ruby/lib/yaml/encoding.rb +33 -0
  481. data/vendor/javascripts/emscripted-ruby/lib/yaml/error.rb +34 -0
  482. data/vendor/javascripts/emscripted-ruby/lib/yaml/loader.rb +14 -0
  483. data/vendor/javascripts/emscripted-ruby/lib/yaml/rubytypes.rb +408 -0
  484. data/vendor/javascripts/emscripted-ruby/lib/yaml/store.rb +43 -0
  485. data/vendor/javascripts/emscripted-ruby/lib/yaml/stream.rb +40 -0
  486. data/vendor/javascripts/emscripted-ruby/lib/yaml/stringio.rb +83 -0
  487. data/vendor/javascripts/emscripted-ruby/lib/yaml/syck.rb +19 -0
  488. data/vendor/javascripts/emscripted-ruby/lib/yaml/tag.rb +91 -0
  489. data/vendor/javascripts/emscripted-ruby/lib/yaml/types.rb +192 -0
  490. data/vendor/javascripts/emscripted-ruby/lib/yaml/yamlnode.rb +54 -0
  491. data/vendor/javascripts/emscripted-ruby/lib/yaml/ypath.rb +52 -0
  492. data/vendor/javascripts/emscripted-ruby/ruby.closure.js +7201 -0
  493. metadata +554 -0
@@ -0,0 +1,272 @@
1
+ warn "Warning:#{caller[0].sub(/:in `.*'\z/, '')}: cgi-lib is deprecated after Ruby 1.8.1; use cgi instead"
2
+
3
+ =begin
4
+
5
+ = simple CGI support library
6
+
7
+ = example
8
+
9
+ == get form values
10
+
11
+ require "cgi-lib.rb"
12
+ query = CGI.new
13
+ query['field'] # <== value of 'field'
14
+ query.keys # <== array of fields
15
+
16
+ and query has Hash class methods
17
+
18
+
19
+ == get cookie values
20
+
21
+ require "cgi-lib.rb"
22
+ query = CGI.new
23
+ query.cookie['name'] # <== cookie value of 'name'
24
+ query.cookie.keys # <== all cookie names
25
+
26
+ and query.cookie has Hash class methods
27
+
28
+
29
+ == print HTTP header and HTML string to $>
30
+
31
+ require "cgi-lib.rb"
32
+ CGI::print{
33
+ CGI::tag("HTML"){
34
+ CGI::tag("HEAD"){ CGI::tag("TITLE"){"TITLE"} } +
35
+ CGI::tag("BODY"){
36
+ CGI::tag("FORM", {"ACTION"=>"test.rb", "METHOD"=>"POST"}){
37
+ CGI::tag("INPUT", {"TYPE"=>"submit", "VALUE"=>"submit"})
38
+ } +
39
+ CGI::tag("HR")
40
+ }
41
+ }
42
+ }
43
+
44
+
45
+ == make raw cookie string
46
+
47
+ require "cgi-lib.rb"
48
+ cookie1 = CGI::cookie({'name' => 'name',
49
+ 'value' => 'value',
50
+ 'path' => 'path', # optional
51
+ 'domain' => 'domain', # optional
52
+ 'expires' => Time.now, # optional
53
+ 'secure' => true # optional
54
+ })
55
+
56
+ CGI::print("Content-Type: text/html", cookie1, cookie2){ "string" }
57
+
58
+
59
+ == print HTTP header and string to $>
60
+
61
+ require "cgi-lib.rb"
62
+ CGI::print{ "string" }
63
+ # == CGI::print("Content-Type: text/html"){ "string" }
64
+ CGI::print("Content-Type: text/html", cookie1, cookie2){ "string" }
65
+
66
+
67
+ === NPH (no-parse-header) mode
68
+
69
+ require "cgi-lib.rb"
70
+ CGI::print("nph"){ "string" }
71
+ # == CGI::print("nph", "Content-Type: text/html"){ "string" }
72
+ CGI::print("nph", "Content-Type: text/html", cookie1, cookie2){ "string" }
73
+
74
+
75
+ == make HTML tag string
76
+
77
+ require "cgi-lib.rb"
78
+ CGI::tag("element", {"attribute_name"=>"attribute_value"}){"content"}
79
+
80
+
81
+ == make HTTP header string
82
+
83
+ require "cgi-lib.rb"
84
+ CGI::header # == CGI::header("Content-Type: text/html")
85
+ CGI::header("Content-Type: text/html", cookie1, cookie2)
86
+
87
+
88
+ === NPH (no-parse-header) mode
89
+
90
+ CGI::header("nph") # == CGI::header("nph", "Content-Type: text/html")
91
+ CGI::header("nph", "Content-Type: text/html", cookie1, cookie2)
92
+
93
+
94
+ == escape url encode
95
+
96
+ require "cgi-lib.rb"
97
+ url_encoded_string = CGI::escape("string")
98
+
99
+
100
+ == unescape url encoded
101
+
102
+ require "cgi-lib.rb"
103
+ string = CGI::unescape("url encoded string")
104
+
105
+
106
+ == escape HTML &"<>
107
+
108
+ require "cgi-lib.rb"
109
+ CGI::escapeHTML("string")
110
+
111
+
112
+ =end
113
+
114
+ require "delegate"
115
+
116
+ class CGI < SimpleDelegator
117
+
118
+ CR = "\015"
119
+ LF = "\012"
120
+ EOL = CR + LF
121
+
122
+ RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
123
+ RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
124
+
125
+ # make rfc1123 date string
126
+ def CGI::rfc1123_date(time)
127
+ t = time.clone.gmtime
128
+ return format("%s, %.2d %s %d %.2d:%.2d:%.2d GMT",
129
+ RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
130
+ t.hour, t.min, t.sec)
131
+ end
132
+
133
+ # escape url encode
134
+ def CGI::escape(str)
135
+ str.gsub(/[^a-zA-Z0-9_\-.]/n){ sprintf("%%%02X", $&.unpack("C")[0]) }
136
+ end
137
+
138
+ # unescape url encoded
139
+ def CGI::unescape(str)
140
+ str.gsub(/\+/, ' ').gsub(/%([0-9a-fA-F]{2})/){ [$1.hex].pack("c") }
141
+ end
142
+
143
+ # escape HTML
144
+ def CGI::escapeHTML(str)
145
+ str.gsub(/&/, "&amp;").gsub(/\"/, "&quot;").gsub(/>/, "&gt;").gsub(/</, "&lt;")
146
+ end
147
+
148
+ # offline mode. read name=value pairs on standard input.
149
+ def read_from_cmdline
150
+ require "shellwords.rb"
151
+ words = Shellwords.shellwords(
152
+ if not ARGV.empty?
153
+ ARGV.join(' ')
154
+ else
155
+ STDERR.print "(offline mode: enter name=value pairs on standard input)\n" if STDIN.tty?
156
+ readlines.join(' ').gsub(/\n/, '')
157
+ end.gsub(/\\=/, '%3D').gsub(/\\&/, '%26'))
158
+
159
+ if words.find{|x| x =~ /=/} then words.join('&') else words.join('+') end
160
+ end
161
+
162
+ def initialize(input = $stdin)
163
+
164
+ @inputs = {}
165
+ @cookie = {}
166
+
167
+ case ENV['REQUEST_METHOD']
168
+ when "GET"
169
+ ENV['QUERY_STRING'] or ""
170
+ when "POST"
171
+ input.read(Integer(ENV['CONTENT_LENGTH'])) or ""
172
+ else
173
+ read_from_cmdline
174
+ end.split(/[&;]/).each do |x|
175
+ key, val = x.split(/=/,2).collect{|x|CGI::unescape(x)}
176
+ if @inputs.include?(key)
177
+ @inputs[key] += "\0" + (val or "")
178
+ else
179
+ @inputs[key] = (val or "")
180
+ end
181
+ end
182
+
183
+ super(@inputs)
184
+
185
+ if ENV.has_key?('HTTP_COOKIE') or ENV.has_key?('COOKIE')
186
+ (ENV['HTTP_COOKIE'] or ENV['COOKIE']).split(/; /).each do |x|
187
+ key, val = x.split(/=/,2)
188
+ key = CGI::unescape(key)
189
+ val = val.split(/&/).collect{|x|CGI::unescape(x)}.join("\0")
190
+ if @cookie.include?(key)
191
+ @cookie[key] += "\0" + val
192
+ else
193
+ @cookie[key] = val
194
+ end
195
+ end
196
+ end
197
+ end
198
+
199
+ attr("inputs")
200
+ attr("cookie")
201
+
202
+ # make HTML tag string
203
+ def CGI::tag(element, attributes = {})
204
+ "<" + escapeHTML(element) + attributes.collect{|name, value|
205
+ " " + escapeHTML(name) + '="' + escapeHTML(value) + '"'
206
+ }.to_s + ">" +
207
+ (iterator? ? yield.to_s + "</" + escapeHTML(element) + ">" : "")
208
+ end
209
+
210
+ # make raw cookie string
211
+ def CGI::cookie(options)
212
+ "Set-Cookie: " + options['name'] + '=' + escape(options['value']) +
213
+ (options['domain'] ? '; domain=' + options['domain'] : '') +
214
+ (options['path'] ? '; path=' + options['path'] : '') +
215
+ (options['expires'] ? '; expires=' + rfc1123_date(options['expires']) : '') +
216
+ (options['secure'] ? '; secure' : '')
217
+ end
218
+
219
+ # make HTTP header string
220
+ def CGI::header(*options)
221
+ if defined?(MOD_RUBY)
222
+ options.each{|option|
223
+ option.sub(/(.*?): (.*)/){
224
+ Apache::request.headers_out[$1] = $2
225
+ }
226
+ }
227
+ Apache::request.send_http_header
228
+ ''
229
+ else
230
+ if options.delete("nph") or (ENV['SERVER_SOFTWARE'] =~ /IIS/)
231
+ [(ENV['SERVER_PROTOCOL'] or "HTTP/1.0") + " 200 OK",
232
+ "Date: " + rfc1123_date(Time.now),
233
+ "Server: " + (ENV['SERVER_SOFTWARE'] or ""),
234
+ "Connection: close"] +
235
+ (options.empty? ? ["Content-Type: text/html"] : options)
236
+ else
237
+ options.empty? ? ["Content-Type: text/html"] : options
238
+ end.join(EOL) + EOL + EOL
239
+ end
240
+ end
241
+
242
+ # print HTTP header and string to $>
243
+ def CGI::print(*options)
244
+ $>.print CGI::header(*options) + yield.to_s
245
+ end
246
+
247
+ # print message to $>
248
+ def CGI::message(message, title = "", header = ["Content-Type: text/html"])
249
+ if message.kind_of?(Hash)
250
+ title = message['title']
251
+ header = message['header']
252
+ message = message['body']
253
+ end
254
+ CGI::print(*header){
255
+ CGI::tag("HTML"){
256
+ CGI::tag("HEAD"){ CGI.tag("TITLE"){ title } } +
257
+ CGI::tag("BODY"){ message }
258
+ }
259
+ }
260
+ true
261
+ end
262
+
263
+ # print error message to $> and exit
264
+ def CGI::error
265
+ CGI::message({'title'=>'ERROR', 'body'=>
266
+ CGI::tag("PRE"){
267
+ "ERROR: " + CGI::tag("STRONG"){ escapeHTML($!.to_s) } + "\n" + escapeHTML($@.join("\n"))
268
+ }
269
+ })
270
+ exit
271
+ end
272
+ end
@@ -0,0 +1,2308 @@
1
+ #
2
+ # cgi.rb - cgi support library
3
+ #
4
+ # Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
5
+ #
6
+ # Copyright (C) 2000 Information-technology Promotion Agency, Japan
7
+ #
8
+ # Author: Wakou Aoyama <wakou@ruby-lang.org>
9
+ #
10
+ # Documentation: Wakou Aoyama (RDoc'd and embellished by William Webber)
11
+ #
12
+ # == Overview
13
+ #
14
+ # The Common Gateway Interface (CGI) is a simple protocol
15
+ # for passing an HTTP request from a web server to a
16
+ # standalone program, and returning the output to the web
17
+ # browser. Basically, a CGI program is called with the
18
+ # parameters of the request passed in either in the
19
+ # environment (GET) or via $stdin (POST), and everything
20
+ # it prints to $stdout is returned to the client.
21
+ #
22
+ # This file holds the +CGI+ class. This class provides
23
+ # functionality for retrieving HTTP request parameters,
24
+ # managing cookies, and generating HTML output. See the
25
+ # class documentation for more details and examples of use.
26
+ #
27
+ # The file cgi/session.rb provides session management
28
+ # functionality; see that file for more details.
29
+ #
30
+ # See http://www.w3.org/CGI/ for more information on the CGI
31
+ # protocol.
32
+
33
+ raise "Please, use ruby 1.5.4 or later." if RUBY_VERSION < "1.5.4"
34
+
35
+ require 'English'
36
+
37
+ # CGI class. See documentation for the file cgi.rb for an overview
38
+ # of the CGI protocol.
39
+ #
40
+ # == Introduction
41
+ #
42
+ # CGI is a large class, providing several categories of methods, many of which
43
+ # are mixed in from other modules. Some of the documentation is in this class,
44
+ # some in the modules CGI::QueryExtension and CGI::HtmlExtension. See
45
+ # CGI::Cookie for specific information on handling cookies, and cgi/session.rb
46
+ # (CGI::Session) for information on sessions.
47
+ #
48
+ # For queries, CGI provides methods to get at environmental variables,
49
+ # parameters, cookies, and multipart request data. For responses, CGI provides
50
+ # methods for writing output and generating HTML.
51
+ #
52
+ # Read on for more details. Examples are provided at the bottom.
53
+ #
54
+ # == Queries
55
+ #
56
+ # The CGI class dynamically mixes in parameter and cookie-parsing
57
+ # functionality, environmental variable access, and support for
58
+ # parsing multipart requests (including uploaded files) from the
59
+ # CGI::QueryExtension module.
60
+ #
61
+ # === Environmental Variables
62
+ #
63
+ # The standard CGI environmental variables are available as read-only
64
+ # attributes of a CGI object. The following is a list of these variables:
65
+ #
66
+ #
67
+ # AUTH_TYPE HTTP_HOST REMOTE_IDENT
68
+ # CONTENT_LENGTH HTTP_NEGOTIATE REMOTE_USER
69
+ # CONTENT_TYPE HTTP_PRAGMA REQUEST_METHOD
70
+ # GATEWAY_INTERFACE HTTP_REFERER SCRIPT_NAME
71
+ # HTTP_ACCEPT HTTP_USER_AGENT SERVER_NAME
72
+ # HTTP_ACCEPT_CHARSET PATH_INFO SERVER_PORT
73
+ # HTTP_ACCEPT_ENCODING PATH_TRANSLATED SERVER_PROTOCOL
74
+ # HTTP_ACCEPT_LANGUAGE QUERY_STRING SERVER_SOFTWARE
75
+ # HTTP_CACHE_CONTROL REMOTE_ADDR
76
+ # HTTP_FROM REMOTE_HOST
77
+ #
78
+ #
79
+ # For each of these variables, there is a corresponding attribute with the
80
+ # same name, except all lower case and without a preceding HTTP_.
81
+ # +content_length+ and +server_port+ are integers; the rest are strings.
82
+ #
83
+ # === Parameters
84
+ #
85
+ # The method #params() returns a hash of all parameters in the request as
86
+ # name/value-list pairs, where the value-list is an Array of one or more
87
+ # values. The CGI object itself also behaves as a hash of parameter names
88
+ # to values, but only returns a single value (as a String) for each
89
+ # parameter name.
90
+ #
91
+ # For instance, suppose the request contains the parameter
92
+ # "favourite_colours" with the multiple values "blue" and "green". The
93
+ # following behaviour would occur:
94
+ #
95
+ # cgi.params["favourite_colours"] # => ["blue", "green"]
96
+ # cgi["favourite_colours"] # => "blue"
97
+ #
98
+ # If a parameter does not exist, the former method will return an empty
99
+ # array, the latter an empty string. The simplest way to test for existence
100
+ # of a parameter is by the #has_key? method.
101
+ #
102
+ # === Cookies
103
+ #
104
+ # HTTP Cookies are automatically parsed from the request. They are available
105
+ # from the #cookies() accessor, which returns a hash from cookie name to
106
+ # CGI::Cookie object.
107
+ #
108
+ # === Multipart requests
109
+ #
110
+ # If a request's method is POST and its content type is multipart/form-data,
111
+ # then it may contain uploaded files. These are stored by the QueryExtension
112
+ # module in the parameters of the request. The parameter name is the name
113
+ # attribute of the file input field, as usual. However, the value is not
114
+ # a string, but an IO object, either an IOString for small files, or a
115
+ # Tempfile for larger ones. This object also has the additional singleton
116
+ # methods:
117
+ #
118
+ # #local_path():: the path of the uploaded file on the local filesystem
119
+ # #original_filename():: the name of the file on the client computer
120
+ # #content_type():: the content type of the file
121
+ #
122
+ # == Responses
123
+ #
124
+ # The CGI class provides methods for sending header and content output to
125
+ # the HTTP client, and mixes in methods for programmatic HTML generation
126
+ # from CGI::HtmlExtension and CGI::TagMaker modules. The precise version of HTML
127
+ # to use for HTML generation is specified at object creation time.
128
+ #
129
+ # === Writing output
130
+ #
131
+ # The simplest way to send output to the HTTP client is using the #out() method.
132
+ # This takes the HTTP headers as a hash parameter, and the body content
133
+ # via a block. The headers can be generated as a string using the #header()
134
+ # method. The output stream can be written directly to using the #print()
135
+ # method.
136
+ #
137
+ # === Generating HTML
138
+ #
139
+ # Each HTML element has a corresponding method for generating that
140
+ # element as a String. The name of this method is the same as that
141
+ # of the element, all lowercase. The attributes of the element are
142
+ # passed in as a hash, and the body as a no-argument block that evaluates
143
+ # to a String. The HTML generation module knows which elements are
144
+ # always empty, and silently drops any passed-in body. It also knows
145
+ # which elements require matching closing tags and which don't. However,
146
+ # it does not know what attributes are legal for which elements.
147
+ #
148
+ # There are also some additional HTML generation methods mixed in from
149
+ # the CGI::HtmlExtension module. These include individual methods for the
150
+ # different types of form inputs, and methods for elements that commonly
151
+ # take particular attributes where the attributes can be directly specified
152
+ # as arguments, rather than via a hash.
153
+ #
154
+ # == Examples of use
155
+ #
156
+ # === Get form values
157
+ #
158
+ # require "cgi"
159
+ # cgi = CGI.new
160
+ # value = cgi['field_name'] # <== value string for 'field_name'
161
+ # # if not 'field_name' included, then return "".
162
+ # fields = cgi.keys # <== array of field names
163
+ #
164
+ # # returns true if form has 'field_name'
165
+ # cgi.has_key?('field_name')
166
+ # cgi.has_key?('field_name')
167
+ # cgi.include?('field_name')
168
+ #
169
+ # CAUTION! cgi['field_name'] returned an Array with the old
170
+ # cgi.rb(included in ruby 1.6)
171
+ #
172
+ # === Get form values as hash
173
+ #
174
+ # require "cgi"
175
+ # cgi = CGI.new
176
+ # params = cgi.params
177
+ #
178
+ # cgi.params is a hash.
179
+ #
180
+ # cgi.params['new_field_name'] = ["value"] # add new param
181
+ # cgi.params['field_name'] = ["new_value"] # change value
182
+ # cgi.params.delete('field_name') # delete param
183
+ # cgi.params.clear # delete all params
184
+ #
185
+ #
186
+ # === Save form values to file
187
+ #
188
+ # require "pstore"
189
+ # db = PStore.new("query.db")
190
+ # db.transaction do
191
+ # db["params"] = cgi.params
192
+ # end
193
+ #
194
+ #
195
+ # === Restore form values from file
196
+ #
197
+ # require "pstore"
198
+ # db = PStore.new("query.db")
199
+ # db.transaction do
200
+ # cgi.params = db["params"]
201
+ # end
202
+ #
203
+ #
204
+ # === Get multipart form values
205
+ #
206
+ # require "cgi"
207
+ # cgi = CGI.new
208
+ # value = cgi['field_name'] # <== value string for 'field_name'
209
+ # value.read # <== body of value
210
+ # value.local_path # <== path to local file of value
211
+ # value.original_filename # <== original filename of value
212
+ # value.content_type # <== content_type of value
213
+ #
214
+ # and value has StringIO or Tempfile class methods.
215
+ #
216
+ # === Get cookie values
217
+ #
218
+ # require "cgi"
219
+ # cgi = CGI.new
220
+ # values = cgi.cookies['name'] # <== array of 'name'
221
+ # # if not 'name' included, then return [].
222
+ # names = cgi.cookies.keys # <== array of cookie names
223
+ #
224
+ # and cgi.cookies is a hash.
225
+ #
226
+ # === Get cookie objects
227
+ #
228
+ # require "cgi"
229
+ # cgi = CGI.new
230
+ # for name, cookie in cgi.cookies
231
+ # cookie.expires = Time.now + 30
232
+ # end
233
+ # cgi.out("cookie" => cgi.cookies) {"string"}
234
+ #
235
+ # cgi.cookies # { "name1" => cookie1, "name2" => cookie2, ... }
236
+ #
237
+ # require "cgi"
238
+ # cgi = CGI.new
239
+ # cgi.cookies['name'].expires = Time.now + 30
240
+ # cgi.out("cookie" => cgi.cookies['name']) {"string"}
241
+ #
242
+ # === Print http header and html string to $DEFAULT_OUTPUT ($>)
243
+ #
244
+ # require "cgi"
245
+ # cgi = CGI.new("html3") # add HTML generation methods
246
+ # cgi.out() do
247
+ # cgi.html() do
248
+ # cgi.head{ cgi.title{"TITLE"} } +
249
+ # cgi.body() do
250
+ # cgi.form() do
251
+ # cgi.textarea("get_text") +
252
+ # cgi.br +
253
+ # cgi.submit
254
+ # end +
255
+ # cgi.pre() do
256
+ # CGI::escapeHTML(
257
+ # "params: " + cgi.params.inspect + "\n" +
258
+ # "cookies: " + cgi.cookies.inspect + "\n" +
259
+ # ENV.collect() do |key, value|
260
+ # key + " --> " + value + "\n"
261
+ # end.join("")
262
+ # )
263
+ # end
264
+ # end
265
+ # end
266
+ # end
267
+ #
268
+ # # add HTML generation methods
269
+ # CGI.new("html3") # html3.2
270
+ # CGI.new("html4") # html4.01 (Strict)
271
+ # CGI.new("html4Tr") # html4.01 Transitional
272
+ # CGI.new("html4Fr") # html4.01 Frameset
273
+ #
274
+ class CGI
275
+
276
+ # :stopdoc:
277
+
278
+ # String for carriage return
279
+ CR = "\015"
280
+
281
+ # String for linefeed
282
+ LF = "\012"
283
+
284
+ # Standard internet newline sequence
285
+ EOL = CR + LF
286
+
287
+ REVISION = '$Id: cgi.rb 15778 2008-03-14 07:45:26Z matz $' #:nodoc:
288
+
289
+ NEEDS_BINMODE = true if /WIN/ni.match(RUBY_PLATFORM)
290
+
291
+ # Path separators in different environments.
292
+ PATH_SEPARATOR = {'UNIX'=>'/', 'WINDOWS'=>'\\', 'MACINTOSH'=>':'}
293
+
294
+ # HTTP status codes.
295
+ HTTP_STATUS = {
296
+ "OK" => "200 OK",
297
+ "PARTIAL_CONTENT" => "206 Partial Content",
298
+ "MULTIPLE_CHOICES" => "300 Multiple Choices",
299
+ "MOVED" => "301 Moved Permanently",
300
+ "REDIRECT" => "302 Found",
301
+ "NOT_MODIFIED" => "304 Not Modified",
302
+ "BAD_REQUEST" => "400 Bad Request",
303
+ "AUTH_REQUIRED" => "401 Authorization Required",
304
+ "FORBIDDEN" => "403 Forbidden",
305
+ "NOT_FOUND" => "404 Not Found",
306
+ "METHOD_NOT_ALLOWED" => "405 Method Not Allowed",
307
+ "NOT_ACCEPTABLE" => "406 Not Acceptable",
308
+ "LENGTH_REQUIRED" => "411 Length Required",
309
+ "PRECONDITION_FAILED" => "412 Rrecondition Failed",
310
+ "SERVER_ERROR" => "500 Internal Server Error",
311
+ "NOT_IMPLEMENTED" => "501 Method Not Implemented",
312
+ "BAD_GATEWAY" => "502 Bad Gateway",
313
+ "VARIANT_ALSO_VARIES" => "506 Variant Also Negotiates"
314
+ }
315
+
316
+ # Abbreviated day-of-week names specified by RFC 822
317
+ RFC822_DAYS = %w[ Sun Mon Tue Wed Thu Fri Sat ]
318
+
319
+ # Abbreviated month names specified by RFC 822
320
+ RFC822_MONTHS = %w[ Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ]
321
+
322
+ # :startdoc:
323
+
324
+ def env_table
325
+ ENV
326
+ end
327
+
328
+ def stdinput
329
+ $stdin
330
+ end
331
+
332
+ def stdoutput
333
+ $DEFAULT_OUTPUT
334
+ end
335
+
336
+ private :env_table, :stdinput, :stdoutput
337
+
338
+ # URL-encode a string.
339
+ # url_encoded_string = CGI::escape("'Stop!' said Fred")
340
+ # # => "%27Stop%21%27+said+Fred"
341
+ def CGI::escape(string)
342
+ string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do
343
+ '%' + $1.unpack('H2' * $1.size).join('%').upcase
344
+ end.tr(' ', '+')
345
+ end
346
+
347
+
348
+ # URL-decode a string.
349
+ # string = CGI::unescape("%27Stop%21%27+said+Fred")
350
+ # # => "'Stop!' said Fred"
351
+ def CGI::unescape(string)
352
+ string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do
353
+ [$1.delete('%')].pack('H*')
354
+ end
355
+ end
356
+
357
+
358
+ # Escape special characters in HTML, namely &\"<>
359
+ # CGI::escapeHTML('Usage: foo "bar" <baz>')
360
+ # # => "Usage: foo &quot;bar&quot; &lt;baz&gt;"
361
+ def CGI::escapeHTML(string)
362
+ string.gsub(/&/n, '&amp;').gsub(/\"/n, '&quot;').gsub(/>/n, '&gt;').gsub(/</n, '&lt;')
363
+ end
364
+
365
+
366
+ # Unescape a string that has been HTML-escaped
367
+ # CGI::unescapeHTML("Usage: foo &quot;bar&quot; &lt;baz&gt;")
368
+ # # => "Usage: foo \"bar\" <baz>"
369
+ def CGI::unescapeHTML(string)
370
+ string.gsub(/&(amp|quot|gt|lt|\#[0-9]+|\#x[0-9A-Fa-f]+);/n) do
371
+ match = $1.dup
372
+ case match
373
+ when 'amp' then '&'
374
+ when 'quot' then '"'
375
+ when 'gt' then '>'
376
+ when 'lt' then '<'
377
+ when /\A#0*(\d+)\z/n then
378
+ if Integer($1) < 256
379
+ Integer($1).chr
380
+ else
381
+ if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
382
+ [Integer($1)].pack("U")
383
+ else
384
+ "&##{$1};"
385
+ end
386
+ end
387
+ when /\A#x([0-9a-f]+)\z/ni then
388
+ if $1.hex < 256
389
+ $1.hex.chr
390
+ else
391
+ if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U)
392
+ [$1.hex].pack("U")
393
+ else
394
+ "&#x#{$1};"
395
+ end
396
+ end
397
+ else
398
+ "&#{match};"
399
+ end
400
+ end
401
+ end
402
+
403
+
404
+ # Escape only the tags of certain HTML elements in +string+.
405
+ #
406
+ # Takes an element or elements or array of elements. Each element
407
+ # is specified by the name of the element, without angle brackets.
408
+ # This matches both the start and the end tag of that element.
409
+ # The attribute list of the open tag will also be escaped (for
410
+ # instance, the double-quotes surrounding attribute values).
411
+ #
412
+ # print CGI::escapeElement('<BR><A HREF="url"></A>', "A", "IMG")
413
+ # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
414
+ #
415
+ # print CGI::escapeElement('<BR><A HREF="url"></A>', ["A", "IMG"])
416
+ # # "<BR>&lt;A HREF=&quot;url&quot;&gt;&lt;/A&gt"
417
+ def CGI::escapeElement(string, *elements)
418
+ elements = elements[0] if elements[0].kind_of?(Array)
419
+ unless elements.empty?
420
+ string.gsub(/<\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?>/ni) do
421
+ CGI::escapeHTML($&)
422
+ end
423
+ else
424
+ string
425
+ end
426
+ end
427
+
428
+
429
+ # Undo escaping such as that done by CGI::escapeElement()
430
+ #
431
+ # print CGI::unescapeElement(
432
+ # CGI::escapeHTML('<BR><A HREF="url"></A>'), "A", "IMG")
433
+ # # "&lt;BR&gt;<A HREF="url"></A>"
434
+ #
435
+ # print CGI::unescapeElement(
436
+ # CGI::escapeHTML('<BR><A HREF="url"></A>'), ["A", "IMG"])
437
+ # # "&lt;BR&gt;<A HREF="url"></A>"
438
+ def CGI::unescapeElement(string, *elements)
439
+ elements = elements[0] if elements[0].kind_of?(Array)
440
+ unless elements.empty?
441
+ string.gsub(/&lt;\/?(?:#{elements.join("|")})(?!\w)(?:.|\n)*?&gt;/ni) do
442
+ CGI::unescapeHTML($&)
443
+ end
444
+ else
445
+ string
446
+ end
447
+ end
448
+
449
+
450
+ # Format a +Time+ object as a String using the format specified by RFC 1123.
451
+ #
452
+ # CGI::rfc1123_date(Time.now)
453
+ # # Sat, 01 Jan 2000 00:00:00 GMT
454
+ def CGI::rfc1123_date(time)
455
+ t = time.clone.gmtime
456
+ return format("%s, %.2d %s %.4d %.2d:%.2d:%.2d GMT",
457
+ RFC822_DAYS[t.wday], t.day, RFC822_MONTHS[t.month-1], t.year,
458
+ t.hour, t.min, t.sec)
459
+ end
460
+
461
+
462
+ # Create an HTTP header block as a string.
463
+ #
464
+ # Includes the empty line that ends the header block.
465
+ #
466
+ # +options+ can be a string specifying the Content-Type (defaults
467
+ # to text/html), or a hash of header key/value pairs. The following
468
+ # header keys are recognized:
469
+ #
470
+ # type:: the Content-Type header. Defaults to "text/html"
471
+ # charset:: the charset of the body, appended to the Content-Type header.
472
+ # nph:: a boolean value. If true, prepend protocol string and status code, and
473
+ # date; and sets default values for "server" and "connection" if not
474
+ # explicitly set.
475
+ # status:: the HTTP status code, returned as the Status header. See the
476
+ # list of available status codes below.
477
+ # server:: the server software, returned as the Server header.
478
+ # connection:: the connection type, returned as the Connection header (for
479
+ # instance, "close".
480
+ # length:: the length of the content that will be sent, returned as the
481
+ # Content-Length header.
482
+ # language:: the language of the content, returned as the Content-Language
483
+ # header.
484
+ # expires:: the time on which the current content expires, as a +Time+
485
+ # object, returned as the Expires header.
486
+ # cookie:: a cookie or cookies, returned as one or more Set-Cookie headers.
487
+ # The value can be the literal string of the cookie; a CGI::Cookie
488
+ # object; an Array of literal cookie strings or Cookie objects; or a
489
+ # hash all of whose values are literal cookie strings or Cookie objects.
490
+ # These cookies are in addition to the cookies held in the
491
+ # @output_cookies field.
492
+ #
493
+ # Other header lines can also be set; they are appended as key: value.
494
+ #
495
+ # header
496
+ # # Content-Type: text/html
497
+ #
498
+ # header("text/plain")
499
+ # # Content-Type: text/plain
500
+ #
501
+ # header("nph" => true,
502
+ # "status" => "OK", # == "200 OK"
503
+ # # "status" => "200 GOOD",
504
+ # "server" => ENV['SERVER_SOFTWARE'],
505
+ # "connection" => "close",
506
+ # "type" => "text/html",
507
+ # "charset" => "iso-2022-jp",
508
+ # # Content-Type: text/html; charset=iso-2022-jp
509
+ # "length" => 103,
510
+ # "language" => "ja",
511
+ # "expires" => Time.now + 30,
512
+ # "cookie" => [cookie1, cookie2],
513
+ # "my_header1" => "my_value"
514
+ # "my_header2" => "my_value")
515
+ #
516
+ # The status codes are:
517
+ #
518
+ # "OK" --> "200 OK"
519
+ # "PARTIAL_CONTENT" --> "206 Partial Content"
520
+ # "MULTIPLE_CHOICES" --> "300 Multiple Choices"
521
+ # "MOVED" --> "301 Moved Permanently"
522
+ # "REDIRECT" --> "302 Found"
523
+ # "NOT_MODIFIED" --> "304 Not Modified"
524
+ # "BAD_REQUEST" --> "400 Bad Request"
525
+ # "AUTH_REQUIRED" --> "401 Authorization Required"
526
+ # "FORBIDDEN" --> "403 Forbidden"
527
+ # "NOT_FOUND" --> "404 Not Found"
528
+ # "METHOD_NOT_ALLOWED" --> "405 Method Not Allowed"
529
+ # "NOT_ACCEPTABLE" --> "406 Not Acceptable"
530
+ # "LENGTH_REQUIRED" --> "411 Length Required"
531
+ # "PRECONDITION_FAILED" --> "412 Precondition Failed"
532
+ # "SERVER_ERROR" --> "500 Internal Server Error"
533
+ # "NOT_IMPLEMENTED" --> "501 Method Not Implemented"
534
+ # "BAD_GATEWAY" --> "502 Bad Gateway"
535
+ # "VARIANT_ALSO_VARIES" --> "506 Variant Also Negotiates"
536
+ #
537
+ # This method does not perform charset conversion.
538
+ #
539
+ def header(options = "text/html")
540
+
541
+ buf = ""
542
+
543
+ case options
544
+ when String
545
+ options = { "type" => options }
546
+ when Hash
547
+ options = options.dup
548
+ end
549
+
550
+ unless options.has_key?("type")
551
+ options["type"] = "text/html"
552
+ end
553
+
554
+ if options.has_key?("charset")
555
+ options["type"] += "; charset=" + options.delete("charset")
556
+ end
557
+
558
+ options.delete("nph") if defined?(MOD_RUBY)
559
+ if options.delete("nph") or
560
+ (/IIS\/(\d+)/n.match(env_table['SERVER_SOFTWARE']) and $1.to_i < 5)
561
+ buf += (env_table["SERVER_PROTOCOL"] or "HTTP/1.0") + " " +
562
+ (HTTP_STATUS[options["status"]] or options["status"] or "200 OK") +
563
+ EOL +
564
+ "Date: " + CGI::rfc1123_date(Time.now) + EOL
565
+
566
+ unless options.has_key?("server")
567
+ options["server"] = (env_table['SERVER_SOFTWARE'] or "")
568
+ end
569
+
570
+ unless options.has_key?("connection")
571
+ options["connection"] = "close"
572
+ end
573
+
574
+ options.delete("status")
575
+ end
576
+
577
+ if options.has_key?("status")
578
+ buf += "Status: " +
579
+ (HTTP_STATUS[options["status"]] or options["status"]) + EOL
580
+ options.delete("status")
581
+ end
582
+
583
+ if options.has_key?("server")
584
+ buf += "Server: " + options.delete("server") + EOL
585
+ end
586
+
587
+ if options.has_key?("connection")
588
+ buf += "Connection: " + options.delete("connection") + EOL
589
+ end
590
+
591
+ buf += "Content-Type: " + options.delete("type") + EOL
592
+
593
+ if options.has_key?("length")
594
+ buf += "Content-Length: " + options.delete("length").to_s + EOL
595
+ end
596
+
597
+ if options.has_key?("language")
598
+ buf += "Content-Language: " + options.delete("language") + EOL
599
+ end
600
+
601
+ if options.has_key?("expires")
602
+ buf += "Expires: " + CGI::rfc1123_date( options.delete("expires") ) + EOL
603
+ end
604
+
605
+ if options.has_key?("cookie")
606
+ if options["cookie"].kind_of?(String) or
607
+ options["cookie"].kind_of?(Cookie)
608
+ buf += "Set-Cookie: " + options.delete("cookie").to_s + EOL
609
+ elsif options["cookie"].kind_of?(Array)
610
+ options.delete("cookie").each{|cookie|
611
+ buf += "Set-Cookie: " + cookie.to_s + EOL
612
+ }
613
+ elsif options["cookie"].kind_of?(Hash)
614
+ options.delete("cookie").each_value{|cookie|
615
+ buf += "Set-Cookie: " + cookie.to_s + EOL
616
+ }
617
+ end
618
+ end
619
+ if @output_cookies
620
+ for cookie in @output_cookies
621
+ buf += "Set-Cookie: " + cookie.to_s + EOL
622
+ end
623
+ end
624
+
625
+ options.each{|key, value|
626
+ buf += key + ": " + value.to_s + EOL
627
+ }
628
+
629
+ if defined?(MOD_RUBY)
630
+ table = Apache::request.headers_out
631
+ buf.scan(/([^:]+): (.+)#{EOL}/n){ |name, value|
632
+ warn sprintf("name:%s value:%s\n", name, value) if $DEBUG
633
+ case name
634
+ when 'Set-Cookie'
635
+ table.add(name, value)
636
+ when /^status$/ni
637
+ Apache::request.status_line = value
638
+ Apache::request.status = value.to_i
639
+ when /^content-type$/ni
640
+ Apache::request.content_type = value
641
+ when /^content-encoding$/ni
642
+ Apache::request.content_encoding = value
643
+ when /^location$/ni
644
+ if Apache::request.status == 200
645
+ Apache::request.status = 302
646
+ end
647
+ Apache::request.headers_out[name] = value
648
+ else
649
+ Apache::request.headers_out[name] = value
650
+ end
651
+ }
652
+ Apache::request.send_http_header
653
+ ''
654
+ else
655
+ buf + EOL
656
+ end
657
+
658
+ end # header()
659
+
660
+
661
+ # Print an HTTP header and body to $DEFAULT_OUTPUT ($>)
662
+ #
663
+ # The header is provided by +options+, as for #header().
664
+ # The body of the document is that returned by the passed-
665
+ # in block. This block takes no arguments. It is required.
666
+ #
667
+ # cgi = CGI.new
668
+ # cgi.out{ "string" }
669
+ # # Content-Type: text/html
670
+ # # Content-Length: 6
671
+ # #
672
+ # # string
673
+ #
674
+ # cgi.out("text/plain") { "string" }
675
+ # # Content-Type: text/plain
676
+ # # Content-Length: 6
677
+ # #
678
+ # # string
679
+ #
680
+ # cgi.out("nph" => true,
681
+ # "status" => "OK", # == "200 OK"
682
+ # "server" => ENV['SERVER_SOFTWARE'],
683
+ # "connection" => "close",
684
+ # "type" => "text/html",
685
+ # "charset" => "iso-2022-jp",
686
+ # # Content-Type: text/html; charset=iso-2022-jp
687
+ # "language" => "ja",
688
+ # "expires" => Time.now + (3600 * 24 * 30),
689
+ # "cookie" => [cookie1, cookie2],
690
+ # "my_header1" => "my_value",
691
+ # "my_header2" => "my_value") { "string" }
692
+ #
693
+ # Content-Length is automatically calculated from the size of
694
+ # the String returned by the content block.
695
+ #
696
+ # If ENV['REQUEST_METHOD'] == "HEAD", then only the header
697
+ # is outputted (the content block is still required, but it
698
+ # is ignored).
699
+ #
700
+ # If the charset is "iso-2022-jp" or "euc-jp" or "shift_jis" then
701
+ # the content is converted to this charset, and the language is set
702
+ # to "ja".
703
+ def out(options = "text/html") # :yield:
704
+
705
+ options = { "type" => options } if options.kind_of?(String)
706
+ content = yield
707
+
708
+ if options.has_key?("charset")
709
+ require "nkf"
710
+ case options["charset"]
711
+ when /iso-2022-jp/ni
712
+ content = NKF::nkf('-m0 -x -j', content)
713
+ options["language"] = "ja" unless options.has_key?("language")
714
+ when /euc-jp/ni
715
+ content = NKF::nkf('-m0 -x -e', content)
716
+ options["language"] = "ja" unless options.has_key?("language")
717
+ when /shift_jis/ni
718
+ content = NKF::nkf('-m0 -x -s', content)
719
+ options["language"] = "ja" unless options.has_key?("language")
720
+ end
721
+ end
722
+
723
+ options["length"] = content.length.to_s
724
+ output = stdoutput
725
+ output.binmode if defined? output.binmode
726
+ output.print header(options)
727
+ output.print content unless "HEAD" == env_table['REQUEST_METHOD']
728
+ end
729
+
730
+
731
+ # Print an argument or list of arguments to the default output stream
732
+ #
733
+ # cgi = CGI.new
734
+ # cgi.print # default: cgi.print == $DEFAULT_OUTPUT.print
735
+ def print(*options)
736
+ stdoutput.print(*options)
737
+ end
738
+
739
+ require "delegate"
740
+
741
+ # Class representing an HTTP cookie.
742
+ #
743
+ # In addition to its specific fields and methods, a Cookie instance
744
+ # is a delegator to the array of its values.
745
+ #
746
+ # See RFC 2965.
747
+ #
748
+ # == Examples of use
749
+ # cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
750
+ # cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
751
+ # cookie1 = CGI::Cookie::new('name' => 'name',
752
+ # 'value' => ['value1', 'value2', ...],
753
+ # 'path' => 'path', # optional
754
+ # 'domain' => 'domain', # optional
755
+ # 'expires' => Time.now, # optional
756
+ # 'secure' => true # optional
757
+ # )
758
+ #
759
+ # cgi.out("cookie" => [cookie1, cookie2]) { "string" }
760
+ #
761
+ # name = cookie1.name
762
+ # values = cookie1.value
763
+ # path = cookie1.path
764
+ # domain = cookie1.domain
765
+ # expires = cookie1.expires
766
+ # secure = cookie1.secure
767
+ #
768
+ # cookie1.name = 'name'
769
+ # cookie1.value = ['value1', 'value2', ...]
770
+ # cookie1.path = 'path'
771
+ # cookie1.domain = 'domain'
772
+ # cookie1.expires = Time.now + 30
773
+ # cookie1.secure = true
774
+ class Cookie < DelegateClass(Array)
775
+
776
+ # Create a new CGI::Cookie object.
777
+ #
778
+ # The contents of the cookie can be specified as a +name+ and one
779
+ # or more +value+ arguments. Alternatively, the contents can
780
+ # be specified as a single hash argument. The possible keywords of
781
+ # this hash are as follows:
782
+ #
783
+ # name:: the name of the cookie. Required.
784
+ # value:: the cookie's value or list of values.
785
+ # path:: the path for which this cookie applies. Defaults to the
786
+ # base directory of the CGI script.
787
+ # domain:: the domain for which this cookie applies.
788
+ # expires:: the time at which this cookie expires, as a +Time+ object.
789
+ # secure:: whether this cookie is a secure cookie or not (default to
790
+ # false). Secure cookies are only transmitted to HTTPS
791
+ # servers.
792
+ #
793
+ # These keywords correspond to attributes of the cookie object.
794
+ def initialize(name = "", *value)
795
+ if name.kind_of?(String)
796
+ @name = name
797
+ @value = value
798
+ %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
799
+ @path = ($1 or "")
800
+ @secure = false
801
+ return super(@value)
802
+ end
803
+
804
+ options = name
805
+ unless options.has_key?("name")
806
+ raise ArgumentError, "`name' required"
807
+ end
808
+
809
+ @name = options["name"]
810
+ @value = Array(options["value"])
811
+ # simple support for IE
812
+ if options["path"]
813
+ @path = options["path"]
814
+ else
815
+ %r|^(.*/)|.match(ENV["SCRIPT_NAME"])
816
+ @path = ($1 or "")
817
+ end
818
+ @domain = options["domain"]
819
+ @expires = options["expires"]
820
+ @secure = options["secure"] == true ? true : false
821
+
822
+ super(@value)
823
+ end
824
+
825
+ attr_accessor("name", "value", "path", "domain", "expires")
826
+ attr_reader("secure")
827
+
828
+ # Set whether the Cookie is a secure cookie or not.
829
+ #
830
+ # +val+ must be a boolean.
831
+ def secure=(val)
832
+ @secure = val if val == true or val == false
833
+ @secure
834
+ end
835
+
836
+ # Convert the Cookie to its string representation.
837
+ def to_s
838
+ buf = ""
839
+ buf += @name + '='
840
+
841
+ if @value.kind_of?(String)
842
+ buf += CGI::escape(@value)
843
+ else
844
+ buf += @value.collect{|v| CGI::escape(v) }.join("&")
845
+ end
846
+
847
+ if @domain
848
+ buf += '; domain=' + @domain
849
+ end
850
+
851
+ if @path
852
+ buf += '; path=' + @path
853
+ end
854
+
855
+ if @expires
856
+ buf += '; expires=' + CGI::rfc1123_date(@expires)
857
+ end
858
+
859
+ if @secure == true
860
+ buf += '; secure'
861
+ end
862
+
863
+ buf
864
+ end
865
+
866
+ end # class Cookie
867
+
868
+
869
+ # Parse a raw cookie string into a hash of cookie-name=>Cookie
870
+ # pairs.
871
+ #
872
+ # cookies = CGI::Cookie::parse("raw_cookie_string")
873
+ # # { "name1" => cookie1, "name2" => cookie2, ... }
874
+ #
875
+ def Cookie::parse(raw_cookie)
876
+ cookies = Hash.new([])
877
+ return cookies unless raw_cookie
878
+
879
+ raw_cookie.split(/[;,]\s?/).each do |pairs|
880
+ name, values = pairs.split('=',2)
881
+ next unless name and values
882
+ name = CGI::unescape(name)
883
+ values ||= ""
884
+ values = values.split('&').collect{|v| CGI::unescape(v) }
885
+ if cookies.has_key?(name)
886
+ values = cookies[name].value + values
887
+ end
888
+ cookies[name] = Cookie::new(name, *values)
889
+ end
890
+
891
+ cookies
892
+ end
893
+
894
+ # Parse an HTTP query string into a hash of key=>value pairs.
895
+ #
896
+ # params = CGI::parse("query_string")
897
+ # # {"name1" => ["value1", "value2", ...],
898
+ # # "name2" => ["value1", "value2", ...], ... }
899
+ #
900
+ def CGI::parse(query)
901
+ params = Hash.new([].freeze)
902
+
903
+ query.split(/[&;]/n).each do |pairs|
904
+ key, value = pairs.split('=',2).collect{|v| CGI::unescape(v) }
905
+ if params.has_key?(key)
906
+ params[key].push(value)
907
+ else
908
+ params[key] = [value]
909
+ end
910
+ end
911
+
912
+ params
913
+ end
914
+
915
+ # Mixin module. It provides the follow functionality groups:
916
+ #
917
+ # 1. Access to CGI environment variables as methods. See
918
+ # documentation to the CGI class for a list of these variables.
919
+ #
920
+ # 2. Access to cookies, including the cookies attribute.
921
+ #
922
+ # 3. Access to parameters, including the params attribute, and overloading
923
+ # [] to perform parameter value lookup by key.
924
+ #
925
+ # 4. The initialize_query method, for initialising the above
926
+ # mechanisms, handling multipart forms, and allowing the
927
+ # class to be used in "offline" mode.
928
+ #
929
+ module QueryExtension
930
+
931
+ %w[ CONTENT_LENGTH SERVER_PORT ].each do |env|
932
+ define_method(env.sub(/^HTTP_/n, '').downcase) do
933
+ (val = env_table[env]) && Integer(val)
934
+ end
935
+ end
936
+
937
+ %w[ AUTH_TYPE CONTENT_TYPE GATEWAY_INTERFACE PATH_INFO
938
+ PATH_TRANSLATED QUERY_STRING REMOTE_ADDR REMOTE_HOST
939
+ REMOTE_IDENT REMOTE_USER REQUEST_METHOD SCRIPT_NAME
940
+ SERVER_NAME SERVER_PROTOCOL SERVER_SOFTWARE
941
+
942
+ HTTP_ACCEPT HTTP_ACCEPT_CHARSET HTTP_ACCEPT_ENCODING
943
+ HTTP_ACCEPT_LANGUAGE HTTP_CACHE_CONTROL HTTP_FROM HTTP_HOST
944
+ HTTP_NEGOTIATE HTTP_PRAGMA HTTP_REFERER HTTP_USER_AGENT ].each do |env|
945
+ define_method(env.sub(/^HTTP_/n, '').downcase) do
946
+ env_table[env]
947
+ end
948
+ end
949
+
950
+ # Get the raw cookies as a string.
951
+ def raw_cookie
952
+ env_table["HTTP_COOKIE"]
953
+ end
954
+
955
+ # Get the raw RFC2965 cookies as a string.
956
+ def raw_cookie2
957
+ env_table["HTTP_COOKIE2"]
958
+ end
959
+
960
+ # Get the cookies as a hash of cookie-name=>Cookie pairs.
961
+ attr_accessor("cookies")
962
+
963
+ # Get the parameters as a hash of name=>values pairs, where
964
+ # values is an Array.
965
+ attr("params")
966
+
967
+ # Set all the parameters.
968
+ def params=(hash)
969
+ @params.clear
970
+ @params.update(hash)
971
+ end
972
+
973
+ def read_multipart(boundary, content_length)
974
+ params = Hash.new([])
975
+ boundary = "--" + boundary
976
+ quoted_boundary = Regexp.quote(boundary, "n")
977
+ buf = ""
978
+ bufsize = 10 * 1024
979
+ boundary_end=""
980
+
981
+ # start multipart/form-data
982
+ stdinput.binmode if defined? stdinput.binmode
983
+ boundary_size = boundary.size + EOL.size
984
+ content_length -= boundary_size
985
+ status = stdinput.read(boundary_size)
986
+ if nil == status
987
+ raise EOFError, "no content body"
988
+ elsif boundary + EOL != status
989
+ raise EOFError, "bad content body"
990
+ end
991
+
992
+ loop do
993
+ head = nil
994
+ if 10240 < content_length
995
+ require "tempfile"
996
+ body = Tempfile.new("CGI")
997
+ else
998
+ begin
999
+ require "stringio"
1000
+ body = StringIO.new
1001
+ rescue LoadError
1002
+ require "tempfile"
1003
+ body = Tempfile.new("CGI")
1004
+ end
1005
+ end
1006
+ body.binmode if defined? body.binmode
1007
+
1008
+ until head and /#{quoted_boundary}(?:#{EOL}|--)/n.match(buf)
1009
+
1010
+ if (not head) and /#{EOL}#{EOL}/n.match(buf)
1011
+ buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
1012
+ head = $1.dup
1013
+ ""
1014
+ end
1015
+ next
1016
+ end
1017
+
1018
+ if head and ( (EOL + boundary + EOL).size < buf.size )
1019
+ body.print buf[0 ... (buf.size - (EOL + boundary + EOL).size)]
1020
+ buf[0 ... (buf.size - (EOL + boundary + EOL).size)] = ""
1021
+ end
1022
+
1023
+ c = if bufsize < content_length
1024
+ stdinput.read(bufsize)
1025
+ else
1026
+ stdinput.read(content_length)
1027
+ end
1028
+ if c.nil? || c.empty?
1029
+ raise EOFError, "bad content body"
1030
+ end
1031
+ buf.concat(c)
1032
+ content_length -= c.size
1033
+ end
1034
+
1035
+ buf = buf.sub(/\A((?:.|\n)*?)(?:[\r\n]{1,2})?#{quoted_boundary}([\r\n]{1,2}|--)/n) do
1036
+ body.print $1
1037
+ if "--" == $2
1038
+ content_length = -1
1039
+ end
1040
+ boundary_end = $2.dup
1041
+ ""
1042
+ end
1043
+
1044
+ body.rewind
1045
+
1046
+ /Content-Disposition:.* filename=(?:"((?:\\.|[^\"\s])*)"|([^;\s]*))/ni.match(head)
1047
+ filename = ($1 or $2 or "")
1048
+ if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
1049
+ /Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
1050
+ (not /MSIE/ni.match(env_table['HTTP_USER_AGENT']))
1051
+ filename = CGI::unescape(filename)
1052
+ end
1053
+
1054
+ /Content-Type: ([^\s]*)/ni.match(head)
1055
+ content_type = ($1 or "")
1056
+
1057
+ (class << body; self; end).class_eval do
1058
+ alias local_path path
1059
+ define_method(:original_filename) {filename.dup.taint}
1060
+ define_method(:content_type) {content_type.dup.taint}
1061
+ end
1062
+
1063
+ /Content-Disposition:.* name="?([^\";\s]*)"?/ni.match(head)
1064
+ name = $1.dup
1065
+
1066
+ if params.has_key?(name)
1067
+ params[name].push(body)
1068
+ else
1069
+ params[name] = [body]
1070
+ end
1071
+ break if buf.size == 0
1072
+ break if content_length == -1
1073
+ end
1074
+ raise EOFError, "bad boundary end of body part" unless boundary_end=~/--/
1075
+
1076
+ params
1077
+ end # read_multipart
1078
+ private :read_multipart
1079
+
1080
+ # offline mode. read name=value pairs on standard input.
1081
+ def read_from_cmdline
1082
+ require "shellwords"
1083
+
1084
+ string = unless ARGV.empty?
1085
+ ARGV.join(' ')
1086
+ else
1087
+ if STDIN.tty?
1088
+ STDERR.print(
1089
+ %|(offline mode: enter name=value pairs on standard input)\n|
1090
+ )
1091
+ end
1092
+ readlines.join(' ').gsub(/\n/n, '')
1093
+ end.gsub(/\\=/n, '%3D').gsub(/\\&/n, '%26')
1094
+
1095
+ words = Shellwords.shellwords(string)
1096
+
1097
+ if words.find{|x| /=/n.match(x) }
1098
+ words.join('&')
1099
+ else
1100
+ words.join('+')
1101
+ end
1102
+ end
1103
+ private :read_from_cmdline
1104
+
1105
+ # Initialize the data from the query.
1106
+ #
1107
+ # Handles multipart forms (in particular, forms that involve file uploads).
1108
+ # Reads query parameters in the @params field, and cookies into @cookies.
1109
+ def initialize_query()
1110
+ if ("POST" == env_table['REQUEST_METHOD']) and
1111
+ %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n.match(env_table['CONTENT_TYPE'])
1112
+ boundary = $1.dup
1113
+ @multipart = true
1114
+ @params = read_multipart(boundary, Integer(env_table['CONTENT_LENGTH']))
1115
+ else
1116
+ @multipart = false
1117
+ @params = CGI::parse(
1118
+ case env_table['REQUEST_METHOD']
1119
+ when "GET", "HEAD"
1120
+ if defined?(MOD_RUBY)
1121
+ Apache::request.args or ""
1122
+ else
1123
+ env_table['QUERY_STRING'] or ""
1124
+ end
1125
+ when "POST"
1126
+ stdinput.binmode if defined? stdinput.binmode
1127
+ stdinput.read(Integer(env_table['CONTENT_LENGTH'])) or ''
1128
+ else
1129
+ read_from_cmdline
1130
+ end
1131
+ )
1132
+ end
1133
+
1134
+ @cookies = CGI::Cookie::parse((env_table['HTTP_COOKIE'] or env_table['COOKIE']))
1135
+ end
1136
+ private :initialize_query
1137
+
1138
+ def multipart?
1139
+ @multipart
1140
+ end
1141
+
1142
+ module Value # :nodoc:
1143
+ def set_params(params)
1144
+ @params = params
1145
+ end
1146
+ def [](idx, *args)
1147
+ if args.size == 0
1148
+ warn "#{caller(1)[0]}:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key']"
1149
+ @params[idx]
1150
+ else
1151
+ super[idx,*args]
1152
+ end
1153
+ end
1154
+ def first
1155
+ warn "#{caller(1)[0]}:CAUTION! cgi['key'] == cgi.params['key'][0]; if want Array, use cgi.params['key']"
1156
+ self
1157
+ end
1158
+ alias last first
1159
+ def to_a
1160
+ @params || [self]
1161
+ end
1162
+ alias to_ary to_a # to be rhs of multiple assignment
1163
+ end
1164
+
1165
+ # Get the value for the parameter with a given key.
1166
+ #
1167
+ # If the parameter has multiple values, only the first will be
1168
+ # retrieved; use #params() to get the array of values.
1169
+ def [](key)
1170
+ params = @params[key]
1171
+ return '' unless params
1172
+ value = params[0]
1173
+ if @multipart
1174
+ if value
1175
+ return value
1176
+ elsif defined? StringIO
1177
+ StringIO.new("")
1178
+ else
1179
+ Tempfile.new("CGI")
1180
+ end
1181
+ else
1182
+ str = if value then value.dup else "" end
1183
+ str.extend(Value)
1184
+ str.set_params(params)
1185
+ str
1186
+ end
1187
+ end
1188
+
1189
+ # Return all parameter keys as an array.
1190
+ def keys(*args)
1191
+ @params.keys(*args)
1192
+ end
1193
+
1194
+ # Returns true if a given parameter key exists in the query.
1195
+ def has_key?(*args)
1196
+ @params.has_key?(*args)
1197
+ end
1198
+ alias key? has_key?
1199
+ alias include? has_key?
1200
+
1201
+ end # QueryExtension
1202
+
1203
+
1204
+ # Prettify (indent) an HTML string.
1205
+ #
1206
+ # +string+ is the HTML string to indent. +shift+ is the indentation
1207
+ # unit to use; it defaults to two spaces.
1208
+ #
1209
+ # print CGI::pretty("<HTML><BODY></BODY></HTML>")
1210
+ # # <HTML>
1211
+ # # <BODY>
1212
+ # # </BODY>
1213
+ # # </HTML>
1214
+ #
1215
+ # print CGI::pretty("<HTML><BODY></BODY></HTML>", "\t")
1216
+ # # <HTML>
1217
+ # # <BODY>
1218
+ # # </BODY>
1219
+ # # </HTML>
1220
+ #
1221
+ def CGI::pretty(string, shift = " ")
1222
+ lines = string.gsub(/(?!\A)<(?:.|\n)*?>/n, "\n\\0").gsub(/<(?:.|\n)*?>(?!\n)/n, "\\0\n")
1223
+ end_pos = 0
1224
+ while end_pos = lines.index(/^<\/(\w+)/n, end_pos)
1225
+ element = $1.dup
1226
+ start_pos = lines.rindex(/^\s*<#{element}/ni, end_pos)
1227
+ lines[start_pos ... end_pos] = "__" + lines[start_pos ... end_pos].gsub(/\n(?!\z)/n, "\n" + shift) + "__"
1228
+ end
1229
+ lines.gsub(/^((?:#{Regexp::quote(shift)})*)__(?=<\/?\w)/n, '\1')
1230
+ end
1231
+
1232
+
1233
+ # Base module for HTML-generation mixins.
1234
+ #
1235
+ # Provides methods for code generation for tags following
1236
+ # the various DTD element types.
1237
+ module TagMaker # :nodoc:
1238
+
1239
+ # Generate code for an element with required start and end tags.
1240
+ #
1241
+ # - -
1242
+ def nn_element_def(element)
1243
+ nOE_element_def(element, <<-END)
1244
+ if block_given?
1245
+ yield.to_s
1246
+ else
1247
+ ""
1248
+ end +
1249
+ "</#{element.upcase}>"
1250
+ END
1251
+ end
1252
+
1253
+ # Generate code for an empty element.
1254
+ #
1255
+ # - O EMPTY
1256
+ def nOE_element_def(element, append = nil)
1257
+ s = <<-END
1258
+ "<#{element.upcase}" + attributes.collect{|name, value|
1259
+ next unless value
1260
+ " " + CGI::escapeHTML(name) +
1261
+ if true == value
1262
+ ""
1263
+ else
1264
+ '="' + CGI::escapeHTML(value) + '"'
1265
+ end
1266
+ }.to_s + ">"
1267
+ END
1268
+ s.sub!(/\Z/, " +") << append if append
1269
+ s
1270
+ end
1271
+
1272
+ # Generate code for an element for which the end (and possibly the
1273
+ # start) tag is optional.
1274
+ #
1275
+ # O O or - O
1276
+ def nO_element_def(element)
1277
+ nOE_element_def(element, <<-END)
1278
+ if block_given?
1279
+ yield.to_s + "</#{element.upcase}>"
1280
+ else
1281
+ ""
1282
+ end
1283
+ END
1284
+ end
1285
+
1286
+ end # TagMaker
1287
+
1288
+
1289
+ #
1290
+ # Mixin module providing HTML generation methods.
1291
+ #
1292
+ # For example,
1293
+ # cgi.a("http://www.example.com") { "Example" }
1294
+ # # => "<A HREF=\"http://www.example.com\">Example</A>"
1295
+ #
1296
+ # Modules Http3, Http4, etc., contain more basic HTML-generation methods
1297
+ # (:title, :center, etc.).
1298
+ #
1299
+ # See class CGI for a detailed example.
1300
+ #
1301
+ module HtmlExtension
1302
+
1303
+
1304
+ # Generate an Anchor element as a string.
1305
+ #
1306
+ # +href+ can either be a string, giving the URL
1307
+ # for the HREF attribute, or it can be a hash of
1308
+ # the element's attributes.
1309
+ #
1310
+ # The body of the element is the string returned by the no-argument
1311
+ # block passed in.
1312
+ #
1313
+ # a("http://www.example.com") { "Example" }
1314
+ # # => "<A HREF=\"http://www.example.com\">Example</A>"
1315
+ #
1316
+ # a("HREF" => "http://www.example.com", "TARGET" => "_top") { "Example" }
1317
+ # # => "<A HREF=\"http://www.example.com\" TARGET=\"_top\">Example</A>"
1318
+ #
1319
+ def a(href = "") # :yield:
1320
+ attributes = if href.kind_of?(String)
1321
+ { "HREF" => href }
1322
+ else
1323
+ href
1324
+ end
1325
+ if block_given?
1326
+ super(attributes){ yield }
1327
+ else
1328
+ super(attributes)
1329
+ end
1330
+ end
1331
+
1332
+ # Generate a Document Base URI element as a String.
1333
+ #
1334
+ # +href+ can either by a string, giving the base URL for the HREF
1335
+ # attribute, or it can be a has of the element's attributes.
1336
+ #
1337
+ # The passed-in no-argument block is ignored.
1338
+ #
1339
+ # base("http://www.example.com/cgi")
1340
+ # # => "<BASE HREF=\"http://www.example.com/cgi\">"
1341
+ def base(href = "") # :yield:
1342
+ attributes = if href.kind_of?(String)
1343
+ { "HREF" => href }
1344
+ else
1345
+ href
1346
+ end
1347
+ if block_given?
1348
+ super(attributes){ yield }
1349
+ else
1350
+ super(attributes)
1351
+ end
1352
+ end
1353
+
1354
+ # Generate a BlockQuote element as a string.
1355
+ #
1356
+ # +cite+ can either be a string, give the URI for the source of
1357
+ # the quoted text, or a hash, giving all attributes of the element,
1358
+ # or it can be omitted, in which case the element has no attributes.
1359
+ #
1360
+ # The body is provided by the passed-in no-argument block
1361
+ #
1362
+ # blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
1363
+ # #=> "<BLOCKQUOTE CITE=\"http://www.example.com/quotes/foo.html\">Foo!</BLOCKQUOTE>
1364
+ def blockquote(cite = nil) # :yield:
1365
+ attributes = if cite.kind_of?(String)
1366
+ { "CITE" => cite }
1367
+ else
1368
+ cite or ""
1369
+ end
1370
+ if block_given?
1371
+ super(attributes){ yield }
1372
+ else
1373
+ super(attributes)
1374
+ end
1375
+ end
1376
+
1377
+
1378
+ # Generate a Table Caption element as a string.
1379
+ #
1380
+ # +align+ can be a string, giving the alignment of the caption
1381
+ # (one of top, bottom, left, or right). It can be a hash of
1382
+ # all the attributes of the element. Or it can be omitted.
1383
+ #
1384
+ # The body of the element is provided by the passed-in no-argument block.
1385
+ #
1386
+ # caption("left") { "Capital Cities" }
1387
+ # # => <CAPTION ALIGN=\"left\">Capital Cities</CAPTION>
1388
+ def caption(align = nil) # :yield:
1389
+ attributes = if align.kind_of?(String)
1390
+ { "ALIGN" => align }
1391
+ else
1392
+ align or ""
1393
+ end
1394
+ if block_given?
1395
+ super(attributes){ yield }
1396
+ else
1397
+ super(attributes)
1398
+ end
1399
+ end
1400
+
1401
+
1402
+ # Generate a Checkbox Input element as a string.
1403
+ #
1404
+ # The attributes of the element can be specified as three arguments,
1405
+ # +name+, +value+, and +checked+. +checked+ is a boolean value;
1406
+ # if true, the CHECKED attribute will be included in the element.
1407
+ #
1408
+ # Alternatively, the attributes can be specified as a hash.
1409
+ #
1410
+ # checkbox("name")
1411
+ # # = checkbox("NAME" => "name")
1412
+ #
1413
+ # checkbox("name", "value")
1414
+ # # = checkbox("NAME" => "name", "VALUE" => "value")
1415
+ #
1416
+ # checkbox("name", "value", true)
1417
+ # # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
1418
+ def checkbox(name = "", value = nil, checked = nil)
1419
+ attributes = if name.kind_of?(String)
1420
+ { "TYPE" => "checkbox", "NAME" => name,
1421
+ "VALUE" => value, "CHECKED" => checked }
1422
+ else
1423
+ name["TYPE"] = "checkbox"
1424
+ name
1425
+ end
1426
+ input(attributes)
1427
+ end
1428
+
1429
+ # Generate a sequence of checkbox elements, as a String.
1430
+ #
1431
+ # The checkboxes will all have the same +name+ attribute.
1432
+ # Each checkbox is followed by a label.
1433
+ # There will be one checkbox for each value. Each value
1434
+ # can be specified as a String, which will be used both
1435
+ # as the value of the VALUE attribute and as the label
1436
+ # for that checkbox. A single-element array has the
1437
+ # same effect.
1438
+ #
1439
+ # Each value can also be specified as a three-element array.
1440
+ # The first element is the VALUE attribute; the second is the
1441
+ # label; and the third is a boolean specifying whether this
1442
+ # checkbox is CHECKED.
1443
+ #
1444
+ # Each value can also be specified as a two-element
1445
+ # array, by omitting either the value element (defaults
1446
+ # to the same as the label), or the boolean checked element
1447
+ # (defaults to false).
1448
+ #
1449
+ # checkbox_group("name", "foo", "bar", "baz")
1450
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
1451
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
1452
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
1453
+ #
1454
+ # checkbox_group("name", ["foo"], ["bar", true], "baz")
1455
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
1456
+ # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
1457
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
1458
+ #
1459
+ # checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
1460
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
1461
+ # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
1462
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
1463
+ #
1464
+ # checkbox_group("NAME" => "name",
1465
+ # "VALUES" => ["foo", "bar", "baz"])
1466
+ #
1467
+ # checkbox_group("NAME" => "name",
1468
+ # "VALUES" => [["foo"], ["bar", true], "baz"])
1469
+ #
1470
+ # checkbox_group("NAME" => "name",
1471
+ # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
1472
+ def checkbox_group(name = "", *values)
1473
+ if name.kind_of?(Hash)
1474
+ values = name["VALUES"]
1475
+ name = name["NAME"]
1476
+ end
1477
+ values.collect{|value|
1478
+ if value.kind_of?(String)
1479
+ checkbox(name, value) + value
1480
+ else
1481
+ if value[value.size - 1] == true
1482
+ checkbox(name, value[0], true) +
1483
+ value[value.size - 2]
1484
+ else
1485
+ checkbox(name, value[0]) +
1486
+ value[value.size - 1]
1487
+ end
1488
+ end
1489
+ }.to_s
1490
+ end
1491
+
1492
+
1493
+ # Generate an File Upload Input element as a string.
1494
+ #
1495
+ # The attributes of the element can be specified as three arguments,
1496
+ # +name+, +size+, and +maxlength+. +maxlength+ is the maximum length
1497
+ # of the file's _name_, not of the file's _contents_.
1498
+ #
1499
+ # Alternatively, the attributes can be specified as a hash.
1500
+ #
1501
+ # See #multipart_form() for forms that include file uploads.
1502
+ #
1503
+ # file_field("name")
1504
+ # # <INPUT TYPE="file" NAME="name" SIZE="20">
1505
+ #
1506
+ # file_field("name", 40)
1507
+ # # <INPUT TYPE="file" NAME="name" SIZE="40">
1508
+ #
1509
+ # file_field("name", 40, 100)
1510
+ # # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
1511
+ #
1512
+ # file_field("NAME" => "name", "SIZE" => 40)
1513
+ # # <INPUT TYPE="file" NAME="name" SIZE="40">
1514
+ def file_field(name = "", size = 20, maxlength = nil)
1515
+ attributes = if name.kind_of?(String)
1516
+ { "TYPE" => "file", "NAME" => name,
1517
+ "SIZE" => size.to_s }
1518
+ else
1519
+ name["TYPE"] = "file"
1520
+ name
1521
+ end
1522
+ attributes["MAXLENGTH"] = maxlength.to_s if maxlength
1523
+ input(attributes)
1524
+ end
1525
+
1526
+
1527
+ # Generate a Form element as a string.
1528
+ #
1529
+ # +method+ should be either "get" or "post", and defaults to the latter.
1530
+ # +action+ defaults to the current CGI script name. +enctype+
1531
+ # defaults to "application/x-www-form-urlencoded".
1532
+ #
1533
+ # Alternatively, the attributes can be specified as a hash.
1534
+ #
1535
+ # See also #multipart_form() for forms that include file uploads.
1536
+ #
1537
+ # form{ "string" }
1538
+ # # <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
1539
+ #
1540
+ # form("get") { "string" }
1541
+ # # <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
1542
+ #
1543
+ # form("get", "url") { "string" }
1544
+ # # <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
1545
+ #
1546
+ # form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
1547
+ # # <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
1548
+ def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
1549
+ attributes = if method.kind_of?(String)
1550
+ { "METHOD" => method, "ACTION" => action,
1551
+ "ENCTYPE" => enctype }
1552
+ else
1553
+ unless method.has_key?("METHOD")
1554
+ method["METHOD"] = "post"
1555
+ end
1556
+ unless method.has_key?("ENCTYPE")
1557
+ method["ENCTYPE"] = enctype
1558
+ end
1559
+ method
1560
+ end
1561
+ if block_given?
1562
+ body = yield
1563
+ else
1564
+ body = ""
1565
+ end
1566
+ if @output_hidden
1567
+ body += @output_hidden.collect{|k,v|
1568
+ "<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">"
1569
+ }.to_s
1570
+ end
1571
+ super(attributes){body}
1572
+ end
1573
+
1574
+ # Generate a Hidden Input element as a string.
1575
+ #
1576
+ # The attributes of the element can be specified as two arguments,
1577
+ # +name+ and +value+.
1578
+ #
1579
+ # Alternatively, the attributes can be specified as a hash.
1580
+ #
1581
+ # hidden("name")
1582
+ # # <INPUT TYPE="hidden" NAME="name">
1583
+ #
1584
+ # hidden("name", "value")
1585
+ # # <INPUT TYPE="hidden" NAME="name" VALUE="value">
1586
+ #
1587
+ # hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
1588
+ # # <INPUT TYPE="hidden" NAME="name" VALUE="value" ID="foo">
1589
+ def hidden(name = "", value = nil)
1590
+ attributes = if name.kind_of?(String)
1591
+ { "TYPE" => "hidden", "NAME" => name, "VALUE" => value }
1592
+ else
1593
+ name["TYPE"] = "hidden"
1594
+ name
1595
+ end
1596
+ input(attributes)
1597
+ end
1598
+
1599
+ # Generate a top-level HTML element as a string.
1600
+ #
1601
+ # The attributes of the element are specified as a hash. The
1602
+ # pseudo-attribute "PRETTY" can be used to specify that the generated
1603
+ # HTML string should be indented. "PRETTY" can also be specified as
1604
+ # a string as the sole argument to this method. The pseudo-attribute
1605
+ # "DOCTYPE", if given, is used as the leading DOCTYPE SGML tag; it
1606
+ # should include the entire text of this tag, including angle brackets.
1607
+ #
1608
+ # The body of the html element is supplied as a block.
1609
+ #
1610
+ # html{ "string" }
1611
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>string</HTML>
1612
+ #
1613
+ # html("LANG" => "ja") { "string" }
1614
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML LANG="ja">string</HTML>
1615
+ #
1616
+ # html("DOCTYPE" => false) { "string" }
1617
+ # # <HTML>string</HTML>
1618
+ #
1619
+ # html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">') { "string" }
1620
+ # # <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>string</HTML>
1621
+ #
1622
+ # html("PRETTY" => " ") { "<BODY></BODY>" }
1623
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1624
+ # # <HTML>
1625
+ # # <BODY>
1626
+ # # </BODY>
1627
+ # # </HTML>
1628
+ #
1629
+ # html("PRETTY" => "\t") { "<BODY></BODY>" }
1630
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
1631
+ # # <HTML>
1632
+ # # <BODY>
1633
+ # # </BODY>
1634
+ # # </HTML>
1635
+ #
1636
+ # html("PRETTY") { "<BODY></BODY>" }
1637
+ # # = html("PRETTY" => " ") { "<BODY></BODY>" }
1638
+ #
1639
+ # html(if $VERBOSE then "PRETTY" end) { "HTML string" }
1640
+ #
1641
+ def html(attributes = {}) # :yield:
1642
+ if nil == attributes
1643
+ attributes = {}
1644
+ elsif "PRETTY" == attributes
1645
+ attributes = { "PRETTY" => true }
1646
+ end
1647
+ pretty = attributes.delete("PRETTY")
1648
+ pretty = " " if true == pretty
1649
+ buf = ""
1650
+
1651
+ if attributes.has_key?("DOCTYPE")
1652
+ if attributes["DOCTYPE"]
1653
+ buf += attributes.delete("DOCTYPE")
1654
+ else
1655
+ attributes.delete("DOCTYPE")
1656
+ end
1657
+ else
1658
+ buf += doctype
1659
+ end
1660
+
1661
+ if block_given?
1662
+ buf += super(attributes){ yield }
1663
+ else
1664
+ buf += super(attributes)
1665
+ end
1666
+
1667
+ if pretty
1668
+ CGI::pretty(buf, pretty)
1669
+ else
1670
+ buf
1671
+ end
1672
+
1673
+ end
1674
+
1675
+ # Generate an Image Button Input element as a string.
1676
+ #
1677
+ # +src+ is the URL of the image to use for the button. +name+
1678
+ # is the input name. +alt+ is the alternative text for the image.
1679
+ #
1680
+ # Alternatively, the attributes can be specified as a hash.
1681
+ #
1682
+ # image_button("url")
1683
+ # # <INPUT TYPE="image" SRC="url">
1684
+ #
1685
+ # image_button("url", "name", "string")
1686
+ # # <INPUT TYPE="image" SRC="url" NAME="name" ALT="string">
1687
+ #
1688
+ # image_button("SRC" => "url", "ATL" => "strng")
1689
+ # # <INPUT TYPE="image" SRC="url" ALT="string">
1690
+ def image_button(src = "", name = nil, alt = nil)
1691
+ attributes = if src.kind_of?(String)
1692
+ { "TYPE" => "image", "SRC" => src, "NAME" => name,
1693
+ "ALT" => alt }
1694
+ else
1695
+ src["TYPE"] = "image"
1696
+ src["SRC"] ||= ""
1697
+ src
1698
+ end
1699
+ input(attributes)
1700
+ end
1701
+
1702
+
1703
+ # Generate an Image element as a string.
1704
+ #
1705
+ # +src+ is the URL of the image. +alt+ is the alternative text for
1706
+ # the image. +width+ is the width of the image, and +height+ is
1707
+ # its height.
1708
+ #
1709
+ # Alternatively, the attributes can be specified as a hash.
1710
+ #
1711
+ # img("src", "alt", 100, 50)
1712
+ # # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
1713
+ #
1714
+ # img("SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50)
1715
+ # # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
1716
+ def img(src = "", alt = "", width = nil, height = nil)
1717
+ attributes = if src.kind_of?(String)
1718
+ { "SRC" => src, "ALT" => alt }
1719
+ else
1720
+ src
1721
+ end
1722
+ attributes["WIDTH"] = width.to_s if width
1723
+ attributes["HEIGHT"] = height.to_s if height
1724
+ super(attributes)
1725
+ end
1726
+
1727
+
1728
+ # Generate a Form element with multipart encoding as a String.
1729
+ #
1730
+ # Multipart encoding is used for forms that include file uploads.
1731
+ #
1732
+ # +action+ is the action to perform. +enctype+ is the encoding
1733
+ # type, which defaults to "multipart/form-data".
1734
+ #
1735
+ # Alternatively, the attributes can be specified as a hash.
1736
+ #
1737
+ # multipart_form{ "string" }
1738
+ # # <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM>
1739
+ #
1740
+ # multipart_form("url") { "string" }
1741
+ # # <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
1742
+ def multipart_form(action = nil, enctype = "multipart/form-data")
1743
+ attributes = if action == nil
1744
+ { "METHOD" => "post", "ENCTYPE" => enctype }
1745
+ elsif action.kind_of?(String)
1746
+ { "METHOD" => "post", "ACTION" => action,
1747
+ "ENCTYPE" => enctype }
1748
+ else
1749
+ unless action.has_key?("METHOD")
1750
+ action["METHOD"] = "post"
1751
+ end
1752
+ unless action.has_key?("ENCTYPE")
1753
+ action["ENCTYPE"] = enctype
1754
+ end
1755
+ action
1756
+ end
1757
+ if block_given?
1758
+ form(attributes){ yield }
1759
+ else
1760
+ form(attributes)
1761
+ end
1762
+ end
1763
+
1764
+
1765
+ # Generate a Password Input element as a string.
1766
+ #
1767
+ # +name+ is the name of the input field. +value+ is its default
1768
+ # value. +size+ is the size of the input field display. +maxlength+
1769
+ # is the maximum length of the inputted password.
1770
+ #
1771
+ # Alternatively, attributes can be specified as a hash.
1772
+ #
1773
+ # password_field("name")
1774
+ # # <INPUT TYPE="password" NAME="name" SIZE="40">
1775
+ #
1776
+ # password_field("name", "value")
1777
+ # # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="40">
1778
+ #
1779
+ # password_field("password", "value", 80, 200)
1780
+ # # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
1781
+ #
1782
+ # password_field("NAME" => "name", "VALUE" => "value")
1783
+ # # <INPUT TYPE="password" NAME="name" VALUE="value">
1784
+ def password_field(name = "", value = nil, size = 40, maxlength = nil)
1785
+ attributes = if name.kind_of?(String)
1786
+ { "TYPE" => "password", "NAME" => name,
1787
+ "VALUE" => value, "SIZE" => size.to_s }
1788
+ else
1789
+ name["TYPE"] = "password"
1790
+ name
1791
+ end
1792
+ attributes["MAXLENGTH"] = maxlength.to_s if maxlength
1793
+ input(attributes)
1794
+ end
1795
+
1796
+ # Generate a Select element as a string.
1797
+ #
1798
+ # +name+ is the name of the element. The +values+ are the options that
1799
+ # can be selected from the Select menu. Each value can be a String or
1800
+ # a one, two, or three-element Array. If a String or a one-element
1801
+ # Array, this is both the value of that option and the text displayed for
1802
+ # it. If a three-element Array, the elements are the option value, displayed
1803
+ # text, and a boolean value specifying whether this option starts as selected.
1804
+ # The two-element version omits either the option value (defaults to the same
1805
+ # as the display text) or the boolean selected specifier (defaults to false).
1806
+ #
1807
+ # The attributes and options can also be specified as a hash. In this
1808
+ # case, options are specified as an array of values as described above,
1809
+ # with the hash key of "VALUES".
1810
+ #
1811
+ # popup_menu("name", "foo", "bar", "baz")
1812
+ # # <SELECT NAME="name">
1813
+ # # <OPTION VALUE="foo">foo</OPTION>
1814
+ # # <OPTION VALUE="bar">bar</OPTION>
1815
+ # # <OPTION VALUE="baz">baz</OPTION>
1816
+ # # </SELECT>
1817
+ #
1818
+ # popup_menu("name", ["foo"], ["bar", true], "baz")
1819
+ # # <SELECT NAME="name">
1820
+ # # <OPTION VALUE="foo">foo</OPTION>
1821
+ # # <OPTION VALUE="bar" SELECTED>bar</OPTION>
1822
+ # # <OPTION VALUE="baz">baz</OPTION>
1823
+ # # </SELECT>
1824
+ #
1825
+ # popup_menu("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
1826
+ # # <SELECT NAME="name">
1827
+ # # <OPTION VALUE="1">Foo</OPTION>
1828
+ # # <OPTION SELECTED VALUE="2">Bar</OPTION>
1829
+ # # <OPTION VALUE="Baz">Baz</OPTION>
1830
+ # # </SELECT>
1831
+ #
1832
+ # popup_menu("NAME" => "name", "SIZE" => 2, "MULTIPLE" => true,
1833
+ # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
1834
+ # # <SELECT NAME="name" MULTIPLE SIZE="2">
1835
+ # # <OPTION VALUE="1">Foo</OPTION>
1836
+ # # <OPTION SELECTED VALUE="2">Bar</OPTION>
1837
+ # # <OPTION VALUE="Baz">Baz</OPTION>
1838
+ # # </SELECT>
1839
+ def popup_menu(name = "", *values)
1840
+
1841
+ if name.kind_of?(Hash)
1842
+ values = name["VALUES"]
1843
+ size = name["SIZE"].to_s if name["SIZE"]
1844
+ multiple = name["MULTIPLE"]
1845
+ name = name["NAME"]
1846
+ else
1847
+ size = nil
1848
+ multiple = nil
1849
+ end
1850
+
1851
+ select({ "NAME" => name, "SIZE" => size,
1852
+ "MULTIPLE" => multiple }){
1853
+ values.collect{|value|
1854
+ if value.kind_of?(String)
1855
+ option({ "VALUE" => value }){ value }
1856
+ else
1857
+ if value[value.size - 1] == true
1858
+ option({ "VALUE" => value[0], "SELECTED" => true }){
1859
+ value[value.size - 2]
1860
+ }
1861
+ else
1862
+ option({ "VALUE" => value[0] }){
1863
+ value[value.size - 1]
1864
+ }
1865
+ end
1866
+ end
1867
+ }.to_s
1868
+ }
1869
+
1870
+ end
1871
+
1872
+ # Generates a radio-button Input element.
1873
+ #
1874
+ # +name+ is the name of the input field. +value+ is the value of
1875
+ # the field if checked. +checked+ specifies whether the field
1876
+ # starts off checked.
1877
+ #
1878
+ # Alternatively, the attributes can be specified as a hash.
1879
+ #
1880
+ # radio_button("name", "value")
1881
+ # # <INPUT TYPE="radio" NAME="name" VALUE="value">
1882
+ #
1883
+ # radio_button("name", "value", true)
1884
+ # # <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED>
1885
+ #
1886
+ # radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo")
1887
+ # # <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">
1888
+ def radio_button(name = "", value = nil, checked = nil)
1889
+ attributes = if name.kind_of?(String)
1890
+ { "TYPE" => "radio", "NAME" => name,
1891
+ "VALUE" => value, "CHECKED" => checked }
1892
+ else
1893
+ name["TYPE"] = "radio"
1894
+ name
1895
+ end
1896
+ input(attributes)
1897
+ end
1898
+
1899
+ # Generate a sequence of radio button Input elements, as a String.
1900
+ #
1901
+ # This works the same as #checkbox_group(). However, it is not valid
1902
+ # to have more than one radiobutton in a group checked.
1903
+ #
1904
+ # radio_group("name", "foo", "bar", "baz")
1905
+ # # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
1906
+ # # <INPUT TYPE="radio" NAME="name" VALUE="bar">bar
1907
+ # # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
1908
+ #
1909
+ # radio_group("name", ["foo"], ["bar", true], "baz")
1910
+ # # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
1911
+ # # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="bar">bar
1912
+ # # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
1913
+ #
1914
+ # radio_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
1915
+ # # <INPUT TYPE="radio" NAME="name" VALUE="1">Foo
1916
+ # # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="2">Bar
1917
+ # # <INPUT TYPE="radio" NAME="name" VALUE="Baz">Baz
1918
+ #
1919
+ # radio_group("NAME" => "name",
1920
+ # "VALUES" => ["foo", "bar", "baz"])
1921
+ #
1922
+ # radio_group("NAME" => "name",
1923
+ # "VALUES" => [["foo"], ["bar", true], "baz"])
1924
+ #
1925
+ # radio_group("NAME" => "name",
1926
+ # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
1927
+ def radio_group(name = "", *values)
1928
+ if name.kind_of?(Hash)
1929
+ values = name["VALUES"]
1930
+ name = name["NAME"]
1931
+ end
1932
+ values.collect{|value|
1933
+ if value.kind_of?(String)
1934
+ radio_button(name, value) + value
1935
+ else
1936
+ if value[value.size - 1] == true
1937
+ radio_button(name, value[0], true) +
1938
+ value[value.size - 2]
1939
+ else
1940
+ radio_button(name, value[0]) +
1941
+ value[value.size - 1]
1942
+ end
1943
+ end
1944
+ }.to_s
1945
+ end
1946
+
1947
+ # Generate a reset button Input element, as a String.
1948
+ #
1949
+ # This resets the values on a form to their initial values. +value+
1950
+ # is the text displayed on the button. +name+ is the name of this button.
1951
+ #
1952
+ # Alternatively, the attributes can be specified as a hash.
1953
+ #
1954
+ # reset
1955
+ # # <INPUT TYPE="reset">
1956
+ #
1957
+ # reset("reset")
1958
+ # # <INPUT TYPE="reset" VALUE="reset">
1959
+ #
1960
+ # reset("VALUE" => "reset", "ID" => "foo")
1961
+ # # <INPUT TYPE="reset" VALUE="reset" ID="foo">
1962
+ def reset(value = nil, name = nil)
1963
+ attributes = if (not value) or value.kind_of?(String)
1964
+ { "TYPE" => "reset", "VALUE" => value, "NAME" => name }
1965
+ else
1966
+ value["TYPE"] = "reset"
1967
+ value
1968
+ end
1969
+ input(attributes)
1970
+ end
1971
+
1972
+ alias scrolling_list popup_menu
1973
+
1974
+ # Generate a submit button Input element, as a String.
1975
+ #
1976
+ # +value+ is the text to display on the button. +name+ is the name
1977
+ # of the input.
1978
+ #
1979
+ # Alternatively, the attributes can be specified as a hash.
1980
+ #
1981
+ # submit
1982
+ # # <INPUT TYPE="submit">
1983
+ #
1984
+ # submit("ok")
1985
+ # # <INPUT TYPE="submit" VALUE="ok">
1986
+ #
1987
+ # submit("ok", "button1")
1988
+ # # <INPUT TYPE="submit" VALUE="ok" NAME="button1">
1989
+ #
1990
+ # submit("VALUE" => "ok", "NAME" => "button1", "ID" => "foo")
1991
+ # # <INPUT TYPE="submit" VALUE="ok" NAME="button1" ID="foo">
1992
+ def submit(value = nil, name = nil)
1993
+ attributes = if (not value) or value.kind_of?(String)
1994
+ { "TYPE" => "submit", "VALUE" => value, "NAME" => name }
1995
+ else
1996
+ value["TYPE"] = "submit"
1997
+ value
1998
+ end
1999
+ input(attributes)
2000
+ end
2001
+
2002
+ # Generate a text field Input element, as a String.
2003
+ #
2004
+ # +name+ is the name of the input field. +value+ is its initial
2005
+ # value. +size+ is the size of the input area. +maxlength+
2006
+ # is the maximum length of input accepted.
2007
+ #
2008
+ # Alternatively, the attributes can be specified as a hash.
2009
+ #
2010
+ # text_field("name")
2011
+ # # <INPUT TYPE="text" NAME="name" SIZE="40">
2012
+ #
2013
+ # text_field("name", "value")
2014
+ # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40">
2015
+ #
2016
+ # text_field("name", "value", 80)
2017
+ # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80">
2018
+ #
2019
+ # text_field("name", "value", 80, 200)
2020
+ # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
2021
+ #
2022
+ # text_field("NAME" => "name", "VALUE" => "value")
2023
+ # # <INPUT TYPE="text" NAME="name" VALUE="value">
2024
+ def text_field(name = "", value = nil, size = 40, maxlength = nil)
2025
+ attributes = if name.kind_of?(String)
2026
+ { "TYPE" => "text", "NAME" => name, "VALUE" => value,
2027
+ "SIZE" => size.to_s }
2028
+ else
2029
+ name["TYPE"] = "text"
2030
+ name
2031
+ end
2032
+ attributes["MAXLENGTH"] = maxlength.to_s if maxlength
2033
+ input(attributes)
2034
+ end
2035
+
2036
+ # Generate a TextArea element, as a String.
2037
+ #
2038
+ # +name+ is the name of the textarea. +cols+ is the number of
2039
+ # columns and +rows+ is the number of rows in the display.
2040
+ #
2041
+ # Alternatively, the attributes can be specified as a hash.
2042
+ #
2043
+ # The body is provided by the passed-in no-argument block
2044
+ #
2045
+ # textarea("name")
2046
+ # # = textarea("NAME" => "name", "COLS" => 70, "ROWS" => 10)
2047
+ #
2048
+ # textarea("name", 40, 5)
2049
+ # # = textarea("NAME" => "name", "COLS" => 40, "ROWS" => 5)
2050
+ def textarea(name = "", cols = 70, rows = 10) # :yield:
2051
+ attributes = if name.kind_of?(String)
2052
+ { "NAME" => name, "COLS" => cols.to_s,
2053
+ "ROWS" => rows.to_s }
2054
+ else
2055
+ name
2056
+ end
2057
+ if block_given?
2058
+ super(attributes){ yield }
2059
+ else
2060
+ super(attributes)
2061
+ end
2062
+ end
2063
+
2064
+ end # HtmlExtension
2065
+
2066
+
2067
+ # Mixin module for HTML version 3 generation methods.
2068
+ module Html3 # :nodoc:
2069
+
2070
+ # The DOCTYPE declaration for this version of HTML
2071
+ def doctype
2072
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">|
2073
+ end
2074
+
2075
+ # Initialise the HTML generation methods for this version.
2076
+ def element_init
2077
+ extend TagMaker
2078
+ methods = ""
2079
+ # - -
2080
+ for element in %w[ A TT I B U STRIKE BIG SMALL SUB SUP EM STRONG
2081
+ DFN CODE SAMP KBD VAR CITE FONT ADDRESS DIV center MAP
2082
+ APPLET PRE XMP LISTING DL OL UL DIR MENU SELECT table TITLE
2083
+ STYLE SCRIPT H1 H2 H3 H4 H5 H6 TEXTAREA FORM BLOCKQUOTE
2084
+ CAPTION ]
2085
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
2086
+ def #{element.downcase}(attributes = {})
2087
+ BEGIN
2088
+ end
2089
+ END
2090
+ end
2091
+
2092
+ # - O EMPTY
2093
+ for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
2094
+ ISINDEX META ]
2095
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
2096
+ def #{element.downcase}(attributes = {})
2097
+ BEGIN
2098
+ end
2099
+ END
2100
+ end
2101
+
2102
+ # O O or - O
2103
+ for element in %w[ HTML HEAD BODY P PLAINTEXT DT DD LI OPTION tr
2104
+ th td ]
2105
+ methods += <<-BEGIN + nO_element_def(element) + <<-END
2106
+ def #{element.downcase}(attributes = {})
2107
+ BEGIN
2108
+ end
2109
+ END
2110
+ end
2111
+ eval(methods)
2112
+ end
2113
+
2114
+ end # Html3
2115
+
2116
+
2117
+ # Mixin module for HTML version 4 generation methods.
2118
+ module Html4 # :nodoc:
2119
+
2120
+ # The DOCTYPE declaration for this version of HTML
2121
+ def doctype
2122
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">|
2123
+ end
2124
+
2125
+ # Initialise the HTML generation methods for this version.
2126
+ def element_init
2127
+ extend TagMaker
2128
+ methods = ""
2129
+ # - -
2130
+ for element in %w[ TT I B BIG SMALL EM STRONG DFN CODE SAMP KBD
2131
+ VAR CITE ABBR ACRONYM SUB SUP SPAN BDO ADDRESS DIV MAP OBJECT
2132
+ H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT OPTGROUP
2133
+ FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
2134
+ TEXTAREA FORM A BLOCKQUOTE CAPTION ]
2135
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
2136
+ def #{element.downcase}(attributes = {})
2137
+ BEGIN
2138
+ end
2139
+ END
2140
+ end
2141
+
2142
+ # - O EMPTY
2143
+ for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META ]
2144
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
2145
+ def #{element.downcase}(attributes = {})
2146
+ BEGIN
2147
+ end
2148
+ END
2149
+ end
2150
+
2151
+ # O O or - O
2152
+ for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
2153
+ COLGROUP TR TH TD HEAD]
2154
+ methods += <<-BEGIN + nO_element_def(element) + <<-END
2155
+ def #{element.downcase}(attributes = {})
2156
+ BEGIN
2157
+ end
2158
+ END
2159
+ end
2160
+ eval(methods)
2161
+ end
2162
+
2163
+ end # Html4
2164
+
2165
+
2166
+ # Mixin module for HTML version 4 transitional generation methods.
2167
+ module Html4Tr # :nodoc:
2168
+
2169
+ # The DOCTYPE declaration for this version of HTML
2170
+ def doctype
2171
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">|
2172
+ end
2173
+
2174
+ # Initialise the HTML generation methods for this version.
2175
+ def element_init
2176
+ extend TagMaker
2177
+ methods = ""
2178
+ # - -
2179
+ for element in %w[ TT I B U S STRIKE BIG SMALL EM STRONG DFN
2180
+ CODE SAMP KBD VAR CITE ABBR ACRONYM FONT SUB SUP SPAN BDO
2181
+ ADDRESS DIV CENTER MAP OBJECT APPLET H1 H2 H3 H4 H5 H6 PRE Q
2182
+ INS DEL DL OL UL DIR MENU LABEL SELECT OPTGROUP FIELDSET
2183
+ LEGEND BUTTON TABLE IFRAME NOFRAMES TITLE STYLE SCRIPT
2184
+ NOSCRIPT TEXTAREA FORM A BLOCKQUOTE CAPTION ]
2185
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
2186
+ def #{element.downcase}(attributes = {})
2187
+ BEGIN
2188
+ end
2189
+ END
2190
+ end
2191
+
2192
+ # - O EMPTY
2193
+ for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
2194
+ COL ISINDEX META ]
2195
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
2196
+ def #{element.downcase}(attributes = {})
2197
+ BEGIN
2198
+ end
2199
+ END
2200
+ end
2201
+
2202
+ # O O or - O
2203
+ for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
2204
+ COLGROUP TR TH TD HEAD ]
2205
+ methods += <<-BEGIN + nO_element_def(element) + <<-END
2206
+ def #{element.downcase}(attributes = {})
2207
+ BEGIN
2208
+ end
2209
+ END
2210
+ end
2211
+ eval(methods)
2212
+ end
2213
+
2214
+ end # Html4Tr
2215
+
2216
+
2217
+ # Mixin module for generating HTML version 4 with framesets.
2218
+ module Html4Fr # :nodoc:
2219
+
2220
+ # The DOCTYPE declaration for this version of HTML
2221
+ def doctype
2222
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">|
2223
+ end
2224
+
2225
+ # Initialise the HTML generation methods for this version.
2226
+ def element_init
2227
+ methods = ""
2228
+ # - -
2229
+ for element in %w[ FRAMESET ]
2230
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
2231
+ def #{element.downcase}(attributes = {})
2232
+ BEGIN
2233
+ end
2234
+ END
2235
+ end
2236
+
2237
+ # - O EMPTY
2238
+ for element in %w[ FRAME ]
2239
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
2240
+ def #{element.downcase}(attributes = {})
2241
+ BEGIN
2242
+ end
2243
+ END
2244
+ end
2245
+ eval(methods)
2246
+ end
2247
+
2248
+ end # Html4Fr
2249
+
2250
+
2251
+ # Creates a new CGI instance.
2252
+ #
2253
+ # +type+ specifies which version of HTML to load the HTML generation
2254
+ # methods for. The following versions of HTML are supported:
2255
+ #
2256
+ # html3:: HTML 3.x
2257
+ # html4:: HTML 4.0
2258
+ # html4Tr:: HTML 4.0 Transitional
2259
+ # html4Fr:: HTML 4.0 with Framesets
2260
+ #
2261
+ # If not specified, no HTML generation methods will be loaded.
2262
+ #
2263
+ # If the CGI object is not created in a standard CGI call environment
2264
+ # (that is, it can't locate REQUEST_METHOD in its environment), then
2265
+ # it will run in "offline" mode. In this mode, it reads its parameters
2266
+ # from the command line or (failing that) from standard input. Otherwise,
2267
+ # cookies and other parameters are parsed automatically from the standard
2268
+ # CGI locations, which varies according to the REQUEST_METHOD.
2269
+ def initialize(type = "query")
2270
+ if defined?(MOD_RUBY) && !ENV.key?("GATEWAY_INTERFACE")
2271
+ Apache.request.setup_cgi_env
2272
+ end
2273
+
2274
+ extend QueryExtension
2275
+ @multipart = false
2276
+ if defined?(CGI_PARAMS)
2277
+ warn "do not use CGI_PARAMS and CGI_COOKIES"
2278
+ @params = CGI_PARAMS.dup
2279
+ @cookies = CGI_COOKIES.dup
2280
+ else
2281
+ initialize_query() # set @params, @cookies
2282
+ end
2283
+ @output_cookies = nil
2284
+ @output_hidden = nil
2285
+
2286
+ case type
2287
+ when "html3"
2288
+ extend Html3
2289
+ element_init()
2290
+ extend HtmlExtension
2291
+ when "html4"
2292
+ extend Html4
2293
+ element_init()
2294
+ extend HtmlExtension
2295
+ when "html4Tr"
2296
+ extend Html4Tr
2297
+ element_init()
2298
+ extend HtmlExtension
2299
+ when "html4Fr"
2300
+ extend Html4Tr
2301
+ element_init()
2302
+ extend Html4Fr
2303
+ element_init()
2304
+ extend HtmlExtension
2305
+ end
2306
+ end
2307
+
2308
+ end # class CGI