laser 0.7.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (319) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +14 -0
  4. data/LICENSE +661 -0
  5. data/README.md +158 -0
  6. data/Rakefile +104 -0
  7. data/VERSION +1 -0
  8. data/bin/laser +7 -0
  9. data/design_docs/goals.md +57 -0
  10. data/design_docs/object_regex.md +426 -0
  11. data/design_docs/type_annotations.md +80 -0
  12. data/ext/laser/BasicBlock.cpp +572 -0
  13. data/ext/laser/BasicBlock.h +118 -0
  14. data/ext/laser/extconf.rb +3 -0
  15. data/features/laser.feature +25 -0
  16. data/features/step_definitions/laser_steps.rb +39 -0
  17. data/features/support/env.rb +14 -0
  18. data/features/support/testdata/1_input +1 -0
  19. data/features/support/testdata/1_output +1 -0
  20. data/features/support/testdata/2_input +4 -0
  21. data/features/support/testdata/2_output +4 -0
  22. data/features/support/testdata/3_input +8 -0
  23. data/features/support/testdata/3_output +11 -0
  24. data/features/support/testdata/4_input +5 -0
  25. data/features/support/testdata/4_output +5 -0
  26. data/features/support/testdata/5_input +13 -0
  27. data/laser.gemspec +382 -0
  28. data/lib/laser.rb +98 -0
  29. data/lib/laser/analysis/annotations.rb +95 -0
  30. data/lib/laser/analysis/annotations/annotation_config.yaml +3 -0
  31. data/lib/laser/analysis/annotations/comment_attachment_annotation.rb +66 -0
  32. data/lib/laser/analysis/annotations/node_pointers_annotation.rb +36 -0
  33. data/lib/laser/analysis/annotations/runtime_annotation.rb +55 -0
  34. data/lib/laser/analysis/argument_expansion.rb +132 -0
  35. data/lib/laser/analysis/arity.rb +34 -0
  36. data/lib/laser/analysis/bindings.rb +144 -0
  37. data/lib/laser/analysis/bootstrap/bootstrap.rb +298 -0
  38. data/lib/laser/analysis/bootstrap/laser_class.rb +106 -0
  39. data/lib/laser/analysis/bootstrap/laser_method.rb +255 -0
  40. data/lib/laser/analysis/bootstrap/laser_module.rb +403 -0
  41. data/lib/laser/analysis/bootstrap/laser_module_copy.rb +74 -0
  42. data/lib/laser/analysis/bootstrap/laser_object.rb +69 -0
  43. data/lib/laser/analysis/bootstrap/laser_proc.rb +150 -0
  44. data/lib/laser/analysis/bootstrap/laser_singleton_class.rb +44 -0
  45. data/lib/laser/analysis/comments.rb +35 -0
  46. data/lib/laser/analysis/control_flow.rb +28 -0
  47. data/lib/laser/analysis/control_flow/alias_analysis.rb +31 -0
  48. data/lib/laser/analysis/control_flow/basic_block.rb +105 -0
  49. data/lib/laser/analysis/control_flow/cfg_builder.rb +2505 -0
  50. data/lib/laser/analysis/control_flow/cfg_instruction.rb +190 -0
  51. data/lib/laser/analysis/control_flow/constant_propagation.rb +742 -0
  52. data/lib/laser/analysis/control_flow/control_flow_graph.rb +370 -0
  53. data/lib/laser/analysis/control_flow/lifetime_analysis.rb +91 -0
  54. data/lib/laser/analysis/control_flow/method_call_search.rb +26 -0
  55. data/lib/laser/analysis/control_flow/raise_properties.rb +25 -0
  56. data/lib/laser/analysis/control_flow/simulation.rb +385 -0
  57. data/lib/laser/analysis/control_flow/static_single_assignment.rb +185 -0
  58. data/lib/laser/analysis/control_flow/unreachability_analysis.rb +57 -0
  59. data/lib/laser/analysis/control_flow/unused_variables.rb +91 -0
  60. data/lib/laser/analysis/control_flow/yield_properties.rb +103 -0
  61. data/lib/laser/analysis/errors.rb +131 -0
  62. data/lib/laser/analysis/laser_utils.rb +18 -0
  63. data/lib/laser/analysis/lexical_analysis.rb +172 -0
  64. data/lib/laser/analysis/method_call.rb +68 -0
  65. data/lib/laser/analysis/protocol_registry.rb +30 -0
  66. data/lib/laser/analysis/scope.rb +118 -0
  67. data/lib/laser/analysis/sexp.rb +159 -0
  68. data/lib/laser/analysis/sexp_analysis.rb +40 -0
  69. data/lib/laser/analysis/sexp_extensions/constant_extraction.rb +115 -0
  70. data/lib/laser/analysis/sexp_extensions/source_location.rb +164 -0
  71. data/lib/laser/analysis/sexp_extensions/type_inference.rb +47 -0
  72. data/lib/laser/analysis/signature.rb +76 -0
  73. data/lib/laser/analysis/special_methods/send.rb +67 -0
  74. data/lib/laser/analysis/unused_methods.rb +21 -0
  75. data/lib/laser/analysis/visitor.rb +141 -0
  76. data/lib/laser/annotation_parser/annotations.treetop +126 -0
  77. data/lib/laser/annotation_parser/annotations_parser.rb +748 -0
  78. data/lib/laser/annotation_parser/class_annotations.treetop +82 -0
  79. data/lib/laser/annotation_parser/class_annotations_parser.rb +654 -0
  80. data/lib/laser/annotation_parser/overload.treetop +24 -0
  81. data/lib/laser/annotation_parser/overload_parser.rb +167 -0
  82. data/lib/laser/annotation_parser/parsers.rb +6 -0
  83. data/lib/laser/annotation_parser/structural.treetop +37 -0
  84. data/lib/laser/annotation_parser/structural_parser.rb +406 -0
  85. data/lib/laser/annotation_parser/useful_parsers.treetop +47 -0
  86. data/lib/laser/annotation_parser/useful_parsers_parser.rb +674 -0
  87. data/lib/laser/rake/task.rb +46 -0
  88. data/lib/laser/runner.rb +189 -0
  89. data/lib/laser/scanner.rb +169 -0
  90. data/lib/laser/standard_library/_thread.rb +110 -0
  91. data/lib/laser/standard_library/abbrev.rb +103 -0
  92. data/lib/laser/standard_library/array.rb +418 -0
  93. data/lib/laser/standard_library/base64.rb +91 -0
  94. data/lib/laser/standard_library/basic_object.rb +55 -0
  95. data/lib/laser/standard_library/benchmark.rb +556 -0
  96. data/lib/laser/standard_library/bignum.rb +185 -0
  97. data/lib/laser/standard_library/cgi.rb +275 -0
  98. data/lib/laser/standard_library/cgi/cookie.rb +147 -0
  99. data/lib/laser/standard_library/cgi/core.rb +791 -0
  100. data/lib/laser/standard_library/cgi/html.rb +1021 -0
  101. data/lib/laser/standard_library/cgi/session.rb +537 -0
  102. data/lib/laser/standard_library/cgi/session/pstore.rb +111 -0
  103. data/lib/laser/standard_library/cgi/util.rb +188 -0
  104. data/lib/laser/standard_library/class_definitions.rb +333 -0
  105. data/lib/laser/standard_library/comparable.rb +125 -0
  106. data/lib/laser/standard_library/complex.rb +162 -0
  107. data/lib/laser/standard_library/enumerable.rb +178 -0
  108. data/lib/laser/standard_library/exceptions.rb +135 -0
  109. data/lib/laser/standard_library/fixnum.rb +188 -0
  110. data/lib/laser/standard_library/float.rb +180 -0
  111. data/lib/laser/standard_library/hash.rb +237 -0
  112. data/lib/laser/standard_library/integer.rb +123 -0
  113. data/lib/laser/standard_library/laser_magic.rb +7 -0
  114. data/lib/laser/standard_library/nil_false_true.rb +113 -0
  115. data/lib/laser/standard_library/numbers.rb +192 -0
  116. data/lib/laser/standard_library/proc.rb +31 -0
  117. data/lib/laser/standard_library/set.rb +1348 -0
  118. data/lib/laser/standard_library/string.rb +666 -0
  119. data/lib/laser/standard_library/stringio.rb +2 -0
  120. data/lib/laser/standard_library/symbol.rb +125 -0
  121. data/lib/laser/standard_library/tsort.rb +242 -0
  122. data/lib/laser/support/acts_as_struct.rb +66 -0
  123. data/lib/laser/support/frequency.rb +55 -0
  124. data/lib/laser/support/inheritable_attributes.rb +145 -0
  125. data/lib/laser/support/module_extensions.rb +94 -0
  126. data/lib/laser/support/placeholder_object.rb +13 -0
  127. data/lib/laser/third_party/rgl/adjacency.rb +221 -0
  128. data/lib/laser/third_party/rgl/base.rb +228 -0
  129. data/lib/laser/third_party/rgl/bidirectional.rb +39 -0
  130. data/lib/laser/third_party/rgl/condensation.rb +47 -0
  131. data/lib/laser/third_party/rgl/connected_components.rb +138 -0
  132. data/lib/laser/third_party/rgl/control_flow.rb +170 -0
  133. data/lib/laser/third_party/rgl/depth_first_spanning_tree.rb +37 -0
  134. data/lib/laser/third_party/rgl/dominators.rb +124 -0
  135. data/lib/laser/third_party/rgl/dot.rb +93 -0
  136. data/lib/laser/third_party/rgl/graphxml.rb +51 -0
  137. data/lib/laser/third_party/rgl/implicit.rb +174 -0
  138. data/lib/laser/third_party/rgl/mutable.rb +117 -0
  139. data/lib/laser/third_party/rgl/rdot.rb +445 -0
  140. data/lib/laser/third_party/rgl/topsort.rb +72 -0
  141. data/lib/laser/third_party/rgl/transitivity.rb +180 -0
  142. data/lib/laser/third_party/rgl/traversal.rb +348 -0
  143. data/lib/laser/types/types.rb +433 -0
  144. data/lib/laser/version.rb +14 -0
  145. data/lib/laser/warning.rb +149 -0
  146. data/lib/laser/warning_sets/default.yml +13 -0
  147. data/lib/laser/warnings/assignment_in_condition.rb +20 -0
  148. data/lib/laser/warnings/comment_spacing.rb +31 -0
  149. data/lib/laser/warnings/extra_blank_lines.rb +30 -0
  150. data/lib/laser/warnings/extra_whitespace.rb +16 -0
  151. data/lib/laser/warnings/hash_symbol_18_warning.rb +63 -0
  152. data/lib/laser/warnings/hash_symbol_19_warning.rb +29 -0
  153. data/lib/laser/warnings/line_length.rb +115 -0
  154. data/lib/laser/warnings/misaligned_unindentation.rb +17 -0
  155. data/lib/laser/warnings/operator_spacing.rb +68 -0
  156. data/lib/laser/warnings/parens_on_declaration.rb +30 -0
  157. data/lib/laser/warnings/rescue_exception.rb +42 -0
  158. data/lib/laser/warnings/semicolon.rb +25 -0
  159. data/lib/laser/warnings/sexp_errors.rb +24 -0
  160. data/lib/laser/warnings/uncalled_method_warning.rb +7 -0
  161. data/lib/laser/warnings/useless_double_quotes.rb +38 -0
  162. data/spec/analysis_specs/annotations_spec.rb +47 -0
  163. data/spec/analysis_specs/annotations_specs/comment_attachment_spec.rb +68 -0
  164. data/spec/analysis_specs/annotations_specs/node_pointers_annotation_spec.rb +90 -0
  165. data/spec/analysis_specs/annotations_specs/runtime_annotation_spec.rb +135 -0
  166. data/spec/analysis_specs/annotations_specs/spec_helper.rb +33 -0
  167. data/spec/analysis_specs/argument_expansion_spec.rb +113 -0
  168. data/spec/analysis_specs/bindings_spec.rb +36 -0
  169. data/spec/analysis_specs/comment_spec.rb +93 -0
  170. data/spec/analysis_specs/control_flow_specs/cfg_instruction_spec.rb +111 -0
  171. data/spec/analysis_specs/control_flow_specs/constant_propagation_spec.rb +560 -0
  172. data/spec/analysis_specs/control_flow_specs/control_flow_graph_spec.rb +5 -0
  173. data/spec/analysis_specs/control_flow_specs/raise_properties_spec.rb +310 -0
  174. data/spec/analysis_specs/control_flow_specs/raise_type_inference_spec.rb +301 -0
  175. data/spec/analysis_specs/control_flow_specs/return_type_inference_spec.rb +431 -0
  176. data/spec/analysis_specs/control_flow_specs/simulation_spec.rb +158 -0
  177. data/spec/analysis_specs/control_flow_specs/spec_helper.rb +110 -0
  178. data/spec/analysis_specs/control_flow_specs/tuple_misuse_inference_spec.rb +125 -0
  179. data/spec/analysis_specs/control_flow_specs/unreachability_analysis_spec.rb +76 -0
  180. data/spec/analysis_specs/control_flow_specs/unused_variable_spec.rb +99 -0
  181. data/spec/analysis_specs/control_flow_specs/yield_properties_spec.rb +372 -0
  182. data/spec/analysis_specs/error_spec.rb +30 -0
  183. data/spec/analysis_specs/laser_class_spec.rb +322 -0
  184. data/spec/analysis_specs/lexical_analysis_spec.rb +184 -0
  185. data/spec/analysis_specs/protocol_registry_spec.rb +63 -0
  186. data/spec/analysis_specs/scope_annotation_spec.rb +1013 -0
  187. data/spec/analysis_specs/scope_spec.rb +126 -0
  188. data/spec/analysis_specs/sexp_analysis_spec.rb +30 -0
  189. data/spec/analysis_specs/sexp_extension_specs/constant_extraction_spec.rb +309 -0
  190. data/spec/analysis_specs/sexp_extension_specs/source_location_spec.rb +231 -0
  191. data/spec/analysis_specs/sexp_extension_specs/spec_helper.rb +1 -0
  192. data/spec/analysis_specs/sexp_extension_specs/type_inference_spec.rb +252 -0
  193. data/spec/analysis_specs/sexp_spec.rb +167 -0
  194. data/spec/analysis_specs/spec_helper.rb +27 -0
  195. data/spec/analysis_specs/unused_methods_spec.rb +65 -0
  196. data/spec/analysis_specs/visitor_spec.rb +64 -0
  197. data/spec/annotation_parser_specs/annotations_parser_spec.rb +89 -0
  198. data/spec/annotation_parser_specs/class_annotation_parser_spec.rb +120 -0
  199. data/spec/annotation_parser_specs/overload_parser_spec.rb +39 -0
  200. data/spec/annotation_parser_specs/parsers_spec.rb +14 -0
  201. data/spec/annotation_parser_specs/spec_helper.rb +1 -0
  202. data/spec/annotation_parser_specs/structural_parser_spec.rb +67 -0
  203. data/spec/laser_spec.rb +14 -0
  204. data/spec/rake_specs/spec_helper.rb +1 -0
  205. data/spec/rake_specs/task_spec.rb +67 -0
  206. data/spec/runner_spec.rb +207 -0
  207. data/spec/scanner_spec.rb +75 -0
  208. data/spec/spec_helper.rb +121 -0
  209. data/spec/standard_library/exceptions_spec.rb +19 -0
  210. data/spec/standard_library/globals_spec.rb +14 -0
  211. data/spec/standard_library/set_spec.rb +31 -0
  212. data/spec/standard_library/spec_helper.rb +1 -0
  213. data/spec/standard_library/standard_library_spec.rb +302 -0
  214. data/spec/support_specs/acts_as_struct_spec.rb +94 -0
  215. data/spec/support_specs/frequency_spec.rb +23 -0
  216. data/spec/support_specs/module_extensions_spec.rb +117 -0
  217. data/spec/support_specs/spec_helper.rb +1 -0
  218. data/spec/type_specs/spec_helper.rb +1 -0
  219. data/spec/type_specs/types_spec.rb +133 -0
  220. data/spec/warning_spec.rb +95 -0
  221. data/spec/warning_specs/assignment_in_condition_spec.rb +68 -0
  222. data/spec/warning_specs/comment_spacing_spec.rb +65 -0
  223. data/spec/warning_specs/extra_blank_lines_spec.rb +70 -0
  224. data/spec/warning_specs/extra_whitespace_spec.rb +33 -0
  225. data/spec/warning_specs/hash_symbol_18_warning_spec.rb +89 -0
  226. data/spec/warning_specs/hash_symbol_19_warning_spec.rb +63 -0
  227. data/spec/warning_specs/line_length_spec.rb +173 -0
  228. data/spec/warning_specs/misaligned_unindentation_spec.rb +35 -0
  229. data/spec/warning_specs/operator_spacing_spec.rb +104 -0
  230. data/spec/warning_specs/parens_on_declaration_spec.rb +57 -0
  231. data/spec/warning_specs/rescue_exception_spec.rb +105 -0
  232. data/spec/warning_specs/semicolon_spec.rb +58 -0
  233. data/spec/warning_specs/spec_helper.rb +1 -0
  234. data/spec/warning_specs/useless_double_quotes_spec.rb +74 -0
  235. data/status_reports/2010/12/2010-12-14.md +163 -0
  236. data/status_reports/2010/12/2010-12-23.md +298 -0
  237. data/status_reports/2010/12/2010-12-24.md +6 -0
  238. data/test/third_party_tests/rgl_tests/TestComponents.rb +65 -0
  239. data/test/third_party_tests/rgl_tests/TestCycles.rb +61 -0
  240. data/test/third_party_tests/rgl_tests/TestDirectedGraph.rb +125 -0
  241. data/test/third_party_tests/rgl_tests/TestDot.rb +18 -0
  242. data/test/third_party_tests/rgl_tests/TestEdge.rb +34 -0
  243. data/test/third_party_tests/rgl_tests/TestGraph.rb +71 -0
  244. data/test/third_party_tests/rgl_tests/TestGraphXML.rb +57 -0
  245. data/test/third_party_tests/rgl_tests/TestImplicit.rb +52 -0
  246. data/test/third_party_tests/rgl_tests/TestRdot.rb +863 -0
  247. data/test/third_party_tests/rgl_tests/TestTransitivity.rb +129 -0
  248. data/test/third_party_tests/rgl_tests/TestTraversal.rb +220 -0
  249. data/test/third_party_tests/rgl_tests/TestUnDirectedGraph.rb +102 -0
  250. data/test/third_party_tests/rgl_tests/examples/north/Graph.log +128 -0
  251. data/test/third_party_tests/rgl_tests/examples/north/g.10.0.graphml +28 -0
  252. data/test/third_party_tests/rgl_tests/examples/north/g.10.1.graphml +28 -0
  253. data/test/third_party_tests/rgl_tests/examples/north/g.10.11.graphml +31 -0
  254. data/test/third_party_tests/rgl_tests/examples/north/g.10.12.graphml +27 -0
  255. data/test/third_party_tests/rgl_tests/examples/north/g.10.13.graphml +27 -0
  256. data/test/third_party_tests/rgl_tests/examples/north/g.10.14.graphml +27 -0
  257. data/test/third_party_tests/rgl_tests/examples/north/g.10.15.graphml +26 -0
  258. data/test/third_party_tests/rgl_tests/examples/north/g.10.16.graphml +26 -0
  259. data/test/third_party_tests/rgl_tests/examples/north/g.10.17.graphml +26 -0
  260. data/test/third_party_tests/rgl_tests/examples/north/g.10.19.graphml +37 -0
  261. data/test/third_party_tests/rgl_tests/examples/north/g.10.2.graphml +28 -0
  262. data/test/third_party_tests/rgl_tests/examples/north/g.10.20.graphml +38 -0
  263. data/test/third_party_tests/rgl_tests/examples/north/g.10.22.graphml +43 -0
  264. data/test/third_party_tests/rgl_tests/examples/north/g.10.24.graphml +30 -0
  265. data/test/third_party_tests/rgl_tests/examples/north/g.10.25.graphml +45 -0
  266. data/test/third_party_tests/rgl_tests/examples/north/g.10.27.graphml +38 -0
  267. data/test/third_party_tests/rgl_tests/examples/north/g.10.28.graphml +30 -0
  268. data/test/third_party_tests/rgl_tests/examples/north/g.10.29.graphml +38 -0
  269. data/test/third_party_tests/rgl_tests/examples/north/g.10.3.graphml +26 -0
  270. data/test/third_party_tests/rgl_tests/examples/north/g.10.30.graphml +34 -0
  271. data/test/third_party_tests/rgl_tests/examples/north/g.10.31.graphml +42 -0
  272. data/test/third_party_tests/rgl_tests/examples/north/g.10.34.graphml +42 -0
  273. data/test/third_party_tests/rgl_tests/examples/north/g.10.37.graphml +28 -0
  274. data/test/third_party_tests/rgl_tests/examples/north/g.10.38.graphml +38 -0
  275. data/test/third_party_tests/rgl_tests/examples/north/g.10.39.graphml +36 -0
  276. data/test/third_party_tests/rgl_tests/examples/north/g.10.4.graphml +26 -0
  277. data/test/third_party_tests/rgl_tests/examples/north/g.10.40.graphml +37 -0
  278. data/test/third_party_tests/rgl_tests/examples/north/g.10.41.graphml +37 -0
  279. data/test/third_party_tests/rgl_tests/examples/north/g.10.42.graphml +26 -0
  280. data/test/third_party_tests/rgl_tests/examples/north/g.10.45.graphml +28 -0
  281. data/test/third_party_tests/rgl_tests/examples/north/g.10.46.graphml +32 -0
  282. data/test/third_party_tests/rgl_tests/examples/north/g.10.5.graphml +31 -0
  283. data/test/third_party_tests/rgl_tests/examples/north/g.10.50.graphml +30 -0
  284. data/test/third_party_tests/rgl_tests/examples/north/g.10.56.graphml +29 -0
  285. data/test/third_party_tests/rgl_tests/examples/north/g.10.57.graphml +32 -0
  286. data/test/third_party_tests/rgl_tests/examples/north/g.10.58.graphml +32 -0
  287. data/test/third_party_tests/rgl_tests/examples/north/g.10.6.graphml +26 -0
  288. data/test/third_party_tests/rgl_tests/examples/north/g.10.60.graphml +32 -0
  289. data/test/third_party_tests/rgl_tests/examples/north/g.10.61.graphml +34 -0
  290. data/test/third_party_tests/rgl_tests/examples/north/g.10.62.graphml +34 -0
  291. data/test/third_party_tests/rgl_tests/examples/north/g.10.68.graphml +30 -0
  292. data/test/third_party_tests/rgl_tests/examples/north/g.10.69.graphml +32 -0
  293. data/test/third_party_tests/rgl_tests/examples/north/g.10.7.graphml +29 -0
  294. data/test/third_party_tests/rgl_tests/examples/north/g.10.70.graphml +26 -0
  295. data/test/third_party_tests/rgl_tests/examples/north/g.10.71.graphml +27 -0
  296. data/test/third_party_tests/rgl_tests/examples/north/g.10.72.graphml +28 -0
  297. data/test/third_party_tests/rgl_tests/examples/north/g.10.74.graphml +29 -0
  298. data/test/third_party_tests/rgl_tests/examples/north/g.10.75.graphml +29 -0
  299. data/test/third_party_tests/rgl_tests/examples/north/g.10.78.graphml +27 -0
  300. data/test/third_party_tests/rgl_tests/examples/north/g.10.79.graphml +34 -0
  301. data/test/third_party_tests/rgl_tests/examples/north/g.10.8.graphml +29 -0
  302. data/test/third_party_tests/rgl_tests/examples/north/g.10.80.graphml +34 -0
  303. data/test/third_party_tests/rgl_tests/examples/north/g.10.82.graphml +35 -0
  304. data/test/third_party_tests/rgl_tests/examples/north/g.10.83.graphml +32 -0
  305. data/test/third_party_tests/rgl_tests/examples/north/g.10.85.graphml +34 -0
  306. data/test/third_party_tests/rgl_tests/examples/north/g.10.86.graphml +34 -0
  307. data/test/third_party_tests/rgl_tests/examples/north/g.10.88.graphml +37 -0
  308. data/test/third_party_tests/rgl_tests/examples/north/g.10.89.graphml +29 -0
  309. data/test/third_party_tests/rgl_tests/examples/north/g.10.9.graphml +26 -0
  310. data/test/third_party_tests/rgl_tests/examples/north/g.10.90.graphml +32 -0
  311. data/test/third_party_tests/rgl_tests/examples/north/g.10.91.graphml +31 -0
  312. data/test/third_party_tests/rgl_tests/examples/north/g.10.92.graphml +26 -0
  313. data/test/third_party_tests/rgl_tests/examples/north/g.10.93.graphml +32 -0
  314. data/test/third_party_tests/rgl_tests/examples/north/g.10.94.graphml +34 -0
  315. data/test/third_party_tests/rgl_tests/examples/north/g.12.8.graphml +40 -0
  316. data/test/third_party_tests/rgl_tests/examples/north/g.14.9.graphml +36 -0
  317. data/test/third_party_tests/rgl_tests/test_helper.rb +7 -0
  318. data/test/third_party_tests/test_inheritable_attributes.rb +187 -0
  319. metadata +470 -0
