eactionpack 2.1.2

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 (338) hide show
  1. data/CHANGELOG +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +469 -0
  4. data/RUNNING_UNIT_TESTS +24 -0
  5. data/Rakefile +146 -0
  6. data/install.rb +30 -0
  7. data/lib/action_controller.rb +79 -0
  8. data/lib/action_controller/assertions.rb +69 -0
  9. data/lib/action_controller/assertions/dom_assertions.rb +39 -0
  10. data/lib/action_controller/assertions/model_assertions.rb +20 -0
  11. data/lib/action_controller/assertions/response_assertions.rb +172 -0
  12. data/lib/action_controller/assertions/routing_assertions.rb +146 -0
  13. data/lib/action_controller/assertions/selector_assertions.rb +491 -0
  14. data/lib/action_controller/assertions/tag_assertions.rb +130 -0
  15. data/lib/action_controller/base.rb +1288 -0
  16. data/lib/action_controller/benchmarking.rb +94 -0
  17. data/lib/action_controller/caching.rb +72 -0
  18. data/lib/action_controller/caching/actions.rb +144 -0
  19. data/lib/action_controller/caching/fragments.rb +138 -0
  20. data/lib/action_controller/caching/pages.rb +154 -0
  21. data/lib/action_controller/caching/sql_cache.rb +18 -0
  22. data/lib/action_controller/caching/sweeping.rb +97 -0
  23. data/lib/action_controller/cgi_ext.rb +16 -0
  24. data/lib/action_controller/cgi_ext/cookie.rb +110 -0
  25. data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
  26. data/lib/action_controller/cgi_ext/session.rb +73 -0
  27. data/lib/action_controller/cgi_ext/stdinput.rb +24 -0
  28. data/lib/action_controller/cgi_process.rb +223 -0
  29. data/lib/action_controller/components.rb +166 -0
  30. data/lib/action_controller/cookies.rb +96 -0
  31. data/lib/action_controller/dispatcher.rb +162 -0
  32. data/lib/action_controller/filters.rb +642 -0
  33. data/lib/action_controller/flash.rb +172 -0
  34. data/lib/action_controller/headers.rb +31 -0
  35. data/lib/action_controller/helpers.rb +221 -0
  36. data/lib/action_controller/http_authentication.rb +124 -0
  37. data/lib/action_controller/integration.rb +634 -0
  38. data/lib/action_controller/layout.rb +309 -0
  39. data/lib/action_controller/mime_responds.rb +173 -0
  40. data/lib/action_controller/mime_type.rb +186 -0
  41. data/lib/action_controller/mime_types.rb +20 -0
  42. data/lib/action_controller/polymorphic_routes.rb +191 -0
  43. data/lib/action_controller/record_identifier.rb +102 -0
  44. data/lib/action_controller/request.rb +764 -0
  45. data/lib/action_controller/request_forgery_protection.rb +140 -0
  46. data/lib/action_controller/request_profiler.rb +169 -0
  47. data/lib/action_controller/rescue.rb +258 -0
  48. data/lib/action_controller/resources.rb +572 -0
  49. data/lib/action_controller/response.rb +76 -0
  50. data/lib/action_controller/routing.rb +387 -0
  51. data/lib/action_controller/routing/builder.rb +203 -0
  52. data/lib/action_controller/routing/optimisations.rb +120 -0
  53. data/lib/action_controller/routing/recognition_optimisation.rb +162 -0
  54. data/lib/action_controller/routing/route.rb +240 -0
  55. data/lib/action_controller/routing/route_set.rb +436 -0
  56. data/lib/action_controller/routing/routing_ext.rb +46 -0
  57. data/lib/action_controller/routing/segments.rb +283 -0
  58. data/lib/action_controller/session/active_record_store.rb +340 -0
  59. data/lib/action_controller/session/cookie_store.rb +166 -0
  60. data/lib/action_controller/session/drb_server.rb +32 -0
  61. data/lib/action_controller/session/drb_store.rb +35 -0
  62. data/lib/action_controller/session/mem_cache_store.rb +98 -0
  63. data/lib/action_controller/session_management.rb +158 -0
  64. data/lib/action_controller/status_codes.rb +88 -0
  65. data/lib/action_controller/streaming.rb +155 -0
  66. data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
  67. data/lib/action_controller/templates/rescues/_trace.erb +26 -0
  68. data/lib/action_controller/templates/rescues/diagnostics.erb +11 -0
  69. data/lib/action_controller/templates/rescues/layout.erb +29 -0
  70. data/lib/action_controller/templates/rescues/missing_template.erb +2 -0
  71. data/lib/action_controller/templates/rescues/routing_error.erb +10 -0
  72. data/lib/action_controller/templates/rescues/template_error.erb +21 -0
  73. data/lib/action_controller/templates/rescues/unknown_action.erb +2 -0
  74. data/lib/action_controller/test_case.rb +83 -0
  75. data/lib/action_controller/test_process.rb +526 -0
  76. data/lib/action_controller/url_rewriter.rb +142 -0
  77. data/lib/action_controller/vendor/html-scanner/html/document.rb +68 -0
  78. data/lib/action_controller/vendor/html-scanner/html/node.rb +537 -0
  79. data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
  80. data/lib/action_controller/vendor/html-scanner/html/selector.rb +828 -0
  81. data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +105 -0
  82. data/lib/action_controller/vendor/html-scanner/html/version.rb +11 -0
  83. data/lib/action_controller/verification.rb +130 -0
  84. data/lib/action_pack.rb +24 -0
  85. data/lib/action_pack/version.rb +9 -0
  86. data/lib/action_view.rb +44 -0
  87. data/lib/action_view/base.rb +335 -0
  88. data/lib/action_view/helpers/active_record_helper.rb +276 -0
  89. data/lib/action_view/helpers/asset_tag_helper.rb +599 -0
  90. data/lib/action_view/helpers/atom_feed_helper.rb +143 -0
  91. data/lib/action_view/helpers/benchmark_helper.rb +33 -0
  92. data/lib/action_view/helpers/cache_helper.rb +40 -0
  93. data/lib/action_view/helpers/capture_helper.rb +161 -0
  94. data/lib/action_view/helpers/date_helper.rb +711 -0
  95. data/lib/action_view/helpers/debug_helper.rb +31 -0
  96. data/lib/action_view/helpers/form_helper.rb +767 -0
  97. data/lib/action_view/helpers/form_options_helper.rb +458 -0
  98. data/lib/action_view/helpers/form_tag_helper.rb +458 -0
  99. data/lib/action_view/helpers/javascript_helper.rb +148 -0
  100. data/lib/action_view/helpers/number_helper.rb +186 -0
  101. data/lib/action_view/helpers/record_identification_helper.rb +20 -0
  102. data/lib/action_view/helpers/record_tag_helper.rb +59 -0
  103. data/lib/action_view/helpers/sanitize_helper.rb +229 -0
  104. data/lib/action_view/helpers/tag_helper.rb +134 -0
  105. data/lib/action_view/helpers/text_helper.rb +507 -0
  106. data/lib/action_view/helpers/url_helper.rb +573 -0
  107. data/lib/action_view/inline_template.rb +20 -0
  108. data/lib/action_view/partial_template.rb +70 -0
  109. data/lib/action_view/partials.rb +158 -0
  110. data/lib/action_view/template.rb +125 -0
  111. data/lib/action_view/template_error.rb +110 -0
  112. data/lib/action_view/template_finder.rb +176 -0
  113. data/lib/action_view/template_handler.rb +34 -0
  114. data/lib/action_view/template_handlers/builder.rb +27 -0
  115. data/lib/action_view/template_handlers/compilable.rb +128 -0
  116. data/lib/action_view/template_handlers/erb.rb +56 -0
  117. data/lib/action_view/test_case.rb +58 -0
  118. data/lib/actionpack.rb +1 -0
  119. data/test/abstract_unit.rb +36 -0
  120. data/test/active_record_unit.rb +105 -0
  121. data/test/activerecord/active_record_store_test.rb +141 -0
  122. data/test/activerecord/render_partial_with_record_identification_test.rb +191 -0
  123. data/test/adv_attr_test.rb +20 -0
  124. data/test/controller/action_pack_assertions_test.rb +543 -0
  125. data/test/controller/addresses_render_test.rb +43 -0
  126. data/test/controller/assert_select_test.rb +331 -0
  127. data/test/controller/base_test.rb +219 -0
  128. data/test/controller/benchmark_test.rb +32 -0
  129. data/test/controller/caching_test.rb +581 -0
  130. data/test/controller/capture_test.rb +89 -0
  131. data/test/controller/cgi_test.rb +116 -0
  132. data/test/controller/components_test.rb +140 -0
  133. data/test/controller/content_type_test.rb +139 -0
  134. data/test/controller/controller_fixtures/app/controllers/admin/user_controller.rb +0 -0
  135. data/test/controller/controller_fixtures/app/controllers/user_controller.rb +0 -0
  136. data/test/controller/controller_fixtures/vendor/plugins/bad_plugin/lib/plugin_controller.rb +0 -0
  137. data/test/controller/cookie_test.rb +146 -0
  138. data/test/controller/custom_handler_test.rb +45 -0
  139. data/test/controller/deprecation/deprecated_base_methods_test.rb +37 -0
  140. data/test/controller/dispatcher_test.rb +105 -0
  141. data/test/controller/fake_controllers.rb +33 -0
  142. data/test/controller/fake_models.rb +11 -0
  143. data/test/controller/filter_params_test.rb +49 -0
  144. data/test/controller/filters_test.rb +881 -0
  145. data/test/controller/flash_test.rb +146 -0
  146. data/test/controller/header_test.rb +14 -0
  147. data/test/controller/helper_test.rb +210 -0
  148. data/test/controller/html-scanner/cdata_node_test.rb +15 -0
  149. data/test/controller/html-scanner/document_test.rb +148 -0
  150. data/test/controller/html-scanner/node_test.rb +89 -0
  151. data/test/controller/html-scanner/sanitizer_test.rb +269 -0
  152. data/test/controller/html-scanner/tag_node_test.rb +238 -0
  153. data/test/controller/html-scanner/text_node_test.rb +50 -0
  154. data/test/controller/html-scanner/tokenizer_test.rb +131 -0
  155. data/test/controller/http_authentication_test.rb +54 -0
  156. data/test/controller/integration_test.rb +252 -0
  157. data/test/controller/integration_upload_test.rb +43 -0
  158. data/test/controller/layout_test.rb +255 -0
  159. data/test/controller/mime_responds_test.rb +514 -0
  160. data/test/controller/mime_type_test.rb +84 -0
  161. data/test/controller/new_render_test.rb +843 -0
  162. data/test/controller/polymorphic_routes_test.rb +174 -0
  163. data/test/controller/record_identifier_test.rb +139 -0
  164. data/test/controller/redirect_test.rb +289 -0
  165. data/test/controller/render_test.rb +484 -0
  166. data/test/controller/request_forgery_protection_test.rb +305 -0
  167. data/test/controller/request_test.rb +928 -0
  168. data/test/controller/rescue_test.rb +517 -0
  169. data/test/controller/resources_test.rb +873 -0
  170. data/test/controller/routing_test.rb +2464 -0
  171. data/test/controller/selector_test.rb +628 -0
  172. data/test/controller/send_file_test.rb +138 -0
  173. data/test/controller/session/cookie_store_test.rb +258 -0
  174. data/test/controller/session/mem_cache_store_test.rb +181 -0
  175. data/test/controller/session_fixation_test.rb +89 -0
  176. data/test/controller/session_management_test.rb +178 -0
  177. data/test/controller/test_test.rb +695 -0
  178. data/test/controller/url_rewriter_test.rb +310 -0
  179. data/test/controller/verification_test.rb +270 -0
  180. data/test/controller/view_paths_test.rb +140 -0
  181. data/test/controller/webservice_test.rb +229 -0
  182. data/test/fixtures/addresses/list.erb +1 -0
  183. data/test/fixtures/bad_customers/_bad_customer.html.erb +1 -0
  184. data/test/fixtures/companies.yml +24 -0
  185. data/test/fixtures/company.rb +10 -0
  186. data/test/fixtures/content_type/render_default_content_types_for_respond_to.rhtml +1 -0
  187. data/test/fixtures/content_type/render_default_for_js.js.erb +1 -0
  188. data/test/fixtures/content_type/render_default_for_rhtml.rhtml +1 -0
  189. data/test/fixtures/content_type/render_default_for_rxml.rxml +1 -0
  190. data/test/fixtures/customers/_customer.html.erb +1 -0
  191. data/test/fixtures/db_definitions/sqlite.sql +49 -0
  192. data/test/fixtures/developer.rb +9 -0
  193. data/test/fixtures/developers.yml +21 -0
  194. data/test/fixtures/developers_projects.yml +13 -0
  195. data/test/fixtures/fun/games/hello_world.erb +1 -0
  196. data/test/fixtures/functional_caching/_partial.erb +3 -0
  197. data/test/fixtures/functional_caching/fragment_cached.html.erb +2 -0
  198. data/test/fixtures/functional_caching/html_fragment_cached_with_partial.html.erb +1 -0
  199. data/test/fixtures/functional_caching/js_fragment_cached_with_partial.js.rjs +1 -0
  200. data/test/fixtures/good_customers/_good_customer.html.erb +1 -0
  201. data/test/fixtures/helpers/abc_helper.rb +5 -0
  202. data/test/fixtures/helpers/fun/games_helper.rb +3 -0
  203. data/test/fixtures/helpers/fun/pdf_helper.rb +3 -0
  204. data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
  205. data/test/fixtures/layout_tests/layouts/controller_name_space/nested.rhtml +1 -0
  206. data/test/fixtures/layout_tests/layouts/item.rhtml +1 -0
  207. data/test/fixtures/layout_tests/layouts/layout_test.rhtml +1 -0
  208. data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
  209. data/test/fixtures/layout_tests/layouts/third_party_template_library.mab +1 -0
  210. data/test/fixtures/layout_tests/views/hello.rhtml +1 -0
  211. data/test/fixtures/layouts/block_with_layout.erb +3 -0
  212. data/test/fixtures/layouts/builder.builder +3 -0
  213. data/test/fixtures/layouts/partial_with_layout.erb +3 -0
  214. data/test/fixtures/layouts/standard.erb +1 -0
  215. data/test/fixtures/layouts/talk_from_action.erb +2 -0
  216. data/test/fixtures/layouts/yield.erb +2 -0
  217. data/test/fixtures/mascot.rb +3 -0
  218. data/test/fixtures/mascots.yml +4 -0
  219. data/test/fixtures/mascots/_mascot.html.erb +1 -0
  220. data/test/fixtures/multipart/binary_file +0 -0
  221. data/test/fixtures/multipart/boundary_problem_file +10 -0
  222. data/test/fixtures/multipart/bracketed_param +5 -0
  223. data/test/fixtures/multipart/large_text_file +10 -0
  224. data/test/fixtures/multipart/mixed_files +0 -0
  225. data/test/fixtures/multipart/mona_lisa.jpg +0 -0
  226. data/test/fixtures/multipart/single_parameter +5 -0
  227. data/test/fixtures/multipart/text_file +10 -0
  228. data/test/fixtures/override/test/hello_world.erb +1 -0
  229. data/test/fixtures/override2/layouts/test/sub.erb +1 -0
  230. data/test/fixtures/post_test/layouts/post.html.erb +1 -0
  231. data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
  232. data/test/fixtures/post_test/post/index.html.erb +1 -0
  233. data/test/fixtures/post_test/post/index.iphone.erb +1 -0
  234. data/test/fixtures/post_test/super_post/index.html.erb +1 -0
  235. data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
  236. data/test/fixtures/project.rb +3 -0
  237. data/test/fixtures/projects.yml +7 -0
  238. data/test/fixtures/public/404.html +1 -0
  239. data/test/fixtures/public/500.html +1 -0
  240. data/test/fixtures/public/images/rails.png +0 -0
  241. data/test/fixtures/public/javascripts/application.js +1 -0
  242. data/test/fixtures/public/javascripts/bank.js +1 -0
  243. data/test/fixtures/public/javascripts/robber.js +1 -0
  244. data/test/fixtures/public/javascripts/version.1.0.js +1 -0
  245. data/test/fixtures/public/stylesheets/bank.css +1 -0
  246. data/test/fixtures/public/stylesheets/robber.css +1 -0
  247. data/test/fixtures/public/stylesheets/version.1.0.css +1 -0
  248. data/test/fixtures/replies.yml +15 -0
  249. data/test/fixtures/reply.rb +7 -0
  250. data/test/fixtures/respond_to/all_types_with_layout.html.erb +1 -0
  251. data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
  252. data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
  253. data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
  254. data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
  255. data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
  256. data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
  257. data/test/fixtures/respond_to/using_defaults.html.erb +1 -0
  258. data/test/fixtures/respond_to/using_defaults.js.rjs +1 -0
  259. data/test/fixtures/respond_to/using_defaults.xml.builder +1 -0
  260. data/test/fixtures/respond_to/using_defaults_with_type_list.html.erb +1 -0
  261. data/test/fixtures/respond_to/using_defaults_with_type_list.js.rjs +1 -0
  262. data/test/fixtures/respond_to/using_defaults_with_type_list.xml.builder +1 -0
  263. data/test/fixtures/scope/test/modgreet.erb +1 -0
  264. data/test/fixtures/shared.html.erb +1 -0
  265. data/test/fixtures/symlink_parent/symlinked_layout.erb +5 -0
  266. data/test/fixtures/test/_customer.erb +1 -0
  267. data/test/fixtures/test/_customer_counter.erb +1 -0
  268. data/test/fixtures/test/_customer_greeting.erb +1 -0
  269. data/test/fixtures/test/_form.erb +1 -0
  270. data/test/fixtures/test/_hash_greeting.erb +1 -0
  271. data/test/fixtures/test/_hash_object.erb +2 -0
  272. data/test/fixtures/test/_hello.builder +1 -0
  273. data/test/fixtures/test/_labelling_form.erb +1 -0
  274. data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
  275. data/test/fixtures/test/_partial.erb +1 -0
  276. data/test/fixtures/test/_partial.html.erb +1 -0
  277. data/test/fixtures/test/_partial.js.erb +1 -0
  278. data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
  279. data/test/fixtures/test/_partial_only.erb +1 -0
  280. data/test/fixtures/test/_person.erb +2 -0
  281. data/test/fixtures/test/_raise.html.erb +1 -0
  282. data/test/fixtures/test/action_talk_to_layout.erb +2 -0
  283. data/test/fixtures/test/block_content_for.erb +2 -0
  284. data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
  285. data/test/fixtures/test/capturing.erb +4 -0
  286. data/test/fixtures/test/content_for.erb +2 -0
  287. data/test/fixtures/test/content_for_concatenated.erb +3 -0
  288. data/test/fixtures/test/content_for_with_parameter.erb +2 -0
  289. data/test/fixtures/test/delete_with_js.rjs +2 -0
  290. data/test/fixtures/test/dot.directory/render_file_with_ivar.erb +1 -0
  291. data/test/fixtures/test/enum_rjs_test.rjs +6 -0
  292. data/test/fixtures/test/erb_content_for.erb +2 -0
  293. data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
  294. data/test/fixtures/test/formatted_xml_erb.builder +1 -0
  295. data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
  296. data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
  297. data/test/fixtures/test/greeting.erb +1 -0
  298. data/test/fixtures/test/greeting.js.rjs +1 -0
  299. data/test/fixtures/test/hello.builder +4 -0
  300. data/test/fixtures/test/hello_world.erb +1 -0
  301. data/test/fixtures/test/hello_world_container.builder +3 -0
  302. data/test/fixtures/test/hello_world_from_rxml.builder +4 -0
  303. data/test/fixtures/test/hello_world_with_layout_false.erb +1 -0
  304. data/test/fixtures/test/hello_xml_world.builder +11 -0
  305. data/test/fixtures/test/list.erb +1 -0
  306. data/test/fixtures/test/non_erb_block_content_for.builder +4 -0
  307. data/test/fixtures/test/potential_conflicts.erb +4 -0
  308. data/test/fixtures/test/render_file_from_template.html.erb +1 -0
  309. data/test/fixtures/test/render_file_with_ivar.erb +1 -0
  310. data/test/fixtures/test/render_file_with_locals.erb +1 -0
  311. data/test/fixtures/test/render_to_string_test.erb +1 -0
  312. data/test/fixtures/test/update_element_with_capture.erb +9 -0
  313. data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
  314. data/test/fixtures/topic.rb +3 -0
  315. data/test/fixtures/topics.yml +22 -0
  316. data/test/fixtures/topics/_topic.html.erb +1 -0
  317. data/test/template/active_record_helper_test.rb +268 -0
  318. data/test/template/asset_tag_helper_test.rb +514 -0
  319. data/test/template/atom_feed_helper_test.rb +179 -0
  320. data/test/template/benchmark_helper_test.rb +60 -0
  321. data/test/template/date_helper_test.rb +1791 -0
  322. data/test/template/deprecated_erb_variable_test.rb +9 -0
  323. data/test/template/erb_util_test.rb +24 -0
  324. data/test/template/form_helper_test.rb +885 -0
  325. data/test/template/form_options_helper_test.rb +1333 -0
  326. data/test/template/form_tag_helper_test.rb +272 -0
  327. data/test/template/javascript_helper_test.rb +73 -0
  328. data/test/template/number_helper_test.rb +97 -0
  329. data/test/template/record_tag_helper_test.rb +54 -0
  330. data/test/template/sanitize_helper_test.rb +48 -0
  331. data/test/template/tag_helper_test.rb +77 -0
  332. data/test/template/template_finder_test.rb +73 -0
  333. data/test/template/template_object_test.rb +95 -0
  334. data/test/template/test_test.rb +56 -0
  335. data/test/template/text_helper_test.rb +367 -0
  336. data/test/template/url_helper_test.rb +544 -0
  337. data/test/testing_sandbox.rb +15 -0
  338. metadata +469 -0
