middleman-core 3.0.0.beta.2 → 3.0.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. data/features/cli_extension.feature +13 -0
  2. data/features/{cli.feature → cli_init.feature} +1 -10
  3. data/features/directory_index.feature +29 -1
  4. data/features/dynamic_pages.feature +1 -0
  5. data/features/extensionless_text_files.feature +0 -2
  6. data/features/front-matter.feature +17 -1
  7. data/features/frontmatter_page_settings.feature +16 -1
  8. data/features/helpers_relative_link_to.feature +68 -0
  9. data/features/unicode_filenames.feature +14 -0
  10. data/fixtures/csspie/config.rb +0 -0
  11. data/fixtures/csspie/source/stylesheets/PIE.htc +96 -0
  12. data/fixtures/dynamic-pages-app/config.rb +3 -0
  13. data/fixtures/frontmatter-app/source/front-matter-auto.erb +6 -0
  14. data/fixtures/frontmatter-app/source/front-matter.html.erb +2 -0
  15. data/fixtures/frontmatter-app/source/json-front-matter-2.php.erb +7 -0
  16. data/fixtures/frontmatter-app/source/json-front-matter-auto.erb +6 -0
  17. data/fixtures/frontmatter-app/source/json-front-matter.html.erb +6 -0
  18. data/fixtures/unicode-filenames-app/config.rb +1 -0
  19. data/fixtures/unicode-filenames-app/source/snowmen-rule-/342/230/203.html +4 -0
  20. data/lib/middleman-core/application.rb +43 -335
  21. data/lib/middleman-core/cli/build.rb +11 -4
  22. data/lib/middleman-core/cli/bundler.rb +40 -0
  23. data/lib/middleman-core/cli/extension.rb +36 -0
  24. data/lib/middleman-core/cli/server.rb +2 -2
  25. data/lib/middleman-core/cli.rb +2 -6
  26. data/lib/middleman-core/core_extensions/assets.rb +35 -31
  27. data/lib/middleman-core/core_extensions/builder.rb +14 -9
  28. data/lib/middleman-core/core_extensions/data.rb +150 -145
  29. data/lib/middleman-core/core_extensions/default_helpers.rb +159 -97
  30. data/lib/middleman-core/core_extensions/extensions.rb +103 -97
  31. data/lib/middleman-core/core_extensions/external_helpers.rb +27 -23
  32. data/lib/middleman-core/core_extensions/file_watcher.rb +140 -110
  33. data/lib/middleman-core/core_extensions/front_matter.rb +155 -175
  34. data/lib/middleman-core/core_extensions/i18n.rb +111 -102
  35. data/lib/middleman-core/core_extensions/rendering.rb +293 -295
  36. data/lib/middleman-core/core_extensions/request.rb +338 -0
  37. data/lib/middleman-core/core_extensions/routing.rb +72 -68
  38. data/lib/middleman-core/core_extensions/show_exceptions.rb +23 -18
  39. data/lib/middleman-core/core_extensions.rb +39 -0
  40. data/lib/middleman-core/extensions/directory_indexes.rb +1 -4
  41. data/lib/middleman-core/extensions/lorem.rb +10 -3
  42. data/lib/middleman-core/extensions.rb +2 -64
  43. data/lib/middleman-core/preview_server.rb +157 -0
  44. data/lib/middleman-core/sitemap/extensions/ignores.rb +73 -68
  45. data/lib/middleman-core/sitemap/extensions/on_disk.rb +65 -58
  46. data/lib/middleman-core/sitemap/extensions/proxies.rb +86 -75
  47. data/lib/middleman-core/sitemap/extensions/traversal.rb +68 -61
  48. data/lib/middleman-core/sitemap/resource.rb +123 -102
  49. data/lib/middleman-core/sitemap/store.rb +170 -149
  50. data/lib/middleman-core/sitemap.rb +57 -57
  51. data/lib/middleman-core/step_definitions/server_steps.rb +13 -3
  52. data/lib/middleman-core/templates/extension/Gemfile +4 -0
  53. data/lib/middleman-core/templates/extension/Rakefile +12 -0
  54. data/lib/middleman-core/templates/extension/features/support/env.rb +4 -0
  55. data/lib/middleman-core/templates/extension/gemspec +24 -0
  56. data/lib/middleman-core/templates/extension/lib/lib.rb +49 -0
  57. data/lib/middleman-core/templates/extension/lib/middleman_extension.rb +1 -0
  58. data/lib/middleman-core/templates/shared/gitignore +14 -0
  59. data/lib/middleman-core/templates.rb +14 -8
  60. data/lib/middleman-core/util.rb +31 -9
  61. data/lib/middleman-core/version.rb +1 -1
  62. data/lib/middleman-core.rb +6 -4
  63. data/middleman-core.gemspec +4 -6
  64. metadata +62 -203
  65. data/lib/middleman-core/vendor/padrino-core-0.10.6/.document +0 -5
  66. data/lib/middleman-core/vendor/padrino-core-0.10.6/.gitignore +0 -22
  67. data/lib/middleman-core/vendor/padrino-core-0.10.6/.yardopts +0 -1
  68. data/lib/middleman-core/vendor/padrino-core-0.10.6/LICENSE.txt +0 -20
  69. data/lib/middleman-core/vendor/padrino-core-0.10.6/README.rdoc +0 -294
  70. data/lib/middleman-core/vendor/padrino-core-0.10.6/Rakefile +0 -5
  71. data/lib/middleman-core/vendor/padrino-core-0.10.6/bin/padrino +0 -9
  72. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/rendering.rb +0 -292
  73. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/routing.rb +0 -943
  74. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/showexceptions.rb +0 -20
  75. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application.rb +0 -269
  76. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/caller.rb +0 -53
  77. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/adapter.rb +0 -24
  78. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/base.rb +0 -150
  79. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/console.rb +0 -20
  80. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/rake.rb +0 -24
  81. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/rake_tasks.rb +0 -59
  82. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/command.rb +0 -38
  83. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/images/404.png +0 -0
  84. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/images/500.png +0 -0
  85. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/loader.rb +0 -211
  86. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/cs.yml +0 -34
  87. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/da.yml +0 -34
  88. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/de.yml +0 -34
  89. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/en.yml +0 -34
  90. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/es.yml +0 -34
  91. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/fr.yml +0 -34
  92. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/hu.yml +0 -34
  93. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/it.yml +0 -40
  94. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/ja.yml +0 -34
  95. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/lv.yml +0 -34
  96. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/nl.yml +0 -34
  97. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/no.yml +0 -35
  98. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/pl.yml +0 -34
  99. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/pt_br.yml +0 -40
  100. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/ru.yml +0 -35
  101. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/tr.yml +0 -34
  102. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/uk.yml +0 -34
  103. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/zh_cn.yml +0 -34
  104. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/zh_tw.yml +0 -34
  105. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/logger.rb +0 -428
  106. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/mounter.rb +0 -224
  107. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/reloader.rb +0 -254
  108. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/router.rb +0 -98
  109. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/server.rb +0 -79
  110. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/support_lite.rb +0 -199
  111. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/tasks.rb +0 -21
  112. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/version.rb +0 -20
  113. data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core.rb +0 -152
  114. data/lib/middleman-core/vendor/padrino-core-0.10.6/padrino-core.gemspec +0 -38
  115. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/.components +0 -6
  116. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/.gitignore +0 -7
  117. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/complex.rb +0 -32
  118. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/simple.rb +0 -33
  119. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/a.rb +0 -9
  120. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/b.rb +0 -4
  121. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/c.rb +0 -1
  122. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/e.rb +0 -13
  123. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/f.rb +0 -2
  124. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/g.rb +0 -2
  125. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/d.rb +0 -4
  126. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/helper.rb +0 -83
  127. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/mini_shoulda.rb +0 -45
  128. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_application.rb +0 -108
  129. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_core.rb +0 -77
  130. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_dependencies.rb +0 -44
  131. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_filters.rb +0 -278
  132. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_locale.rb +0 -21
  133. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_logger.rb +0 -154
  134. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_mounter.rb +0 -177
  135. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_reloader_complex.rb +0 -75
  136. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_reloader_simple.rb +0 -98
  137. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_rendering.rb +0 -461
  138. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_restful_routing.rb +0 -33
  139. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_router.rb +0 -146
  140. data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_routing.rb +0 -1680
  141. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.document +0 -5
  142. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.gitignore +0 -21
  143. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.yardopts +0 -1
  144. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/LICENSE.txt +0 -20
  145. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/README.rdoc +0 -239
  146. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/Rakefile +0 -5
  147. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/asset_tag_helpers.rb +0 -417
  148. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_builder/abstract_form_builder.rb +0 -251
  149. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_builder/standard_form_builder.rb +0 -43
  150. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_helpers.rb +0 -787
  151. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/format_helpers.rb +0 -381
  152. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/cs.yml +0 -103
  153. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/da.yml +0 -91
  154. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/de.yml +0 -81
  155. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/en.yml +0 -103
  156. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/es.yml +0 -103
  157. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/fr.yml +0 -80
  158. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/hu.yml +0 -103
  159. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/it.yml +0 -89
  160. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/ja.yml +0 -103
  161. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/lv.yml +0 -103
  162. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/nl.yml +0 -82
  163. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/no.yml +0 -91
  164. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/pl.yml +0 -95
  165. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/pt_br.yml +0 -103
  166. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/ru.yml +0 -103
  167. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/tr.yml +0 -103
  168. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/uk.yml +0 -103
  169. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/zh_cn.yml +0 -104
  170. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/zh_tw.yml +0 -103
  171. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/number_helpers.rb +0 -288
  172. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/abstract_handler.rb +0 -98
  173. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/erb_handler.rb +0 -79
  174. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/haml_handler.rb +0 -63
  175. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/slim_handler.rb +0 -81
  176. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers.rb +0 -175
  177. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/render_helpers.rb +0 -60
  178. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/tag_helpers.rb +0 -260
  179. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/translation_helpers.rb +0 -38
  180. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers.rb +0 -59
  181. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/padrino-helpers.gemspec +0 -27
  182. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/app.rb +0 -73
  183. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.erb +0 -14
  184. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.haml +0 -12
  185. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.slim +0 -13
  186. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.erb +0 -14
  187. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.haml +0 -12
  188. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.slim +0 -12
  189. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.erb +0 -11
  190. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.haml +0 -9
  191. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.slim +0 -9
  192. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.erb +0 -5
  193. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.haml +0 -5
  194. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.slim +0 -5
  195. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.erb +0 -20
  196. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.haml +0 -15
  197. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.slim +0 -15
  198. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.erb +0 -72
  199. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.haml +0 -59
  200. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.slim +0 -59
  201. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.erb +0 -86
  202. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.haml +0 -70
  203. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.slim +0 -70
  204. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.erb +0 -5
  205. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.haml +0 -4
  206. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.slim +0 -4
  207. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.erb +0 -3
  208. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.haml +0 -3
  209. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.slim +0 -3
  210. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.erb +0 -3
  211. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.haml +0 -3
  212. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.slim +0 -3
  213. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_erb.erb +0 -1
  214. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_haml.haml +0 -1
  215. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_slim.slim +0 -1
  216. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.erb +0 -1
  217. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.haml +0 -1
  218. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.slim +0 -1
  219. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/app.rb +0 -50
  220. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engine.haml +0 -5
  221. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_erb.erb +0 -1
  222. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_haml.haml +0 -1
  223. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_slim.slim +0 -1
  224. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/erb/test.erb +0 -1
  225. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/explicit_engine.haml +0 -5
  226. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/haml/test.haml +0 -1
  227. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/_user.haml +0 -7
  228. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/haml_template.haml +0 -1
  229. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/some_template.haml +0 -2
  230. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/helper.rb +0 -66
  231. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_asset_tag_helpers.rb +0 -328
  232. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_form_builder.rb +0 -1106
  233. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_form_helpers.rb +0 -770
  234. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_format_helpers.rb +0 -227
  235. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_locale.rb +0 -20
  236. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_number_helpers.rb +0 -139
  237. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_output_helpers.rb +0 -153
  238. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_render_helpers.rb +0 -76
  239. data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_tag_helpers.rb +0 -106
  240. data/lib/middleman-core/watcher.rb +0 -196
