rango 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (382) hide show
  1. data/CHANGELOG +6 -0
  2. data/CONTRIBUTORS +1 -0
  3. data/README.textile +4 -1
  4. data/bin/rango +1 -1
  5. data/lib/rango.rb +78 -12
  6. data/lib/rango/contrib/pagination.rb +2 -0
  7. data/lib/rango/controller.rb +58 -12
  8. data/lib/rango/environments.rb +26 -0
  9. data/lib/rango/exceptions.rb +2 -14
  10. data/lib/rango/gv.rb +7 -90
  11. data/lib/rango/gv/static.rb +22 -0
  12. data/lib/rango/helpers.rb +0 -1
  13. data/lib/rango/helpers/assets.rb +2 -0
  14. data/lib/rango/helpers/general.rb +1 -0
  15. data/lib/rango/helpers/syntax.rb +2 -0
  16. data/lib/rango/mini.rb +30 -0
  17. data/lib/rango/mixins/application.rb +5 -3
  18. data/lib/rango/mixins/configurable.rb +1 -0
  19. data/lib/rango/mixins/render.rb +13 -84
  20. data/lib/rango/orm/tasks/datamapper.rake +2 -2
  21. data/lib/rango/project.rb +2 -2
  22. data/lib/rango/rack/middlewares/basic.rb +15 -11
  23. data/lib/rango/rack/request.rb +5 -3
  24. data/lib/rango/router.rb +20 -2
  25. data/lib/rango/router/adapters/rack_mount.rb +0 -1
  26. data/lib/rango/router/adapters/rack_router.rb +0 -1
  27. data/lib/rango/router/adapters/urlmap.rb +0 -1
  28. data/lib/rango/router/adapters/usher.rb +0 -1
  29. data/lib/rango/settings/framework.rb +2 -43
  30. data/lib/rango/templates/{erubis.rb → exts/erubis.rb} +0 -19
  31. data/lib/rango/templates/exts/tilt.rb +16 -0
  32. data/lib/rango/templates/helpers.rb +107 -0
  33. data/lib/rango/templates/template.rb +44 -115
  34. data/lib/rango/utils.rb +9 -4
  35. data/spec/rango/controller_spec.rb +3 -1
  36. data/spec/rango/environments_spec.rb +68 -0
  37. data/spec/rango/gv_spec.rb +10 -0
  38. data/spec/rango/mini_spec.rb +58 -0
  39. data/spec/rango/project_spec.rb +1 -1
  40. data/spec/rango/templates/template_spec.rb +81 -0
  41. data/spec/rango/utils_spec.rb +33 -0
  42. data/spec/rango_spec.rb +3 -17
  43. data/spec/spec_helper.rb +5 -3
  44. data/spec/stubs/config.ru +5 -0
  45. data/spec/stubs/templates/capture.html.erb +1 -1
  46. data/spec/stubs/templates/erubis.html.erubis +2 -0
  47. data/spec/stubs/templates/inheritance/basic/base.html.haml +2 -0
  48. data/spec/stubs/templates/inheritance/basic/index.html.haml +2 -0
  49. data/spec/stubs/templates/inheritance/capture/erb/base.html.erb +3 -0
  50. data/spec/stubs/templates/inheritance/capture/erb/index.html.erb +4 -0
  51. data/spec/stubs/templates/inheritance/capture/erubis/base.html.erubis +3 -0
  52. data/spec/stubs/templates/inheritance/capture/erubis/index.html.erubis +4 -0
  53. data/spec/stubs/templates/inheritance/capture/haml/base.html.haml +2 -0
  54. data/spec/stubs/templates/inheritance/capture/haml/index.html.haml +3 -0
  55. data/spec/stubs/templates/test.html.haml +1 -0
  56. data/spec/stubs/templates/variables.html.haml +1 -0
  57. data/stubs/app/content/init.rb.rbt +2 -1
  58. data/stubs/app/content/views.rb.rbt +2 -0
  59. data/stubs/bigapp/content/views/%controller%.rb.rbt +2 -0
  60. data/stubs/project/content/config.ru.rbt +3 -0
  61. data/stubs/project/content/init.rb.rbt +11 -5
  62. data/stubs/project/content/settings.rb +0 -2
  63. data/stubs/project/content/settings_local.rb.rbt +1 -1
  64. data/stubs/project/content/templates/base.html.haml.rbt +1 -0
  65. metadata +42 -329
  66. data/examples/README.textile +0 -12
  67. data/examples/blog/Gemfile +0 -80
  68. data/examples/blog/Rakefile +0 -12
  69. data/examples/blog/TODO.txt +0 -0
  70. data/examples/blog/bin/autospec +0 -3
  71. data/examples/blog/bin/css2sass +0 -3
  72. data/examples/blog/bin/cucumber +0 -3
  73. data/examples/blog/bin/haml +0 -3
  74. data/examples/blog/bin/html2haml +0 -3
  75. data/examples/blog/bin/htmldiff +0 -3
  76. data/examples/blog/bin/launchy +0 -3
  77. data/examples/blog/bin/ldiff +0 -3
  78. data/examples/blog/bin/nokogiri +0 -3
  79. data/examples/blog/bin/racksh +0 -3
  80. data/examples/blog/bin/rackup +0 -3
  81. data/examples/blog/bin/rake +0 -3
  82. data/examples/blog/bin/rango +0 -3
  83. data/examples/blog/bin/sass +0 -3
  84. data/examples/blog/bin/shotgun +0 -3
  85. data/examples/blog/bin/simple-templater +0 -3
  86. data/examples/blog/bin/spec +0 -3
  87. data/examples/blog/bin/tt +0 -3
  88. data/examples/blog/blog/init.rb +0 -9
  89. data/examples/blog/blog/models.rb +0 -21
  90. data/examples/blog/blog/views.rb +0 -16
  91. data/examples/blog/config.ru +0 -19
  92. data/examples/blog/gems/cache/addressable-2.1.1.gem +0 -0
  93. data/examples/blog/gems/cache/builder-2.1.2.gem +0 -0
  94. data/examples/blog/gems/cache/bundler-0.7.0.gem +0 -0
  95. data/examples/blog/gems/cache/cli-0.0.1.gem +0 -0
  96. data/examples/blog/gems/cache/configuration-1.1.0.gem +0 -0
  97. data/examples/blog/gems/cache/cucumber-0.4.4.gem +0 -0
  98. data/examples/blog/gems/cache/data_objects-0.10.0.gem +0 -0
  99. data/examples/blog/gems/cache/diff-lcs-1.1.2.gem +0 -0
  100. data/examples/blog/gems/cache/dm-core-0.10.1.gem +0 -0
  101. data/examples/blog/gems/cache/dm-timestamps-0.10.1.gem +0 -0
  102. data/examples/blog/gems/cache/do_mysql-0.10.0.gem +0 -0
  103. data/examples/blog/gems/cache/do_sqlite3-0.10.0.gem +0 -0
  104. data/examples/blog/gems/cache/extlib-0.9.13.gem +0 -0
  105. data/examples/blog/gems/cache/fuzzyhash-0.0.9.gem +0 -0
  106. data/examples/blog/gems/cache/haml-2.2.14.gem +0 -0
  107. data/examples/blog/gems/cache/launchy-0.3.3.gem +0 -0
  108. data/examples/blog/gems/cache/media-path-0.1.gem +0 -0
  109. data/examples/blog/gems/cache/nokogiri-1.4.0.gem +0 -0
  110. data/examples/blog/gems/cache/polyglot-0.2.9.gem +0 -0
  111. data/examples/blog/gems/cache/rack-1.0.1.gem +0 -0
  112. data/examples/blog/gems/cache/rack-test-0.5.2.gem +0 -0
  113. data/examples/blog/gems/cache/racksh-0.9.4.2.gem +0 -0
  114. data/examples/blog/gems/cache/rake-0.8.7.gem +0 -0
  115. data/examples/blog/gems/cache/rango-0.1.0.gem +0 -0
  116. data/examples/blog/gems/cache/rspec-1.2.9.gem +0 -0
  117. data/examples/blog/gems/cache/rubyexts-0.0.1.gem +0 -0
  118. data/examples/blog/gems/cache/shotgun-0.4.gem +0 -0
  119. data/examples/blog/gems/cache/simple-templater-0.0.1.gem +0 -0
  120. data/examples/blog/gems/cache/term-ansicolor-1.0.4.gem +0 -0
  121. data/examples/blog/gems/cache/treetop-1.4.2.gem +0 -0
  122. data/examples/blog/gems/cache/usher-0.5.11.gem +0 -0
  123. data/examples/blog/gems/cache/webrat-0.5.3.gem +0 -0
  124. data/examples/blog/init.rb +0 -49
  125. data/examples/blog/settings.rb +0 -15
  126. data/examples/blog/settings_local.rb +0 -6
  127. data/examples/blog/spec/blog/init_spec.rb +0 -7
  128. data/examples/blog/spec/blog/models_spec.rb +0 -28
  129. data/examples/blog/spec/blog/views_spec.rb +0 -22
  130. data/examples/blog/spec/spec.opts +0 -5
  131. data/examples/blog/spec/spec_helper.rb +0 -27
  132. data/examples/blog/templates/base.html.haml +0 -16
  133. data/examples/blog/templates/index.html.haml +0 -12
  134. data/lib/rango/boot.rb +0 -55
  135. data/lib/rango/helpers/README +0 -179
  136. data/lib/rango/helpers/merb-helpers.rb +0 -3
  137. data/lib/rango/helpers/merb-helpers/core_ext.rb +0 -58
  138. data/lib/rango/helpers/merb-helpers/core_ext/numeric.rb +0 -389
  139. data/lib/rango/helpers/merb-helpers/date_time_formatting.rb +0 -146
  140. data/lib/rango/helpers/merb-helpers/date_time_helpers.rb +0 -191
  141. data/lib/rango/helpers/merb-helpers/form/builder.rb +0 -450
  142. data/lib/rango/helpers/merb-helpers/form/helpers.rb +0 -453
  143. data/lib/rango/helpers/merb-helpers/form_helpers.rb +0 -21
  144. data/lib/rango/helpers/merb-helpers/tag_helpers.rb +0 -63
  145. data/lib/rango/helpers/merb-helpers/text_helpers.rb +0 -73
  146. data/lib/rango/loggers/logger.rb +0 -100
  147. data/lib/rango/mixins/chainable.rb +0 -68
  148. data/lib/rango/mixins/hookable.rb +0 -32
  149. data/lib/rango/mixins/import.rb +0 -89
  150. data/lib/rango/mixins/mini.rb +0 -29
  151. data/lib/rango/mixins/strategy.rb +0 -28
  152. data/lib/rango/rango.rb +0 -93
  153. data/lib/rango/router/specification.txt +0 -11
  154. data/lib/rango/templates/adapter.rb +0 -19
  155. data/lib/rango/templates/adapters/erb.rb +0 -63
  156. data/lib/rango/templates/adapters/erubis.rb +0 -65
  157. data/lib/rango/templates/adapters/haml.rb +0 -26
  158. data/lib/rango/templates/templates.txt +0 -39
  159. data/spec/factories.rb +0 -22
  160. data/spec/rango/boot_spec.rb +0 -15
  161. data/spec/rango/helpers/merb-helpers/core_ext/numeric_spec.rb +0 -0
  162. data/spec/rango/helpers/merb-helpers/core_ext_spec.rb +0 -21
  163. data/spec/rango/helpers/merb-helpers/date_time_formatting_spec.rb +0 -0
  164. data/spec/rango/helpers/merb-helpers/date_time_helpers_spec.rb +0 -0
  165. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/application.rb +0 -4
  166. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_check_box.rb +0 -4
  167. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_file_field.rb +0 -4
  168. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_hidden_field.rb +0 -4
  169. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_option_tag.rb +0 -4
  170. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_password_field.rb +0 -4
  171. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_radio_button.rb +0 -4
  172. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_radio_group.rb +0 -4
  173. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_select.rb +0 -4
  174. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_text_area.rb +0 -4
  175. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/bound_text_field.rb +0 -4
  176. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/button.rb +0 -4
  177. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/check_box.rb +0 -4
  178. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/custom_builder.rb +0 -4
  179. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/delete_button.rb +0 -4
  180. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/exceptions.rb +0 -25
  181. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/field_set.rb +0 -4
  182. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/fields_for.rb +0 -3
  183. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/file_field.rb +0 -4
  184. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/foo.rb +0 -23
  185. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/form.rb +0 -4
  186. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/form_for.rb +0 -4
  187. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/hacker.rb +0 -4
  188. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/hidden_field.rb +0 -4
  189. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/label.rb +0 -4
  190. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/numeric_ext.rb +0 -4
  191. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/option_tag.rb +0 -4
  192. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/password_field.rb +0 -4
  193. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/radio_button.rb +0 -4
  194. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/radio_group.rb +0 -4
  195. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/relative_date.rb +0 -4
  196. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/relative_date_span.rb +0 -4
  197. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/select.rb +0 -4
  198. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/specs_controller.rb +0 -13
  199. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/submit.rb +0 -4
  200. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/tag_helper.rb +0 -23
  201. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/text_area.rb +0 -4
  202. data/spec/rango/helpers/merb-helpers/fixture/app/controllers/text_field.rb +0 -4
  203. data/spec/rango/helpers/merb-helpers/fixture/app/helpers/global_helpers.rb +0 -7
  204. data/spec/rango/helpers/merb-helpers/fixture/app/models/fake_dm_model.rb +0 -27
  205. data/spec/rango/helpers/merb-helpers/fixture/app/models/first_generic_fake_model.rb +0 -59
  206. data/spec/rango/helpers/merb-helpers/fixture/app/models/hacker_generic_model.rb +0 -7
  207. data/spec/rango/helpers/merb-helpers/fixture/app/models/second_generic_fake_model.rb +0 -20
  208. data/spec/rango/helpers/merb-helpers/fixture/app/models/third_generic_fake_model.rb +0 -5
  209. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/basic.html.erb +0 -4
  210. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/basic_unchecked.html.erb +0 -3
  211. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/checked.html.erb +0 -4
  212. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/errors.html.erb +0 -4
  213. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/label.html.erb +0 -3
  214. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/on_and_off.html.erb +0 -3
  215. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_check_box_specs/raise_value_error.html.erb +0 -3
  216. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/additional_attributes.html.erb +0 -3
  217. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/takes_string.html.erb +0 -3
  218. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_file_field_specs/with_label.html.erb +0 -3
  219. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/basic.html.erb +0 -3
  220. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/errors.html.erb +0 -3
  221. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/hidden_error.html.erb +0 -3
  222. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_hidden_field_specs/label.html.erb +0 -3
  223. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/grouped.html.erb +0 -3
  224. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/nested.html.erb +0 -3
  225. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_option_tag_specs/text_and_value.html.erb +0 -4
  226. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/attributes.html.erb +0 -3
  227. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/basic.html.erb +0 -3
  228. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_password_field_specs/label.html.erb +0 -3
  229. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_button_specs/basic.html.erb +0 -3
  230. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/basic.html.erb +0 -3
  231. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/hashes.html.erb +0 -3
  232. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/mixed.html.erb +0 -4
  233. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_radio_group_specs/override_id.html.erb +0 -3
  234. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/basic.html.erb +0 -3
  235. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/blank.html.erb +0 -3
  236. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/label.html.erb +0 -3
  237. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/multiple.html.erb +0 -3
  238. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/prompt.html.erb +0 -3
  239. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/with_options.html.erb +0 -3
  240. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_select_specs/with_options_with_blank.html.erb +0 -3
  241. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_area_specs/basic.html.erb +0 -3
  242. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_area_specs/label.html.erb +0 -3
  243. data/spec/rango/helpers/merb-helpers/fixture/app/views/bound_text_field_specs/basic.html.erb +0 -3
  244. data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/button_with_label.html.erb +0 -1
  245. data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/button_with_values.html.erb +0 -1
  246. data/spec/rango/helpers/merb-helpers/fixture/app/views/button_specs/disabled_button.html.erb +0 -1
  247. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/basic.html.erb +0 -1
  248. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/boolean.html.erb +0 -1
  249. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/disabled.html.erb +0 -1
  250. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/label.html.erb +0 -1
  251. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/on_off_is_boolean.html.erb +0 -1
  252. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raise_unless_both_on_and_off.html.erb +0 -2
  253. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raises_error_if_not_boolean.html.erb +0 -1
  254. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/raises_error_if_on_off_and_boolean_false.html.erb +0 -1
  255. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/simple.html.erb +0 -1
  256. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/to_string.html.erb +0 -8
  257. data/spec/rango/helpers/merb-helpers/fixture/app/views/check_box_specs/unchecked.html.erb +0 -2
  258. data/spec/rango/helpers/merb-helpers/fixture/app/views/custom_builder_specs/everything.html.erb +0 -10
  259. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_explicit_url.html.erb +0 -1
  260. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_extra_params.html.erb +0 -1
  261. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/delete_with_label.html.erb +0 -1
  262. data/spec/rango/helpers/merb-helpers/fixture/app/views/delete_button_specs/simple_delete.html.erb +0 -1
  263. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/client_error.html.erb +0 -37
  264. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/internal_server_error.html.erb +0 -216
  265. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/not_acceptable.html.erb +0 -38
  266. data/spec/rango/helpers/merb-helpers/fixture/app/views/exeptions/not_found.html.erb +0 -40
  267. data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/basic.html.erb +0 -3
  268. data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/midstream.html.erb +0 -7
  269. data/spec/rango/helpers/merb-helpers/fixture/app/views/fields_for_specs/nil.html.erb +0 -3
  270. data/spec/rango/helpers/merb-helpers/fixture/app/views/fieldset_specs/legend.html.erb +0 -3
  271. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/disabled.html.erb +0 -1
  272. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/makes_multipart.html.erb +0 -3
  273. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/with_label.html.erb +0 -1
  274. data/spec/rango/helpers/merb-helpers/fixture/app/views/file_field_specs/with_values.html.erb +0 -1
  275. data/spec/rango/helpers/merb-helpers/fixture/app/views/foo/bar.html.erb +0 -0
  276. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_for_specs/basic.html.erb +0 -3
  277. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/create_a_form.html.erb +0 -3
  278. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/create_a_multipart_form.html.erb +0 -3
  279. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/fake_delete_if_set.html.erb +0 -3
  280. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/fake_put_if_set.html.erb +0 -3
  281. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/get_if_set.html.erb +0 -3
  282. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/post_by_default.html.erb +0 -3
  283. data/spec/rango/helpers/merb-helpers/fixture/app/views/form_specs/resourceful_form.html.erb +0 -3
  284. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/file_field.html.erb +0 -3
  285. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/hidden_field.html.erb +0 -3
  286. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/option_tag.html.erb +0 -4
  287. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/password_field.html.erb +0 -3
  288. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/radio_button.html.erb +0 -3
  289. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/radio_group.html.erb +0 -3
  290. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/text_area.html.erb +0 -3
  291. data/spec/rango/helpers/merb-helpers/fixture/app/views/hacker/text_field.html.erb +0 -3
  292. data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/basic.html.erb +0 -1
  293. data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/disabled.html.erb +0 -1
  294. data/spec/rango/helpers/merb-helpers/fixture/app/views/hidden_field_specs/label.html.erb +0 -1
  295. data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic.html.erb +0 -1
  296. data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic_with_attributes.html.erb +0 -1
  297. data/spec/rango/helpers/merb-helpers/fixture/app/views/label_specs/basic_with_class.html.erb +0 -1
  298. data/spec/rango/helpers/merb-helpers/fixture/app/views/layout/application.html.erb +0 -11
  299. data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/minutes_to_hours.html.erb +0 -1
  300. data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/to_concurrency_default.html.erb +0 -1
  301. data/spec/rango/helpers/merb-helpers/fixture/app/views/numeric_ext_specs/two_digits.html.erb +0 -1
  302. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/array.html.erb +0 -1
  303. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/clean.html.erb +0 -1
  304. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/collection.html.erb +0 -1
  305. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/multiple_selects.html.erb +0 -1
  306. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/no_extra_attributes.html.erb +0 -1
  307. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/optgroups.html.erb +0 -1
  308. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/selected.html.erb +0 -1
  309. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/with_blank.html.erb +0 -1
  310. data/spec/rango/helpers/merb-helpers/fixture/app/views/option_tag_specs/with_prompt.html.erb +0 -1
  311. data/spec/rango/helpers/merb-helpers/fixture/app/views/password_field_specs/basic.html.erb +0 -1
  312. data/spec/rango/helpers/merb-helpers/fixture/app/views/password_field_specs/disabled.html.erb +0 -1
  313. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/basic.html.erb +0 -1
  314. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/checked.html.erb +0 -1
  315. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/disabled.html.erb +0 -1
  316. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/label.html.erb +0 -1
  317. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_button_specs/unchecked.html.erb +0 -1
  318. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/attributes.html.erb +0 -1
  319. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/basic.html.erb +0 -1
  320. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/checked.html.erb +0 -1
  321. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/hash.html.erb +0 -1
  322. data/spec/rango/helpers/merb-helpers/fixture/app/views/radio_group_specs/specific_attributes.html.erb +0 -1
  323. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_span_specs/date_span_on_same_day.html.erb +0 -1
  324. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_span_specs/date_span_on_same_day_on_different_year.html.erb +0 -1
  325. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_date_with_year.html.erb +0 -1
  326. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_date_without_year.html.erb +0 -1
  327. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_today.html.erb +0 -1
  328. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_tomorrow.html.erb +0 -1
  329. data/spec/rango/helpers/merb-helpers/fixture/app/views/relative_date_specs/relative_yesterday.html.erb +0 -1
  330. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/basic.html.erb +0 -1
  331. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/blank.html.erb +0 -1
  332. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/multiple.html.erb +0 -1
  333. data/spec/rango/helpers/merb-helpers/fixture/app/views/select_specs/selected.html.erb +0 -1
  334. data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/disabled_submit.html.erb +0 -1
  335. data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/submit_with_label.html.erb +0 -1
  336. data/spec/rango/helpers/merb-helpers/fixture/app/views/submit_specs/submit_with_values.html.erb +0 -1
  337. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/nested_tags.html.erb +0 -5
  338. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_attributes.html.erb +0 -1
  339. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_content.html.erb +0 -1
  340. data/spec/rango/helpers/merb-helpers/fixture/app/views/tag_helper/tag_with_content_in_the_block.html.erb +0 -3
  341. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/basic.html.erb +0 -1
  342. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/disabled.html.erb +0 -1
  343. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/label.html.erb +0 -1
  344. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_area_specs/nil.html.erb +0 -1
  345. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/basic.html.erb +0 -1
  346. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/class.html.erb +0 -1
  347. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/disabled.html.erb +0 -1
  348. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/label.html.erb +0 -1
  349. data/spec/rango/helpers/merb-helpers/fixture/app/views/text_field_specs/symbolized_name.html.erb +0 -1
  350. data/spec/rango/helpers/merb-helpers/fixture/config/environments/development.rb +0 -8
  351. data/spec/rango/helpers/merb-helpers/fixture/config/environments/production.rb +0 -7
  352. data/spec/rango/helpers/merb-helpers/fixture/config/environments/test.rb +0 -8
  353. data/spec/rango/helpers/merb-helpers/fixture/config/init.rb +0 -48
  354. data/spec/rango/helpers/merb-helpers/fixture/config/rack.rb +0 -13
  355. data/spec/rango/helpers/merb-helpers/fixture/config/router.rb +0 -40
  356. data/spec/rango/helpers/merb-helpers/fixture/public/images/merb.jpg +0 -0
  357. data/spec/rango/helpers/merb-helpers/fixture/public/merb.fcgi +0 -4
  358. data/spec/rango/helpers/merb-helpers/fixture/public/stylesheets/master.css +0 -119
  359. data/spec/rango/helpers/merb-helpers/form/builder_spec.rb +0 -0
  360. data/spec/rango/helpers/merb-helpers/form/helpers_spec.rb +0 -0
  361. data/spec/rango/helpers/merb-helpers/form_helpers_spec.rb +0 -0
  362. data/spec/rango/helpers/merb-helpers/merb_helpers_config_spec.rb +0 -85
  363. data/spec/rango/helpers/merb-helpers/merb_helpers_date_time_spec.rb +0 -270
  364. data/spec/rango/helpers/merb-helpers/merb_helpers_form_spec.rb +0 -1372
  365. data/spec/rango/helpers/merb-helpers/merb_helpers_tag_helper_spec.rb +0 -46
  366. data/spec/rango/helpers/merb-helpers/merb_helpers_text_spec.rb +0 -71
  367. data/spec/rango/helpers/merb-helpers/numeric_extlib_spec.rb +0 -138
  368. data/spec/rango/helpers/merb-helpers/ordinalize_spec.rb +0 -55
  369. data/spec/rango/helpers/merb-helpers/tag_helpers_spec.rb +0 -0
  370. data/spec/rango/helpers/merb-helpers/text_helpers_spec.rb +0 -0
  371. data/spec/rango/helpers/merb-helpers_spec.rb +0 -0
  372. data/spec/rango/mixins/chainable_spec.rb +0 -0
  373. data/spec/rango/mixins/hookable_spec.rb +0 -0
  374. data/spec/rango/mixins/import_spec.rb +0 -0
  375. data/spec/rango/mixins/mini_spec.rb +0 -0
  376. data/spec/rango/mixins/strategy_spec.rb +0 -0
  377. data/spec/rango/rango_spec.rb +0 -0
  378. data/spec/rango/templates/adapter_spec.rb +0 -0
  379. data/spec/rango/templates/adapters/erb_spec.rb +0 -0
  380. data/spec/rango/templates/adapters/erubis_spec.rb +0 -117
  381. data/spec/rango/templates/adapters/haml_spec.rb +0 -0
  382. data/spec/rango/templates/adapters/template_helpers.rb +0 -38
