middleman 2.0.16.1 → 3.0.0.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. data/.gitignore +2 -1
  2. data/CHANGELOG +16 -8
  3. data/features/builder.feature +2 -5
  4. data/features/cache_buster.feature +1 -1
  5. data/features/clean_build.feature +0 -1
  6. data/features/coffee-script.feature +3 -3
  7. data/features/custom_layout_engines.feature +10 -0
  8. data/features/directory_index.feature +0 -1
  9. data/features/dynamic_pages.feature +0 -1
  10. data/features/fonts.feature +0 -1
  11. data/features/{padrino_helpers.feature → former_padrino_helpers.feature} +1 -1
  12. data/features/sprockets.feature +34 -5
  13. data/features/sprockets_gems.feature +7 -4
  14. data/features/step_definitions/asset_host_steps.rb +7 -6
  15. data/features/step_definitions/builder_steps.rb +4 -0
  16. data/features/step_definitions/middleman_steps.rb +22 -16
  17. data/features/step_definitions/page_layout_steps.rb +10 -8
  18. data/fixtures/custom-layout-app/config.rb +1 -0
  19. data/fixtures/custom-layout-app/source/index.html.erb +1 -0
  20. data/fixtures/custom-layout-app/source/layout.haml +6 -0
  21. data/fixtures/sprockets-app/config.rb +2 -1
  22. data/fixtures/sprockets-app/source/library/css/bootstrap_include.css.scss +1 -0
  23. data/fixtures/sprockets-app/source/library/css/plain.css +3 -0
  24. data/fixtures/sprockets-app/source/library/css/sprockets_base1.css.scss +1 -0
  25. data/fixtures/sprockets-app/source/library/css/sprockets_base2.css.scss +1 -0
  26. data/fixtures/sprockets-app/source/library/css/sprockets_sub.css.scss +1 -0
  27. data/fixtures/sprockets-app/source/{jquery_include.js → library/js/jquery_include.js} +0 -0
  28. data/fixtures/sprockets-app/source/library/js/plain.js +3 -0
  29. data/fixtures/sprockets-app/source/library/{javascripts → js}/sprockets_base.js +0 -0
  30. data/fixtures/sprockets-app/source/library/{javascripts → js}/sprockets_sub.js +0 -0
  31. data/fixtures/test-app/config.rb +5 -4
  32. data/fixtures/test-app/source/{padrino_test.html.haml → former_padrino_test.html.haml} +0 -0
  33. data/fixtures/test-app/source/stylesheets/sprockets_base1.css.scss +1 -0
  34. data/fixtures/test-app/source/stylesheets/sprockets_base2.css.scss +1 -0
  35. data/fixtures/test-app/source/stylesheets/sprockets_sub.css.scss +1 -0
  36. data/lib/middleman.rb +27 -25
  37. data/lib/middleman/base.rb +408 -166
  38. data/lib/middleman/builder.rb +78 -162
  39. data/lib/middleman/cli.rb +61 -32
  40. data/lib/middleman/core_extensions/assets.rb +4 -44
  41. data/lib/middleman/core_extensions/builder.rb +12 -16
  42. data/lib/middleman/core_extensions/compass.rb +28 -57
  43. data/lib/middleman/core_extensions/data.rb +65 -49
  44. data/lib/middleman/core_extensions/default_helpers.rb +33 -18
  45. data/lib/middleman/core_extensions/features.rb +48 -26
  46. data/lib/middleman/core_extensions/file_watcher.rb +66 -0
  47. data/lib/middleman/core_extensions/front_matter.rb +91 -86
  48. data/lib/middleman/core_extensions/rendering.rb +9 -8
  49. data/lib/middleman/core_extensions/routing.rb +19 -53
  50. data/lib/middleman/core_extensions/sitemap.rb +229 -0
  51. data/lib/middleman/core_extensions/sprockets.rb +53 -37
  52. data/lib/middleman/features/asset_host.rb +20 -10
  53. data/lib/middleman/features/automatic_image_sizes.rb +12 -9
  54. data/lib/middleman/features/cache_buster.rb +38 -25
  55. data/lib/middleman/features/directory_indexes.rb +31 -28
  56. data/lib/middleman/features/minify_css.rb +3 -2
  57. data/lib/middleman/features/minify_css/cssmin.rb +55 -0
  58. data/lib/middleman/features/minify_javascript.rb +12 -5
  59. data/lib/middleman/features/relative_assets.rb +28 -25
  60. data/lib/middleman/features/sitemap_tree.rb +34 -0
  61. data/lib/middleman/guard.rb +57 -23
  62. data/lib/middleman/renderers/erb.rb +29 -0
  63. data/lib/middleman/renderers/liquid.rb +3 -12
  64. data/lib/middleman/renderers/markdown.rb +16 -15
  65. data/lib/middleman/renderers/sass.rb +34 -38
  66. data/lib/middleman/vendor/hooks-0.2.0/CHANGES.textile +9 -0
  67. data/lib/middleman/vendor/hooks-0.2.0/Gemfile +3 -0
  68. data/lib/middleman/vendor/hooks-0.2.0/README.rdoc +107 -0
  69. data/lib/middleman/vendor/hooks-0.2.0/Rakefile +12 -0
  70. data/lib/middleman/vendor/hooks-0.2.0/hooks.gemspec +22 -0
  71. data/lib/middleman/vendor/hooks-0.2.0/lib/hooks.rb +109 -0
  72. data/lib/middleman/vendor/hooks-0.2.0/lib/hooks/inheritable_attribute.rb +33 -0
  73. data/lib/middleman/vendor/hooks-0.2.0/test/hooks_test.rb +141 -0
  74. data/lib/middleman/vendor/hooks-0.2.0/test/inheritable_attribute_test.rb +55 -0
  75. data/lib/middleman/vendor/hooks-0.2.0/test/test_helper.rb +10 -0
  76. data/lib/middleman/vendor/padrino-core-0.10.5/.document +5 -0
  77. data/lib/middleman/vendor/padrino-core-0.10.5/.gitignore +22 -0
  78. data/lib/middleman/vendor/padrino-core-0.10.5/.yardopts +1 -0
  79. data/lib/middleman/vendor/padrino-core-0.10.5/LICENSE.txt +20 -0
  80. data/lib/middleman/vendor/padrino-core-0.10.5/README.rdoc +294 -0
  81. data/lib/middleman/vendor/padrino-core-0.10.5/Rakefile +5 -0
  82. data/lib/middleman/vendor/padrino-core-0.10.5/bin/padrino +9 -0
  83. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core.rb +167 -0
  84. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application.rb +270 -0
  85. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application/rendering.rb +292 -0
  86. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application/routing.rb +934 -0
  87. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/application/showexceptions.rb +20 -0
  88. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/caller.rb +53 -0
  89. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/adapter.rb +24 -0
  90. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/base.rb +151 -0
  91. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/console.rb +20 -0
  92. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/rake.rb +24 -0
  93. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/cli/rake_tasks.rb +59 -0
  94. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/command.rb +38 -0
  95. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/images/404.png +0 -0
  96. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/images/500.png +0 -0
  97. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/loader.rb +210 -0
  98. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/cs.yml +34 -0
  99. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/da.yml +34 -0
  100. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/de.yml +34 -0
  101. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/en.yml +34 -0
  102. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/es.yml +34 -0
  103. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/fr.yml +34 -0
  104. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/hu.yml +34 -0
  105. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/it.yml +40 -0
  106. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/ja.yml +34 -0
  107. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/lv.yml +34 -0
  108. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/nl.yml +34 -0
  109. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/no.yml +35 -0
  110. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/pl.yml +34 -0
  111. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/pt_br.yml +40 -0
  112. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/ru.yml +35 -0
  113. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/tr.yml +34 -0
  114. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/uk.yml +34 -0
  115. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/zh_cn.yml +34 -0
  116. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/locale/zh_tw.yml +34 -0
  117. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/logger.rb +345 -0
  118. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/mounter.rb +224 -0
  119. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/reloader.rb +254 -0
  120. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/router.rb +98 -0
  121. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/server.rb +79 -0
  122. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/support_lite.rb +199 -0
  123. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/tasks.rb +21 -0
  124. data/lib/middleman/vendor/padrino-core-0.10.5/lib/padrino-core/version.rb +20 -0
  125. data/lib/middleman/vendor/padrino-core-0.10.5/padrino-core.gemspec +38 -0
  126. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/.components +6 -0
  127. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/.gitignore +7 -0
  128. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/complex.rb +32 -0
  129. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/apps/simple.rb +33 -0
  130. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/a.rb +9 -0
  131. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/b.rb +4 -0
  132. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/c.rb +1 -0
  133. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/circular/e.rb +13 -0
  134. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/circular/f.rb +2 -0
  135. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/circular/g.rb +2 -0
  136. data/lib/middleman/vendor/padrino-core-0.10.5/test/fixtures/dependencies/d.rb +4 -0
  137. data/lib/middleman/vendor/padrino-core-0.10.5/test/helper.rb +81 -0
  138. data/lib/middleman/vendor/padrino-core-0.10.5/test/mini_shoulda.rb +45 -0
  139. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_application.rb +108 -0
  140. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_core.rb +79 -0
  141. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_dependencies.rb +44 -0
  142. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_filters.rb +278 -0
  143. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_locale.rb +21 -0
  144. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_logger.rb +100 -0
  145. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_mounter.rb +177 -0
  146. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_reloader_complex.rb +75 -0
  147. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_reloader_simple.rb +98 -0
  148. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_rendering.rb +461 -0
  149. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_restful_routing.rb +33 -0
  150. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_router.rb +146 -0
  151. data/lib/middleman/vendor/padrino-core-0.10.5/test/test_routing.rb +1673 -0
  152. data/lib/middleman/vendor/padrino-helpers-0.10.5/.document +5 -0
  153. data/lib/middleman/vendor/padrino-helpers-0.10.5/.gitignore +21 -0
  154. data/lib/middleman/vendor/padrino-helpers-0.10.5/.yardopts +1 -0
  155. data/lib/middleman/vendor/padrino-helpers-0.10.5/LICENSE.txt +20 -0
  156. data/lib/middleman/vendor/padrino-helpers-0.10.5/README.rdoc +239 -0
  157. data/lib/middleman/vendor/padrino-helpers-0.10.5/Rakefile +5 -0
  158. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers.rb +58 -0
  159. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/asset_tag_helpers.rb +420 -0
  160. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/form_builder/abstract_form_builder.rb +220 -0
  161. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/form_builder/standard_form_builder.rb +43 -0
  162. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/form_helpers.rb +602 -0
  163. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/format_helpers.rb +381 -0
  164. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/cs.yml +103 -0
  165. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/da.yml +91 -0
  166. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/de.yml +81 -0
  167. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/en.yml +103 -0
  168. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/es.yml +103 -0
  169. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/fr.yml +80 -0
  170. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/hu.yml +103 -0
  171. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/it.yml +89 -0
  172. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/ja.yml +103 -0
  173. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/lv.yml +103 -0
  174. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/nl.yml +82 -0
  175. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/no.yml +91 -0
  176. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/pl.yml +95 -0
  177. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/pt_br.yml +103 -0
  178. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/ru.yml +103 -0
  179. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/tr.yml +103 -0
  180. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/uk.yml +103 -0
  181. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/zh_cn.yml +104 -0
  182. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/locale/zh_tw.yml +103 -0
  183. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/number_helpers.rb +288 -0
  184. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers.rb +175 -0
  185. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/abstract_handler.rb +98 -0
  186. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/erb_handler.rb +79 -0
  187. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/haml_handler.rb +63 -0
  188. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/output_helpers/slim_handler.rb +81 -0
  189. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/render_helpers.rb +60 -0
  190. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/tag_helpers.rb +103 -0
  191. data/lib/middleman/vendor/padrino-helpers-0.10.5/lib/padrino-helpers/translation_helpers.rb +38 -0
  192. data/lib/middleman/vendor/padrino-helpers-0.10.5/padrino-helpers.gemspec +27 -0
  193. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/app.rb +73 -0
  194. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/capture_concat.erb +14 -0
  195. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/capture_concat.haml +12 -0
  196. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/capture_concat.slim +13 -0
  197. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_for.erb +14 -0
  198. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_for.haml +12 -0
  199. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_for.slim +12 -0
  200. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_tag.erb +11 -0
  201. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_tag.haml +9 -0
  202. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/content_tag.slim +9 -0
  203. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/current_engine.erb +5 -0
  204. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/current_engine.haml +5 -0
  205. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/current_engine.slim +5 -0
  206. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/fields_for.erb +20 -0
  207. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/fields_for.haml +15 -0
  208. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/fields_for.slim +15 -0
  209. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_for.erb +56 -0
  210. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_for.haml +47 -0
  211. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_for.slim +47 -0
  212. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_tag.erb +56 -0
  213. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_tag.haml +45 -0
  214. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/form_tag.slim +45 -0
  215. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/link_to.erb +5 -0
  216. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/link_to.haml +4 -0
  217. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/link_to.slim +4 -0
  218. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/mail_to.erb +3 -0
  219. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/mail_to.haml +3 -0
  220. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/mail_to.slim +3 -0
  221. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/meta_tag.erb +3 -0
  222. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/meta_tag.haml +3 -0
  223. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/meta_tag.slim +3 -0
  224. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/partials/_erb.erb +1 -0
  225. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/partials/_haml.haml +1 -0
  226. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/partials/_slim.slim +1 -0
  227. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/simple_partial.erb +1 -0
  228. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/simple_partial.haml +1 -0
  229. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/markup_app/views/simple_partial.slim +1 -0
  230. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/app.rb +50 -0
  231. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engine.haml +5 -0
  232. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engines/_erb.erb +1 -0
  233. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engines/_haml.haml +1 -0
  234. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/current_engines/_slim.slim +1 -0
  235. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/erb/test.erb +1 -0
  236. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/explicit_engine.haml +5 -0
  237. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/haml/test.haml +1 -0
  238. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/template/_user.haml +7 -0
  239. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/template/haml_template.haml +1 -0
  240. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/fixtures/render_app/views/template/some_template.haml +2 -0
  241. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/helper.rb +66 -0
  242. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_asset_tag_helpers.rb +320 -0
  243. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_form_builder.rb +996 -0
  244. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_form_helpers.rb +645 -0
  245. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_format_helpers.rb +227 -0
  246. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_locale.rb +20 -0
  247. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_number_helpers.rb +136 -0
  248. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_output_helpers.rb +153 -0
  249. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_render_helpers.rb +76 -0
  250. data/lib/middleman/vendor/padrino-helpers-0.10.5/test/test_tag_helpers.rb +105 -0
  251. data/lib/middleman/version.rb +1 -1
  252. data/middleman-x86-mingw32.gemspec +16 -33
  253. data/middleman.gemspec +16 -31
  254. metadata +590 -349
  255. data/features/sinatra.feature +0 -6
  256. data/lib/middleman/core_extensions/rack_map.rb +0 -35
  257. data/lib/middleman/renderers/coffee_script.rb +0 -8
  258. data/lib/middleman/renderers/haml.rb +0 -31
  259. data/lib/middleman/renderers/slim.rb +0 -8