@@ -0,0 +1,143 @@
1
+ # Adds easy defaults to writing Atom feeds with the Builder template engine (this does not work on ERb or any other
2
+ # template languages).
3
+ module ActionView
4
+ module Helpers #:nodoc:
5
+ module AtomFeedHelper
6
+ # Full usage example:
7
+ #
8
+ # config/routes.rb:
9
+ # ActionController::Routing::Routes.draw do |map|
10
+ # map.resources :posts
11
+ # map.root :controller => "posts"
12
+ # end
13
+ #
14
+ # app/controllers/posts_controller.rb:
15
+ # class PostsController < ApplicationController::Base
16
+ # # GET /posts.html
17
+ # # GET /posts.atom
18
+ # def index
19
+ # @posts = Post.find(:all)
20
+ #
21
+ # respond_to do |format|
22
+ # format.html
23
+ # format.atom
24
+ # end
25
+ # end
26
+ # end
27
+ #
28
+ # app/views/posts/index.atom.builder:
29
+ # atom_feed do |feed|
30
+ # feed.title("My great blog!")
31
+ # feed.updated((@posts.first.created_at))
32
+ #
33
+ # for post in @posts
34
+ # feed.entry(post) do |entry|
35
+ # entry.title(post.title)
36
+ # entry.content(post.body, :type => 'html')
37
+ #
38
+ # entry.author do |author|
39
+ # author.name("DHH")
40
+ # end
41
+ # end
42
+ # end
43
+ # end
44
+ #
45
+ # The options for atom_feed are:
46
+ #
47
+ # * <tt>:language</tt>: Defaults to "en-US".
48
+ # * <tt>:root_url</tt>: The HTML alternative that this feed is doubling for. Defaults to / on the current host.
49
+ # * <tt>:url</tt>: The URL for this feed. Defaults to the current URL.
50
+ # * <tt>:schema_date</tt>: The date at which the tag scheme for the feed was first used. A good default is the year you
51
+ # created the feed. See http://feedvalidator.org/docs/error/InvalidTAG.html for more information. If not specified,
52
+ # 2005 is used (as an "I don't care" value).
53
+ #
54
+ # Other namespaces can be added to the root element:
55
+ #
56
+ # app/views/posts/index.atom.builder:
57
+ # atom_feed({'xmlns:app' => 'http://www.w3.org/2007/app',
58
+ # 'xmlns:openSearch' => 'http://a9.com/-/spec/opensearch/1.1/'}) do |feed|
59
+ # feed.title("My great blog!")
60
+ # feed.updated((@posts.first.created_at))
61
+ # feed.tag!(openSearch:totalResults, 10)
62
+ #
63
+ # for post in @posts
64
+ # feed.entry(post) do |entry|
65
+ # entry.title(post.title)
66
+ # entry.content(post.body, :type => 'html')
67
+ # entry.tag!('app:edited', Time.now)
68
+ #
69
+ # entry.author do |author|
70
+ # author.name("DHH")
71
+ # end
72
+ # end
73
+ # end
74
+ # end
75
+ #
76
+ #
77
+ # atom_feed yields an AtomFeedBuilder instance.
78
+ def atom_feed(options = {}, &block)
79
+ if options[:schema_date]
80
+ options[:schema_date] = options[:schema_date].strftime("%Y-%m-%d") if options[:schema_date].respond_to?(:strftime)
81
+ else
82
+ options[:schema_date] = "2005" # The Atom spec copyright date
83
+ end
84
+
85
+ xml = options[:xml] || eval("xml", block.binding)
86
+ xml.instruct!
87
+
88
+ feed_opts = {"xml:lang" => options[:language] || "en-US", "xmlns" => 'http://www.w3.org/2005/Atom'}
89
+ feed_opts.merge!(options).reject!{|k,v| !k.to_s.match(/^xml/)}
90
+
91
+ xml.feed(feed_opts) do
92
+ xml.id("tag:#{request.host},#{options[:schema_date]}:#{request.request_uri.split(".")[0]}")
93
+ xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:root_url] || (request.protocol + request.host_with_port))
94
+ xml.link(:rel => 'self', :type => 'application/atom+xml', :href => options[:url] || request.url)
95
+
96
+ yield AtomFeedBuilder.new(xml, self, options)
97
+ end
98
+ end
99
+
100
+
101
+ class AtomFeedBuilder
102
+ def initialize(xml, view, feed_options = {})
103
+ @xml, @view, @feed_options = xml, view, feed_options
104
+ end
105
+
106
+ # Accepts a Date or Time object and inserts it in the proper format. If nil is passed, current time in UTC is used.
107
+ def updated(date_or_time = nil)
108
+ @xml.updated((date_or_time || Time.now.utc).xmlschema)
109
+ end
110
+
111
+ # Creates an entry tag for a specific record and prefills the id using class and id.
112
+ #
113
+ # Options:
114
+ #
115
+ # * <tt>:published</tt>: Time first published. Defaults to the created_at attribute on the record if one such exists.
116
+ # * <tt>:updated</tt>: Time of update. Defaults to the updated_at attribute on the record if one such exists.
117
+ # * <tt>:url</tt>: The URL for this entry. Defaults to the polymorphic_url for the record.
118
+ def entry(record, options = {})
119
+ @xml.entry do
120
+ @xml.id("tag:#{@view.request.host},#{@feed_options[:schema_date]}:#{record.class}/#{record.id}")
121
+
122
+ if options[:published] || (record.respond_to?(:created_at) && record.created_at)
123
+ @xml.published((options[:published] || record.created_at).xmlschema)
124
+ end
125
+
126
+ if options[:updated] || (record.respond_to?(:updated_at) && record.updated_at)
127
+ @xml.updated((options[:updated] || record.updated_at).xmlschema)
128
+ end
129
+
130
+ @xml.link(:rel => 'alternate', :type => 'text/html', :href => options[:url] || @view.polymorphic_url(record))
131
+
132
+ yield @xml
133
+ end
134
+ end
135
+
136
+ private
137
+ def method_missing(method, *arguments, &block)
138
+ @xml.__send__(method, *arguments, &block)
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,33 @@
1
+ require 'benchmark'
2
+
3
+ module ActionView
4
+ module Helpers
5
+ # This helper offers a method to measure the execution time of a block
6
+ # in a template.
7
+ module BenchmarkHelper
8
+ # Allows you to measure the execution time of a block
9
+ # in a template and records the result to the log. Wrap this block around
10
+ # expensive operations or possible bottlenecks to get a time reading
11
+ # for the operation. For example, let's say you thought your file
12
+ # processing method was taking too long; you could wrap it in a benchmark block.
13
+ #
14
+ # <% benchmark "Process data files" do %>
15
+ # <%= expensive_files_operation %>
16
+ # <% end %>
17
+ #
18
+ # That would add something like "Process data files (0.34523)" to the log,
19
+ # which you can then use to compare timings when optimizing your code.
20
+ #
21
+ # You may give an optional logger level as the second argument
22
+ # (:debug, :info, :warn, :error); the default value is :info.
23
+ def benchmark(message = "Benchmarking", level = :info)
24
+ if controller.logger
25
+ real = Benchmark.realtime { yield }
26
+ controller.logger.send(level, "#{message} (#{'%.5f' % real})")
27
+ else
28
+ yield
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,40 @@
1
+ module ActionView
2
+ module Helpers
3
+ # This helper to exposes a method for caching of view fragments.
4
+ # See ActionController::Caching::Fragments for usage instructions.
5
+ module CacheHelper
6
+ # A method for caching fragments of a view rather than an entire
7
+ # action or page. This technique is useful caching pieces like
8
+ # menus, lists of news topics, static HTML fragments, and so on.
9
+ # This method takes a block that contains the content you wish
10
+ # to cache. See ActionController::Caching::Fragments for more
11
+ # information.
12
+ #
13
+ # ==== Examples
14
+ # If you wanted to cache a navigation menu, you could do the
15
+ # following.
16
+ #
17
+ # <% cache do %>
18
+ # <%= render :partial => "menu" %>
19
+ # <% end %>
20
+ #
21
+ # You can also cache static content...
22
+ #
23
+ # <% cache do %>
24
+ # <p>Hello users! Welcome to our website!</p>
25
+ # <% end %>
26
+ #
27
+ # ...and static content mixed with RHTML content.
28
+ #
29
+ # <% cache do %>
30
+ # Topics:
31
+ # <%= render :partial => "topics", :collection => @topic_list %>
32
+ # <i>Topics listed alphabetically</i>
33
+ # <% end %>
34
+ def cache(name = {}, options = nil, &block)
35
+ handler = Template.handler_class_for_extension(current_render_extension.to_sym)
36
+ handler.new(@controller).cache_fragment(block, name, options)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,161 @@
1
+ module ActionView
2
+ module Helpers
3
+ # CaptureHelper exposes methods to let you extract generated markup which
4
+ # can be used in other parts of a template or layout file.
5
+ # It provides a method to capture blocks into variables through capture and
6
+ # a way to capture a block of markup for use in a layout through content_for.
7
+ module CaptureHelper
8
+ # The capture method allows you to extract part of a template into a
9
+ # variable. You can then use this variable anywhere in your templates or layout.
10
+ #
11
+ # ==== Examples
12
+ # The capture method can be used in ERb templates...
13
+ #
14
+ # <% @greeting = capture do %>
15
+ # Welcome to my shiny new web page! The date and time is
16
+ # <%= Time.now %>
17
+ # <% end %>
18
+ #
19
+ # ...and Builder (RXML) templates.
20
+ #
21
+ # @timestamp = capture do
22
+ # "The current timestamp is #{Time.now}."
23
+ # end
24
+ #
25
+ # You can then use that variable anywhere else. For example:
26
+ #
27
+ # <html>
28
+ # <head><title><%= @greeting %></title></head>
29
+ # <body>
30
+ # <b><%= @greeting %></b>
31
+ # </body></html>
32
+ #
33
+ def capture(*args, &block)
34
+ # execute the block
35
+ begin
36
+ buffer = eval(ActionView::Base.erb_variable, block.binding)
37
+ rescue
38
+ buffer = nil
39
+ end
40
+
41
+ if buffer.nil?
42
+ capture_block(*args, &block).to_s
43
+ else
44
+ capture_erb_with_buffer(buffer, *args, &block).to_s
45
+ end
46
+ end
47
+
48
+ # Calling content_for stores a block of markup in an identifier for later use.
49
+ # You can make subsequent calls to the stored content in other templates or the layout
50
+ # by passing the identifier as an argument to <tt>yield</tt>.
51
+ #
52
+ # ==== Examples
53
+ #
54
+ # <% content_for :not_authorized do %>
55
+ # alert('You are not authorized to do that!')
56
+ # <% end %>
57
+ #
58
+ # You can then use <tt>yield :not_authorized</tt> anywhere in your templates.
59
+ #
60
+ # <%= yield :not_authorized if current_user.nil? %>
61
+ #
62
+ # You can also use this syntax alongside an existing call to <tt>yield</tt> in a layout. For example:
63
+ #
64
+ # <%# This is the layout %>
65
+ # <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
66
+ # <head>
67
+ # <title>My Website</title>
68
+ # <%= yield :script %>
69
+ # </head>
70
+ # <body>
71
+ # <%= yield %>
72
+ # </body>
73
+ # </html>
74
+ #
75
+ # And now, we'll create a view that has a content_for call that
76
+ # creates the <tt>script</tt> identifier.
77
+ #
78
+ # <%# This is our view %>
79
+ # Please login!
80
+ #
81
+ # <% content_for :script do %>
82
+ # <script type="text/javascript">alert('You are not authorized to view this page!')</script>
83
+ # <% end %>
84
+ #
85
+ # Then, in another view, you could to do something like this:
86
+ #
87
+ # <%= link_to_remote 'Logout', :action => 'logout' %>
88
+ #
89
+ # <% content_for :script do %>
90
+ # <%= javascript_include_tag :defaults %>
91
+ # <% end %>
92
+ #
93
+ # That will place <script> tags for Prototype, Scriptaculous, and application.js (if it exists)
94
+ # on the page; this technique is useful if you'll only be using these scripts in a few views.
95
+ #
96
+ # Note that content_for concatenates the blocks it is given for a particular
97
+ # identifier in order. For example:
98
+ #
99
+ # <% content_for :navigation do %>
100
+ # <li><%= link_to 'Home', :action => 'index' %></li>
101
+ # <% end %>
102
+ #
103
+ # <%# Add some other content, or use a different template: %>
104
+ #
105
+ # <% content_for :navigation do %>
106
+ # <li><%= link_to 'Login', :action => 'login' %></li>
107
+ # <% end %>
108
+ #
109
+ # Then, in another template or layout, this code would render both links in order:
110
+ #
111
+ # <ul><%= yield :navigation %></ul>
112
+ #
113
+ # Lastly, simple content can be passed as a parameter:
114
+ #
115
+ # <% content_for :script, javascript_include_tag(:defaults) %>
116
+ #
117
+ # WARNING: content_for is ignored in caches. So you shouldn't use it
118
+ # for elements that will be fragment cached.
119
+ #
120
+ # The deprecated way of accessing a content_for block is to use an instance variable
121
+ # named <tt>@content_for_#{name_of_the_content_block}</tt>. The preferred usage is now
122
+ # <tt><%= yield :footer %></tt>.
123
+ def content_for(name, content = nil, &block)
124
+ existing_content_for = instance_variable_get("@content_for_#{name}").to_s
125
+ new_content_for = existing_content_for + (block_given? ? capture(&block) : content)
126
+ instance_variable_set("@content_for_#{name}", new_content_for)
127
+ end
128
+
129
+ private
130
+ def capture_block(*args, &block)
131
+ block.call(*args)
132
+ end
133
+
134
+ def capture_erb(*args, &block)
135
+ buffer = eval(ActionView::Base.erb_variable, block.binding)
136
+ capture_erb_with_buffer(buffer, *args, &block)
137
+ end
138
+
139
+ def capture_erb_with_buffer(buffer, *args, &block)
140
+ pos = buffer.length
141
+ block.call(*args)
142
+
143
+ # extract the block
144
+ data = buffer[pos..-1]
145
+
146
+ # replace it in the original with empty string
147
+ buffer[pos..-1] = ''
148
+
149
+ data
150
+ end
151
+
152
+ def erb_content_for(name, &block)
153
+ eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_erb(&block)"
154
+ end
155
+
156
+ def block_content_for(name, &block)
157
+ eval "@content_for_#{name} = (@content_for_#{name} || '') + capture_block(&block)"
158
+ end
159
+ end
160
+ end
161
+ end
@@ -0,0 +1,711 @@
1
+ require "date"
2
+ require 'action_view/helpers/tag_helper'
3
+
4
+ module ActionView
5
+ module Helpers
6
+ # The Date Helper primarily creates select/option tags for different kinds of dates and date elements. All of the select-type methods
7
+ # share a number of common options that are as follows:
8
+ #
9
+ # * <tt>:prefix</tt> - overwrites the default prefix of "date" used for the select names. So specifying "birthday" would give
10
+ # birthday[month] instead of date[month] if passed to the select_month method.
11
+ # * <tt>:include_blank</tt> - set to true if it should be possible to set an empty date.
12
+ # * <tt>:discard_type</tt> - set to true if you want to discard the type part of the select name. If set to true, the select_month
13
+ # method would use simply "date" (which can be overwritten using <tt>:prefix</tt>) instead of "date[month]".
14
+ module DateHelper
15
+ include ActionView::Helpers::TagHelper
16
+ DEFAULT_PREFIX = 'date' unless const_defined?('DEFAULT_PREFIX')
17
+
18
+ # Reports the approximate distance in time between two Time or Date objects or integers as seconds.
19
+ # Set <tt>include_seconds</tt> to true if you want more detailed approximations when distance < 1 min, 29 secs
20
+ # Distances are reported based on the following table:
21
+ #
22
+ # 0 <-> 29 secs # => less than a minute
23
+ # 30 secs <-> 1 min, 29 secs # => 1 minute
24
+ # 1 min, 30 secs <-> 44 mins, 29 secs # => [2..44] minutes
25
+ # 44 mins, 30 secs <-> 89 mins, 29 secs # => about 1 hour
26
+ # 89 mins, 29 secs <-> 23 hrs, 59 mins, 29 secs # => about [2..24] hours
27
+ # 23 hrs, 59 mins, 29 secs <-> 47 hrs, 59 mins, 29 secs # => 1 day
28
+ # 47 hrs, 59 mins, 29 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => [2..29] days
29
+ # 29 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs # => about 1 month
30
+ # 59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec # => [2..12] months
31
+ # 1 yr <-> 2 yrs minus 1 secs # => about 1 year
32
+ # 2 yrs <-> max time or date # => over [2..X] years
33
+ #
34
+ # With <tt>include_seconds</tt> = true and the difference < 1 minute 29 seconds:
35
+ # 0-4 secs # => less than 5 seconds
36
+ # 5-9 secs # => less than 10 seconds
37
+ # 10-19 secs # => less than 20 seconds
38
+ # 20-39 secs # => half a minute
39
+ # 40-59 secs # => less than a minute
40
+ # 60-89 secs # => 1 minute
41
+ #
42
+ # ==== Examples
43
+ # from_time = Time.now
44
+ # distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hour
45
+ # distance_of_time_in_words(from_time, 50.minutes.from_now) # => about 1 hour
46
+ # distance_of_time_in_words(from_time, from_time + 15.seconds) # => less than a minute
47
+ # distance_of_time_in_words(from_time, from_time + 15.seconds, true) # => less than 20 seconds
48
+ # distance_of_time_in_words(from_time, 3.years.from_now) # => over 3 years
49
+ # distance_of_time_in_words(from_time, from_time + 60.hours) # => about 3 days
50
+ # distance_of_time_in_words(from_time, from_time + 45.seconds, true) # => less than a minute
51
+ # distance_of_time_in_words(from_time, from_time - 45.seconds, true) # => less than a minute
52
+ # distance_of_time_in_words(from_time, 76.seconds.from_now) # => 1 minute
53
+ # distance_of_time_in_words(from_time, from_time + 1.year + 3.days) # => about 1 year
54
+ # distance_of_time_in_words(from_time, from_time + 4.years + 15.days + 30.minutes + 5.seconds) # => over 4 years
55
+ #
56
+ # to_time = Time.now + 6.years + 19.days
57
+ # distance_of_time_in_words(from_time, to_time, true) # => over 6 years
58
+ # distance_of_time_in_words(to_time, from_time, true) # => over 6 years
59
+ # distance_of_time_in_words(Time.now, Time.now) # => less than a minute
60
+ #
61
+ def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false)
62
+ from_time = from_time.to_time if from_time.respond_to?(:to_time)
63
+ to_time = to_time.to_time if to_time.respond_to?(:to_time)
64
+ distance_in_minutes = (((to_time - from_time).abs)/60).round
65
+ distance_in_seconds = ((to_time - from_time).abs).round
66
+
67
+ case distance_in_minutes
68
+ when 0..1
69
+ return (distance_in_minutes == 0) ? 'less than a minute' : '1 minute' unless include_seconds
70
+ case distance_in_seconds
71
+ when 0..4 then 'less than 5 seconds'
72
+ when 5..9 then 'less than 10 seconds'
73
+ when 10..19 then 'less than 20 seconds'
74
+ when 20..39 then 'half a minute'
75
+ when 40..59 then 'less than a minute'
76
+ else '1 minute'
77
+ end
78
+
79
+ when 2..44 then "#{distance_in_minutes} minutes"
80
+ when 45..89 then 'about 1 hour'
81
+ when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours"
82
+ when 1440..2879 then '1 day'
83
+ when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
84
+ when 43200..86399 then 'about 1 month'
85
+ when 86400..525599 then "#{(distance_in_minutes / 43200).round} months"
86
+ when 525600..1051199 then 'about 1 year'
87
+ else "over #{(distance_in_minutes / 525600).round} years"
88
+ end
89
+ end
90
+
91
+ # Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.
92
+ #
93
+ # ==== Examples
94
+ # time_ago_in_words(3.minutes.from_now) # => 3 minutes
95
+ # time_ago_in_words(Time.now - 15.hours) # => 15 hours
96
+ # time_ago_in_words(Time.now) # => less than a minute
97
+ #
98
+ # from_time = Time.now - 3.days - 14.minutes - 25.seconds # => 3 days
99
+ def time_ago_in_words(from_time, include_seconds = false)
100
+ distance_of_time_in_words(from_time, Time.now, include_seconds)
101
+ end
102
+
103
+ alias_method :distance_of_time_in_words_to_now, :time_ago_in_words
104
+
105
+ # Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based attribute (identified by
106
+ # +method+) on an object assigned to the template (identified by +object+). It's possible to tailor the selects through the +options+ hash,
107
+ # which accepts all the keys that each of the individual select builders do (like <tt>:use_month_numbers</tt> for select_month) as well as a range of
108
+ # discard options. The discard options are <tt>:discard_year</tt>, <tt>:discard_month</tt> and <tt>:discard_day</tt>. Set to true, they'll
109
+ # drop the respective select. Discarding the month select will also automatically discard the day select. It's also possible to explicitly
110
+ # set the order of the tags using the <tt>:order</tt> option with an array of symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in
111
+ # the desired order. Symbols may be omitted and the respective select is not included.
112
+ #
113
+ # Pass the <tt>:default</tt> option to set the default date. Use a Time object or a Hash of <tt>:year</tt>, <tt>:month</tt>, <tt>:day</tt>, <tt>:hour</tt>, <tt>:minute</tt>, and <tt>:second</tt>.
114
+ #
115
+ # Passing <tt>:disabled => true</tt> as part of the +options+ will make elements inaccessible for change.
116
+ #
117
+ # If anything is passed in the +html_options+ hash it will be applied to every select tag in the set.
118
+ #
119
+ # NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed.
120
+ #
121
+ # ==== Examples
122
+ # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute
123
+ # date_select("post", "written_on")
124
+ #
125
+ # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute,
126
+ # # with the year in the year drop down box starting at 1995.
127
+ # date_select("post", "written_on", :start_year => 1995)
128
+ #
129
+ # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute,
130
+ # # with the year in the year drop down box starting at 1995, numbers used for months instead of words,
131
+ # # and without a day select box.
132
+ # date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true,
133
+ # :discard_day => true, :include_blank => true)
134
+ #
135
+ # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute
136
+ # # with the fields ordered as day, month, year rather than month, day, year.
137
+ # date_select("post", "written_on", :order => [:day, :month, :year])
138
+ #
139
+ # # Generates a date select that when POSTed is stored in the user variable, in the birthday attribute
140
+ # # lacking a year field.
141
+ # date_select("user", "birthday", :order => [:month, :day])
142
+ #
143
+ # # Generates a date select that when POSTed is stored in the user variable, in the birthday attribute
144
+ # # which is initially set to the date 3 days from the current date
145
+ # date_select("post", "written_on", :default => 3.days.from_now)
146
+ #
147
+ # # Generates a date select that when POSTed is stored in the credit_card variable, in the bill_due attribute
148
+ # # that will have a default day of 20.
149
+ # date_select("credit_card", "bill_due", :default => { :day => 20 })
150
+ #
151
+ # The selects are prepared for multi-parameter assignment to an Active Record object.
152
+ #
153
+ # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that all month
154
+ # choices are valid.
155
+ def date_select(object_name, method, options = {}, html_options = {})
156
+ InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_date_select_tag(options, html_options)
157
+ end
158
+
159
+ # Returns a set of select tags (one for hour, minute and optionally second) pre-selected for accessing a specified
160
+ # time-based attribute (identified by +method+) on an object assigned to the template (identified by +object+).
161
+ # You can include the seconds with <tt>:include_seconds</tt>.
162
+ #
163
+ # If anything is passed in the html_options hash it will be applied to every select tag in the set.
164
+ #
165
+ # ==== Examples
166
+ # # Creates a time select tag that, when POSTed, will be stored in the post variable in the sunrise attribute
167
+ # time_select("post", "sunrise")
168
+ #
169
+ # # Creates a time select tag that, when POSTed, will be stored in the order variable in the submitted attribute
170
+ # time_select("order", "submitted")
171
+ #
172
+ # # Creates a time select tag that, when POSTed, will be stored in the mail variable in the sent_at attribute
173
+ # time_select("mail", "sent_at")
174
+ #
175
+ # # Creates a time select tag with a seconds field that, when POSTed, will be stored in the post variables in
176
+ # # the sunrise attribute.
177
+ # time_select("post", "start_time", :include_seconds => true)
178
+ #
179
+ # # Creates a time select tag with a seconds field that, when POSTed, will be stored in the entry variables in
180
+ # # the submission_time attribute.
181
+ # time_select("entry", "submission_time", :include_seconds => true)
182
+ #
183
+ # # You can set the :minute_step to 15 which will give you: 00, 15, 30 and 45.
184
+ # time_select 'game', 'game_time', {:minute_step => 15}
185
+ #
186
+ # The selects are prepared for multi-parameter assignment to an Active Record object.
187
+ #
188
+ # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that all month
189
+ # choices are valid.
190
+ def time_select(object_name, method, options = {}, html_options = {})
191
+ InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_time_select_tag(options, html_options)
192
+ end
193
+
194
+ # Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a specified datetime-based
195
+ # attribute (identified by +method+) on an object assigned to the template (identified by +object+). Examples:
196
+ #
197
+ # If anything is passed in the html_options hash it will be applied to every select tag in the set.
198
+ #
199
+ # ==== Examples
200
+ # # Generates a datetime select that, when POSTed, will be stored in the post variable in the written_on attribute
201
+ # datetime_select("post", "written_on")
202
+ #
203
+ # # Generates a datetime select with a year select that starts at 1995 that, when POSTed, will be stored in the
204
+ # # post variable in the written_on attribute.
205
+ # datetime_select("post", "written_on", :start_year => 1995)
206
+ #
207
+ # # Generates a datetime select with a default value of 3 days from the current time that, when POSTed, will be stored in the
208
+ # # trip variable in the departing attribute.
209
+ # datetime_select("trip", "departing", :default => 3.days.from_now)
210
+ #
211
+ # # Generates a datetime select that discards the type that, when POSTed, will be stored in the post variable as the written_on
212
+ # # attribute.
213
+ # datetime_select("post", "written_on", :discard_type => true)
214
+ #
215
+ # The selects are prepared for multi-parameter assignment to an Active Record object.
216
+ def datetime_select(object_name, method, options = {}, html_options = {})
217
+ InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_datetime_select_tag(options, html_options)
218
+ end
219
+
220
+ # Returns a set of html select-tags (one for year, month, day, hour, and minute) pre-selected with the +datetime+.
221
+ # It's also possible to explicitly set the order of the tags using the <tt>:order</tt> option with an array of
222
+ # symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in the desired order. If you do not supply a Symbol, it
223
+ # will be appended onto the <tt>:order</tt> passed in. You can also add <tt>:date_separator</tt> and <tt>:time_separator</tt>
224
+ # keys to the +options+ to control visual display of the elements.
225
+ #
226
+ # If anything is passed in the html_options hash it will be applied to every select tag in the set.
227
+ #
228
+ # ==== Examples
229
+ # my_date_time = Time.now + 4.days
230
+ #
231
+ # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
232
+ # select_datetime(my_date_time)
233
+ #
234
+ # # Generates a datetime select that defaults to today (no specified datetime)
235
+ # select_datetime()
236
+ #
237
+ # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
238
+ # # with the fields ordered year, month, day rather than month, day, year.
239
+ # select_datetime(my_date_time, :order => [:year, :month, :day])
240
+ #
241
+ # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
242
+ # # with a '/' between each date field.
243
+ # select_datetime(my_date_time, :date_separator => '/')
244
+ #
245
+ # # Generates a datetime select that discards the type of the field and defaults to the datetime in
246
+ # # my_date_time (four days after today)
247
+ # select_datetime(my_date_time, :discard_type => true)
248
+ #
249
+ # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today)
250
+ # # prefixed with 'payday' rather than 'date'
251
+ # select_datetime(my_date_time, :prefix => 'payday')
252
+ #
253
+ def select_datetime(datetime = Time.current, options = {}, html_options = {})
254
+ separator = options[:datetime_separator] || ''
255
+ select_date(datetime, options, html_options) + separator + select_time(datetime, options, html_options)
256
+ end
257
+
258
+ # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+.
259
+ # It's possible to explicitly set the order of the tags using the <tt>:order</tt> option with an array of
260
+ # symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in the desired order. If you do not supply a Symbol, it
261
+ # will be appended onto the <tt>:order</tt> passed in.
262
+ #
263
+ # If anything is passed in the html_options hash it will be applied to every select tag in the set.
264
+ #
265
+ # ==== Examples
266
+ # my_date = Time.today + 6.days
267
+ #
268
+ # # Generates a date select that defaults to the date in my_date (six days after today)
269
+ # select_date(my_date)
270
+ #
271
+ # # Generates a date select that defaults to today (no specified date)
272
+ # select_date()
273
+ #
274
+ # # Generates a date select that defaults to the date in my_date (six days after today)
275
+ # # with the fields ordered year, month, day rather than month, day, year.
276
+ # select_date(my_date, :order => [:year, :month, :day])
277
+ #
278
+ # # Generates a date select that discards the type of the field and defaults to the date in
279
+ # # my_date (six days after today)
280
+ # select_datetime(my_date_time, :discard_type => true)
281
+ #
282
+ # # Generates a date select that defaults to the datetime in my_date (six days after today)
283
+ # # prefixed with 'payday' rather than 'date'
284
+ # select_datetime(my_date_time, :prefix => 'payday')
285
+ #
286
+ def select_date(date = Date.current, options = {}, html_options = {})
287
+ options[:order] ||= []
288
+ [:year, :month, :day].each { |o| options[:order].push(o) unless options[:order].include?(o) }
289
+
290
+ select_date = ''
291
+ options[:order].each do |o|
292
+ select_date << self.send("select_#{o}", date, options, html_options)
293
+ end
294
+ select_date
295
+ end
296
+
297
+ # Returns a set of html select-tags (one for hour and minute)
298
+ # You can set <tt>:time_separator</tt> key to format the output, and
299
+ # the <tt>:include_seconds</tt> option to include an input for seconds.
300
+ #
301
+ # If anything is passed in the html_options hash it will be applied to every select tag in the set.
302
+ #
303
+ # ==== Examples
304
+ # my_time = Time.now + 5.days + 7.hours + 3.minutes + 14.seconds
305
+ #
306
+ # # Generates a time select that defaults to the time in my_time
307
+ # select_time(my_time)
308
+ #
309
+ # # Generates a time select that defaults to the current time (no specified time)
310
+ # select_time()
311
+ #
312
+ # # Generates a time select that defaults to the time in my_time,
313
+ # # which has fields separated by ':'
314
+ # select_time(my_time, :time_separator => ':')
315
+ #
316
+ # # Generates a time select that defaults to the time in my_time,
317
+ # # that also includes an input for seconds
318
+ # select_time(my_time, :include_seconds => true)
319
+ #
320
+ # # Generates a time select that defaults to the time in my_time, that has fields
321
+ # # separated by ':' and includes an input for seconds
322
+ # select_time(my_time, :time_separator => ':', :include_seconds => true)
323
+ #
324
+ def select_time(datetime = Time.current, options = {}, html_options = {})
325
+ separator = options[:time_separator] || ''
326
+ select_hour(datetime, options, html_options) + separator + select_minute(datetime, options, html_options) + (options[:include_seconds] ? separator + select_second(datetime, options, html_options) : '')
327
+ end
328
+
329
+ # Returns a select tag with options for each of the seconds 0 through 59 with the current second selected.
330
+ # The <tt>second</tt> can also be substituted for a second number.
331
+ # Override the field name using the <tt>:field_name</tt> option, 'second' by default.
332
+ #
333
+ # ==== Examples
334
+ # my_time = Time.now + 16.minutes
335
+ #
336
+ # # Generates a select field for seconds that defaults to the seconds for the time in my_time
337
+ # select_second(my_time)
338
+ #
339
+ # # Generates a select field for seconds that defaults to the number given
340
+ # select_second(33)
341
+ #
342
+ # # Generates a select field for seconds that defaults to the seconds for the time in my_time
343
+ # # that is named 'interval' rather than 'second'
344
+ # select_second(my_time, :field_name => 'interval')
345
+ #
346
+ def select_second(datetime, options = {}, html_options = {})
347
+ val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.sec) : ''
348
+ if options[:use_hidden]
349
+ options[:include_seconds] ? hidden_html(options[:field_name] || 'second', val, options) : ''
350
+ else
351
+ second_options = []
352
+ 0.upto(59) do |second|
353
+ second_options << ((val == second) ?
354
+ content_tag(:option, leading_zero_on_single_digits(second), :value => leading_zero_on_single_digits(second), :selected => "selected") :
355
+ content_tag(:option, leading_zero_on_single_digits(second), :value => leading_zero_on_single_digits(second))
356
+ )
357
+ second_options << "\n"
358
+ end
359
+ select_html(options[:field_name] || 'second', second_options.join, options, html_options)
360
+ end
361
+ end
362
+
363
+ # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected.
364
+ # Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute selected
365
+ # The <tt>minute</tt> can also be substituted for a minute number.
366
+ # Override the field name using the <tt>:field_name</tt> option, 'minute' by default.
367
+ #
368
+ # ==== Examples
369
+ # my_time = Time.now + 6.hours
370
+ #
371
+ # # Generates a select field for minutes that defaults to the minutes for the time in my_time
372
+ # select_minute(my_time)
373
+ #
374
+ # # Generates a select field for minutes that defaults to the number given
375
+ # select_minute(14)
376
+ #
377
+ # # Generates a select field for minutes that defaults to the minutes for the time in my_time
378
+ # # that is named 'stride' rather than 'second'
379
+ # select_minute(my_time, :field_name => 'stride')
380
+ #
381
+ def select_minute(datetime, options = {}, html_options = {})
382
+ val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.min) : ''
383
+ if options[:use_hidden]
384
+ hidden_html(options[:field_name] || 'minute', val, options)
385
+ else
386
+ minute_options = []
387
+ 0.step(59, options[:minute_step] || 1) do |minute|
388
+ minute_options << ((val == minute) ?
389
+ content_tag(:option, leading_zero_on_single_digits(minute), :value => leading_zero_on_single_digits(minute), :selected => "selected") :
390
+ content_tag(:option, leading_zero_on_single_digits(minute), :value => leading_zero_on_single_digits(minute))
391
+ )
392
+ minute_options << "\n"
393
+ end
394
+ select_html(options[:field_name] || 'minute', minute_options.join, options, html_options)
395
+ end
396
+ end
397
+
398
+ # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected.
399
+ # The <tt>hour</tt> can also be substituted for a hour number.
400
+ # Override the field name using the <tt>:field_name</tt> option, 'hour' by default.
401
+ #
402
+ # ==== Examples
403
+ # my_time = Time.now + 6.hours
404
+ #
405
+ # # Generates a select field for minutes that defaults to the minutes for the time in my_time
406
+ # select_minute(my_time)
407
+ #
408
+ # # Generates a select field for minutes that defaults to the number given
409
+ # select_minute(14)
410
+ #
411
+ # # Generates a select field for minutes that defaults to the minutes for the time in my_time
412
+ # # that is named 'stride' rather than 'second'
413
+ # select_minute(my_time, :field_name => 'stride')
414
+ #
415
+ def select_hour(datetime, options = {}, html_options = {})
416
+ val = datetime ? (datetime.kind_of?(Fixnum) ? datetime : datetime.hour) : ''
417
+ if options[:use_hidden]
418
+ hidden_html(options[:field_name] || 'hour', val, options)
419
+ else
420
+ hour_options = []
421
+ 0.upto(23) do |hour|
422
+ hour_options << ((val == hour) ?
423
+ content_tag(:option, leading_zero_on_single_digits(hour), :value => leading_zero_on_single_digits(hour), :selected => "selected") :
424
+ content_tag(:option, leading_zero_on_single_digits(hour), :value => leading_zero_on_single_digits(hour))
425
+ )
426
+ hour_options << "\n"
427
+ end
428
+ select_html(options[:field_name] || 'hour', hour_options.join, options, html_options)
429
+ end
430
+ end
431
+
432
+ # Returns a select tag with options for each of the days 1 through 31 with the current day selected.
433
+ # The <tt>date</tt> can also be substituted for a hour number.
434
+ # Override the field name using the <tt>:field_name</tt> option, 'day' by default.
435
+ #
436
+ # ==== Examples
437
+ # my_date = Time.today + 2.days
438
+ #
439
+ # # Generates a select field for days that defaults to the day for the date in my_date
440
+ # select_day(my_time)
441
+ #
442
+ # # Generates a select field for days that defaults to the number given
443
+ # select_day(5)
444
+ #
445
+ # # Generates a select field for days that defaults to the day for the date in my_date
446
+ # # that is named 'due' rather than 'day'
447
+ # select_day(my_time, :field_name => 'due')
448
+ #
449
+ def select_day(date, options = {}, html_options = {})
450
+ val = date ? (date.kind_of?(Fixnum) ? date : date.day) : ''
451
+ if options[:use_hidden]
452
+ hidden_html(options[:field_name] || 'day', val, options)
453
+ else
454
+ day_options = []
455
+ 1.upto(31) do |day|
456
+ day_options << ((val == day) ?
457
+ content_tag(:option, day, :value => day, :selected => "selected") :
458
+ content_tag(:option, day, :value => day)
459
+ )
460
+ day_options << "\n"
461
+ end
462
+ select_html(options[:field_name] || 'day', day_options.join, options, html_options)
463
+ end
464
+ end
465
+
466
+ # Returns a select tag with options for each of the months January through December with the current month selected.
467
+ # The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are used as values
468
+ # (what's submitted to the server). It's also possible to use month numbers for the presentation instead of names --
469
+ # set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names,
470
+ # set the <tt>:add_month_numbers</tt> key in +options+ to true. If you would prefer to show month names as abbreviations,
471
+ # set the <tt>:use_short_month</tt> key in +options+ to true. If you want to use your own month names, set the
472
+ # <tt>:use_month_names</tt> key in +options+ to an array of 12 month names. Override the field name using the
473
+ # <tt>:field_name</tt> option, 'month' by default.
474
+ #
475
+ # ==== Examples
476
+ # # Generates a select field for months that defaults to the current month that
477
+ # # will use keys like "January", "March".
478
+ # select_month(Date.today)
479
+ #
480
+ # # Generates a select field for months that defaults to the current month that
481
+ # # is named "start" rather than "month"
482
+ # select_month(Date.today, :field_name => 'start')
483
+ #
484
+ # # Generates a select field for months that defaults to the current month that
485
+ # # will use keys like "1", "3".
486
+ # select_month(Date.today, :use_month_numbers => true)
487
+ #
488
+ # # Generates a select field for months that defaults to the current month that
489
+ # # will use keys like "1 - January", "3 - March".
490
+ # select_month(Date.today, :add_month_numbers => true)
491
+ #
492
+ # # Generates a select field for months that defaults to the current month that
493
+ # # will use keys like "Jan", "Mar".
494
+ # select_month(Date.today, :use_short_month => true)
495
+ #
496
+ # # Generates a select field for months that defaults to the current month that
497
+ # # will use keys like "Januar", "Marts."
498
+ # select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...))
499
+ #
500
+ def select_month(date, options = {}, html_options = {})
501
+ val = date ? (date.kind_of?(Fixnum) ? date : date.month) : ''
502
+ if options[:use_hidden]
503
+ hidden_html(options[:field_name] || 'month', val, options)
504
+ else
505
+ month_options = []
506
+ month_names = options[:use_month_names] || (options[:use_short_month] ? Date::ABBR_MONTHNAMES : Date::MONTHNAMES)
507
+ month_names.unshift(nil) if month_names.size < 13
508
+ 1.upto(12) do |month_number|
509
+ month_name = if options[:use_month_numbers]
510
+ month_number
511
+ elsif options[:add_month_numbers]
512
+ month_number.to_s + ' - ' + month_names[month_number]
513
+ else
514
+ month_names[month_number]
515
+ end
516
+
517
+ month_options << ((val == month_number) ?
518
+ content_tag(:option, month_name, :value => month_number, :selected => "selected") :
519
+ content_tag(:option, month_name, :value => month_number)
520
+ )
521
+ month_options << "\n"
522
+ end
523
+ select_html(options[:field_name] || 'month', month_options.join, options, html_options)
524
+ end
525
+ end
526
+
527
+ # Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius
528
+ # can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. Both ascending and descending year
529
+ # lists are supported by making <tt>:start_year</tt> less than or greater than <tt>:end_year</tt>. The <tt>date</tt> can also be
530
+ # substituted for a year given as a number. Override the field name using the <tt>:field_name</tt> option, 'year' by default.
531
+ #
532
+ # ==== Examples
533
+ # # Generates a select field for years that defaults to the current year that
534
+ # # has ascending year values
535
+ # select_year(Date.today, :start_year => 1992, :end_year => 2007)
536
+ #
537
+ # # Generates a select field for years that defaults to the current year that
538
+ # # is named 'birth' rather than 'year'
539
+ # select_year(Date.today, :field_name => 'birth')
540
+ #
541
+ # # Generates a select field for years that defaults to the current year that
542
+ # # has descending year values
543
+ # select_year(Date.today, :start_year => 2005, :end_year => 1900)
544
+ #
545
+ # # Generates a select field for years that defaults to the year 2006 that
546
+ # # has ascending year values
547
+ # select_year(2006, :start_year => 2000, :end_year => 2010)
548
+ #
549
+ def select_year(date, options = {}, html_options = {})
550
+ val = date ? (date.kind_of?(Fixnum) ? date : date.year) : ''
551
+ if options[:use_hidden]
552
+ hidden_html(options[:field_name] || 'year', val, options)
553
+ else
554
+ year_options = []
555
+ y = date ? (date.kind_of?(Fixnum) ? (y = (date == 0) ? Date.today.year : date) : date.year) : Date.today.year
556
+
557
+ start_year, end_year = (options[:start_year] || y-5), (options[:end_year] || y+5)
558
+ step_val = start_year < end_year ? 1 : -1
559
+ start_year.step(end_year, step_val) do |year|
560
+ year_options << ((val == year) ?
561
+ content_tag(:option, year, :value => year, :selected => "selected") :
562
+ content_tag(:option, year, :value => year)
563
+ )
564
+ year_options << "\n"
565
+ end
566
+ select_html(options[:field_name] || 'year', year_options.join, options, html_options)
567
+ end
568
+ end
569
+
570
+ private
571
+
572
+ def select_html(type, html_options, options, select_tag_options = {})
573
+ name_and_id_from_options(options, type)
574
+ select_options = {:id => options[:id], :name => options[:name]}
575
+ select_options.merge!(:disabled => 'disabled') if options[:disabled]
576
+ select_options.merge!(select_tag_options) unless select_tag_options.empty?
577
+ select_html = "\n"
578
+ select_html << content_tag(:option, '', :value => '') + "\n" if options[:include_blank]
579
+ select_html << html_options.to_s
580
+ content_tag(:select, select_html, select_options) + "\n"
581
+ end
582
+
583
+ def hidden_html(type, value, options)
584
+ name_and_id_from_options(options, type)
585
+ hidden_html = tag(:input, :type => "hidden", :id => options[:id], :name => options[:name], :value => value) + "\n"
586
+ end
587
+
588
+ def name_and_id_from_options(options, type)
589
+ options[:name] = (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
590
+ options[:id] = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '')
591
+ end
592
+
593
+ def leading_zero_on_single_digits(number)
594
+ number > 9 ? number : "0#{number}"
595
+ end
596
+ end
597
+
598
+ class InstanceTag #:nodoc:
599
+ include DateHelper
600
+
601
+ def to_date_select_tag(options = {}, html_options = {})
602
+ date_or_time_select(options.merge(:discard_hour => true), html_options)
603
+ end
604
+
605
+ def to_time_select_tag(options = {}, html_options = {})
606
+ date_or_time_select(options.merge(:discard_year => true, :discard_month => true), html_options)
607
+ end
608
+
609
+ def to_datetime_select_tag(options = {}, html_options = {})
610
+ date_or_time_select(options, html_options)
611
+ end
612
+
613
+ private
614
+ def date_or_time_select(options, html_options = {})
615
+ defaults = { :discard_type => true }
616
+ options = defaults.merge(options)
617
+ datetime = value(object)
618
+ datetime ||= default_time_from_options(options[:default]) unless options[:include_blank]
619
+
620
+ position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }
621
+
622
+ order = (options[:order] ||= [:year, :month, :day])
623
+
624
+ # Discard explicit and implicit by not being included in the :order
625
+ discard = {}
626
+ discard[:year] = true if options[:discard_year] or !order.include?(:year)
627
+ discard[:month] = true if options[:discard_month] or !order.include?(:month)
628
+ discard[:day] = true if options[:discard_day] or discard[:month] or !order.include?(:day)
629
+ discard[:hour] = true if options[:discard_hour]
630
+ discard[:minute] = true if options[:discard_minute] or discard[:hour]
631
+ discard[:second] = true unless options[:include_seconds] && !discard[:minute]
632
+
633
+ # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are valid
634
+ # (otherwise it could be 31 and february wouldn't be a valid date)
635
+ if datetime && discard[:day] && !discard[:month]
636
+ datetime = datetime.change(:day => 1)
637
+ end
638
+
639
+ # Maintain valid dates by including hidden fields for discarded elements
640
+ [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }
641
+
642
+ # Ensure proper ordering of :hour, :minute and :second
643
+ [:hour, :minute, :second].each { |o| order.delete(o); order.push(o) }
644
+
645
+ date_or_time_select = ''
646
+ order.reverse.each do |param|
647
+ # Send hidden fields for discarded elements once output has started
648
+ # This ensures AR can reconstruct valid dates using ParseDate
649
+ next if discard[param] && date_or_time_select.empty?
650
+
651
+ date_or_time_select.insert(0, self.send("select_#{param}", datetime, options_with_prefix(position[param], options.merge(:use_hidden => discard[param])), html_options))
652
+ date_or_time_select.insert(0,
653
+ case param
654
+ when :hour then (discard[:year] && discard[:day] ? "" : " &mdash; ")
655
+ when :minute then " : "
656
+ when :second then options[:include_seconds] ? " : " : ""
657
+ else ""
658
+ end)
659
+
660
+ end
661
+
662
+ date_or_time_select
663
+ end
664
+
665
+ def options_with_prefix(position, options)
666
+ prefix = "#{@object_name}"
667
+ if options[:index]
668
+ prefix << "[#{options[:index]}]"
669
+ elsif @auto_index
670
+ prefix << "[#{@auto_index}]"
671
+ end
672
+ options.merge(:prefix => "#{prefix}[#{@method_name}(#{position}i)]")
673
+ end
674
+
675
+ def default_time_from_options(default)
676
+ case default
677
+ when nil
678
+ Time.current
679
+ when Date, Time
680
+ default
681
+ else
682
+ # Rename :minute and :second to :min and :sec
683
+ default[:min] ||= default[:minute]
684
+ default[:sec] ||= default[:second]
685
+
686
+ time = Time.current
687
+
688
+ [:year, :month, :day, :hour, :min, :sec].each do |key|
689
+ default[key] ||= time.send(key)
690
+ end
691
+
692
+ Time.utc_time(default[:year], default[:month], default[:day], default[:hour], default[:min], default[:sec])
693
+ end
694
+ end
695
+ end
696
+
697
+ class FormBuilder
698
+ def date_select(method, options = {}, html_options = {})
699
+ @template.date_select(@object_name, method, options.merge(:object => @object), html_options)
700
+ end
701
+
702
+ def time_select(method, options = {}, html_options = {})
703
+ @template.time_select(@object_name, method, options.merge(:object => @object), html_options)
704
+ end
705
+
706
+ def datetime_select(method, options = {}, html_options = {})
707
+ @template.datetime_select(@object_name, method, options.merge(:object => @object), html_options)
708
+ end
709
+ end
710
+ end
711
+ end