@@ -1,146 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "date"
4
-
5
- module DateAndTimeFormatting
6
- def self.included(base)
7
- base.class_eval do
8
- include DateAndTimeFormatting::InstanceMethods
9
- include OrdinalizedFormatting
10
- extend DateAndTimeFormatting::ClassMethods
11
- end
12
- end
13
-
14
- module InstanceMethods
15
- # Formats a date/time instance using a defined format
16
- #
17
- # ==== Parameters
18
- # format<Symbol>:: of the format key from Date.date_formats
19
- #
20
- # ==== Returns
21
- # String:: formatted string
22
- #
23
- # ==== Example
24
- # Time.now.formatted(:rfc822) # => "Sun, 16 Nov 2007 00:21:16 -0800"
25
- # Time.now.formatted(:db) # => "2008-11-16 00:22:09"
26
- #
27
- # You can also add your own formats using +Date.add_format+ when your app loads.
28
- #
29
- # # Add the following to your init.rb
30
- # Rango::BootLoader.before_app_loads do
31
- # Date.add_format(:matt, "%H:%M:%S %Y-%m-%d")
32
- # end
33
- #
34
- # # Format a Time instance with the format you just specified
35
- # Time.now.formatted(:matt) # => "00:00:00 2007-11-02"
36
- #
37
- #--
38
- # @public
39
- def formatted(format = :default)
40
- self.strftime(Date.formats[format])
41
- end
42
- end
43
-
44
- module ClassMethods
45
- @@formats = {
46
- :db => "%Y-%m-%d %H:%M:%S",
47
- :time => "%H:%M", # 21:12
48
- :date => "%Y-%m-%d", # 2008-12-04
49
- :short => "%d %b %H:%M", # 01 Sep 21:12
50
- :long => "%B %d, %Y %H:%M",
51
- :rfc822 => "%a, %d %b %Y %H:%M:%S %z"
52
- }
53
-
54
- # Lists the date and time formats
55
- #
56
- # ==== Returns
57
- # Hash:: a hash with all formats available
58
- # --
59
- # @public
60
- def formats
61
- @@formats
62
- end
63
-
64
- # Adds a date and time format
65
- #
66
- # Because this operation is not thread safe, you should define
67
- # custom formats when you load you application. The recommended way
68
- # to do that, is to use the before_app_loads bootloader.
69
- #
70
- # If you want to add a format at runtime, you will need to use a mutex
71
- # and synchronize it yourself.
72
- #
73
- # ==== Parameters
74
- # key<Symbol>:: name of the format
75
- # format<Hash>:: time format to use
76
- #
77
- # ==== Returns
78
- # Hash:: a hash with all formats available
79
- #
80
- # ==== Example
81
- #
82
- # Rango::BootLoader.before_app_loads do
83
- # Date.add_format(:matt, "%H:%M:%S %Y-%m-%d")
84
- # end
85
- #
86
- #
87
- # --
88
- # @public
89
- def add_format(key, format)
90
- formats.merge!({key => format})
91
- end
92
- end
93
- end
94
-
95
- module Ordinalize
96
- # Ordinalize turns a number into an ordinal string used to denote the
97
- # position in an ordered sequence such as 1st, 2nd, 3rd, 4th.
98
- #
99
- # ==== Examples
100
- # 1.ordinalize # => "1st"
101
- # 2.ordinalize # => "2nd"
102
- # 1002.ordinalize # => "1002nd"
103
- # 1003.ordinalize # => "1003rd"
104
- def ordinalize
105
- if (11..13).include?(self % 100)
106
- "#{self}th"
107
- else
108
- case self % 10
109
- when 1; "#{self}st"
110
- when 2; "#{self}nd"
111
- when 3; "#{self}rd"
112
- else "#{self}th"
113
- end
114
- end
115
- end
116
- end
117
-
118
- Integer.send :include, Ordinalize
119
-
120
- # Time.now.to_ordinalized_s :long
121
- # => "February 28th, 2006 21:10"
122
- module OrdinalizedFormatting
123
- def to_ordinalized_s(format = :default)
124
- format = Date.formats[format]
125
- return self.to_s if format.nil?
126
- strftime_ordinalized(format)
127
- end
128
-
129
- # Gives you a relative date in an attractive format
130
- #
131
- # ==== Parameters
132
- # format<String>:: strftime string used to format a time/date object
133
- # locale<String, Symbol>:: An optional value which can be used by localization plugins
134
- #
135
- # ==== Returns
136
- # String:: Ordinalized time/date object
137
- #
138
- # ==== Examples
139
- # 5.days.ago.strftime_ordinalized('%b %d, %Y') # =>
140
- def strftime_ordinalized(fmt, format = nil)
141
- strftime(fmt.gsub(/(^|[^-])%d/, '\1_%d_')).gsub(/_(\d+)_/) { |s| s[1..-2].to_i.ordinalize }
142
- end
143
- end
144
-
145
- Time.send(:include, DateAndTimeFormatting)
146
- Date.send(:include, DateAndTimeFormatting)
@@ -1,191 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Rango
4
- module Helpers
5
- # Provides a number of methods for displaying and dealing with dates and times
6
- #
7
- # Parts were strongly based on http://ar-code.svn.engineyard.com/plugins/relative_time_helpers/, and
8
- # active_support
9
- #
10
- # The key methods are `relative_date`, `relative_date_span`, and `relative_time_span`. This also gives
11
- # you the Rails style Time DSL for working with numbers eg. 3.months.ago or 5.days.until(1.year.from_now)
12
- module DateAndTime
13
- @@time_class = Time
14
- @@time_output = {
15
- :today => 'today',
16
- :yesterday => 'yesterday',
17
- :tomorrow => 'tomorrow',
18
- :initial_format => '%b %d',
19
- :year_format => ', %Y'
20
- }
21
-
22
- def self.time_class
23
- @@time_class
24
- end
25
-
26
- # ==== Parameters
27
- # format<Symbol>:: time format to use
28
- # locale<String, Symbol>:: An optional value which can be used by localization plugins
29
- #
30
- # ==== Returns
31
- # String:: a string used to format time using #strftime
32
- def self.time_output(format, locale=nil)
33
- @@time_output[format]
34
- end
35
-
36
- # Gives you a relative date in an attractive format
37
- #
38
- # ==== Parameters
39
- # time<~to_date>:: The Date or Time to test
40
- # locale<String, Symbol>:: An optional value which can be used by localization plugins
41
- #
42
- # ==== Returns
43
- # String:: Relative date
44
- #
45
- # ==== Examples
46
- # relative_date(Time.now.utc) => "today"
47
- # relative_date(5.days.ago) => "March 5th"
48
- # relative_date(1.year.ago) => "March 10th, 2007"
49
- def relative_date(time, locale=nil)
50
- date = time.to_date
51
- today = DateAndTime.time_class.now.to_date
52
- if date == today
53
- DateAndTime.time_output(:today, locale)
54
- elsif date == (today - 1)
55
- DateAndTime.time_output(:yesterday, locale)
56
- elsif date == (today + 1)
57
- DateAndTime.time_output(:tomorrow, locale)
58
- else
59
- fmt = DateAndTime.time_output(:initial_format, locale).dup
60
- fmt << DateAndTime.time_output(:year_format, locale) unless date.year == today.year
61
- time.strftime_ordinalized(fmt, locale)
62
- end
63
- end
64
-
65
- # Gives you a relative date span in an attractive format
66
- #
67
- # ==== Parameters
68
- # times<~first,~last>:: The Dates or Times to test
69
- #
70
- # ==== Returns
71
- # String:: The sexy relative date span
72
- #
73
- # ==== Examples
74
- # relative_date([1.second.ago, 10.seconds.ago]) => "March 10th"
75
- # relative_date([1.year.ago, 1.year.ago) => "March 10th, 2007"
76
- # relative_date([Time.now, 1.day.from_now]) => "March 10th - 11th"
77
- # relative_date([Time.now, 1.year.ago]) => "March 10th, 2007 - March 10th, 2008"
78
- def relative_date_span(times)
79
- times = [times.first, times.last].collect! { |t| t.to_date }
80
- times.sort!
81
- if times.first == times.last
82
- relative_date(times.first)
83
- else
84
- first = times.first; last = times.last; now = DateAndTime.time_class.now
85
- arr = [first.strftime_ordinalized('%b %d')]
86
- arr << ", #{first.year}" unless first.year == last.year
87
- arr << ' - '
88
- arr << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
89
- arr << last.day.ordinalize
90
- arr << ", #{last.year}" unless first.year == last.year && last.year == now.year
91
- arr.to_s
92
- end
93
- end
94
-
95
- # Gives you a relative date span in an attractive format
96
- #
97
- # ==== Parameters
98
- # times<~first,~last>:: The Dates or Times to test
99
- #
100
- # ==== Returns
101
- # String:: The sexy relative time span
102
- #
103
- # ==== Examples
104
- # relative_time_span([1.second.ago, 10.seconds.ago]) => "12:00 - 12:09 AM March 10th"
105
- # relative_time_span([1.year.ago, 1.year.ago) => "12:09 AM March 10th, 2007"
106
- # relative_time_span([Time.now, 13.hours.from_now]) => "12:09 AM - 1:09 PM March 10th"
107
- # relative_time_span([Time.now, 1.year.ago]) => "12:09 AM March 10th, 2007 - 12:09 AM March 10th, 2008"
108
- def relative_time_span(times)
109
- times = [times.first, times.last].collect! { |t| t.to_time }
110
- times.sort!
111
- if times.first == times.last
112
- "#{prettier_time(times.first)} #{relative_date(times.first)}"
113
- elsif times.first.to_date == times.last.to_date
114
- same_half = (times.first.hour/12 == times.last.hour/12)
115
- "#{prettier_time(times.first, !same_half)} - #{prettier_time(times.last)} #{relative_date(times.first)}"
116
-
117
- else
118
- first = times.first; last = times.last; now = DateAndTime.time_class.now
119
- arr = [prettier_time(first)]
120
- arr << ' '
121
- arr << first.strftime_ordinalized('%b %d')
122
- arr << ", #{first.year}" unless first.year == last.year
123
- arr << ' - '
124
- arr << prettier_time(last)
125
- arr << ' '
126
- arr << last.strftime('%b') << ' ' unless first.year == last.year && first.month == last.month
127
- arr << last.day.ordinalize
128
- arr << ", #{last.year}" unless first.year == last.year && last.year == now.year
129
- arr.to_s
130
- end
131
- end
132
-
133
- # Condenses time... very similar to time_ago_in_words in ActionPack
134
- #
135
- # ==== Parameters
136
- # from_time<~to_time>:: The Date or Time to start from
137
- # to_time<~to_time>:: The Date or Time to go to, Defaults to Time.now.utc
138
- # include_seconds<Boolean>:: Count the seconds initially, Defaults to false
139
- # locale<String, Symbol>:: An optional value which can be used by localization plugins
140
- #
141
- # ==== Returns
142
- # String:: The time distance
143
- #
144
- # ==== Examples
145
- # time_lost_in_words(3.minutes.from_now) # => 3 minutes
146
- # time_lost_in_words(Time.now - 15.hours) # => 15 hours
147
- # time_lost_in_words(Time.now, 3.minutes.from_now) # => 3 minutes
148
- # time_lost_in_words(Time.now) # => less than a minute
149
- # time_lost_in_words(Time.now, Time.now, true) # => less than 5 seconds
150
- #
151
- def time_lost_in_words(from_time, to_time = Time.now.utc, include_seconds = false, locale=nil)
152
- from_time = from_time.to_time if from_time.respond_to?(:to_time)
153
- to_time = to_time.to_time if to_time.respond_to?(:to_time)
154
- distance_in_minutes = (((to_time - from_time).abs)/60).round
155
- distance_in_seconds = ((to_time - from_time).abs).round
156
-
157
- case distance_in_minutes
158
- when 0..1
159
- return (distance_in_minutes == 0) ? 'less than a minute' : '1 minute' unless include_seconds
160
- case distance_in_seconds
161
- when 0..4 then 'less than 5 seconds'
162
- when 5..9 then 'less than 10 seconds'
163
- when 10..19 then 'less than 20 seconds'
164
- when 20..39 then 'half a minute'
165
- when 40..59 then 'less than a minute'
166
- else '1 minute'
167
- end
168
-
169
- when 2..44 then "#{distance_in_minutes} minutes"
170
- when 45..89 then 'about 1 hour'
171
- when 90..1439 then "about #{(distance_in_minutes.to_f / 60.0).round} hours"
172
- when 1440..2879 then '1 day'
173
- when 2880..43199 then "#{(distance_in_minutes / 1440).round} days"
174
- when 43200..86399 then 'about 1 month'
175
- when 86400..525599 then "#{(distance_in_minutes / 43200).round} months"
176
- when 525600..1051199 then 'about 1 year'
177
- else "over #{(distance_in_minutes / 525600).round} years"
178
- end
179
- end
180
- alias :time_ago_in_words :time_lost_in_words
181
-
182
- def prettier_time(time, ampm=true, locale=nil)
183
- time.strftime("%I:%M#{" %p" if ampm}").sub(/^0/, '')
184
- end
185
- end
186
- end
187
- end
188
-
189
- class Rango::Controller
190
- include Rango::Helpers::DateAndTime
191
- end
@@ -1,450 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require_relative "../tag_helpers"
4
-
5
- module Rango
6
- module Helpers
7
- module Form
8
- module Builder
9
- class Base
10
- include Rango::Helpers::Tag
11
- include Rango::Templates::TemplateHelpers
12
-
13
- def initialize(obj, name, origin)
14
- @obj, @origin = obj, origin
15
- @name = name || @obj.class.name.snake_case.split("/").last
16
- end
17
-
18
- def form(attrs = {}, &block)
19
- captured = @origin.capture(&block)
20
- fake_method_tag = process_form_attrs(attrs)
21
- tag(:form, fake_method_tag + captured, attrs)
22
- end
23
-
24
- def fieldset(attrs, &block)
25
- legend = (l_attr = attrs.delete(:legend)) ? tag(:legend, l_attr) : ""
26
- tag(:fieldset, legend + @origin.capture(&block), attrs)
27
- # @origin.concat(contents, block.binding)
28
- end
29
-
30
- %w(text password hidden file).each do |kind|
31
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
32
- def bound_#{kind}_field(method, attrs = {})
33
- name = control_name(method)
34
- update_bound_controls(method, attrs, "#{kind}")
35
- unbound_#{kind}_field({
36
- :name => name,
37
- :value => control_value(method)
38
- }.merge(attrs))
39
- end
40
-
41
- def unbound_#{kind}_field(attrs)
42
- update_unbound_controls(attrs, "#{kind}")
43
- self_closing_tag(:input, {:type => "#{kind}"}.merge(attrs))
44
- end
45
- RUBY
46
- end
47
-
48
- def bound_check_box(method, attrs = {})
49
- name = control_name(method)
50
- update_bound_controls(method, attrs, "checkbox")
51
- unbound_check_box({:name => name}.merge(attrs))
52
- end
53
-
54
- def unbound_check_box(attrs)
55
- update_unbound_controls(attrs, "checkbox")
56
- if attrs.delete(:boolean)
57
- on, off = attrs.delete(:on), attrs.delete(:off)
58
- unbound_hidden_field(:name => attrs[:name], :value => off) <<
59
- self_closing_tag(:input, {:type => "checkbox", :value => on}.merge(attrs))
60
- else
61
- self_closing_tag(:input, {:type => "checkbox"}.merge(attrs))
62
- end
63
- end
64
-
65
- def bound_radio_button(method, attrs = {})
66
- name = control_name(method)
67
- update_bound_controls(method, attrs, "radio")
68
- unbound_radio_button({:name => name, :value => control_value(method)}.merge(attrs))
69
- end
70
-
71
- def unbound_radio_button(attrs)
72
- update_unbound_controls(attrs, "radio")
73
- self_closing_tag(:input, {:type => "radio"}.merge(attrs))
74
- end
75
-
76
- def bound_radio_group(method, arr)
77
- val = control_value(method)
78
- arr.map do |attrs|
79
- attrs = {:value => attrs} unless attrs.is_a?(Hash)
80
- attrs[:checked] = true if (val == attrs[:value])
81
- radio_group_item(method, attrs)
82
- end.join
83
- end
84
-
85
- def unbound_radio_group(arr, attrs = {})
86
- arr.map do |ind_attrs|
87
- ind_attrs = {:value => ind_attrs} unless ind_attrs.is_a?(Hash)
88
- joined = attrs.merge(ind_attrs)
89
- joined.merge!(:label => joined[:label] || joined[:value])
90
- unbound_radio_button(joined)
91
- end.join
92
- end
93
-
94
- def bound_select(method, attrs = {})
95
- name = control_name(method)
96
- update_bound_controls(method, attrs, "select")
97
- unbound_select({:name => name}.merge(attrs))
98
- end
99
-
100
- def unbound_select(attrs = {})
101
- update_unbound_controls(attrs, "select")
102
- attrs[:name] << "[]" if attrs[:multiple] && !(attrs[:name] =~ /\[\]$/)
103
- tag(:select, options_for(attrs), attrs)
104
- end
105
-
106
- def bound_text_area(method, attrs = {})
107
- name = "#{@name}[#{method}]"
108
- update_bound_controls(method, attrs, "text_area")
109
- unbound_text_area(control_value(method), {:name => name}.merge(attrs))
110
- end
111
-
112
- def unbound_text_area(contents, attrs)
113
- update_unbound_controls(attrs, "text_area")
114
- tag(:textarea, contents, attrs)
115
- end
116
-
117
- def button(contents, attrs)
118
- update_unbound_controls(attrs, "button")
119
- tag(:button, contents, attrs)
120
- end
121
-
122
- def submit(value, attrs)
123
- attrs[:type] ||= "submit"
124
- attrs[:value] ||= value
125
- update_unbound_controls(attrs, "submit")
126
- self_closing_tag(:input, attrs)
127
- end
128
-
129
- private
130
-
131
- def process_form_attrs(attrs)
132
- method = attrs[:method]
133
-
134
- # Unless the method is :get, fake out the method using :post
135
- attrs[:method] = :post unless attrs[:method] == :get
136
- # Use a fake PUT if the object is not new, otherwise use the method
137
- # passed in. Defaults to :post if no method is set.
138
- method ||= (@obj.respond_to?(:new_record?) && !@obj.new_record?) || (@obj.respond_to?(:new?) && !@obj.new?) ? :put : :post
139
-
140
- attrs[:enctype] = "multipart/form-data" if attrs.delete(:multipart) || @multipart
141
-
142
- method == :post || method == :get ? "" : fake_out_method(attrs, method)
143
- end
144
-
145
- # This can be overridden to use another method to fake out methods
146
- def fake_out_method(attrs, method)
147
- self_closing_tag(:input, :type => "hidden", :name => "_method", :value => method)
148
- end
149
-
150
- def update_bound_controls(method, attrs, type)
151
- case type
152
- when "checkbox"
153
- update_bound_check_box(method, attrs)
154
- when "select"
155
- update_bound_select(method, attrs)
156
- end
157
- end
158
-
159
- def update_bound_check_box(method, attrs)
160
- raise ArgumentError, ":value can't be used with a bound_check_box" if attrs.has_key?(:value)
161
-
162
- attrs[:boolean] = attrs.fetch(:boolean, true)
163
-
164
- val = control_value(method)
165
- attrs[:checked] = attrs.key?(:on) ? val == attrs[:on] : considered_true?(val)
166
- end
167
-
168
- def update_bound_select(method, attrs)
169
- attrs[:value_method] ||= method
170
- attrs[:text_method] ||= attrs[:value_method] || :to_s
171
- attrs[:selected] ||= control_value(attrs[:value_method])
172
- end
173
-
174
- def update_unbound_controls(attrs, type)
175
- case type
176
- when "checkbox"
177
- update_unbound_check_box(attrs)
178
- when "radio"
179
- update_unbound_radio_button(attrs)
180
- when "file"
181
- @multipart = true
182
- end
183
-
184
- attrs[:disabled] ? attrs[:disabled] = "disabled" : attrs.delete(:disabled)
185
- end
186
-
187
- def update_unbound_check_box(attrs)
188
- boolean = attrs[:boolean] || (attrs[:on] && attrs[:off]) ? true : false
189
-
190
- case
191
- when attrs.key?(:on) ^ attrs.key?(:off)
192
- raise ArgumentError, ":on and :off must be specified together"
193
- when (attrs[:boolean] == false) && (attrs.key?(:on))
194
- raise ArgumentError, ":boolean => false cannot be used with :on and :off"
195
- when boolean && attrs.key?(:value)
196
- raise ArgumentError, ":value can't be used with a boolean checkbox"
197
- end
198
-
199
- if attrs[:boolean] = boolean
200
- attrs[:on] ||= "1"; attrs[:off] ||= "0"
201
- end
202
-
203
- attrs[:checked] = "checked" if attrs.delete(:checked)
204
- end
205
-
206
- def update_unbound_radio_button(attrs)
207
- attrs[:checked] = "checked" if attrs.delete(:checked)
208
- end
209
-
210
- # Accepts a collection (hash, array, enumerable, your type) and returns a string of option tags.
211
- # Given a collection where the elements respond to first and last (such as a two-element array),
212
- # the "lasts" serve as option values and the "firsts" as option text. Hashes are turned into
213
- # this form automatically, so the keys become "firsts" and values become lasts. If selected is
214
- # specified, the matching "last" or element will get the selected option-tag. Selected may also
215
- # be an array of values to be selected when using a multiple select.
216
- #
217
- # ==== Parameters
218
- # attrs<Hash>:: HTML attributes and options
219
- #
220
- # ==== Options
221
- # +selected+:: The value of a selected object, which may be either a string or an array.
222
- # +prompt+:: Adds an addtional option tag with the provided string with no value.
223
- # +include_blank+:: Adds an additional blank option tag with no value.
224
- #
225
- # ==== Returns
226
- # String:: HTML
227
- #
228
- # ==== Examples
229
- # <%= options_for [["apple", "Apple Pie"], ["orange", "Orange Juice"]], :selected => "orange"
230
- # => <option value="apple">Apple Pie</option><option value="orange" selected="selected">Orange Juice</option>
231
- #
232
- # <%= options_for [["apple", "Apple Pie"], ["orange", "Orange Juice"]], :selected => ["orange", "apple"], :prompt => "Select One"
233
- # => <option value="">Select One</option><option value="apple" selected="selected">Apple Pie</option><option value="orange" selected="selected">Orange Juice</option>
234
- def options_for(attrs)
235
- blank, prompt = attrs.delete(:include_blank), attrs.delete(:prompt)
236
- b = blank || prompt ? tag(:option, prompt || "", :value => "") : ""
237
-
238
- # yank out the options attrs
239
- collection, selected, text_method, value_method =
240
- attrs.extract!(:collection, :selected, :text_method, :value_method)
241
-
242
- # if the collection is a Hash, optgroups are a-coming
243
- if collection.is_a?(Hash)
244
- ([b] + collection.map do |g,col|
245
- tag(:optgroup, options(col, text_method, value_method, selected), :label => g)
246
- end).join
247
- else
248
- options(collection || [], text_method, value_method, selected, b)
249
- end
250
- end
251
-
252
- def options(col, text_meth, value_meth, sel, b = nil)
253
- ([b] + col.map do |item|
254
- text_meth = text_meth && item.respond_to?(text_meth) ? text_meth : :last
255
- value_meth = value_meth && item.respond_to?(value_meth) ? value_meth : :first
256
-
257
- text = item.is_a?(String) ? item : item.send(text_meth)
258
- value = item.is_a?(String) ? item : item.send(value_meth)
259
-
260
- # unless Rango.disabled?(:merb_helper_escaping)
261
- # text = Rango::Parse.escape_xml(text)
262
- # value = Rango::Parse.escape_xml(value)
263
- # end
264
-
265
- option_attrs = {:value => value}
266
- if sel.is_a?(Array)
267
- option_attrs.merge!(:selected => "selected") if value.in? sel
268
- else
269
- option_attrs.merge!(:selected => "selected") if value == sel
270
- end
271
- tag(:option, text, option_attrs)
272
- end).join
273
- end
274
-
275
- def radio_group_item(method, attrs)
276
- attrs.merge!(:checked => "checked") if attrs[:checked]
277
- bound_radio_button(method, attrs)
278
- end
279
-
280
- def considered_true?(value)
281
- value && value != "false" && value != "0" && value != 0
282
- end
283
-
284
- def control_name(method)
285
- @obj ? "#{@name}[#{method}]" : method
286
- end
287
-
288
- def control_value(method)
289
- value = @obj ? @obj.send(method) : @origin.params[method]
290
- # if Rango.disabled?(:merb_helper_escaping)
291
- value.to_s
292
- # else
293
- # Rango::Parse.escape_xml(value.to_s)
294
- # end
295
- end
296
-
297
- def add_css_class(attrs, new_class)
298
- attrs[:class] = attrs[:class] ? "#{attrs[:class]} #{new_class}" : new_class
299
- end
300
- end
301
-
302
- class Form < Base
303
- def label(contents, attrs = {})
304
- if contents
305
- if contents.is_a?(Hash)
306
- label_attrs = contents
307
- contents = label_attrs.delete(:title)
308
- else
309
- label_attrs = attrs
310
- end
311
- tag(:label, contents, label_attrs)
312
- else
313
- ""
314
- end
315
- end
316
-
317
- %w(text password file).each do |kind|
318
- self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
319
- def unbound_#{kind}_field(attrs = {})
320
- unbound_label(attrs) + super
321
- end
322
- RUBY
323
- end
324
-
325
- def unbound_label(attrs = {})
326
- if attrs[:id]
327
- label_attrs = {:for => attrs[:id]}
328
- elsif attrs[:name]
329
- label_attrs = {:for => attrs[:name]}
330
- else
331
- label_attrs = {}
332
- end
333
-
334
- label_option = attrs.delete(:label)
335
- if label_option.is_a? Hash
336
- label(label_attrs.merge(label_option))
337
- else
338
- label(label_option, label_attrs)
339
- end
340
- end
341
-
342
- def unbound_check_box(attrs = {})
343
- label_text = unbound_label(attrs)
344
- super + label_text
345
- end
346
-
347
- def unbound_hidden_field(attrs = {})
348
- attrs.delete(:label)
349
- super
350
- end
351
-
352
- def unbound_radio_button(attrs = {})
353
- label_text = unbound_label(attrs)
354
- super + label_text
355
- end
356
-
357
- def unbound_select(attrs = {})
358
- unbound_label(attrs) + super
359
- end
360
-
361
- def unbound_text_area(contents, attrs = {})
362
- unbound_label(attrs) + super
363
- end
364
-
365
- def button(contents, attrs = {})
366
- unbound_label(attrs) + super
367
- end
368
-
369
- def submit(value, attrs = {})
370
- unbound_label(attrs) + super
371
- end
372
-
373
- private
374
-
375
- def update_bound_controls(method, attrs, type)
376
- attrs.merge!(:id => "#{@name}_#{method}") unless attrs[:id]
377
- super
378
- end
379
-
380
- def update_unbound_controls(attrs, type)
381
- attrs.merge!(:id => attrs[:name]) if attrs[:name] && !attrs[:id]
382
-
383
- case type
384
- when "text", "radio", "password", "hidden", "checkbox", "file"
385
- add_css_class(attrs, type)
386
- end
387
- super
388
- end
389
-
390
- def radio_group_item(method, attrs)
391
- unless attrs[:id]
392
- attrs.merge!(:id => "#{@name}_#{method}_#{attrs[:value]}")
393
- end
394
-
395
- attrs.merge!(:label => attrs[:label] || attrs[:value])
396
- super
397
- end
398
- end
399
-
400
- module Errorifier
401
- def error_messages_for(obj, error_class, build_li, header, before)
402
- obj ||= @obj
403
- return "" unless obj.respond_to?(:errors)
404
-
405
- sequel = !obj.errors.respond_to?(:each)
406
- errors = sequel ? obj.errors.full_messages : obj.errors
407
-
408
- return "" if errors.empty?
409
-
410
- header_message = header % [errors.size, errors.size == 1 ? "" : "s"]
411
- markup = %Q{<div class='#{error_class}'>#{header_message}<ul>}
412
- errors.each {|err| markup << (build_li % (sequel ? err : err.join(" ")))}
413
- markup << %Q{</ul></div>}
414
- end
415
-
416
- private
417
-
418
- def update_bound_controls(method, attrs, type)
419
- if @obj && !@obj.errors.on(method.to_sym).blank?
420
- add_css_class(attrs, "error")
421
- end
422
- super
423
- end
424
- end
425
-
426
- class FormWithErrors < Form
427
- include Errorifier
428
- end
429
-
430
- module Resourceful
431
- private
432
-
433
- def process_form_attrs(attrs)
434
- attrs[:action] ||= @origin.url(@name, @obj) if @origin
435
- super
436
- end
437
- end
438
-
439
- class ResourcefulForm < Form
440
- include Resourceful
441
- end
442
-
443
- class ResourcefulFormWithErrors < FormWithErrors
444
- include Errorifier
445
- include Resourceful
446
- end
447
- end
448
- end
449
- end
450
- end