@@ -0,0 +1,1021 @@
1
+ # Base module for HTML-generation mixins.
2
+ #
3
+ # Provides methods for code generation for tags following
4
+ # the various DTD element types.
5
+ class CGI
6
+ module TagMaker # :nodoc:
7
+
8
+ # Generate code for an element with required start and end tags.
9
+ #
10
+ # - -
11
+ def nn_element_def(element)
12
+ nOE_element_def(element, <<-END)
13
+ if block_given?
14
+ yield.to_s
15
+ else
16
+ ""
17
+ end +
18
+ "</#{element.upcase}>"
19
+ END
20
+ end
21
+
22
+ # Generate code for an empty element.
23
+ #
24
+ # - O EMPTY
25
+ def nOE_element_def(element, append = nil)
26
+ s = <<-END
27
+ attributes={attributes=>nil} if attributes.kind_of?(String)
28
+ "<#{element.upcase}" + attributes.collect{|name, value|
29
+ next unless value
30
+ " " + CGI::escapeHTML(name.to_s) +
31
+ if true == value
32
+ ""
33
+ else
34
+ '="' + CGI::escapeHTML(value.to_s) + '"'
35
+ end
36
+ }.join + ">"
37
+ END
38
+ s.sub!(/\Z/, " +") << append if append
39
+ s
40
+ end
41
+
42
+ # Generate code for an element for which the end (and possibly the
43
+ # start) tag is optional.
44
+ #
45
+ # O O or - O
46
+ def nO_element_def(element)
47
+ nOE_element_def(element, <<-END)
48
+ if block_given?
49
+ yield.to_s + "</#{element.upcase}>"
50
+ else
51
+ ""
52
+ end
53
+ END
54
+ end
55
+
56
+ end # TagMaker
57
+
58
+
59
+ #
60
+ # Mixin module providing HTML generation methods.
61
+ #
62
+ # For example,
63
+ # cgi.a("http://www.example.com") { "Example" }
64
+ # # => "<A HREF=\"http://www.example.com\">Example</A>"
65
+ #
66
+ # Modules Http3, Http4, etc., contain more basic HTML-generation methods
67
+ # (:title, :center, etc.).
68
+ #
69
+ # See class CGI for a detailed example.
70
+ #
71
+ module HtmlExtension
72
+
73
+
74
+ # Generate an Anchor element as a string.
75
+ #
76
+ # +href+ can either be a string, giving the URL
77
+ # for the HREF attribute, or it can be a hash of
78
+ # the element's attributes.
79
+ #
80
+ # The body of the element is the string returned by the no-argument
81
+ # block passed in.
82
+ #
83
+ # a("http://www.example.com") { "Example" }
84
+ # # => "<A HREF=\"http://www.example.com\">Example</A>"
85
+ #
86
+ # a("HREF" => "http://www.example.com", "TARGET" => "_top") { "Example" }
87
+ # # => "<A HREF=\"http://www.example.com\" TARGET=\"_top\">Example</A>"
88
+ #
89
+ def a(href = "") # :yield:
90
+ attributes = if href.kind_of?(String)
91
+ { "HREF" => href }
92
+ else
93
+ href
94
+ end
95
+ if block_given?
96
+ super(attributes){ yield }
97
+ else
98
+ super(attributes)
99
+ end
100
+ end
101
+
102
+ # Generate a Document Base URI element as a String.
103
+ #
104
+ # +href+ can either by a string, giving the base URL for the HREF
105
+ # attribute, or it can be a has of the element's attributes.
106
+ #
107
+ # The passed-in no-argument block is ignored.
108
+ #
109
+ # base("http://www.example.com/cgi")
110
+ # # => "<BASE HREF=\"http://www.example.com/cgi\">"
111
+ def base(href = "") # :yield:
112
+ attributes = if href.kind_of?(String)
113
+ { "HREF" => href }
114
+ else
115
+ href
116
+ end
117
+ if block_given?
118
+ super(attributes){ yield }
119
+ else
120
+ super(attributes)
121
+ end
122
+ end
123
+
124
+ # Generate a BlockQuote element as a string.
125
+ #
126
+ # +cite+ can either be a string, give the URI for the source of
127
+ # the quoted text, or a hash, giving all attributes of the element,
128
+ # or it can be omitted, in which case the element has no attributes.
129
+ #
130
+ # The body is provided by the passed-in no-argument block
131
+ #
132
+ # blockquote("http://www.example.com/quotes/foo.html") { "Foo!" }
133
+ # #=> "<BLOCKQUOTE CITE=\"http://www.example.com/quotes/foo.html\">Foo!</BLOCKQUOTE>
134
+ def blockquote(cite = {}) # :yield:
135
+ attributes = if cite.kind_of?(String)
136
+ { "CITE" => cite }
137
+ else
138
+ cite
139
+ end
140
+ if block_given?
141
+ super(attributes){ yield }
142
+ else
143
+ super(attributes)
144
+ end
145
+ end
146
+
147
+
148
+ # Generate a Table Caption element as a string.
149
+ #
150
+ # +align+ can be a string, giving the alignment of the caption
151
+ # (one of top, bottom, left, or right). It can be a hash of
152
+ # all the attributes of the element. Or it can be omitted.
153
+ #
154
+ # The body of the element is provided by the passed-in no-argument block.
155
+ #
156
+ # caption("left") { "Capital Cities" }
157
+ # # => <CAPTION ALIGN=\"left\">Capital Cities</CAPTION>
158
+ def caption(align = {}) # :yield:
159
+ attributes = if align.kind_of?(String)
160
+ { "ALIGN" => align }
161
+ else
162
+ align
163
+ end
164
+ if block_given?
165
+ super(attributes){ yield }
166
+ else
167
+ super(attributes)
168
+ end
169
+ end
170
+
171
+
172
+ # Generate a Checkbox Input element as a string.
173
+ #
174
+ # The attributes of the element can be specified as three arguments,
175
+ # +name+, +value+, and +checked+. +checked+ is a boolean value;
176
+ # if true, the CHECKED attribute will be included in the element.
177
+ #
178
+ # Alternatively, the attributes can be specified as a hash.
179
+ #
180
+ # checkbox("name")
181
+ # # = checkbox("NAME" => "name")
182
+ #
183
+ # checkbox("name", "value")
184
+ # # = checkbox("NAME" => "name", "VALUE" => "value")
185
+ #
186
+ # checkbox("name", "value", true)
187
+ # # = checkbox("NAME" => "name", "VALUE" => "value", "CHECKED" => true)
188
+ def checkbox(name = "", value = nil, checked = nil)
189
+ attributes = if name.kind_of?(String)
190
+ { "TYPE" => "checkbox", "NAME" => name,
191
+ "VALUE" => value, "CHECKED" => checked }
192
+ else
193
+ name["TYPE"] = "checkbox"
194
+ name
195
+ end
196
+ input(attributes)
197
+ end
198
+
199
+ # Generate a sequence of checkbox elements, as a String.
200
+ #
201
+ # The checkboxes will all have the same +name+ attribute.
202
+ # Each checkbox is followed by a label.
203
+ # There will be one checkbox for each value. Each value
204
+ # can be specified as a String, which will be used both
205
+ # as the value of the VALUE attribute and as the label
206
+ # for that checkbox. A single-element array has the
207
+ # same effect.
208
+ #
209
+ # Each value can also be specified as a three-element array.
210
+ # The first element is the VALUE attribute; the second is the
211
+ # label; and the third is a boolean specifying whether this
212
+ # checkbox is CHECKED.
213
+ #
214
+ # Each value can also be specified as a two-element
215
+ # array, by omitting either the value element (defaults
216
+ # to the same as the label), or the boolean checked element
217
+ # (defaults to false).
218
+ #
219
+ # checkbox_group("name", "foo", "bar", "baz")
220
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
221
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="bar">bar
222
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
223
+ #
224
+ # checkbox_group("name", ["foo"], ["bar", true], "baz")
225
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="foo">foo
226
+ # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="bar">bar
227
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="baz">baz
228
+ #
229
+ # checkbox_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
230
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="1">Foo
231
+ # # <INPUT TYPE="checkbox" CHECKED NAME="name" VALUE="2">Bar
232
+ # # <INPUT TYPE="checkbox" NAME="name" VALUE="Baz">Baz
233
+ #
234
+ # checkbox_group("NAME" => "name",
235
+ # "VALUES" => ["foo", "bar", "baz"])
236
+ #
237
+ # checkbox_group("NAME" => "name",
238
+ # "VALUES" => [["foo"], ["bar", true], "baz"])
239
+ #
240
+ # checkbox_group("NAME" => "name",
241
+ # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
242
+ def checkbox_group(name = "", *values)
243
+ if name.kind_of?(Hash)
244
+ values = name["VALUES"]
245
+ name = name["NAME"]
246
+ end
247
+ values.collect{|value|
248
+ if value.kind_of?(String)
249
+ checkbox(name, value) + value
250
+ else
251
+ if value[-1] == true || value[-1] == false
252
+ checkbox(name, value[0], value[-1]) +
253
+ value[-2]
254
+ else
255
+ checkbox(name, value[0]) +
256
+ value[-1]
257
+ end
258
+ end
259
+ }.join
260
+ end
261
+
262
+
263
+ # Generate an File Upload Input element as a string.
264
+ #
265
+ # The attributes of the element can be specified as three arguments,
266
+ # +name+, +size+, and +maxlength+. +maxlength+ is the maximum length
267
+ # of the file's _name_, not of the file's _contents_.
268
+ #
269
+ # Alternatively, the attributes can be specified as a hash.
270
+ #
271
+ # See #multipart_form() for forms that include file uploads.
272
+ #
273
+ # file_field("name")
274
+ # # <INPUT TYPE="file" NAME="name" SIZE="20">
275
+ #
276
+ # file_field("name", 40)
277
+ # # <INPUT TYPE="file" NAME="name" SIZE="40">
278
+ #
279
+ # file_field("name", 40, 100)
280
+ # # <INPUT TYPE="file" NAME="name" SIZE="40" MAXLENGTH="100">
281
+ #
282
+ # file_field("NAME" => "name", "SIZE" => 40)
283
+ # # <INPUT TYPE="file" NAME="name" SIZE="40">
284
+ def file_field(name = "", size = 20, maxlength = nil)
285
+ attributes = if name.kind_of?(String)
286
+ { "TYPE" => "file", "NAME" => name,
287
+ "SIZE" => size.to_s }
288
+ else
289
+ name["TYPE"] = "file"
290
+ name
291
+ end
292
+ attributes["MAXLENGTH"] = maxlength.to_s if maxlength
293
+ input(attributes)
294
+ end
295
+
296
+
297
+ # Generate a Form element as a string.
298
+ #
299
+ # +method+ should be either "get" or "post", and defaults to the latter.
300
+ # +action+ defaults to the current CGI script name. +enctype+
301
+ # defaults to "application/x-www-form-urlencoded".
302
+ #
303
+ # Alternatively, the attributes can be specified as a hash.
304
+ #
305
+ # See also #multipart_form() for forms that include file uploads.
306
+ #
307
+ # form{ "string" }
308
+ # # <FORM METHOD="post" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
309
+ #
310
+ # form("get") { "string" }
311
+ # # <FORM METHOD="get" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
312
+ #
313
+ # form("get", "url") { "string" }
314
+ # # <FORM METHOD="get" ACTION="url" ENCTYPE="application/x-www-form-urlencoded">string</FORM>
315
+ #
316
+ # form("METHOD" => "post", "ENCTYPE" => "enctype") { "string" }
317
+ # # <FORM METHOD="post" ENCTYPE="enctype">string</FORM>
318
+ def form(method = "post", action = script_name, enctype = "application/x-www-form-urlencoded")
319
+ attributes = if method.kind_of?(String)
320
+ { "METHOD" => method, "ACTION" => action,
321
+ "ENCTYPE" => enctype }
322
+ else
323
+ unless method.has_key?("METHOD")
324
+ method["METHOD"] = "post"
325
+ end
326
+ unless method.has_key?("ENCTYPE")
327
+ method["ENCTYPE"] = enctype
328
+ end
329
+ method
330
+ end
331
+ if block_given?
332
+ body = yield
333
+ else
334
+ body = ""
335
+ end
336
+ if @output_hidden
337
+ body += @output_hidden.collect{|k,v|
338
+ "<INPUT TYPE=\"HIDDEN\" NAME=\"#{k}\" VALUE=\"#{v}\">"
339
+ }.join
340
+ end
341
+ super(attributes){body}
342
+ end
343
+
344
+ # Generate a Hidden Input element as a string.
345
+ #
346
+ # The attributes of the element can be specified as two arguments,
347
+ # +name+ and +value+.
348
+ #
349
+ # Alternatively, the attributes can be specified as a hash.
350
+ #
351
+ # hidden("name")
352
+ # # <INPUT TYPE="hidden" NAME="name">
353
+ #
354
+ # hidden("name", "value")
355
+ # # <INPUT TYPE="hidden" NAME="name" VALUE="value">
356
+ #
357
+ # hidden("NAME" => "name", "VALUE" => "reset", "ID" => "foo")
358
+ # # <INPUT TYPE="hidden" NAME="name" VALUE="value" ID="foo">
359
+ def hidden(name = "", value = nil)
360
+ attributes = if name.kind_of?(String)
361
+ { "TYPE" => "hidden", "NAME" => name, "VALUE" => value }
362
+ else
363
+ name["TYPE"] = "hidden"
364
+ name
365
+ end
366
+ input(attributes)
367
+ end
368
+
369
+ # Generate a top-level HTML element as a string.
370
+ #
371
+ # The attributes of the element are specified as a hash. The
372
+ # pseudo-attribute "PRETTY" can be used to specify that the generated
373
+ # HTML string should be indented. "PRETTY" can also be specified as
374
+ # a string as the sole argument to this method. The pseudo-attribute
375
+ # "DOCTYPE", if given, is used as the leading DOCTYPE SGML tag; it
376
+ # should include the entire text of this tag, including angle brackets.
377
+ #
378
+ # The body of the html element is supplied as a block.
379
+ #
380
+ # html{ "string" }
381
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML>string</HTML>
382
+ #
383
+ # html("LANG" => "ja") { "string" }
384
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><HTML LANG="ja">string</HTML>
385
+ #
386
+ # html("DOCTYPE" => false) { "string" }
387
+ # # <HTML>string</HTML>
388
+ #
389
+ # html("DOCTYPE" => '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">') { "string" }
390
+ # # <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>string</HTML>
391
+ #
392
+ # html("PRETTY" => " ") { "<BODY></BODY>" }
393
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
394
+ # # <HTML>
395
+ # # <BODY>
396
+ # # </BODY>
397
+ # # </HTML>
398
+ #
399
+ # html("PRETTY" => "\t") { "<BODY></BODY>" }
400
+ # # <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
401
+ # # <HTML>
402
+ # # <BODY>
403
+ # # </BODY>
404
+ # # </HTML>
405
+ #
406
+ # html("PRETTY") { "<BODY></BODY>" }
407
+ # # = html("PRETTY" => " ") { "<BODY></BODY>" }
408
+ #
409
+ # html(if $VERBOSE then "PRETTY" end) { "HTML string" }
410
+ #
411
+ def html(attributes = {}) # :yield:
412
+ if nil == attributes
413
+ attributes = {}
414
+ elsif "PRETTY" == attributes
415
+ attributes = { "PRETTY" => true }
416
+ end
417
+ pretty = attributes.delete("PRETTY")
418
+ pretty = " " if true == pretty
419
+ buf = ""
420
+
421
+ if attributes.has_key?("DOCTYPE")
422
+ if attributes["DOCTYPE"]
423
+ buf += attributes.delete("DOCTYPE")
424
+ else
425
+ attributes.delete("DOCTYPE")
426
+ end
427
+ else
428
+ buf += doctype
429
+ end
430
+
431
+ if block_given?
432
+ buf += super(attributes){ yield }
433
+ else
434
+ buf += super(attributes)
435
+ end
436
+
437
+ if pretty
438
+ CGI::pretty(buf, pretty)
439
+ else
440
+ buf
441
+ end
442
+
443
+ end
444
+
445
+ # Generate an Image Button Input element as a string.
446
+ #
447
+ # +src+ is the URL of the image to use for the button. +name+
448
+ # is the input name. +alt+ is the alternative text for the image.
449
+ #
450
+ # Alternatively, the attributes can be specified as a hash.
451
+ #
452
+ # image_button("url")
453
+ # # <INPUT TYPE="image" SRC="url">
454
+ #
455
+ # image_button("url", "name", "string")
456
+ # # <INPUT TYPE="image" SRC="url" NAME="name" ALT="string">
457
+ #
458
+ # image_button("SRC" => "url", "ALT" => "string")
459
+ # # <INPUT TYPE="image" SRC="url" ALT="string">
460
+ def image_button(src = "", name = nil, alt = nil)
461
+ attributes = if src.kind_of?(String)
462
+ { "TYPE" => "image", "SRC" => src, "NAME" => name,
463
+ "ALT" => alt }
464
+ else
465
+ src["TYPE"] = "image"
466
+ src["SRC"] ||= ""
467
+ src
468
+ end
469
+ input(attributes)
470
+ end
471
+
472
+
473
+ # Generate an Image element as a string.
474
+ #
475
+ # +src+ is the URL of the image. +alt+ is the alternative text for
476
+ # the image. +width+ is the width of the image, and +height+ is
477
+ # its height.
478
+ #
479
+ # Alternatively, the attributes can be specified as a hash.
480
+ #
481
+ # img("src", "alt", 100, 50)
482
+ # # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
483
+ #
484
+ # img("SRC" => "src", "ALT" => "alt", "WIDTH" => 100, "HEIGHT" => 50)
485
+ # # <IMG SRC="src" ALT="alt" WIDTH="100" HEIGHT="50">
486
+ def img(src = "", alt = "", width = nil, height = nil)
487
+ attributes = if src.kind_of?(String)
488
+ { "SRC" => src, "ALT" => alt }
489
+ else
490
+ src
491
+ end
492
+ attributes["WIDTH"] = width.to_s if width
493
+ attributes["HEIGHT"] = height.to_s if height
494
+ super(attributes)
495
+ end
496
+
497
+
498
+ # Generate a Form element with multipart encoding as a String.
499
+ #
500
+ # Multipart encoding is used for forms that include file uploads.
501
+ #
502
+ # +action+ is the action to perform. +enctype+ is the encoding
503
+ # type, which defaults to "multipart/form-data".
504
+ #
505
+ # Alternatively, the attributes can be specified as a hash.
506
+ #
507
+ # multipart_form{ "string" }
508
+ # # <FORM METHOD="post" ENCTYPE="multipart/form-data">string</FORM>
509
+ #
510
+ # multipart_form("url") { "string" }
511
+ # # <FORM METHOD="post" ACTION="url" ENCTYPE="multipart/form-data">string</FORM>
512
+ def multipart_form(action = nil, enctype = "multipart/form-data")
513
+ attributes = if action == nil
514
+ { "METHOD" => "post", "ENCTYPE" => enctype }
515
+ elsif action.kind_of?(String)
516
+ { "METHOD" => "post", "ACTION" => action,
517
+ "ENCTYPE" => enctype }
518
+ else
519
+ unless action.has_key?("METHOD")
520
+ action["METHOD"] = "post"
521
+ end
522
+ unless action.has_key?("ENCTYPE")
523
+ action["ENCTYPE"] = enctype
524
+ end
525
+ action
526
+ end
527
+ if block_given?
528
+ form(attributes){ yield }
529
+ else
530
+ form(attributes)
531
+ end
532
+ end
533
+
534
+
535
+ # Generate a Password Input element as a string.
536
+ #
537
+ # +name+ is the name of the input field. +value+ is its default
538
+ # value. +size+ is the size of the input field display. +maxlength+
539
+ # is the maximum length of the inputted password.
540
+ #
541
+ # Alternatively, attributes can be specified as a hash.
542
+ #
543
+ # password_field("name")
544
+ # # <INPUT TYPE="password" NAME="name" SIZE="40">
545
+ #
546
+ # password_field("name", "value")
547
+ # # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="40">
548
+ #
549
+ # password_field("password", "value", 80, 200)
550
+ # # <INPUT TYPE="password" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
551
+ #
552
+ # password_field("NAME" => "name", "VALUE" => "value")
553
+ # # <INPUT TYPE="password" NAME="name" VALUE="value">
554
+ def password_field(name = "", value = nil, size = 40, maxlength = nil)
555
+ attributes = if name.kind_of?(String)
556
+ { "TYPE" => "password", "NAME" => name,
557
+ "VALUE" => value, "SIZE" => size.to_s }
558
+ else
559
+ name["TYPE"] = "password"
560
+ name
561
+ end
562
+ attributes["MAXLENGTH"] = maxlength.to_s if maxlength
563
+ input(attributes)
564
+ end
565
+
566
+ # Generate a Select element as a string.
567
+ #
568
+ # +name+ is the name of the element. The +values+ are the options that
569
+ # can be selected from the Select menu. Each value can be a String or
570
+ # a one, two, or three-element Array. If a String or a one-element
571
+ # Array, this is both the value of that option and the text displayed for
572
+ # it. If a three-element Array, the elements are the option value, displayed
573
+ # text, and a boolean value specifying whether this option starts as selected.
574
+ # The two-element version omits either the option value (defaults to the same
575
+ # as the display text) or the boolean selected specifier (defaults to false).
576
+ #
577
+ # The attributes and options can also be specified as a hash. In this
578
+ # case, options are specified as an array of values as described above,
579
+ # with the hash key of "VALUES".
580
+ #
581
+ # popup_menu("name", "foo", "bar", "baz")
582
+ # # <SELECT NAME="name">
583
+ # # <OPTION VALUE="foo">foo</OPTION>
584
+ # # <OPTION VALUE="bar">bar</OPTION>
585
+ # # <OPTION VALUE="baz">baz</OPTION>
586
+ # # </SELECT>
587
+ #
588
+ # popup_menu("name", ["foo"], ["bar", true], "baz")
589
+ # # <SELECT NAME="name">
590
+ # # <OPTION VALUE="foo">foo</OPTION>
591
+ # # <OPTION VALUE="bar" SELECTED>bar</OPTION>
592
+ # # <OPTION VALUE="baz">baz</OPTION>
593
+ # # </SELECT>
594
+ #
595
+ # popup_menu("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
596
+ # # <SELECT NAME="name">
597
+ # # <OPTION VALUE="1">Foo</OPTION>
598
+ # # <OPTION SELECTED VALUE="2">Bar</OPTION>
599
+ # # <OPTION VALUE="Baz">Baz</OPTION>
600
+ # # </SELECT>
601
+ #
602
+ # popup_menu("NAME" => "name", "SIZE" => 2, "MULTIPLE" => true,
603
+ # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
604
+ # # <SELECT NAME="name" MULTIPLE SIZE="2">
605
+ # # <OPTION VALUE="1">Foo</OPTION>
606
+ # # <OPTION SELECTED VALUE="2">Bar</OPTION>
607
+ # # <OPTION VALUE="Baz">Baz</OPTION>
608
+ # # </SELECT>
609
+ def popup_menu(name = "", *values)
610
+
611
+ if name.kind_of?(Hash)
612
+ values = name["VALUES"]
613
+ size = name["SIZE"].to_s if name["SIZE"]
614
+ multiple = name["MULTIPLE"]
615
+ name = name["NAME"]
616
+ else
617
+ size = nil
618
+ multiple = nil
619
+ end
620
+
621
+ select({ "NAME" => name, "SIZE" => size,
622
+ "MULTIPLE" => multiple }){
623
+ values.collect{|value|
624
+ if value.kind_of?(String)
625
+ option({ "VALUE" => value }){ value }
626
+ else
627
+ if value[value.size - 1] == true
628
+ option({ "VALUE" => value[0], "SELECTED" => true }){
629
+ value[value.size - 2]
630
+ }
631
+ else
632
+ option({ "VALUE" => value[0] }){
633
+ value[value.size - 1]
634
+ }
635
+ end
636
+ end
637
+ }.join
638
+ }
639
+
640
+ end
641
+
642
+ # Generates a radio-button Input element.
643
+ #
644
+ # +name+ is the name of the input field. +value+ is the value of
645
+ # the field if checked. +checked+ specifies whether the field
646
+ # starts off checked.
647
+ #
648
+ # Alternatively, the attributes can be specified as a hash.
649
+ #
650
+ # radio_button("name", "value")
651
+ # # <INPUT TYPE="radio" NAME="name" VALUE="value">
652
+ #
653
+ # radio_button("name", "value", true)
654
+ # # <INPUT TYPE="radio" NAME="name" VALUE="value" CHECKED>
655
+ #
656
+ # radio_button("NAME" => "name", "VALUE" => "value", "ID" => "foo")
657
+ # # <INPUT TYPE="radio" NAME="name" VALUE="value" ID="foo">
658
+ def radio_button(name = "", value = nil, checked = nil)
659
+ attributes = if name.kind_of?(String)
660
+ { "TYPE" => "radio", "NAME" => name,
661
+ "VALUE" => value, "CHECKED" => checked }
662
+ else
663
+ name["TYPE"] = "radio"
664
+ name
665
+ end
666
+ input(attributes)
667
+ end
668
+
669
+ # Generate a sequence of radio button Input elements, as a String.
670
+ #
671
+ # This works the same as #checkbox_group(). However, it is not valid
672
+ # to have more than one radiobutton in a group checked.
673
+ #
674
+ # radio_group("name", "foo", "bar", "baz")
675
+ # # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
676
+ # # <INPUT TYPE="radio" NAME="name" VALUE="bar">bar
677
+ # # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
678
+ #
679
+ # radio_group("name", ["foo"], ["bar", true], "baz")
680
+ # # <INPUT TYPE="radio" NAME="name" VALUE="foo">foo
681
+ # # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="bar">bar
682
+ # # <INPUT TYPE="radio" NAME="name" VALUE="baz">baz
683
+ #
684
+ # radio_group("name", ["1", "Foo"], ["2", "Bar", true], "Baz")
685
+ # # <INPUT TYPE="radio" NAME="name" VALUE="1">Foo
686
+ # # <INPUT TYPE="radio" CHECKED NAME="name" VALUE="2">Bar
687
+ # # <INPUT TYPE="radio" NAME="name" VALUE="Baz">Baz
688
+ #
689
+ # radio_group("NAME" => "name",
690
+ # "VALUES" => ["foo", "bar", "baz"])
691
+ #
692
+ # radio_group("NAME" => "name",
693
+ # "VALUES" => [["foo"], ["bar", true], "baz"])
694
+ #
695
+ # radio_group("NAME" => "name",
696
+ # "VALUES" => [["1", "Foo"], ["2", "Bar", true], "Baz"])
697
+ def radio_group(name = "", *values)
698
+ if name.kind_of?(Hash)
699
+ values = name["VALUES"]
700
+ name = name["NAME"]
701
+ end
702
+ values.collect{|value|
703
+ if value.kind_of?(String)
704
+ radio_button(name, value) + value
705
+ else
706
+ if value[-1] == true || value[-1] == false
707
+ radio_button(name, value[0], value[-1]) +
708
+ value[-2]
709
+ else
710
+ radio_button(name, value[0]) +
711
+ value[-1]
712
+ end
713
+ end
714
+ }.join
715
+ end
716
+
717
+ # Generate a reset button Input element, as a String.
718
+ #
719
+ # This resets the values on a form to their initial values. +value+
720
+ # is the text displayed on the button. +name+ is the name of this button.
721
+ #
722
+ # Alternatively, the attributes can be specified as a hash.
723
+ #
724
+ # reset
725
+ # # <INPUT TYPE="reset">
726
+ #
727
+ # reset("reset")
728
+ # # <INPUT TYPE="reset" VALUE="reset">
729
+ #
730
+ # reset("VALUE" => "reset", "ID" => "foo")
731
+ # # <INPUT TYPE="reset" VALUE="reset" ID="foo">
732
+ def reset(value = nil, name = nil)
733
+ attributes = if (not value) or value.kind_of?(String)
734
+ { "TYPE" => "reset", "VALUE" => value, "NAME" => name }
735
+ else
736
+ value["TYPE"] = "reset"
737
+ value
738
+ end
739
+ input(attributes)
740
+ end
741
+
742
+ alias scrolling_list popup_menu
743
+
744
+ # Generate a submit button Input element, as a String.
745
+ #
746
+ # +value+ is the text to display on the button. +name+ is the name
747
+ # of the input.
748
+ #
749
+ # Alternatively, the attributes can be specified as a hash.
750
+ #
751
+ # submit
752
+ # # <INPUT TYPE="submit">
753
+ #
754
+ # submit("ok")
755
+ # # <INPUT TYPE="submit" VALUE="ok">
756
+ #
757
+ # submit("ok", "button1")
758
+ # # <INPUT TYPE="submit" VALUE="ok" NAME="button1">
759
+ #
760
+ # submit("VALUE" => "ok", "NAME" => "button1", "ID" => "foo")
761
+ # # <INPUT TYPE="submit" VALUE="ok" NAME="button1" ID="foo">
762
+ def submit(value = nil, name = nil)
763
+ attributes = if (not value) or value.kind_of?(String)
764
+ { "TYPE" => "submit", "VALUE" => value, "NAME" => name }
765
+ else
766
+ value["TYPE"] = "submit"
767
+ value
768
+ end
769
+ input(attributes)
770
+ end
771
+
772
+ # Generate a text field Input element, as a String.
773
+ #
774
+ # +name+ is the name of the input field. +value+ is its initial
775
+ # value. +size+ is the size of the input area. +maxlength+
776
+ # is the maximum length of input accepted.
777
+ #
778
+ # Alternatively, the attributes can be specified as a hash.
779
+ #
780
+ # text_field("name")
781
+ # # <INPUT TYPE="text" NAME="name" SIZE="40">
782
+ #
783
+ # text_field("name", "value")
784
+ # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="40">
785
+ #
786
+ # text_field("name", "value", 80)
787
+ # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80">
788
+ #
789
+ # text_field("name", "value", 80, 200)
790
+ # # <INPUT TYPE="text" NAME="name" VALUE="value" SIZE="80" MAXLENGTH="200">
791
+ #
792
+ # text_field("NAME" => "name", "VALUE" => "value")
793
+ # # <INPUT TYPE="text" NAME="name" VALUE="value">
794
+ def text_field(name = "", value = nil, size = 40, maxlength = nil)
795
+ attributes = if name.kind_of?(String)
796
+ { "TYPE" => "text", "NAME" => name, "VALUE" => value,
797
+ "SIZE" => size.to_s }
798
+ else
799
+ name["TYPE"] = "text"
800
+ name
801
+ end
802
+ attributes["MAXLENGTH"] = maxlength.to_s if maxlength
803
+ input(attributes)
804
+ end
805
+
806
+ # Generate a TextArea element, as a String.
807
+ #
808
+ # +name+ is the name of the textarea. +cols+ is the number of
809
+ # columns and +rows+ is the number of rows in the display.
810
+ #
811
+ # Alternatively, the attributes can be specified as a hash.
812
+ #
813
+ # The body is provided by the passed-in no-argument block
814
+ #
815
+ # textarea("name")
816
+ # # = textarea("NAME" => "name", "COLS" => 70, "ROWS" => 10)
817
+ #
818
+ # textarea("name", 40, 5)
819
+ # # = textarea("NAME" => "name", "COLS" => 40, "ROWS" => 5)
820
+ def textarea(name = "", cols = 70, rows = 10) # :yield:
821
+ attributes = if name.kind_of?(String)
822
+ { "NAME" => name, "COLS" => cols.to_s,
823
+ "ROWS" => rows.to_s }
824
+ else
825
+ name
826
+ end
827
+ if block_given?
828
+ super(attributes){ yield }
829
+ else
830
+ super(attributes)
831
+ end
832
+ end
833
+
834
+ end # HtmlExtension
835
+
836
+
837
+ # Mixin module for HTML version 3 generation methods.
838
+ module Html3 # :nodoc:
839
+
840
+ # The DOCTYPE declaration for this version of HTML
841
+ def doctype
842
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">|
843
+ end
844
+
845
+ # Initialise the HTML generation methods for this version.
846
+ def element_init
847
+ extend TagMaker
848
+ methods = ""
849
+ # - -
850
+ for element in %w[ A TT I B U STRIKE BIG SMALL SUB SUP EM STRONG
851
+ DFN CODE SAMP KBD VAR CITE FONT ADDRESS DIV center MAP
852
+ APPLET PRE XMP LISTING DL OL UL DIR MENU SELECT table TITLE
853
+ STYLE SCRIPT H1 H2 H3 H4 H5 H6 TEXTAREA FORM BLOCKQUOTE
854
+ CAPTION ]
855
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
856
+ def #{element.downcase}(attributes = {})
857
+ BEGIN
858
+ end
859
+ END
860
+ end
861
+
862
+ # - O EMPTY
863
+ for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
864
+ ISINDEX META ]
865
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
866
+ def #{element.downcase}(attributes = {})
867
+ BEGIN
868
+ end
869
+ END
870
+ end
871
+
872
+ # O O or - O
873
+ for element in %w[ HTML HEAD BODY P PLAINTEXT DT DD LI OPTION tr
874
+ th td ]
875
+ methods += <<-BEGIN + nO_element_def(element) + <<-END
876
+ def #{element.downcase}(attributes = {})
877
+ BEGIN
878
+ end
879
+ END
880
+ end
881
+ eval(methods)
882
+ end
883
+
884
+ end # Html3
885
+
886
+
887
+ # Mixin module for HTML version 4 generation methods.
888
+ module Html4 # :nodoc:
889
+
890
+ # The DOCTYPE declaration for this version of HTML
891
+ def doctype
892
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">|
893
+ end
894
+
895
+ # Initialise the HTML generation methods for this version.
896
+ def element_init
897
+ extend TagMaker
898
+ methods = ""
899
+ # - -
900
+ for element in %w[ TT I B BIG SMALL EM STRONG DFN CODE SAMP KBD
901
+ VAR CITE ABBR ACRONYM SUB SUP SPAN BDO ADDRESS DIV MAP OBJECT
902
+ H1 H2 H3 H4 H5 H6 PRE Q INS DEL DL OL UL LABEL SELECT OPTGROUP
903
+ FIELDSET LEGEND BUTTON TABLE TITLE STYLE SCRIPT NOSCRIPT
904
+ TEXTAREA FORM A BLOCKQUOTE CAPTION ]
905
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
906
+ def #{element.downcase}(attributes = {})
907
+ BEGIN
908
+ end
909
+ END
910
+ end
911
+
912
+ # - O EMPTY
913
+ for element in %w[ IMG BASE BR AREA LINK PARAM HR INPUT COL META ]
914
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
915
+ def #{element.downcase}(attributes = {})
916
+ BEGIN
917
+ end
918
+ END
919
+ end
920
+
921
+ # O O or - O
922
+ for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
923
+ COLGROUP TR TH TD HEAD]
924
+ methods += <<-BEGIN + nO_element_def(element) + <<-END
925
+ def #{element.downcase}(attributes = {})
926
+ BEGIN
927
+ end
928
+ END
929
+ end
930
+ eval(methods)
931
+ end
932
+
933
+ end # Html4
934
+
935
+
936
+ # Mixin module for HTML version 4 transitional generation methods.
937
+ module Html4Tr # :nodoc:
938
+
939
+ # The DOCTYPE declaration for this version of HTML
940
+ def doctype
941
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">|
942
+ end
943
+
944
+ # Initialise the HTML generation methods for this version.
945
+ def element_init
946
+ extend TagMaker
947
+ methods = ""
948
+ # - -
949
+ for element in %w[ TT I B U S STRIKE BIG SMALL EM STRONG DFN
950
+ CODE SAMP KBD VAR CITE ABBR ACRONYM FONT SUB SUP SPAN BDO
951
+ ADDRESS DIV CENTER MAP OBJECT APPLET H1 H2 H3 H4 H5 H6 PRE Q
952
+ INS DEL DL OL UL DIR MENU LABEL SELECT OPTGROUP FIELDSET
953
+ LEGEND BUTTON TABLE IFRAME NOFRAMES TITLE STYLE SCRIPT
954
+ NOSCRIPT TEXTAREA FORM A BLOCKQUOTE CAPTION ]
955
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
956
+ def #{element.downcase}(attributes = {})
957
+ BEGIN
958
+ end
959
+ END
960
+ end
961
+
962
+ # - O EMPTY
963
+ for element in %w[ IMG BASE BASEFONT BR AREA LINK PARAM HR INPUT
964
+ COL ISINDEX META ]
965
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
966
+ def #{element.downcase}(attributes = {})
967
+ BEGIN
968
+ end
969
+ END
970
+ end
971
+
972
+ # O O or - O
973
+ for element in %w[ HTML BODY P DT DD LI OPTION THEAD TFOOT TBODY
974
+ COLGROUP TR TH TD HEAD ]
975
+ methods += <<-BEGIN + nO_element_def(element) + <<-END
976
+ def #{element.downcase}(attributes = {})
977
+ BEGIN
978
+ end
979
+ END
980
+ end
981
+ eval(methods)
982
+ end
983
+
984
+ end # Html4Tr
985
+
986
+
987
+ # Mixin module for generating HTML version 4 with framesets.
988
+ module Html4Fr # :nodoc:
989
+
990
+ # The DOCTYPE declaration for this version of HTML
991
+ def doctype
992
+ %|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">|
993
+ end
994
+
995
+ # Initialise the HTML generation methods for this version.
996
+ def element_init
997
+ methods = ""
998
+ # - -
999
+ for element in %w[ FRAMESET ]
1000
+ methods += <<-BEGIN + nn_element_def(element) + <<-END
1001
+ def #{element.downcase}(attributes = {})
1002
+ BEGIN
1003
+ end
1004
+ END
1005
+ end
1006
+
1007
+ # - O EMPTY
1008
+ for element in %w[ FRAME ]
1009
+ methods += <<-BEGIN + nOE_element_def(element) + <<-END
1010
+ def #{element.downcase}(attributes = {})
1011
+ BEGIN
1012
+ end
1013
+ END
1014
+ end
1015
+ eval(methods)
1016
+ end
1017
+
1018
+ end # Html4Fr
1019
+ end
1020
+
1021
+