@@ -0,0 +1,220 @@
1
+ module Padrino
2
+ module Helpers
3
+ module FormBuilder # @private
4
+ class AbstractFormBuilder # @private
5
+ attr_accessor :template, :object
6
+
7
+ def initialize(template, object, options={})
8
+ @template = template
9
+ @object = build_object(object)
10
+ @options = options
11
+ raise "FormBuilder template must be initialized!" unless template
12
+ raise "FormBuilder object must not be a nil value. If there's no object, use a symbol instead! (i.e :user)" unless object
13
+ end
14
+
15
+ # f.error_messages
16
+ def error_messages(*params)
17
+ params.unshift object
18
+ @template.error_messages_for(*params)
19
+ end
20
+
21
+ # f.error_message_on(field)
22
+ def error_message_on(field, options={})
23
+ @template.error_message_on(object, field, options)
24
+ end
25
+
26
+ # f.label :username, :caption => "Nickname"
27
+ def label(field, options={})
28
+ options.reverse_merge!(:caption => "#{field_human_name(field)}: ")
29
+ @template.label_tag(field_id(field), options)
30
+ end
31
+
32
+ # f.hidden_field :session_id, :value => "45"
33
+ def hidden_field(field, options={})
34
+ options.reverse_merge!(:value => field_value(field), :id => field_id(field))
35
+ @template.hidden_field_tag field_name(field), options
36
+ end
37
+
38
+ # f.text_field :username, :value => "(blank)", :id => 'username'
39
+ def text_field(field, options={})
40
+ options.reverse_merge!(:value => field_value(field), :id => field_id(field))
41
+ options.merge!(:class => field_error(field, options))
42
+ @template.text_field_tag field_name(field), options
43
+ end
44
+
45
+ # f.text_area :summary, :value => "(enter summary)", :id => 'summary'
46
+ def text_area(field, options={})
47
+ options.reverse_merge!(:value => field_value(field), :id => field_id(field))
48
+ options.merge!(:class => field_error(field, options))
49
+ @template.text_area_tag field_name(field), options
50
+ end
51
+
52
+ # f.password_field :password, :id => 'password'
53
+ def password_field(field, options={})
54
+ options.reverse_merge!(:value => field_value(field), :id => field_id(field))
55
+ options.merge!(:class => field_error(field, options))
56
+ @template.password_field_tag field_name(field), options
57
+ end
58
+
59
+ # f.select :color, :options => ['red', 'green'], :include_blank => true
60
+ # f.select :color, :collection => @colors, :fields => [:name, :id]
61
+ def select(field, options={})
62
+ options.reverse_merge!(:id => field_id(field), :selected => field_value(field))
63
+ options.merge!(:class => field_error(field, options))
64
+ @template.select_tag field_name(field), options
65
+ end
66
+
67
+ # f.check_box :remember_me, :value => 'true', :uncheck_value => '0'
68
+ def check_box(field, options={})
69
+ unchecked_value = options.delete(:uncheck_value) || '0'
70
+ options.reverse_merge!(:id => field_id(field), :value => '1')
71
+ options.reverse_merge!(:checked => true) if values_matches_field?(field, options[:value])
72
+ html = @template.hidden_field_tag(options[:name] || field_name(field), :value => unchecked_value, :id => nil)
73
+ html << @template.check_box_tag(field_name(field), options)
74
+ end
75
+
76
+ # f.radio_button :gender, :value => 'male'
77
+ def radio_button(field, options={})
78
+ options.reverse_merge!(:id => field_id(field, options[:value]))
79
+ options.reverse_merge!(:checked => true) if values_matches_field?(field, options[:value])
80
+ @template.radio_button_tag field_name(field), options
81
+ end
82
+
83
+ # f.file_field :photo, :class => 'avatar'
84
+ def file_field(field, options={})
85
+ options.reverse_merge!(:id => field_id(field))
86
+ options.merge!(:class => field_error(field, options))
87
+ @template.file_field_tag field_name(field), options
88
+ end
89
+
90
+ # f.submit "Update", :class => 'large'
91
+ def submit(caption="Submit", options={})
92
+ @template.submit_tag caption, options
93
+ end
94
+
95
+ # f.image_submit "buttons/submit.png", :class => 'large'
96
+ def image_submit(source, options={})
97
+ @template.image_submit_tag source, options
98
+ end
99
+
100
+ # Supports nested fields for a child model within a form
101
+ # f.fields_for :addresses
102
+ # f.fields_for :addresses, address
103
+ # f.fields_for :addresses, @addresses
104
+ def fields_for(child_association, instance_or_collection=nil, &block)
105
+ default_collection = self.object.send(child_association)
106
+ include_index = default_collection.respond_to?(:each)
107
+ nested_options = { :parent => self, :association => child_association }
108
+ nested_objects = instance_or_collection ? Array(instance_or_collection) : Array(default_collection)
109
+ result = nested_objects.each_with_index.map do |child_instance, index|
110
+ nested_options[:index] = include_index ? index : nil
111
+ @template.fields_for(child_instance, { :nested => nested_options }, &block)
112
+ end.join("\n")
113
+ end
114
+
115
+ protected
116
+ # Returns the known field types for a formbuilder
117
+ def self.field_types
118
+ [:hidden_field, :text_field, :text_area, :password_field, :file_field, :radio_button, :check_box, :select]
119
+ end
120
+
121
+ # Returns true if the value matches the value in the field
122
+ # field_has_value?(:gender, 'male')
123
+ def values_matches_field?(field, value)
124
+ value.present? && (field_value(field).to_s == value.to_s || field_value(field).to_s == 'true')
125
+ end
126
+
127
+ # Add a :invalid css class to the field if it contain an error
128
+ def field_error(field, options)
129
+ error = @object.errors[field] rescue nil
130
+ error.blank? ? options[:class] : [options[:class], :invalid].flatten.compact.join(" ")
131
+ end
132
+
133
+ # Returns the human name of the field. Look that use builtin I18n.
134
+ def field_human_name(field)
135
+ I18n.translate("#{object_model_name}.attributes.#{field}", :count => 1, :default => field.to_s.humanize, :scope => :models)
136
+ end
137
+
138
+ # Returns the name for the given field
139
+ # field_name(:username) => "user[username]"
140
+ # field_name(:number) => "user[telephone_attributes][number]"
141
+ # field_name(:street) => "user[addresses_attributes][0][street]"
142
+ def field_name(field=nil)
143
+ result = []
144
+ if root_form?
145
+ result << object_model_name
146
+ elsif nested_form?
147
+ parent_form = @options[:nested][:parent]
148
+ attributes_name = "#{@options[:nested][:association]}_attributes"
149
+ nested_index = @options[:nested][:index]
150
+ fragment = [parent_form.field_name, "[#{attributes_name}", "]"]
151
+ fragment.insert(2, "][#{nested_index}") if nested_index
152
+ result << fragment
153
+ end
154
+ result << "[#{field}]" unless field.blank?
155
+ result.flatten.join
156
+ end
157
+
158
+ # Returns the id for the given field
159
+ # field_id(:username) => "user_username"
160
+ # field_id(:gender, :male) => "user_gender_male"
161
+ # field_name(:number) => "user_telephone_attributes_number"
162
+ # field_name(:street) => "user_addresses_attributes_0_street"
163
+ def field_id(field=nil, value=nil)
164
+ result = []
165
+ if root_form?
166
+ result << object_model_name
167
+ elsif nested_form?
168
+ parent_form = @options[:nested][:parent]
169
+ attributes_name = "#{@options[:nested][:association]}_attributes"
170
+ nested_index = @options[:nested][:index]
171
+ fragment = [parent_form.field_id, "_#{attributes_name}"]
172
+ fragment.push("_#{nested_index}") if nested_index
173
+ result << fragment
174
+ end
175
+ result << "_#{field}" unless field.blank?
176
+ result << "_#{value}" unless value.blank?
177
+ result.flatten.join
178
+ end
179
+
180
+ # Returns the child object if it exists
181
+ def nested_object_id
182
+ nested_form? && object.respond_to?(:new_record?) && !object.new_record? && object.id
183
+ end
184
+
185
+ # Returns true if this form object is nested in a parent form
186
+ def nested_form?
187
+ @options[:nested] && @options[:nested][:parent] && @options[:nested][:parent].respond_to?(:object)
188
+ end
189
+
190
+ # Returns the value for the object's field
191
+ # field_value(:username) => "Joey"
192
+ def field_value(field)
193
+ @object && @object.respond_to?(field) ? @object.send(field) : ""
194
+ end
195
+
196
+ # explicit_object is either a symbol or a record
197
+ # Returns a new record of the type specified in the object
198
+ def build_object(object_or_symbol)
199
+ object_or_symbol.is_a?(Symbol) ? @template.instance_variable_get("@#{object_or_symbol}") || object_class(object_or_symbol).new : object_or_symbol
200
+ end
201
+
202
+ # Returns the object's models name
203
+ # => user_assignment
204
+ def object_model_name(explicit_object=object)
205
+ explicit_object.is_a?(Symbol) ? explicit_object : explicit_object.class.to_s.underscore.gsub(/\//, '_')
206
+ end
207
+
208
+ # Returns the class type for the given object
209
+ def object_class(explicit_object)
210
+ explicit_object.is_a?(Symbol) ? explicit_object.to_s.camelize.constantize : explicit_object.class
211
+ end
212
+
213
+ # Returns true if this form is the top-level (not nested)
214
+ def root_form?
215
+ !nested_form?
216
+ end
217
+ end # AbstractFormBuilder
218
+ end # FormBuilder
219
+ end # Helpers
220
+ end # Padrino
@@ -0,0 +1,43 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/abstract_form_builder') unless defined?(AbstractFormBuilder)
2
+
3
+ module Padrino
4
+ module Helpers
5
+ module FormBuilder # @private
6
+ class StandardFormBuilder < AbstractFormBuilder # @private
7
+
8
+ ##
9
+ # StandardFormBuilder
10
+ #
11
+ # text_field_block(:username, { :class => 'long' }, { :class => 'wide-label' })
12
+ # text_area_block(:summary, { :class => 'long' }, { :class => 'wide-label' })
13
+ # password_field_block(:password, { :class => 'long' }, { :class => 'wide-label' })
14
+ # file_field_block(:photo, { :class => 'long' }, { :class => 'wide-label' })
15
+ # check_box_block(:remember_me, { :class => 'long' }, { :class => 'wide-label' })
16
+ # select_block(:color, :options => ['green', 'black'])
17
+ #
18
+ (self.field_types - [ :hidden_field, :radio_button ]).each do |field_type|
19
+ class_eval <<-EOF
20
+ def #{field_type}_block(field, options={}, label_options={})
21
+ label_options.reverse_merge!(:caption => options.delete(:caption)) if options[:caption]
22
+ field_html = label(field, label_options)
23
+ field_html << #{field_type}(field, options)
24
+ @template.content_tag(:p, field_html)
25
+ end
26
+ EOF
27
+ end
28
+
29
+ # submit_block("Update")
30
+ def submit_block(caption, options={})
31
+ submit_html = self.submit(caption, options)
32
+ @template.content_tag(:p, submit_html)
33
+ end
34
+
35
+ # image_submit_block("submit.png")
36
+ def image_submit_block(source, options={})
37
+ submit_html = self.image_submit(source, options)
38
+ @template.content_tag(:p, submit_html)
39
+ end
40
+ end # StandardFormBuilder
41
+ end # FormBuilder
42
+ end # Helpers
43
+ end # Padrino
@@ -0,0 +1,602 @@
1
+ module Padrino
2
+ module Helpers
3
+ ##
4
+ # Helpers related to producing form related tags and inputs into templates.
5
+ #
6
+ module FormHelpers
7
+ ##
8
+ # Constructs a form for object using given or default form_builder
9
+ #
10
+ # @param [Object] object
11
+ # The object for which the form is being built.
12
+ # @param [String] url
13
+ # The url this form will submit to.
14
+ # @param [Hash] settings
15
+ # The settings associated with this form. Accepts html options.
16
+ # @option settings [String] :builder ("StandardFormBuilder")
17
+ # The FormBuilder class to use such as StandardFormBuilder.
18
+ # @param [Proc] block
19
+ # The fields and content inside this form.
20
+ #
21
+ # @yield [AbstractFormBuilder] The form builder used to compose fields.
22
+ #
23
+ # @return [String] The html object-backed form with the specified options and input fields.
24
+ #
25
+ # @example
26
+ # form_for :user, '/register' do |f| ... end
27
+ # form_for @user, '/register', :id => 'register' do |f| ... end
28
+ #
29
+ # @api public
30
+ def form_for(object, url, settings={}, &block)
31
+ form_html = capture_html(builder_instance(object, settings), &block)
32
+ form_tag(url, settings) { form_html }
33
+ end
34
+
35
+ ##
36
+ # Constructs form fields for an object using given or default form_builder
37
+ # Used within an existing form to allow alternate objects within one form
38
+ #
39
+ # @param [Object] object
40
+ # The object for which the fields are being built.
41
+ # @param [Hash] settings
42
+ # The settings associated with these fields. Accepts html options.
43
+ # @param [Proc] block
44
+ # The content inside this set of fields.
45
+ #
46
+ # @return [String] The html fields with the specified options.
47
+ #
48
+ # @example
49
+ # fields_for @user.assignment do |assignment| ... end
50
+ # fields_for :assignment do |assigment| ... end
51
+ #
52
+ # @api public
53
+ def fields_for(object, settings={}, &block)
54
+ instance = builder_instance(object, settings)
55
+ fields_html = capture_html(instance, &block)
56
+ fields_html << instance.hidden_field(:id) if instance.send(:nested_object_id)
57
+ concat_content fields_html
58
+ end
59
+
60
+ ##
61
+ # Constructs a form without object based on options
62
+ #
63
+ # @param [String] url
64
+ # The url this form will submit to.
65
+ # @param [Hash] options
66
+ # The html options associated with this form.
67
+ # @param [Proc] block
68
+ # The fields and content inside this form.
69
+ #
70
+ # @return [String] The html form with the specified options and input fields.
71
+ #
72
+ # @example
73
+ # form_tag '/register', :class => "registration_form" do ... end
74
+ #
75
+ # @api public
76
+ def form_tag(url, options={}, &block)
77
+ desired_method = options[:method]
78
+ data_method = options.delete(:method) if options[:method].to_s !~ /get|post/i
79
+ options.reverse_merge!(:method => "post", :action => url)
80
+ options[:enctype] = "multipart/form-data" if options.delete(:multipart)
81
+ options["data-remote"] = "true" if options.delete(:remote)
82
+ options["data-method"] = data_method if data_method
83
+ options["accept-charset"] ||= "UTF-8"
84
+ inner_form_html = hidden_form_method_field(desired_method)
85
+ inner_form_html += capture_html(&block)
86
+ concat_content content_tag(:form, inner_form_html, options)
87
+ end
88
+
89
+ ##
90
+ # Returns the hidden method field for 'put' and 'delete' forms
91
+ # Only 'get' and 'post' are allowed within browsers;
92
+ # 'put' and 'delete' are just specified using hidden fields with form action still 'put'.
93
+ #
94
+ # @param [String] desired_method
95
+ # The method this hidden field represents (i.e put or delete))
96
+ #
97
+ # @return [String] The hidden field representing the +desired_method+ for the form.
98
+ #
99
+ # @example
100
+ # # Generate: <input name="_method" value="delete" />
101
+ # hidden_form_method_field('delete')
102
+ #
103
+ # @api semipublic
104
+ def hidden_form_method_field(desired_method)
105
+ return '' if desired_method.blank? || desired_method.to_s =~ /get|post/i
106
+ hidden_field_tag(:_method, :value => desired_method)
107
+ end
108
+
109
+ ##
110
+ # Constructs a field_set to group fields with given options
111
+ #
112
+ # @overload field_set_tag(legend=nil, options={}, &block)
113
+ # @param [String] legend The legend caption for the fieldset
114
+ # @param [Hash] options The html options for the fieldset.
115
+ # @param [Proc] block The content inside the fieldset.
116
+ # @overload field_set_tag(options={}, &block)
117
+ # @param [Hash] options The html options for the fieldset.
118
+ # @param [Proc] block The content inside the fieldset.
119
+ #
120
+ # @return [String] The html for the fieldset tag based on given +options+.
121
+ #
122
+ # @example
123
+ # field_set_tag(:class => "office-set") { }
124
+ # field_set_tag("Office", :class => 'office-set') { }
125
+ #
126
+ # @api public
127
+ def field_set_tag(*args, &block)
128
+ options = args.extract_options!
129
+ legend_text = args[0].is_a?(String) ? args.first : nil
130
+ legend_html = legend_text.blank? ? '' : content_tag(:legend, legend_text)
131
+ field_set_content = legend_html + capture_html(&block)
132
+ concat_content content_tag(:fieldset, field_set_content, options)
133
+ end
134
+
135
+ ##
136
+ # Constructs list html for the errors for a given symbol
137
+ #
138
+ # @overload error_messages_for(*objects, options = {})
139
+ # @param [Array<Object>] object Splat of objects to display errors for.
140
+ # @param [Hash] options Error message display options.
141
+ # @option options [String] :header_tag ("h2")
142
+ # Used for the header of the error div
143
+ # @option options [String] :id ("errorExplanation")
144
+ # The id of the error div.
145
+ # @option options [String] :class ("errorExplanation")
146
+ # The class of the error div.
147
+ # @option options [Array<Object>] :object
148
+ # The object (or array of objects) for which to display errors,
149
+ # if you need to escape the instance variable convention.
150
+ # @option options [String] :object_name
151
+ # The object name to use in the header, or any text that you prefer.
152
+ # If +:object_name+ is not set, the name of the first object will be used.
153
+ # @option options [String] :header_message ("X errors prohibited this object from being saved")
154
+ # The message in the header of the error div. Pass +nil+ or an empty string
155
+ # to avoid the header message altogether.
156
+ # @option options [String] :message ("There were problems with the following fields:")
157
+ # The explanation message after the header message and before
158
+ # the error list. Pass +nil+ or an empty string to avoid the explanation message
159
+ # altogether.
160
+ #
161
+ # @return [String] The html section with all errors for the specified +objects+
162
+ #
163
+ # @example
164
+ # error_messages_for :user
165
+ #
166
+ # @api public
167
+ def error_messages_for(*objects)
168
+ options = objects.extract_options!.symbolize_keys
169
+ objects = objects.map { |object_name|
170
+ object_name.is_a?(Symbol) ? instance_variable_get("@#{object_name}") : object_name
171
+ }.compact
172
+ count = objects.inject(0) { |sum, object| sum + object.errors.size }
173
+
174
+ unless count.zero?
175
+ html = {}
176
+ [:id, :class, :style].each do |key|
177
+ if options.include?(key)
178
+ value = options[key]
179
+ html[key] = value unless value.blank?
180
+ else
181
+ html[key] = 'field-errors' unless key == :style
182
+ end
183
+ end
184
+
185
+ options[:object_name] ||= objects.first.class
186
+
187
+ I18n.with_options :locale => options[:locale], :scope => [:models, :errors, :template] do |locale|
188
+ header_message = if options.include?(:header_message)
189
+ options[:header_message]
190
+ else
191
+ object_name = options[:object_name].to_s.underscore.gsub(/\//, ' ')
192
+ object_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1)
193
+ locale.t :header, :count => count, :model => object_name
194
+ end
195
+ message = options.include?(:message) ? options[:message] : locale.t(:body)
196
+ error_messages = objects.map { |object|
197
+ object_name = options[:object_name].to_s.underscore.gsub(/\//, ' ')
198
+ object.errors.map { |f, msg|
199
+ field = I18n.t(f, :default => f.to_s.humanize, :scope => [:models, object_name, :attributes])
200
+ content_tag(:li, "%s %s" % [field, msg])
201
+ }
202
+ }.join
203
+
204
+ contents = ''
205
+ contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
206
+ contents << content_tag(:p, message) unless message.blank?
207
+ contents << content_tag(:ul, error_messages)
208
+
209
+ content_tag(:div, contents, html)
210
+ end
211
+ else
212
+ ''
213
+ end
214
+ end
215
+
216
+ ##
217
+ # Returns a string containing the error message attached to the +method+ on the +object+ if one exists.
218
+ #
219
+ # @param [Object] object
220
+ # The object to display the error for.
221
+ # @param [Symbol] field
222
+ # The field on the +object+ to display the error for.
223
+ # @param [Hash] options
224
+ # The options to control the error display.
225
+ # @option options [String] :tag ("div")
226
+ # The tag that encloses the error.
227
+ # @option options [String] :prepend ("")
228
+ # The text to prepend before the field error.
229
+ # @option options [String] :append ("")
230
+ # The text to append after the field error.
231
+ #
232
+ # @example
233
+ # # => <span class="error">can't be blank</div>
234
+ # error_message_on :post, :title
235
+ # error_message_on @post, :title
236
+ #
237
+ # # => <div class="custom" style="border:1px solid red">can't be blank</div>
238
+ # error_message_on :post, :title, :tag => :id, :class => :custom, :style => "border:1px solid red"
239
+ #
240
+ # # => <div class="error">This title can't be blank (or it won't work)</div>
241
+ # error_message_on :post, :title, :prepend => "This title", :append => "(or it won't work)"
242
+ #
243
+ # @return [String] The html display of an error for a particular +object+ and +field+.
244
+ #
245
+ # @api public
246
+ def error_message_on(object, field, options={})
247
+ object = object.is_a?(Symbol) ? instance_variable_get("@#{object}") : object
248
+ error = object.errors[field] rescue nil
249
+ if error
250
+ options.reverse_merge!(:tag => :span, :class => :error)
251
+ tag = options.delete(:tag)
252
+ # Array(error).first is necessary because some orm give us an array others directly a value
253
+ error = [options.delete(:prepend), Array(error).first, options.delete(:append)].compact.join(" ")
254
+ content_tag(tag, error, options)
255
+ else
256
+ ''
257
+ end
258
+ end
259
+
260
+ ##
261
+ # Constructs a label tag from the given options
262
+ #
263
+ # @param [String] name
264
+ # The name of the field to label.
265
+ # @param [Hash] options
266
+ # The html options for this label.
267
+ # @option options :caption
268
+ # The caption for this label.
269
+ # @param [Proc] block
270
+ # The content to be inserted into the label.
271
+ #
272
+ # @return [String] The html for this label with the given +options+.
273
+ #
274
+ # @example
275
+ # label_tag :username, :class => 'long-label'
276
+ # label_tag :username, :class => 'long-label' do ... end
277
+ #
278
+ # @api public
279
+ def label_tag(name, options={}, &block)
280
+ options.reverse_merge!(:caption => "#{name.to_s.humanize}: ", :for => name)
281
+ caption_text = options.delete(:caption)
282
+ caption_text << "<span class='required'>*</span> " if options.delete(:required)
283
+ if block_given? # label with inner content
284
+ label_content = caption_text + capture_html(&block)
285
+ concat_content(content_tag(:label, label_content, options))
286
+ else # regular label
287
+ content_tag(:label, caption_text, options)
288
+ end
289
+ end
290
+
291
+ ##
292
+ # Constructs a text field input from the given options
293
+ #
294
+ # @macro [new] input_field_doc
295
+ # @param [String] name
296
+ # The name of the input field.
297
+ # @param [Hash] options
298
+ # The html options for the input field.
299
+ #
300
+ # @return [String] The html input field based on the +options+ specified
301
+ #
302
+ # @example
303
+ # text_field_tag :username, :class => 'long'
304
+ #
305
+ # @api public
306
+ def text_field_tag(name, options={})
307
+ options.reverse_merge!(:name => name)
308
+ input_tag(:text, options)
309
+ end
310
+
311
+ ##
312
+ # Constructs a hidden field input from the given options
313
+ #
314
+ # @macro input_field_doc
315
+ #
316
+ # @example
317
+ # hidden_field_tag :session_key, :value => "__secret__"
318
+ #
319
+ # @api public
320
+ def hidden_field_tag(name, options={})
321
+ options.reverse_merge!(:name => name)
322
+ input_tag(:hidden, options)
323
+ end
324
+
325
+ ##
326
+ # Constructs a text area input from the given options
327
+ #
328
+ # @macro input_field_doc
329
+ #
330
+ # @example
331
+ # text_area_tag :username, :class => 'long', :value => "Demo?"
332
+ #
333
+ # @api public
334
+ def text_area_tag(name, options={})
335
+ options.reverse_merge!(:name => name, :rows => "", :cols => "")
336
+ content_tag(:textarea, options.delete(:value).to_s, options)
337
+ end
338
+
339
+ ##
340
+ # Constructs a password field input from the given options
341
+ #
342
+ # @macro input_field_doc
343
+ #
344
+ # @example
345
+ # password_field_tag :password, :class => 'long'
346
+ #
347
+ # @api public
348
+ def password_field_tag(name, options={})
349
+ options.reverse_merge!(:name => name)
350
+ input_tag(:password, options)
351
+ end
352
+
353
+ ##
354
+ # Constructs a check_box from the given options
355
+ #
356
+ # @macro input_field_doc
357
+ #
358
+ # @example
359
+ # check_box_tag :remember_me, :value => 'Yes'
360
+ #
361
+ # @api public
362
+ def check_box_tag(name, options={})
363
+ options.reverse_merge!(:name => name, :value => '1')
364
+ input_tag(:checkbox, options)
365
+ end
366
+
367
+ ##
368
+ # Constructs a radio_button from the given options
369
+ #
370
+ # @macro input_field_doc
371
+ #
372
+ # @example
373
+ # radio_button_tag :remember_me, :value => 'true'
374
+ #
375
+ # @api public
376
+ def radio_button_tag(name, options={})
377
+ options.reverse_merge!(:name => name)
378
+ input_tag(:radio, options)
379
+ end
380
+
381
+ ##
382
+ # Constructs a file field input from the given options
383
+ #
384
+ # @macro input_field_doc
385
+ #
386
+ # @example
387
+ # file_field_tag :photo, :class => 'long'
388
+ #
389
+ # @api public
390
+ def file_field_tag(name, options={})
391
+ options.reverse_merge!(:name => name)
392
+ input_tag(:file, options)
393
+ end
394
+
395
+ ##
396
+ # Constructs a select from the given options
397
+ #
398
+ # @example
399
+ # options = [['caption', 'value'], ['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
400
+ # options = ['option', 'red', 'yellow' ]
401
+ # select_tag(:favorite_color, :options => ['red', 'yellow'], :selected => 'green1')
402
+ # select_tag(:country, :collection => @countries, :fields => [:name, :code], :include_blank => 'None')
403
+ #
404
+ # # Optgroups can be generated using :grouped_options => (Hash or nested Array)
405
+ # grouped_options = [['Friends',['Yoda',['Obiwan',1]]],['Enemies',['Palpatine',['Darth Vader',3]]]]
406
+ # grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
407
+ # select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])
408
+ #
409
+ # # Optgroups can be generated using :grouped_options => (Hash or nested Array)
410
+ # grouped_options = [['Friends',['Yoda',['Obiwan',1]]],['Enemies',['Palpatine',['Darth Vader',3]]]]
411
+ # grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
412
+ # select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])
413
+ #
414
+ # @param [String] name
415
+ # The name of the input field.
416
+ # @param [Hash] options
417
+ # The html options for the input field.
418
+ # @option options [Array<String, Array>] :options
419
+ # Explicit options to display in the select. Can be strings or string tuples.
420
+ # @option options [Array<Array>] :grouped_options
421
+ # List of options for each group in the select. See examples for details.
422
+ # @option options [Array<Object>] :collection
423
+ # Collection of objects used as options in the select.
424
+ # @option options [Array<Symbol>] :fields
425
+ # The attributes used as "label" and "value" for each +collection+ object.
426
+ # @option options [String] :selected (nil)
427
+ # The option value initially selected.
428
+ # @option options [Boolean] :include_blank (false)
429
+ # Include a blank option in the select.
430
+ # @option options [Boolean] :multiple (false)
431
+ # Allow multiple options to be selected at once.
432
+ #
433
+ # @return [String] The html input field based on the +options+ specified
434
+ #
435
+ # @api public
436
+ def select_tag(name, options={})
437
+ options.reverse_merge!(:name => name)
438
+ collection, fields = options.delete(:collection), options.delete(:fields)
439
+ options[:options] = options_from_collection(collection, fields) if collection
440
+ prompt = options.delete(:include_blank)
441
+ select_options_html = if options[:options]
442
+ options_for_select(options.delete(:options), options.delete(:selected))
443
+ elsif options[:grouped_options]
444
+ grouped_options_for_select(options.delete(:grouped_options), options.delete(:selected), prompt)
445
+ end
446
+ select_options_html = select_options_html.unshift(blank_option(prompt)) if select_options_html.is_a?(Array)
447
+ options.merge!(:name => "#{options[:name]}[]") if options[:multiple]
448
+ content_tag(:select, select_options_html, options)
449
+ end
450
+
451
+ ##
452
+ # Constructs a button input from the given options
453
+ #
454
+ # @param [String] caption
455
+ # The caption for the button.
456
+ # @param [Hash] options
457
+ # The html options for the input field.
458
+ #
459
+ # @return [String] The html button based on the +options+ specified.
460
+ #
461
+ # @example
462
+ # button_tag "Cancel", :class => 'clear'
463
+ #
464
+ # @api public
465
+ def button_tag(caption, options = {})
466
+ options.reverse_merge!(:value => caption)
467
+ input_tag(:button, options)
468
+ end
469
+
470
+ ##
471
+ # Constructs a submit button from the given options
472
+ #
473
+ # @param [String] caption
474
+ # The caption for the submit button.
475
+ # @param [Hash] options
476
+ # The html options for the input field.
477
+ #
478
+ # @return [String] The html submit button based on the +options+ specified.
479
+ #
480
+ # @example
481
+ # submit_tag "Create", :class => 'success'
482
+ #
483
+ # @api public
484
+ def submit_tag(caption="Submit", options={})
485
+ options.reverse_merge!(:value => caption)
486
+ input_tag(:submit, options)
487
+ end
488
+
489
+ # Constructs a submit button from the given options
490
+ #
491
+ # @param [String] source
492
+ # The source image path for the button.
493
+ # @param [Hash] options
494
+ # The html options for the input field.
495
+ #
496
+ # @return [String] The html image button based on the +options+ specified.
497
+ #
498
+ # @example
499
+ # submit_tag "Create", :class => 'success'
500
+ #
501
+ # @api public
502
+ def image_submit_tag(source, options={})
503
+ options.reverse_merge!(:src => image_path(source))
504
+ input_tag(:image, options)
505
+ end
506
+
507
+ protected
508
+
509
+ ##
510
+ # Returns an array of option items for a select field based on the given collection
511
+ # fields is an array containing the fields to display from each item in the collection
512
+ #
513
+ def options_from_collection(collection, fields)
514
+ collection.map { |item| [ item.send(fields.first), item.send(fields.last) ] }
515
+ end
516
+
517
+ #
518
+ # Returns the options tags for a select based on the given option items
519
+ #
520
+ def options_for_select(option_items, selected_value=nil)
521
+ return '' if option_items.blank?
522
+ option_items.map do |caption, value|
523
+ value ||= caption
524
+ content_tag(:option, caption, :value => value, :selected => option_is_selected?(value, caption, selected_value))
525
+ end
526
+ end
527
+
528
+ #
529
+ # Returns the optgroups with options tags for a select based on the given :grouped_options items
530
+ #
531
+ def grouped_options_for_select(collection, selected=nil, prompt=false)
532
+ if collection.is_a?(Hash)
533
+ collection.map do |key, value|
534
+ content_tag :optgroup, :label => key do
535
+ options_for_select(value, selected)
536
+ end
537
+ end
538
+ elsif collection.is_a?(Array)
539
+ collection.map do |optgroup|
540
+ content_tag :optgroup, :label => optgroup.first do
541
+ options_for_select(optgroup.last, selected)
542
+ end
543
+ end
544
+ end
545
+ end
546
+
547
+ #
548
+ # Returns the blank option serving as a prompt if passed
549
+ #
550
+ def blank_option(prompt)
551
+ return unless prompt
552
+ case prompt
553
+ when String then content_tag(:option, prompt, :value => '')
554
+ when Array then content_tag(:option, prompt.first, :value => prompt.last)
555
+ else content_tag(:option, '', :value => '')
556
+ end
557
+ end
558
+
559
+ private
560
+ ##
561
+ # Returns the FormBuilder class to use based on all available setting sources
562
+ # If explicitly defined, returns that, otherwise returns defaults.
563
+ #
564
+ # @example
565
+ # configured_form_builder_class(nil) => StandardFormBuilder
566
+ #
567
+ # @api private
568
+ def configured_form_builder_class(explicit_builder=nil)
569
+ default_builder = self.respond_to?(:settings) && self.settings.default_builder
570
+ configured_builder = explicit_builder || default_builder || 'StandardFormBuilder'
571
+ configured_builder = "Padrino::Helpers::FormBuilder::#{configured_builder}".constantize if configured_builder.is_a?(String)
572
+ configured_builder
573
+ end
574
+
575
+ ##
576
+ # Returns an initialized builder instance for the given object and settings
577
+ #
578
+ # @example
579
+ # builder_instance(@account, :nested => { ... }) => <FormBuilder>
580
+ #
581
+ # @api private
582
+ def builder_instance(object, settings={})
583
+ builder_class = configured_form_builder_class(settings.delete(:builder))
584
+ builder_class.new(self, object, settings)
585
+ end
586
+
587
+ ##
588
+ # Returns whether the option should be selected or not
589
+ #
590
+ # @example
591
+ # option_is_selected?("red", "Red", ["red", "blue"]) => true
592
+ # option_is_selected?("red", "Red", ["green", "blue"]) => false
593
+ #
594
+ # @api private
595
+ def option_is_selected?(value, caption, selected_values)
596
+ Array(selected_values).any? do |selected|
597
+ [value.to_s, caption.to_s].include?(selected.to_s)
598
+ end
599
+ end
600
+ end # FormHelpers
601
+ end # Helpers
602
+ end # Padrino