@@ -1,943 +0,0 @@
1
- require 'http_router' unless defined?(HttpRouter)
2
- require 'padrino-core/support_lite' unless defined?(SupportLite)
3
-
4
- ##
5
- # Adds to Sinatra +controller+ informations
6
- #
7
- # @private
8
- class Sinatra::Request
9
- attr_accessor :route_obj
10
-
11
- def controller
12
- route_obj && route_obj.controller
13
- end
14
- end
15
-
16
- ##
17
- # HttpRouter adapter
18
- #
19
- # @private
20
- class HttpRouter
21
- def rewrite_partial_path_info(env, request); end
22
- def rewrite_path_info(env, request); end
23
-
24
- def process_destination_path(path, env)
25
- Thread.current['padrino.instance'].instance_eval do
26
- request.route_obj = path.route
27
- @_response_buffer = nil
28
- @route = path.route
29
- @params ||= {}
30
- @params.update(env['router.params'])
31
- @block_params = if path.route.is_a?(HttpRouter::RegexRoute)
32
- params_list = env['router.request'].extra_env['router.regex_match'].to_a
33
- params_list.shift
34
- @params[:captures] = params_list
35
- params_list
36
- else
37
- env['router.request'].params
38
- end
39
- # Provide access to the current controller to the request
40
- # Now we can eval route, but because we have "throw halt" we need to be
41
- # (en)sure to reset old layout and run controller after filters.
42
- original_params = @params
43
- parent_layout = @layout
44
- successful = false
45
- begin
46
- filter! :before
47
- (@route.before_filters - settings.filters[:before]).each { |block| instance_eval(&block) }
48
- @layout = path.route.use_layout if path.route.use_layout
49
- @route.custom_conditions.each { |block| pass if block.bind(self).call == false } if @route.custom_conditions
50
- @block_params = @block_params[0, @route.dest.arity] if @route.dest.arity > 0
51
- halt_response = catch(:halt) { route_eval { @route.dest[self, @block_params] } }
52
- @_response_buffer = halt_response.is_a?(Array) ? halt_response.last : halt_response
53
- successful = true
54
- halt halt_response
55
- ensure
56
- (@route.after_filters - settings.filters[:after]).each { |block| instance_eval(&block) } if successful
57
- @layout = parent_layout
58
- @params = original_params
59
- end
60
- end
61
- end
62
-
63
- # @private
64
- class Route
65
- attr_accessor :use_layout, :controller, :cache, :cache_key, :cache_expires_in
66
-
67
- def before_filters(&block)
68
- @_before_filters ||= []
69
- @_before_filters << block if block_given?
70
-
71
- @_before_filters
72
- end
73
-
74
- def after_filters(&block)
75
- @_after_filters ||= []
76
- @_after_filters << block if block_given?
77
-
78
- @_after_filters
79
- end
80
-
81
- def custom_conditions(&block)
82
- @_custom_conditions ||= []
83
- @_custom_conditions << block if block_given?
84
-
85
- @_custom_conditions
86
- end
87
- end
88
- end
89
-
90
- module Padrino
91
- class Filter # @private
92
- attr_reader :block
93
-
94
- def initialize(mode, scoped_controller, options, args, &block)
95
- @mode, @scoped_controller, @options, @args, @block = mode, scoped_controller, options, args, block
96
- end
97
-
98
- def apply?(request)
99
- detect = @args.any? do |arg|
100
- case arg
101
- when Symbol then request.route_obj && (request.route_obj.named == arg or request.route_obj.named == [@scoped_controller, arg].flatten.join("_").to_sym)
102
- else arg === request.path_info
103
- end
104
- end || @options.any? do |name, val|
105
- case name
106
- when :agent then val === request.user_agent
107
- else val === request.send(name)
108
- end
109
- end
110
- detect ^ !@mode
111
- end
112
-
113
- def to_proc
114
- if @args.empty? && @options.empty?
115
- block
116
- else
117
- filter = self
118
- proc { instance_eval(&filter.block) if filter.apply?(request) }
119
- end
120
- end
121
- end
122
-
123
- ##
124
- # Padrino provides advanced routing definition support to make routes and
125
- # url generation much easier. This routing system supports named route
126
- # aliases and easy access to url paths. The benefits of this is that instead
127
- # of having to hard-code route urls into every area of your application, now
128
- # we can just define the urls in a single spot and then attach an alias
129
- # which can be used to refer to the url throughout the application.
130
- #
131
- module Routing
132
- # Defines common content-type alias mappings
133
- CONTENT_TYPE_ALIASES = { :htm => :html } unless defined?(CONTENT_TYPE_ALIASES)
134
- # Defines the available route priorities supporting route deferrals.
135
- ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2} unless defined?(ROUTE_PRIORITY)
136
-
137
- # Raised when a route was invalid or cannot be processed.
138
- class UnrecognizedException < RuntimeError; end
139
-
140
- class Parent < String # @private
141
- attr_reader :map
142
- attr_reader :optional
143
- attr_reader :options
144
-
145
- alias_method :optional?, :optional
146
-
147
- def initialize(value, options={})
148
- super(value.to_s)
149
- @map = options.delete(:map)
150
- @optional = options.delete(:optional)
151
- @options = options
152
- end
153
- end
154
-
155
- class << self
156
- ##
157
- # Main class that register this extension.
158
- #
159
- def registered(app)
160
- app.send(:include, InstanceMethods)
161
- app.extend(ClassMethods)
162
- end
163
- alias :included :registered
164
- end
165
-
166
- # Class methods responsible for enhanced routing for controllers.
167
- module ClassMethods
168
- ##
169
- # Method for organize in a better way our routes.
170
- #
171
- # @param [Array] args
172
- # Controller arguments.
173
- #
174
- # @yield []
175
- # The given block will be used to define the routes within the
176
- # Controller.
177
- #
178
- # @example
179
- # controller :admin do
180
- # get :index do; ...; end
181
- # get :show, :with => :id do; ...; end
182
- # end
183
- #
184
- # url(:admin_index) # => "/admin"
185
- # url(:admin_show, :id => 1) # "/admin/show/1"
186
- #
187
- # @example Using named routes follow the sinatra way:
188
- # controller "/admin" do
189
- # get "/index" do; ...; end
190
- # get "/show/:id" do; ...; end
191
- # end
192
- #
193
- # @example Supply +:provides+ to all controller routes:
194
- # controller :provides => [:html, :xml, :json] do
195
- # get :index do; "respond to html, xml and json"; end
196
- # post :index do; "respond to html, xml and json"; end
197
- # get :foo do; "respond to html, xml and json"; end
198
- # end
199
- #
200
- # @example Specify parent resources in padrino with the +:parent+ option on the controller:
201
- # controllers :product, :parent => :user do
202
- # get :index do
203
- # # url is generated as "/user/#{params[:user_id]}/product"
204
- # # url_for(:product, :index, :user_id => 5) => "/user/5/product"
205
- # end
206
- # get :show, :with => :id do
207
- # # url is generated as "/user/#{params[:user_id]}/product/show/#{params[:id]}"
208
- # # url_for(:product, :show, :user_id => 5, :id => 10) => "/user/5/product/show/10"
209
- # end
210
- # end
211
- #
212
- # @example Specify conditions to run for all routes:
213
- # controller :conditions => {:protect => true} do
214
- # def self.protect(protected)
215
- # condition do
216
- # halt 403, "No secrets for you!" unless params[:key] == "s3cr3t"
217
- # end if protected
218
- # end
219
- #
220
- # # This route will only return "secret stuff" if the user goes to
221
- # # `/private?key=s3cr3t`.
222
- # get("/private") { "secret stuff" }
223
- #
224
- # # And this one, too!
225
- # get("/also-private") { "secret stuff" }
226
- #
227
- # # But you can override the conditions for each route as needed.
228
- # # This route will be publicly accessible without providing the
229
- # # secret key.
230
- # get :index, :protect => false do
231
- # "Welcome!"
232
- # end
233
- # end
234
- #
235
- # @example Supply default values:
236
- # controller :lang => :de do
237
- # get :index, :map => "/:lang" do; "params[:lang] == :de"; end
238
- # end
239
- #
240
- # In a controller before and after filters are scoped and didn't affect other controllers or main app.
241
- # In a controller layout are scoped and didn't affect others controllers and main app.
242
- #
243
- # @example
244
- # controller :posts do
245
- # layout :post
246
- # before { foo }
247
- # after { bar }
248
- # end
249
- #
250
- def controller(*args, &block)
251
- if block_given?
252
- options = args.extract_options!
253
-
254
- # Controller defaults
255
- @_controller, original_controller = args, @_controller
256
- @_parents, original_parent = options.delete(:parent), @_parents
257
- @_provides, original_provides = options.delete(:provides), @_provides
258
- @_use_format, original_use_format = options.delete(:use_format), @_use_format
259
- @_cache, original_cache = options.delete(:cache), @_cache
260
- @_map, original_map = options.delete(:map), @_map
261
- @_conditions, original_conditions = options.delete(:conditions), @_conditions
262
- @_defaults, original_defaults = options, @_defaults
263
-
264
- # Application defaults
265
- @filters, original_filters = { :before => @filters[:before].dup, :after => @filters[:after].dup }, @filters
266
- @layout, original_layout = nil, @layout
267
-
268
- instance_eval(&block)
269
-
270
- # Application defaults
271
- @filters = original_filters
272
- @layout = original_layout
273
-
274
- # Controller defaults
275
- @_controller, @_parents, @_cache = original_controller, original_parent, original_cache
276
- @_defaults, @_provides, @_map = original_defaults, original_provides, original_map
277
- @_conditions, @_use_format = original_conditions, original_use_format
278
- else
279
- include(*args) if extensions.any?
280
- end
281
- end
282
- alias :controllers :controller
283
-
284
- ##
285
- # Add a before filter hook
286
- #
287
- # @see #construct_filter
288
- #
289
- def before(*args, &block)
290
- add_filter :before, &(args.empty? ? block : construct_filter(*args, &block))
291
- end
292
-
293
- ##
294
- # Add an after filter hook
295
- #
296
- # @see #construct_filter
297
- #
298
- def after(*args, &block)
299
- add_filter :after, &(args.empty? ? block : construct_filter(*args, &block))
300
- end
301
-
302
- ##
303
- # Adds a filter hook to a request.
304
- #
305
- def add_filter(type, &block)
306
- filters[type] << block
307
- end
308
-
309
- ##
310
- # Creates a filter to process before/after the matching route.
311
- #
312
- # @param [Array] args
313
- #
314
- # @example We are be able to filter with String path
315
- # before('/') { 'only to :index' }
316
- # get(:index} { 'foo' } # => filter match only before this.
317
- # get(:main) { 'bar' }
318
- #
319
- # @example is the same of
320
- # before(:index) { 'only to :index' }
321
- # get(:index} { 'foo' } # => filter match only before this.
322
- # get(:main) { 'bar' }
323
- #
324
- # @example it works only for the given controller
325
- # controller :foo do
326
- # before(:index) { 'only to for :foo_index' }
327
- # get(:index} { 'foo' } # => filter match only before this.
328
- # get(:main) { 'bar' }
329
- # end
330
- #
331
- # controller :bar do
332
- # before(:index) { 'only to for :bar_index' }
333
- # get(:index} { 'foo' } # => filter match only before this.
334
- # get(:main) { 'bar' }
335
- # end
336
- #
337
- # @example if filters based on a symbol or regexp
338
- # before :index, /main/ do; ... end
339
- # # => match oly path that are +/+ or contains +main+
340
- #
341
- # @example filtering everything except an occurency
342
- # before :except => :index do; ...; end
343
- #
344
- # @example you can also filter using a request param
345
- # before :agent => /IE/ do; ...; end
346
- # # => match +HTTP_USER_AGENT+ containing +IE+
347
- #
348
- # @see http://www.padrinorb.com/guides/controllers#route-filters
349
- #
350
- def construct_filter(*args, &block)
351
- options = args.last.is_a?(Hash) ? args.pop : {}
352
- except = options.key?(:except) && Array(options.delete(:except))
353
- raise("You cannot use except with other options specified") if except && (!args.empty? || !options.empty?)
354
- options = except.last.is_a?(Hash) ? except.pop : {} if except
355
- Filter.new(!except, @_controller, options, Array(except || args), &block)
356
- end
357
-
358
- ##
359
- # Provides many parents with shallowing.
360
- #
361
- # @param [Symbol] name
362
- # The parent name.
363
- #
364
- # @param [Hash] options
365
- # Additional options.
366
- #
367
- # @example
368
- # controllers :product do
369
- # parent :shop, :optional => true, :map => "/my/stand"
370
- # parent :category, :optional => true
371
- # get :show, :with => :id do
372
- # # generated urls:
373
- # # "/product/show/#{params[:id]}"
374
- # # "/my/stand/#{params[:shop_id]}/product/show/#{params[:id]}"
375
- # # "/my/stand/#{params[:shop_id]}/category/#{params[:category_id]}/product/show/#{params[:id]}"
376
- # # url_for(:product, :show, :id => 10) => "/product/show/10"
377
- # # url_for(:product, :show, :shop_id => 5, :id => 10) => "/my/stand/5/product/show/10"
378
- # # url_for(:product, :show, :shop_id => 5, :category_id => 1, :id => 10) => "/my/stand/5/category/1/product/show/10"
379
- # end
380
- # end
381
- #
382
- def parent(name, options={})
383
- defaults = { :optional => false, :map => name.to_s }
384
- options = defaults.merge(options)
385
- @_parents = Array(@_parents) unless @_parents.is_a?(Array)
386
- @_parents << Parent.new(name, options)
387
- end
388
-
389
- ##
390
- # Using {HttpRouter}, for features and configurations.
391
- #
392
- # @example
393
- # router.add('/greedy/:greed')
394
- # router.recognize('/simple')
395
- #
396
- # @see http://github.com/joshbuddy/http_router
397
- #
398
- def router
399
- @router ||= HttpRouter.new
400
- block_given? ? yield(@router) : @router
401
- end
402
- alias :urls :router
403
-
404
- # Compiles the routes including deferred routes.
405
- def compiled_router
406
- if deferred_routes.empty?
407
- router
408
- else
409
- deferred_routes.each { |_, routes| routes.each { |(route, dest)| route.to(dest) } }
410
- @deferred_routes = nil
411
- router
412
- end
413
- end
414
-
415
- # Returns all routes that were deferred based on their priority.
416
- def deferred_routes
417
- @deferred_routes ||= Hash[ROUTE_PRIORITY.values.sort.map{|p| [p, []]}]
418
- end
419
-
420
- ##
421
- # Resets the http router and all deferred routes.
422
- #
423
- def reset_router!
424
- @deferred_routes = nil
425
- router.reset!
426
- end
427
-
428
- ##
429
- # Recognize a given path
430
- #
431
- # @param [String] path
432
- # Path+Query to parse
433
- #
434
- # @return [Symbol, Hash]
435
- # Returns controller and query params.
436
- #
437
- # @example Giving a controller like:
438
- # controller :foo do
439
- # get :bar, :map => 'foo-bar-:id'; ...; end
440
- # end
441
- #
442
- # @example You should be able to reverse:
443
- # MyApp.url(:foo_bar, :id => :mine)
444
- # # => /foo-bar-mine
445
- #
446
- # @example Into this:
447
- # MyApp.recognize_path('foo-bar-mine')
448
- # # => [:foo_bar, :id => :mine]
449
- #
450
- def recognize_path(path)
451
- responses = @router.recognize(Rack::MockRequest.env_for(path))
452
- [responses[0].path.route.named, responses[0].params]
453
- end
454
-
455
- ##
456
- # Instance method for url generation.
457
- #
458
- # @example
459
- # url(:show, :id => 1)
460
- # url(:show, :name => 'test', :id => 24)
461
- # url(:show, 1)
462
- # url(:controller_name, :show, :id => 21)
463
- # url(:controller_show, :id => 29)
464
- #
465
- def url(*args)
466
- params = args.extract_options! # parameters is hash at end
467
- names, params_array = args.partition{|a| a.is_a?(Symbol)}
468
- name = names.join("_").to_sym # route name is concatenated with underscores
469
- if params.is_a?(Hash)
470
- params[:format] = params[:format].to_s unless params[:format].nil?
471
- params = value_to_param(params)
472
- end
473
- url = if params_array.empty?
474
- compiled_router.url(name, params)
475
- else
476
- compiled_router.url(name, *(params_array << params))
477
- end
478
- url[0,0] = conform_uri(uri_root) if defined?(uri_root)
479
- url[0,0] = conform_uri(ENV['RACK_BASE_URI']) if ENV['RACK_BASE_URI']
480
- url = "/" if url.blank?
481
- url
482
- rescue HttpRouter::InvalidRouteException
483
- route_error = "route mapping for url(#{name.inspect}) could not be found!"
484
- raise Padrino::Routing::UnrecognizedException.new(route_error)
485
- end
486
- alias :url_for :url
487
-
488
- def get(path, *args, &block) # @private
489
- conditions = @conditions.dup
490
- route('GET', path, *args, &block)
491
-
492
- @conditions = conditions
493
- route('HEAD', path, *args, &block)
494
- end
495
-
496
- private
497
- # Parse params from the url method
498
- def value_to_param(value)
499
- case value
500
- when Array
501
- value.map { |v| value_to_param(v) }.compact
502
- when Hash
503
- value.inject({}) do |memo, (k,v)|
504
- v = value_to_param(v)
505
- memo[k] = v unless v.nil?
506
- memo
507
- end
508
- when nil then nil
509
- else value.respond_to?(:to_param) ? value.to_param : value
510
- end
511
- end
512
-
513
- # Add prefix slash if its not present and remove trailing slashes.
514
- def conform_uri(uri_string)
515
- uri_string.gsub(/^(?!\/)(.*)/, '/\1').gsub(/[\/]+$/, '')
516
- end
517
-
518
- ##
519
- # Rewrite default routes.
520
- #
521
- # @example
522
- # get :index # => "/"
523
- # get :index, "/" # => "/"
524
- # get :index, :map => "/" # => "/"
525
- # get :show, "/show-me" # => "/show-me"
526
- # get :show, :map => "/show-me" # => "/show-me"
527
- # get "/foo/bar" # => "/show"
528
- # get :index, :parent => :user # => "/user/:user_id/index"
529
- # get :show, :with => :id, :parent => :user # => "/user/:user_id/show/:id"
530
- # get :show, :with => :id # => "/show/:id"
531
- # get [:show, :id] # => "/show/:id"
532
- # get :show, :with => [:id, :name] # => "/show/:id/:name"
533
- # get [:show, :id, :name] # => "/show/:id/:name"
534
- # get :list, :provides => :js # => "/list.{:format,js)"
535
- # get :list, :provides => :any # => "/list(.:format)"
536
- # get :list, :provides => [:js, :json] # => "/list.{!format,js|json}"
537
- # get :list, :provides => [:html, :js, :json] # => "/list(.{!format,js|json})"
538
- # get :list, :priority => :low # Defers route to be last
539
- # get /pattern/, :name => :foo, :generate_with => '/foo' # Generates :foo as /foo
540
- def route(verb, path, *args, &block)
541
- options = case args.size
542
- when 2
543
- args.last.merge(:map => args.first)
544
- when 1
545
- map = args.shift if args.first.is_a?(String)
546
- if args.first.is_a?(Hash)
547
- map ? args.first.merge(:map => map) : args.first
548
- else
549
- {:map => map || args.first}
550
- end
551
- when 0
552
- {}
553
- else raise
554
- end
555
-
556
- # Do padrino parsing. We dup options so we can build HEAD request correctly
557
- route_options = options.dup
558
- route_options[:provides] = @_provides if @_provides
559
- path, *route_options[:with] = path if path.is_a?(Array)
560
- path, name, options, route_options = *parse_route(path, route_options, verb)
561
- options.reverse_merge!(@_conditions) if @_conditions
562
-
563
- # Sinatra defaults
564
- method_name = "#{verb} #{path}"
565
- unbound_method = generate_method(method_name, &block)
566
-
567
- block = block.arity != 0 ?
568
- proc { |a,p| unbound_method.bind(a).call(*p) } :
569
- proc { |a,p| unbound_method.bind(a).call }
570
-
571
- invoke_hook(:route_added, verb, path, block)
572
-
573
- # HTTPRouter route construction
574
- route = router.add(path, route_options)
575
- route.name(name) if name
576
- priority_name = options.delete(:priority) || :normal
577
- priority = ROUTE_PRIORITY[priority_name] or raise("Priority #{priority_name} not recognized, try #{ROUTE_PRIORITY.keys.join(', ')}")
578
- route.cache = options.key?(:cache) ? options.delete(:cache) : @_cache
579
- route.send(verb.downcase.to_sym)
580
- route.host(options.delete(:host)) if options.key?(:host)
581
- route.user_agent(options.delete(:agent)) if options.key?(:agent)
582
- if options.key?(:default_values)
583
- defaults = options.delete(:default_values)
584
- route.default(defaults) if defaults
585
- end
586
- options.delete_if do |option, args|
587
- if route.send(:significant_variable_names).include?(option)
588
- route.matching(option => Array(args).first)
589
- true
590
- end
591
- end
592
-
593
- # Add Sinatra conditions
594
- options.each { |o, a| route.respond_to?(o) ? route.send(o, *a) : send(o, *a) }
595
- conditions, @conditions = @conditions, []
596
- route.custom_conditions.concat(conditions)
597
-
598
- invoke_hook(:padrino_route_added, route, verb, path, args, options, block)
599
-
600
- # Add Application defaults
601
- route.before_filters.concat(@filters[:before])
602
- route.after_filters.concat(@filters[:after])
603
- if @_controller
604
- route.use_layout = @layout
605
- route.controller = Array(@_controller)[0].to_s
606
- end
607
-
608
- deferred_routes[priority] << [route, block]
609
-
610
- route
611
- end
612
-
613
- ##
614
- # Returns the final parsed route details (modified to reflect all
615
- # Padrino options) given the raw route. Raw route passed in could be
616
- # a named alias or a string and is parsed to reflect provides formats,
617
- # controllers, parents, 'with' parameters, and other options.
618
- #
619
- def parse_route(path, options, verb)
620
- # We need save our originals path/options so we can perform correctly cache.
621
- original = [path, options.dup]
622
-
623
- # options for the route directly
624
- route_options = {}
625
-
626
- # We need check if path is a symbol, if that it's a named route
627
- map = options.delete(:map)
628
-
629
- if path.kind_of?(Symbol) # path i.e :index or :show
630
- name = path # The route name
631
- path = map ? map.dup : (path == :index ? '/' : path.to_s) # The route path
632
- end
633
-
634
- # Build our controller
635
- controller = Array(@_controller).map { |c| c.to_s }
636
-
637
- case path
638
- when String # path i.e "/index" or "/show"
639
- # Now we need to parse our 'with' params
640
- if with_params = options.delete(:with)
641
- path = process_path_for_with_params(path, with_params)
642
- end
643
-
644
- # Now we need to parse our provides
645
- options.delete(:provides) if options[:provides].nil?
646
-
647
- if @_use_format or format_params = options[:provides]
648
- process_path_for_provides(path, format_params)
649
- options[:matching] ||= {}
650
- options[:matching][:format] = /[^\.]+/
651
- end
652
-
653
- absolute_map = map && map[0] == ?/
654
-
655
- unless controller.empty?
656
- # Now we need to add our controller path only if not mapped directly
657
- if map.blank? and !absolute_map
658
- controller_path = controller.join("/")
659
- path.gsub!(%r{^\(/\)|/\?}, "")
660
- path = File.join(controller_path, path)
661
- end
662
- # Here we build the correct name route
663
- end
664
-
665
- # Now we need to parse our 'parent' params and parent scope
666
- if !absolute_map and parent_params = options.delete(:parent) || @_parents
667
- parent_params = Array(@_parents) + Array(parent_params)
668
- path = process_path_for_parent_params(path, parent_params)
669
- end
670
-
671
- # Add any controller level map to the front of the path
672
- path = "#{@_map}/#{path}".squeeze('/') unless absolute_map or @_map.blank?
673
-
674
- # Small reformats
675
- path.gsub!(%r{/\?$}, '(/)') # Remove index path
676
- path.gsub!(%r{//$}, '/') # Remove index path
677
- path[0,0] = "/" if path !~ %r{^\(?/} # Paths must start with a /
678
- path.sub!(%r{/(\))?$}, '\\1') if path != "/" # Remove latest trailing delimiter
679
- path.gsub!(/\/(\(\.|$)/, '\\1') # Remove trailing slashes
680
- path.squeeze!('/')
681
- when Regexp
682
- route_options[:path_for_generation] = options.delete(:generate_with) if options.key?(:generate_with)
683
- end
684
-
685
- name = options.delete(:route_name) if name.nil? && options.key?(:route_name)
686
- name = options.delete(:name) if name.nil? && options.key?(:name)
687
- if name
688
- controller_name = controller.join("_")
689
- name = "#{controller_name}_#{name}".to_sym unless controller_name.blank?
690
- end
691
-
692
- # Merge in option defaults
693
- options.reverse_merge!(:default_values => @_defaults)
694
-
695
- [path, name, options, route_options]
696
- end
697
-
698
- ##
699
- # Processes the existing path and appends the 'with' parameters onto the route
700
- # Used for calculating path in route method.
701
- #
702
- def process_path_for_with_params(path, with_params)
703
- File.join(path, Array(with_params).map(&:inspect).join("/"))
704
- end
705
-
706
- ##
707
- # Processes the existing path and prepends the 'parent' parameters onto the route
708
- # Used for calculating path in route method.
709
- #
710
- def process_path_for_parent_params(path, parent_params)
711
- parent_prefix = parent_params.flatten.compact.uniq.map do |param|
712
- map = (param.respond_to?(:map) && param.map ? param.map : param.to_s)
713
- part = "#{map}/:#{param.to_s.singularize}_id/"
714
- part = "(#{part})" if param.respond_to?(:optional) && param.optional?
715
- part
716
- end
717
-
718
- [parent_prefix, path].flatten.join("")
719
- end
720
-
721
- ##
722
- # Processes the existing path and appends the 'format' suffix onto the route
723
- # Used for calculating path in route method.
724
- #
725
- def process_path_for_provides(path, format_params)
726
- path << "(.:format)" unless path[-10, 10] == '(.:format)'
727
- end
728
-
729
- ##
730
- # Allows routing by MIME-types specified in the URL or ACCEPT header.
731
- #
732
- # By default, if a non-provided mime-type is specified in a URL, the
733
- # route will not match an thus return a 404.
734
- #
735
- # Setting the :treat_format_as_accept option to true allows treating
736
- # missing mime types specified in the URL as if they were specified
737
- # in the ACCEPT header and thus return 406.
738
- #
739
- # If no type is specified, the first in the provides-list will be
740
- # returned.
741
- #
742
- # @example
743
- # get "/a", :provides => [:html, :js]
744
- # # => GET /a => :html
745
- # # => GET /a.js => :js
746
- # # => GET /a.xml => 404
747
- #
748
- # get "/b", :provides => [:html]
749
- # # => GET /b; ACCEPT: html => html
750
- # # => GET /b; ACCEPT: js => 406
751
- #
752
- # enable :treat_format_as_accept
753
- # get "/c", :provides => [:html, :js]
754
- # # => GET /c.xml => 406
755
- #
756
- def provides(*types)
757
- @_use_format = true
758
- condition do
759
- mime_types = types.map { |t| mime_type(t) }
760
- url_format = params[:format].to_sym if params[:format]
761
- accepts = request.accept.map { |a| a.split(";")[0].strip }
762
-
763
- # per rfc2616-sec14:
764
- # Assume */* if no ACCEPT header is given.
765
- catch_all = (accepts.delete "*/*" || accepts.empty?)
766
- matching_types = accepts.empty? ? mime_types.slice(0,1) : (accepts & mime_types)
767
-
768
- if !url_format && matching_types.first
769
- type = ::Rack::Mime::MIME_TYPES.find { |k, v| v == matching_types.first }[0].sub(/\./,'').to_sym
770
- accept_format = CONTENT_TYPE_ALIASES[type] || type
771
- elsif catch_all
772
- type = types.first
773
- accept_format = CONTENT_TYPE_ALIASES[type] || type
774
- end
775
-
776
- matched_format = types.include?(:any) ||
777
- types.include?(accept_format) ||
778
- types.include?(url_format) ||
779
- ((!url_format) && request.accept.empty? && types.include?(:html))
780
-
781
- # per rfc2616-sec14:
782
- # answer with 406 if accept is given but types to not match any
783
- # provided type
784
- halt 406 if
785
- (!url_format && !accepts.empty? && !matched_format) ||
786
- (settings.respond_to?(:treat_format_as_accept) && settings.treat_format_as_accept && url_format && !matched_format)
787
-
788
- if matched_format
789
- @_content_type = url_format || accept_format || :html
790
- content_type(@_content_type, :charset => 'utf-8')
791
- end
792
-
793
- matched_format
794
- end
795
- end
796
- end
797
-
798
- ##
799
- # Instance methods related to recognizing and processing routes and serving static files.
800
- #
801
- module InstanceMethods
802
- ##
803
- # Instance method for url generation.
804
- #
805
- # @example
806
- # url(:show, :id => 1)
807
- # url(:show, :name => :test)
808
- # url(:show, 1)
809
- # url("/foo")
810
- #
811
- # @see Padrino::Routing::ClassMethods#url
812
- #
813
- def url(*args)
814
- # Delegate to Sinatra 1.2 for simple url("/foo")
815
- # http://www.sinatrarb.com/intro#Generating%20URLs
816
- return super if args.first.is_a?(String) && !args[1].is_a?(Hash)
817
-
818
- # Delegate to Padrino named route url generation
819
- settings.url(*args)
820
- end
821
- alias :url_for :url
822
-
823
- ##
824
- # Returns the recognized path for a route.
825
- #
826
- def recognize_path(path)
827
- settings.recognize_path(path)
828
- end
829
-
830
- ##
831
- # Returns the current path within a route from specified +path_params+.
832
- #
833
- def current_path(*path_params)
834
- if path_params.last.is_a?(Hash)
835
- path_params[-1] = params.merge(path_params[-1])
836
- else
837
- path_params << params
838
- end
839
- @route.url(*path_params)
840
- end
841
-
842
- ##
843
- # Returns the current route
844
- #
845
- # @example
846
- # -if route.controller == :press
847
- # %li=show_article
848
- #
849
- def route
850
- @route
851
- end
852
-
853
- ##
854
- # This is mostly just a helper so request.path_info isn't changed when
855
- # serving files from the public directory.
856
- #
857
- def static_file?(path_info)
858
- return if (public_dir = settings.public_folder).nil?
859
- public_dir = File.expand_path(public_dir)
860
- path = File.expand_path(public_dir + unescape(path_info))
861
- return if path[0, public_dir.length] != public_dir
862
- return unless File.file?(path)
863
- return path
864
- end
865
-
866
- #
867
- # Method for deliver static files.
868
- #
869
- def static!
870
- if path = static_file?(request.path_info)
871
- env['sinatra.static_file'] = path
872
- cache_control *settings.static_cache_control if settings.static_cache_control?
873
- send_file(path, :disposition => nil)
874
- end
875
- end
876
-
877
- ##
878
- # Return the request format, this is useful when we need to respond to
879
- # a given Content-Type.
880
- #
881
- # @param [Symbol, nil] type
882
- #
883
- # @param [Hash] params
884
- #
885
- # @example
886
- # get :index, :provides => :any do
887
- # case content_type
888
- # when :js then ...
889
- # when :json then ...
890
- # when :html then ...
891
- # end
892
- # end
893
- #
894
- def content_type(type=nil, params={})
895
- unless type.nil?
896
- super(type, params)
897
- @_content_type = type
898
- end
899
- @_content_type
900
- end
901
-
902
- private
903
- def filter!(type, base=settings)
904
- base.filters[type].each { |block| instance_eval(&block) }
905
- end
906
-
907
- def dispatch!
908
- static! if settings.static? && (request.get? || request.head?)
909
- route!
910
- rescue ::Exception => boom
911
- filter! :before
912
- handle_exception!(boom)
913
- ensure
914
- filter! :after unless env['sinatra.static_file']
915
- end
916
-
917
- def route!(base=settings, pass_block=nil)
918
- Thread.current['padrino.instance'] = self
919
- if base.compiled_router and match = base.compiled_router.call(@request.env)
920
- if match.respond_to?(:each)
921
- route_eval do
922
- match[1].each {|k,v| response[k] = v}
923
- status match[0]
924
- route_missing if match[0] == 404
925
- end
926
- end
927
- else
928
- filter! :before
929
- end
930
-
931
- # Run routes defined in superclass.
932
- if base.superclass.respond_to?(:router)
933
- route!(base.superclass, pass_block)
934
- return
935
- end
936
-
937
- route_eval(&pass_block) if pass_block
938
-
939
- route_missing
940
- end
941
- end # InstanceMethods
942
- end # Routing
943
- end # Padrino