middleman-core 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +10 -0
- data/features/helpers_auto_javascript_include_tag.feature +21 -0
- data/features/helpers_auto_stylesheet_link_tag.feature +21 -0
- data/features/i18n_builder.feature +23 -13
- data/features/i18n_preview.feature +9 -9
- data/features/markdown_kramdown.feature +1 -1
- data/fixtures/i18n-test-app/source/{layout.erb → layouts/layout.erb} +0 -0
- data/fixtures/i18n-test-app/source/{morning.en.html.erb → localizable/morning.en.html.erb} +0 -0
- data/fixtures/i18n-test-app/source/{morning.es.html.erb → localizable/morning.es.html.erb} +0 -0
- data/fixtures/i18n-test-app/source/{one.en.md → localizable/one.en.md} +0 -0
- data/fixtures/i18n-test-app/source/{one.es.md → localizable/one.es.md} +0 -0
- data/lib/middleman-core/application.rb +4 -0
- data/lib/middleman-core/cli/build.rb +14 -2
- data/lib/middleman-core/cli/init.rb +1 -0
- data/lib/middleman-core/core_extensions.rb +6 -1
- data/lib/middleman-core/core_extensions/file_watcher.rb +1 -0
- data/lib/middleman-core/core_extensions/request.rb +2 -4
- data/lib/middleman-core/extensions.rb +13 -5
- data/lib/middleman-core/meta_pages.rb +25 -11
- data/lib/middleman-core/meta_pages/sitemap_resource.rb +2 -2
- data/lib/middleman-core/meta_pages/templates/config.html.erb +7 -9
- data/lib/middleman-core/meta_pages/templates/index.html.erb +3 -3
- data/lib/middleman-core/meta_pages/templates/sitemap.html.erb +6 -6
- data/lib/middleman-core/sitemap/extensions/redirects.rb +1 -2
- data/lib/middleman-core/sitemap/extensions/request_endpoints.rb +2 -3
- data/lib/middleman-core/sitemap/resource.rb +7 -13
- data/lib/middleman-core/util.rb +2 -3
- data/lib/middleman-core/version.rb +1 -1
- data/lib/middleman-more/core_extensions/default_helpers.rb +9 -5
- data/lib/middleman-more/core_extensions/i18n.rb +17 -10
- data/lib/middleman-more/extensions/{automatic-alt-tags.rb → automatic_alt_tags.rb} +0 -0
- data/lib/middleman-more/extensions/gzip.rb +29 -6
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/.document +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/.gitignore +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/.yardopts +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/LICENSE.txt +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/README.rdoc +5 -5
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/Rakefile +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/bin/padrino +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core.rb +4 -10
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/application.rb +39 -35
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/application/flash.rb +7 -7
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering.rb +317 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/application/rendering/extensions/erubis.rb +15 -6
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/application/rendering/extensions/haml.rb +2 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/application/rendering/extensions/slim.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/application/routing.rb +406 -368
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/showexceptions.rb +21 -0
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/caller.rb +53 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/cli/adapter.rb +4 -4
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/cli/base.rb +40 -39
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/cli/console.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/cli/rake.rb +2 -2
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/cli/rake_tasks.rb +2 -4
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/command.rb +2 -2
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/images/404.png +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/images/500.png +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/loader.rb +14 -15
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/cs.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/da.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/de.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/en.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/es.yml +1 -2
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/fr.yml +2 -3
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/hu.yml +1 -2
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/it.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/ja.yml +1 -2
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/lv.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/nl.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/no.yml +0 -2
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/pl.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/pt_br.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/ro.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/ru.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/sv.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/tr.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/uk.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/zh_cn.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/locale/zh_tw.yml +0 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/logger.rb +30 -36
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/module.rb +3 -3
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/mounter.rb +59 -59
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/reloader.rb +23 -23
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/router.rb +10 -13
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/server.rb +17 -19
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/support_lite.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/tasks.rb +3 -3
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/lib/padrino-core/version.rb +1 -1
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/padrino-core.gemspec +2 -2
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/app_gem/Gemfile +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/app_gem/app/app.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/app_gem/app_gem.gemspec +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/app_gem/lib/app_gem.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/app_gem/lib/app_gem/version.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/apps/.components +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/apps/.gitignore +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/apps/complex.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/apps/simple.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/dependencies/a.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/dependencies/b.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/dependencies/c.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/dependencies/circular/e.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/dependencies/circular/f.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/dependencies/circular/g.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/fixtures/dependencies/d.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/helper.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/mini_shoulda.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_application.rb +7 -7
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_core.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_csrf_protection.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_dependencies.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_filters.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_flash.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_locale.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_logger.rb +29 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_mounter.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_reloader_complex.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_reloader_simple.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_rendering.rb +15 -2
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering_extensions.rb +14 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_restful_routing.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_router.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_routing.rb +69 -11
- data/lib/vendored-middleman-deps/{padrino-core-0.11.2 → padrino-core-0.11.4}/test/test_support_lite.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/.document +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/.gitignore +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/.yardopts +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/LICENSE.txt +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/README.rdoc +1 -1
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/Rakefile +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers.rb +3 -6
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/asset_tag_helpers.rb +34 -42
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/breadcrumb_helpers.rb +183 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/form_builder/abstract_form_builder.rb +126 -118
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/form_builder/standard_form_builder.rb +6 -9
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/form_helpers.rb +252 -195
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/format_helpers.rb +29 -42
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/cs.yml +14 -14
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/da.yml +1 -1
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/de.yml +1 -1
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/en.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/es.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/fr.yml +1 -2
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/hu.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/it.yml +2 -2
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/ja.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/lv.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/nl.yml +1 -1
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/no.yml +1 -1
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/pl.yml +7 -7
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/pt_br.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/ro.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/ru.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/sv.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/tr.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/uk.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/zh_cn.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/locale/zh_tw.yml +16 -16
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/number_helpers.rb +10 -15
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/output_helpers.rb +50 -58
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/output_helpers/abstract_handler.rb +16 -18
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/output_helpers/erb_handler.rb +11 -12
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/output_helpers/haml_handler.rb +9 -9
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/output_helpers/slim_handler.rb +11 -13
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/render_helpers.rb +5 -6
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/tag_helpers.rb +26 -22
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/lib/padrino-helpers/translation_helpers.rb +4 -6
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/padrino-helpers.gemspec +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/app.rb +7 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.erb +8 -0
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.haml +5 -0
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.slim +6 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/capture_concat.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/capture_concat.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/capture_concat.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/content_for.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/content_for.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/content_for.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/content_tag.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/content_tag.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/content_tag.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/current_engine.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/current_engine.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/current_engine.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/fields_for.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/fields_for.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/fields_for.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/form_for.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/form_for.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/form_for.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/form_tag.erb +9 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/form_tag.haml +8 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/form_tag.slim +9 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/link_to.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/link_to.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/link_to.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/mail_to.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/mail_to.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/mail_to.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/meta_tag.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/meta_tag.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/meta_tag.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/partials/_erb.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/partials/_haml.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/partials/_slim.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/simple_partial.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/simple_partial.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/markup_app/views/simple_partial.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/app.rb +1 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/current_engine.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/current_engines/_erb.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/current_engines/_haml.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/current_engines/_slim.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/double_capture_erb.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/double_capture_haml.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/double_capture_slim.slim +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/erb/test.erb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/explicit_engine.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/haml/test.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/template/_user.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/template/haml_template.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/fixtures/render_app/views/template/some_template.haml +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/helper.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_asset_tag_helpers.rb +9 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_breadcrumb_helpers.rb +134 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_form_builder.rb +38 -6
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_form_helpers.rb +230 -12
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_format_helpers.rb +3 -3
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_locale.rb +0 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_number_helpers.rb +4 -0
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_output_helpers.rb +1 -1
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_render_helpers.rb +1 -1
- data/lib/vendored-middleman-deps/{padrino-helpers-0.11.2 → padrino-helpers-0.11.4}/test/test_tag_helpers.rb +3 -3
- data/middleman-core.gemspec +7 -8
- data/spec/spec_helper.rb +1 -1
- metadata +220 -215
- data/lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/rendering.rb +0 -320
- data/lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/application/showexceptions.rb +0 -20
- data/lib/vendored-middleman-deps/padrino-core-0.11.2/lib/padrino-core/caller.rb +0 -53
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.2/lib/padrino-helpers/breadcrumb_helpers.rb +0 -171
|
@@ -13,7 +13,7 @@ begin
|
|
|
13
13
|
src << " #{@bufvar}.concat((" << code << ').to_s);'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
-
def add_expr_escaped(src, code)
|
|
16
|
+
def add_expr_escaped(src, code)
|
|
17
17
|
src << " #{@bufvar}.safe_concat " << code << ';'
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -37,19 +37,28 @@ begin
|
|
|
37
37
|
#
|
|
38
38
|
# @api private
|
|
39
39
|
class Template < Tilt::ErubisTemplate
|
|
40
|
+
def render(*args)
|
|
41
|
+
app = args.first
|
|
42
|
+
app_class = app.class
|
|
43
|
+
@padrino_app = app.kind_of?(Padrino::Application) ||
|
|
44
|
+
(app_class.respond_to?(:erb) && app_class.erb[:engine_class] == Padrino::Erubis::SafeBufferTemplate)
|
|
45
|
+
super
|
|
46
|
+
end
|
|
47
|
+
|
|
40
48
|
def precompiled_preamble(locals)
|
|
49
|
+
buf = @padrino_app ? "ActiveSupport::SafeBuffer.new" : "''"
|
|
41
50
|
old_postamble = super.split("\n")[0..-2]
|
|
42
|
-
[old_postamble, "#{@outvar} = _buf = (#{@outvar} ||
|
|
51
|
+
[old_postamble, "#{@outvar} = _buf = (#{@outvar} || #{buf})"].join("\n")
|
|
43
52
|
end
|
|
44
53
|
end
|
|
45
54
|
end
|
|
46
55
|
end
|
|
47
|
-
|
|
48
|
-
Tilt.prefer
|
|
56
|
+
|
|
57
|
+
Tilt.prefer(Padrino::Erubis::Template, :erb)
|
|
49
58
|
|
|
50
59
|
if defined? Padrino::Rendering
|
|
51
|
-
Padrino::Rendering.engine_configurations[:erb] =
|
|
60
|
+
Padrino::Rendering.engine_configurations[:erb] =
|
|
52
61
|
{:engine_class => Padrino::Erubis::SafeBufferTemplate}
|
|
53
62
|
end
|
|
54
63
|
rescue LoadError
|
|
55
|
-
end
|
|
64
|
+
end
|
|
File without changes
|
|
@@ -4,7 +4,6 @@ require 'padrino-core/support_lite' unless defined?(SupportLite)
|
|
|
4
4
|
##
|
|
5
5
|
# Adds to Sinatra +controller+ informations
|
|
6
6
|
#
|
|
7
|
-
# @private
|
|
8
7
|
class Sinatra::Request
|
|
9
8
|
attr_accessor :route_obj
|
|
10
9
|
|
|
@@ -16,10 +15,7 @@ class Sinatra::Request
|
|
|
16
15
|
end
|
|
17
16
|
end
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
# HttpRouter adapter
|
|
21
|
-
#
|
|
22
|
-
# @private
|
|
18
|
+
|
|
23
19
|
class HttpRouter
|
|
24
20
|
def rewrite_partial_path_info(env, request); end
|
|
25
21
|
def rewrite_path_info(env, request); end
|
|
@@ -49,7 +45,7 @@ class HttpRouter
|
|
|
49
45
|
filter! :before
|
|
50
46
|
(@route.before_filters - settings.filters[:before]).each { |block| instance_eval(&block) }
|
|
51
47
|
@layout = path.route.use_layout if path.route.use_layout
|
|
52
|
-
@route.custom_conditions.each { |block| pass if block.bind(self).call == false }
|
|
48
|
+
@route.custom_conditions.each { |block| pass if block.bind(self).call == false }
|
|
53
49
|
halt_response = catch(:halt) { route_eval { @route.dest[self, @block_params] } }
|
|
54
50
|
@_response_buffer = halt_response.is_a?(Array) ? halt_response.last : halt_response
|
|
55
51
|
successful = true
|
|
@@ -62,7 +58,6 @@ class HttpRouter
|
|
|
62
58
|
end
|
|
63
59
|
end
|
|
64
60
|
|
|
65
|
-
# @private
|
|
66
61
|
class Route
|
|
67
62
|
VALID_HTTP_VERBS.replace %w[GET POST PUT PATCH DELETE HEAD OPTIONS LINK UNLINK]
|
|
68
63
|
|
|
@@ -98,14 +93,56 @@ class HttpRouter
|
|
|
98
93
|
[]
|
|
99
94
|
end
|
|
100
95
|
end
|
|
96
|
+
|
|
97
|
+
def to(dest = nil, &dest_block)
|
|
98
|
+
@dest = dest || dest_block || raise("you didn't specify a destination")
|
|
99
|
+
|
|
100
|
+
@router.current_order ||= 0
|
|
101
|
+
@order = @router.current_order
|
|
102
|
+
@router.current_order += 1
|
|
103
|
+
|
|
104
|
+
if @dest.respond_to?(:url_mount=)
|
|
105
|
+
urlmount = UrlMount.new(@path_for_generation, @default_values || {}) # TODO url mount should accept nil here.
|
|
106
|
+
urlmount.url_mount = @router.url_mount if @router.url_mount
|
|
107
|
+
@dest.url_mount = urlmount
|
|
108
|
+
end
|
|
109
|
+
self
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
attr_accessor :order
|
|
113
|
+
|
|
101
114
|
end
|
|
102
115
|
|
|
103
|
-
|
|
104
|
-
|
|
116
|
+
attr_accessor :current_order
|
|
117
|
+
|
|
118
|
+
def sort!
|
|
119
|
+
@routes.sort!{ |a, b| a.order <=> b.order }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
class Node::SpanningRegex
|
|
123
|
+
def to_code
|
|
124
|
+
params_count = @ordered_indicies.size
|
|
125
|
+
whole_path_var = "whole_path#{root.next_counter}"
|
|
126
|
+
"#{whole_path_var} = request.joined_path
|
|
127
|
+
if match = #{@matcher.inspect}.match(#{whole_path_var}) and match.begin(0).zero?
|
|
128
|
+
_#{whole_path_var} = request.path.dup
|
|
129
|
+
" << param_capturing_code << "
|
|
130
|
+
remaining_path = #{whole_path_var}[match[0].size + (#{whole_path_var}[match[0].size] == ?/ ? 1 : 0), #{whole_path_var}.size]
|
|
131
|
+
request.path = remaining_path.split('/')
|
|
132
|
+
#{node_to_code}
|
|
133
|
+
request.path = _#{whole_path_var}
|
|
134
|
+
request.params.slice!(#{-params_count}, #{params_count})
|
|
135
|
+
end
|
|
136
|
+
"
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# Monkey patching the Request class. Using Rack::Utils.unescape rather than
|
|
141
|
+
# URI.unescape which can't handle utf-8 chars
|
|
105
142
|
class Request
|
|
106
143
|
def initialize(path, rack_request)
|
|
107
144
|
@rack_request = rack_request
|
|
108
|
-
@path = Rack::Utils.unescape(
|
|
145
|
+
@path = path.split(/\//).map{|part| Rack::Utils.unescape(part) }
|
|
109
146
|
@path.shift if @path.first == ''
|
|
110
147
|
@path.push('') if path[-1] == ?/
|
|
111
148
|
@extra_env = {}
|
|
@@ -146,7 +183,7 @@ class HttpRouter
|
|
|
146
183
|
end
|
|
147
184
|
|
|
148
185
|
module Padrino
|
|
149
|
-
class Filter
|
|
186
|
+
class Filter
|
|
150
187
|
attr_reader :block
|
|
151
188
|
|
|
152
189
|
def initialize(mode, scoped_controller, options, args, &block)
|
|
@@ -187,7 +224,7 @@ module Padrino
|
|
|
187
224
|
# which can be used to refer to the url throughout the application.
|
|
188
225
|
#
|
|
189
226
|
module Routing
|
|
190
|
-
# Defines common content-type alias mappings
|
|
227
|
+
# Defines common content-type alias mappings.
|
|
191
228
|
CONTENT_TYPE_ALIASES = { :htm => :html } unless defined?(CONTENT_TYPE_ALIASES)
|
|
192
229
|
# Defines the available route priorities supporting route deferrals.
|
|
193
230
|
ROUTE_PRIORITY = {:high => 0, :normal => 1, :low => 2} unless defined?(ROUTE_PRIORITY)
|
|
@@ -195,7 +232,7 @@ module Padrino
|
|
|
195
232
|
# Raised when a route was invalid or cannot be processed.
|
|
196
233
|
class UnrecognizedException < RuntimeError; end
|
|
197
234
|
|
|
198
|
-
class Parent < String
|
|
235
|
+
class Parent < String
|
|
199
236
|
attr_reader :map
|
|
200
237
|
attr_reader :optional
|
|
201
238
|
attr_reader :options
|
|
@@ -295,8 +332,10 @@ module Padrino
|
|
|
295
332
|
# get :index, :map => "/:lang" do; "params[:lang] == :de"; end
|
|
296
333
|
# end
|
|
297
334
|
#
|
|
298
|
-
# In a controller, before and after filters are scoped and don't
|
|
299
|
-
#
|
|
335
|
+
# In a controller, before and after filters are scoped and don't
|
|
336
|
+
# affect other controllers or the main app.
|
|
337
|
+
# In a controller, layouts are scoped and don't affect other
|
|
338
|
+
# controllers or the main app.
|
|
300
339
|
#
|
|
301
340
|
# @example
|
|
302
341
|
# controller :posts do
|
|
@@ -309,7 +348,7 @@ module Padrino
|
|
|
309
348
|
if block_given?
|
|
310
349
|
options = args.extract_options!
|
|
311
350
|
|
|
312
|
-
# Controller defaults
|
|
351
|
+
# Controller defaults.
|
|
313
352
|
@_controller, original_controller = args, @_controller
|
|
314
353
|
@_parents, original_parent = options.delete(:parent), @_parents
|
|
315
354
|
@_provides, original_provides = options.delete(:provides), @_provides
|
|
@@ -319,17 +358,17 @@ module Padrino
|
|
|
319
358
|
@_conditions, original_conditions = options.delete(:conditions), @_conditions
|
|
320
359
|
@_defaults, original_defaults = options, @_defaults
|
|
321
360
|
|
|
322
|
-
# Application defaults
|
|
361
|
+
# Application defaults.
|
|
323
362
|
@filters, original_filters = { :before => @filters[:before].dup, :after => @filters[:after].dup }, @filters
|
|
324
363
|
@layout, original_layout = nil, @layout
|
|
325
364
|
|
|
326
365
|
instance_eval(&block)
|
|
327
366
|
|
|
328
|
-
# Application defaults
|
|
367
|
+
# Application defaults.
|
|
329
368
|
@filters = original_filters
|
|
330
369
|
@layout = original_layout
|
|
331
370
|
|
|
332
|
-
# Controller defaults
|
|
371
|
+
# Controller defaults.
|
|
333
372
|
@_controller, @_parents, @_cache = original_controller, original_parent, original_cache
|
|
334
373
|
@_defaults, @_provides, @_map = original_defaults, original_provides, original_map
|
|
335
374
|
@_conditions, @_use_format = original_conditions, original_use_format
|
|
@@ -340,7 +379,7 @@ module Padrino
|
|
|
340
379
|
alias :controllers :controller
|
|
341
380
|
|
|
342
381
|
##
|
|
343
|
-
# Add a before filter hook
|
|
382
|
+
# Add a before filter hook.
|
|
344
383
|
#
|
|
345
384
|
# @see #construct_filter
|
|
346
385
|
#
|
|
@@ -349,7 +388,7 @@ module Padrino
|
|
|
349
388
|
end
|
|
350
389
|
|
|
351
390
|
##
|
|
352
|
-
# Add an after filter hook
|
|
391
|
+
# Add an after filter hook.
|
|
353
392
|
#
|
|
354
393
|
# @see #construct_filter
|
|
355
394
|
#
|
|
@@ -360,7 +399,7 @@ module Padrino
|
|
|
360
399
|
##
|
|
361
400
|
# Adds a filter hook to a request.
|
|
362
401
|
#
|
|
363
|
-
def
|
|
402
|
+
def add_filter(type, &block)
|
|
364
403
|
filters[type] << block
|
|
365
404
|
end
|
|
366
405
|
|
|
@@ -394,9 +433,9 @@ module Padrino
|
|
|
394
433
|
#
|
|
395
434
|
# @example if filters based on a symbol or regexp
|
|
396
435
|
# before :index, /main/ do; ... end
|
|
397
|
-
# # => match
|
|
436
|
+
# # => match only path that are +/+ or contains +main+
|
|
398
437
|
#
|
|
399
|
-
# @example filtering everything except an
|
|
438
|
+
# @example filtering everything except an occurrence
|
|
400
439
|
# before :except => :index do; ...; end
|
|
401
440
|
#
|
|
402
441
|
# @example you can also filter using a request param
|
|
@@ -445,7 +484,7 @@ module Padrino
|
|
|
445
484
|
end
|
|
446
485
|
|
|
447
486
|
##
|
|
448
|
-
# Using
|
|
487
|
+
# Using HttpRouter, for features and configurations.
|
|
449
488
|
#
|
|
450
489
|
# @example
|
|
451
490
|
# router.add('/greedy/:greed')
|
|
@@ -459,32 +498,26 @@ module Padrino
|
|
|
459
498
|
end
|
|
460
499
|
alias :urls :router
|
|
461
500
|
|
|
462
|
-
# Compiles the routes including deferred routes.
|
|
463
501
|
def compiled_router
|
|
464
|
-
if deferred_routes
|
|
465
|
-
|
|
466
|
-
else
|
|
467
|
-
deferred_routes.each { |_, routes| routes.each { |(route, dest)| route.to(dest) } }
|
|
502
|
+
if @deferred_routes
|
|
503
|
+
deferred_routes.each { |routes| routes.each { |(route, dest)| route.to(dest) } }
|
|
468
504
|
@deferred_routes = nil
|
|
469
|
-
router
|
|
505
|
+
router.sort!
|
|
470
506
|
end
|
|
507
|
+
router
|
|
471
508
|
end
|
|
472
509
|
|
|
473
|
-
# Returns all routes that were deferred based on their priority.
|
|
474
510
|
def deferred_routes
|
|
475
|
-
@deferred_routes ||=
|
|
511
|
+
@deferred_routes ||= ROUTE_PRIORITY.map{[]}
|
|
476
512
|
end
|
|
477
513
|
|
|
478
|
-
##
|
|
479
|
-
# Resets the http router and all deferred routes.
|
|
480
|
-
#
|
|
481
514
|
def reset_router!
|
|
482
515
|
@deferred_routes = nil
|
|
483
516
|
router.reset!
|
|
484
517
|
end
|
|
485
518
|
|
|
486
519
|
##
|
|
487
|
-
# Recognize a given path
|
|
520
|
+
# Recognize a given path.
|
|
488
521
|
#
|
|
489
522
|
# @param [String] path
|
|
490
523
|
# Path+Query to parse
|
|
@@ -545,7 +578,7 @@ module Padrino
|
|
|
545
578
|
end
|
|
546
579
|
alias :url_for :url
|
|
547
580
|
|
|
548
|
-
def get(path, *args, &block)
|
|
581
|
+
def get(path, *args, &block)
|
|
549
582
|
conditions = @conditions.dup
|
|
550
583
|
route('GET', path, *args, &block)
|
|
551
584
|
|
|
@@ -554,334 +587,330 @@ module Padrino
|
|
|
554
587
|
end
|
|
555
588
|
|
|
556
589
|
private
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
end
|
|
590
|
+
# Parse params from the url method
|
|
591
|
+
def value_to_param(value)
|
|
592
|
+
case value
|
|
593
|
+
when Array
|
|
594
|
+
value.map { |v| value_to_param(v) }.compact
|
|
595
|
+
when Hash
|
|
596
|
+
value.inject({}) do |memo, (k,v)|
|
|
597
|
+
v = value_to_param(v)
|
|
598
|
+
memo[k] = v unless v.nil?
|
|
599
|
+
memo
|
|
600
|
+
end
|
|
601
|
+
when nil then nil
|
|
602
|
+
else value.respond_to?(:to_param) ? value.to_param : value
|
|
571
603
|
end
|
|
604
|
+
end
|
|
572
605
|
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
606
|
+
# Add prefix slash if its not present and remove trailing slashes.
|
|
607
|
+
def conform_uri(uri_string)
|
|
608
|
+
uri_string.gsub(/^(?!\/)(.*)/, '/\1').gsub(/[\/]+$/, '')
|
|
609
|
+
end
|
|
577
610
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
611
|
+
##
|
|
612
|
+
# Rewrite default routes.
|
|
613
|
+
#
|
|
614
|
+
# @example
|
|
615
|
+
# get :index # => "/"
|
|
616
|
+
# get :index, "/" # => "/"
|
|
617
|
+
# get :index, :map => "/" # => "/"
|
|
618
|
+
# get :show, "/show-me" # => "/show-me"
|
|
619
|
+
# get :show, :map => "/show-me" # => "/show-me"
|
|
620
|
+
# get "/foo/bar" # => "/show"
|
|
621
|
+
# get :index, :parent => :user # => "/user/:user_id/index"
|
|
622
|
+
# get :show, :with => :id, :parent => :user # => "/user/:user_id/show/:id"
|
|
623
|
+
# get :show, :with => :id # => "/show/:id"
|
|
624
|
+
# get [:show, :id] # => "/show/:id"
|
|
625
|
+
# get :show, :with => [:id, :name] # => "/show/:id/:name"
|
|
626
|
+
# get [:show, :id, :name] # => "/show/:id/:name"
|
|
627
|
+
# get :list, :provides => :js # => "/list.{:format,js)"
|
|
628
|
+
# get :list, :provides => :any # => "/list(.:format)"
|
|
629
|
+
# get :list, :provides => [:js, :json] # => "/list.{!format,js|json}"
|
|
630
|
+
# get :list, :provides => [:html, :js, :json] # => "/list(.{!format,js|json})"
|
|
631
|
+
# get :list, :priority => :low # Defers route to be last
|
|
632
|
+
# get /pattern/, :name => :foo, :generate_with => '/foo' # Generates :foo as /foo
|
|
633
|
+
def route(verb, path, *args, &block)
|
|
634
|
+
options = case args.size
|
|
635
|
+
when 2
|
|
636
|
+
args.last.merge(:map => args.first)
|
|
637
|
+
when 1
|
|
638
|
+
map = args.shift if args.first.is_a?(String)
|
|
639
|
+
if args.first.is_a?(Hash)
|
|
640
|
+
map ? args.first.merge(:map => map) : args.first
|
|
641
|
+
else
|
|
642
|
+
{:map => map || args.first}
|
|
643
|
+
end
|
|
644
|
+
when 0
|
|
645
|
+
{}
|
|
646
|
+
else raise
|
|
647
|
+
end
|
|
615
648
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
649
|
+
# Do padrino parsing. We dup options so we can build HEAD request correctly.
|
|
650
|
+
route_options = options.dup
|
|
651
|
+
route_options[:provides] = @_provides if @_provides
|
|
619
652
|
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
end
|
|
653
|
+
# CSRF protection is always active except when explicitly switched off.
|
|
654
|
+
if allow_disabled_csrf
|
|
655
|
+
unless route_options[:csrf_protection] == false
|
|
656
|
+
route_options[:csrf_protection] = true
|
|
625
657
|
end
|
|
658
|
+
end
|
|
626
659
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
end
|
|
660
|
+
path, *route_options[:with] = path if path.is_a?(Array)
|
|
661
|
+
action = path
|
|
662
|
+
path, name, route_parents, options, route_options = *parse_route(path, route_options, verb)
|
|
663
|
+
options.reverse_merge!(@_conditions) if @_conditions
|
|
664
|
+
|
|
665
|
+
# Sinatra defaults
|
|
666
|
+
method_name = "#{verb} #{path}"
|
|
667
|
+
unbound_method = generate_method(method_name, &block)
|
|
668
|
+
|
|
669
|
+
block = block.arity != 0 ?
|
|
670
|
+
proc { |a,p| unbound_method.bind(a).call(*p) } :
|
|
671
|
+
proc { |a,p| unbound_method.bind(a).call }
|
|
672
|
+
|
|
673
|
+
invoke_hook(:route_added, verb, path, block)
|
|
674
|
+
|
|
675
|
+
# HTTPRouter route construction
|
|
676
|
+
route = router.add(path, route_options)
|
|
677
|
+
route.name = name if name
|
|
678
|
+
route.action = action
|
|
679
|
+
priority_name = options.delete(:priority) || :normal
|
|
680
|
+
priority = ROUTE_PRIORITY[priority_name] or raise("Priority #{priority_name} not recognized, try #{ROUTE_PRIORITY.keys.join(', ')}")
|
|
681
|
+
route.cache = options.key?(:cache) ? options.delete(:cache) : @_cache
|
|
682
|
+
route.parent = route_parents ? (route_parents.count == 1 ? route_parents.first : route_parents) : route_parents
|
|
683
|
+
route.add_request_method(verb.downcase.to_sym)
|
|
684
|
+
route.host = options.delete(:host) if options.key?(:host)
|
|
685
|
+
route.user_agent = options.delete(:agent) if options.key?(:agent)
|
|
686
|
+
if options.key?(:default_values)
|
|
687
|
+
defaults = options.delete(:default_values)
|
|
688
|
+
route.add_default_values(defaults) if defaults
|
|
689
|
+
end
|
|
690
|
+
options.delete_if do |option, _args|
|
|
691
|
+
if route.significant_variable_names.include?(option)
|
|
692
|
+
route.add_match_with(option => Array(_args).first)
|
|
693
|
+
true
|
|
662
694
|
end
|
|
695
|
+
end
|
|
663
696
|
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
invoke_hook(:padrino_route_added, route, verb, path, args, options, block)
|
|
697
|
+
# Add Sinatra conditions.
|
|
698
|
+
options.each { |o, a| route.respond_to?(o) ? route.send(o, *a) : send(o, *a) }
|
|
699
|
+
conditions, @conditions = @conditions, []
|
|
700
|
+
route.custom_conditions.concat(conditions)
|
|
670
701
|
|
|
671
|
-
|
|
672
|
-
route.before_filters.concat(@filters[:before])
|
|
673
|
-
route.after_filters.concat(@filters[:after])
|
|
674
|
-
if @_controller
|
|
675
|
-
route.use_layout = @layout
|
|
676
|
-
route.controller = Array(@_controller)[0].to_s
|
|
677
|
-
end
|
|
702
|
+
invoke_hook(:padrino_route_added, route, verb, path, args, options, block)
|
|
678
703
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
704
|
+
# Add Application defaults.
|
|
705
|
+
route.before_filters.concat(@filters[:before])
|
|
706
|
+
route.after_filters.concat(@filters[:after])
|
|
707
|
+
if @_controller
|
|
708
|
+
route.use_layout = @layout
|
|
709
|
+
route.controller = Array(@_controller)[0].to_s
|
|
682
710
|
end
|
|
683
711
|
|
|
684
|
-
|
|
685
|
-
# Returns the final parsed route details (modified to reflect all
|
|
686
|
-
# Padrino options) given the raw route. Raw route passed in could be
|
|
687
|
-
# a named alias or a string and is parsed to reflect provides formats,
|
|
688
|
-
# controllers, parents, 'with' parameters, and other options.
|
|
689
|
-
#
|
|
690
|
-
def parse_route(path, options, verb)
|
|
691
|
-
# We need save our originals path/options so we can perform correctly cache.
|
|
692
|
-
original = [path, options.dup]
|
|
693
|
-
|
|
694
|
-
# options for the route directly
|
|
695
|
-
route_options = {}
|
|
696
|
-
|
|
697
|
-
# We need check if path is a symbol, if that it's a named route
|
|
698
|
-
map = options.delete(:map)
|
|
699
|
-
|
|
700
|
-
if path.kind_of?(Symbol) # path i.e :index or :show
|
|
701
|
-
name = path # The route name
|
|
702
|
-
path = map ? map.dup : (path == :index ? '/' : path.to_s) # The route path
|
|
703
|
-
end
|
|
712
|
+
deferred_routes[priority] << [route, block]
|
|
704
713
|
|
|
705
|
-
|
|
706
|
-
|
|
714
|
+
route
|
|
715
|
+
end
|
|
707
716
|
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
717
|
+
##
|
|
718
|
+
# Returns the final parsed route details (modified to reflect all
|
|
719
|
+
# Padrino options) given the raw route. Raw route passed in could be
|
|
720
|
+
# a named alias or a string and is parsed to reflect provides formats,
|
|
721
|
+
# controllers, parents, 'with' parameters, and other options.
|
|
722
|
+
#
|
|
723
|
+
def parse_route(path, options, verb)
|
|
724
|
+
route_options = {}
|
|
714
725
|
|
|
715
|
-
|
|
716
|
-
|
|
726
|
+
# We need check if path is a symbol, if that it's a named route.
|
|
727
|
+
map = options.delete(:map)
|
|
717
728
|
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
729
|
+
# path i.e :index or :show
|
|
730
|
+
if path.kind_of?(Symbol)
|
|
731
|
+
name = path
|
|
732
|
+
path = map ? map.dup : (path == :index ? '/' : path.to_s)
|
|
733
|
+
end
|
|
723
734
|
|
|
724
|
-
|
|
735
|
+
# Build our controller
|
|
736
|
+
controller = Array(@_controller).map(&:to_s)
|
|
725
737
|
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
end
|
|
733
|
-
# Here we build the correct name route
|
|
734
|
-
end
|
|
738
|
+
case path
|
|
739
|
+
when String # path i.e "/index" or "/show"
|
|
740
|
+
# Now we need to parse our 'with' params
|
|
741
|
+
if with_params = options.delete(:with)
|
|
742
|
+
path = process_path_for_with_params(path, with_params)
|
|
743
|
+
end
|
|
735
744
|
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
parent_params = (Array(@_parents) + Array(parent_params)).uniq
|
|
739
|
-
path = process_path_for_parent_params(path, parent_params)
|
|
740
|
-
end
|
|
745
|
+
# Now we need to parse our provides
|
|
746
|
+
options.delete(:provides) if options[:provides].nil?
|
|
741
747
|
|
|
742
|
-
|
|
743
|
-
path
|
|
744
|
-
|
|
745
|
-
#
|
|
746
|
-
path.gsub!(%r{/\?$}, '(/)') # Remove index path
|
|
747
|
-
path.gsub!(%r{//$}, '/') # Remove index path
|
|
748
|
-
path[0,0] = "/" if path !~ %r{^\(?/} # Paths must start with a /
|
|
749
|
-
path.sub!(%r{/(\))?$}, '\\1') if path != "/" # Remove latest trailing delimiter
|
|
750
|
-
path.gsub!(/\/(\(\.|$)/, '\\1') # Remove trailing slashes
|
|
751
|
-
path.squeeze!('/')
|
|
752
|
-
when Regexp
|
|
753
|
-
route_options[:path_for_generation] = options.delete(:generate_with) if options.key?(:generate_with)
|
|
748
|
+
if @_use_format or format_params = options[:provides]
|
|
749
|
+
process_path_for_provides(path, format_params)
|
|
750
|
+
# options[:add_match_with] ||= {}
|
|
751
|
+
# options[:add_match_with][:format] = /[^\.]+/
|
|
754
752
|
end
|
|
755
753
|
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
754
|
+
absolute_map = map && map[0] == ?/
|
|
755
|
+
|
|
756
|
+
unless controller.empty?
|
|
757
|
+
# Now we need to add our controller path only if not mapped directly
|
|
758
|
+
if map.blank? and !absolute_map
|
|
759
|
+
controller_path = controller.join("/")
|
|
760
|
+
path.gsub!(%r{^\(/\)|/\?}, "")
|
|
761
|
+
path = File.join(controller_path, path) unless @_map
|
|
762
|
+
end
|
|
761
763
|
end
|
|
762
764
|
|
|
763
|
-
#
|
|
764
|
-
options.
|
|
765
|
+
# Now we need to parse our 'parent' params and parent scope.
|
|
766
|
+
if !absolute_map and parent_params = options.delete(:parent) || @_parents
|
|
767
|
+
parent_params = (Array(@_parents) + Array(parent_params)).uniq
|
|
768
|
+
path = process_path_for_parent_params(path, parent_params)
|
|
769
|
+
end
|
|
765
770
|
|
|
766
|
-
|
|
771
|
+
# Add any controller level map to the front of the path.
|
|
772
|
+
path = "#{@_map}/#{path}".squeeze('/') unless absolute_map or @_map.blank?
|
|
773
|
+
|
|
774
|
+
# Small reformats
|
|
775
|
+
path.gsub!(%r{/\?$}, '(/)') # Remove index path
|
|
776
|
+
path.gsub!(%r{//$}, '/') # Remove index path
|
|
777
|
+
path[0,0] = "/" if path !~ %r{^\(?/} # Paths must start with a /
|
|
778
|
+
path.sub!(%r{/(\))?$}, '\\1') if path != "/" # Remove latest trailing delimiter
|
|
779
|
+
path.gsub!(/\/(\(\.|$)/, '\\1') # Remove trailing slashes
|
|
780
|
+
path.squeeze!('/')
|
|
781
|
+
when Regexp
|
|
782
|
+
route_options[:path_for_generation] = options.delete(:generate_with) if options.key?(:generate_with)
|
|
767
783
|
end
|
|
768
784
|
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
File.join(path, Array(with_params).map(&:inspect).join("/"))
|
|
785
|
+
name = options.delete(:route_name) if name.nil? && options.key?(:route_name)
|
|
786
|
+
name = options.delete(:name) if name.nil? && options.key?(:name)
|
|
787
|
+
if name
|
|
788
|
+
controller_name = controller.join("_")
|
|
789
|
+
name = "#{controller_name}_#{name}".to_sym unless controller_name.blank?
|
|
775
790
|
end
|
|
776
791
|
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
# Used for calculating path in route method.
|
|
780
|
-
#
|
|
781
|
-
def process_path_for_parent_params(path, parent_params)
|
|
782
|
-
parent_prefix = parent_params.flatten.compact.uniq.map do |param|
|
|
783
|
-
map = (param.respond_to?(:map) && param.map ? param.map : param.to_s)
|
|
784
|
-
part = "#{map}/:#{param.to_s.singularize}_id/"
|
|
785
|
-
part = "(#{part})" if param.respond_to?(:optional) && param.optional?
|
|
786
|
-
part
|
|
787
|
-
end
|
|
792
|
+
# Merge in option defaults.
|
|
793
|
+
options.reverse_merge!(:default_values => @_defaults)
|
|
788
794
|
|
|
789
|
-
|
|
790
|
-
|
|
795
|
+
[path, name, parent_params, options, route_options]
|
|
796
|
+
end
|
|
791
797
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
+
##
|
|
799
|
+
# Processes the existing path and appends the 'with' parameters onto the route
|
|
800
|
+
# Used for calculating path in route method.
|
|
801
|
+
#
|
|
802
|
+
def process_path_for_with_params(path, with_params)
|
|
803
|
+
File.join(path, Array(with_params).map(&:inspect).join("/"))
|
|
804
|
+
end
|
|
805
|
+
|
|
806
|
+
##
|
|
807
|
+
# Processes the existing path and prepends the 'parent' parameters onto the route
|
|
808
|
+
# Used for calculating path in route method.
|
|
809
|
+
#
|
|
810
|
+
def process_path_for_parent_params(path, parent_params)
|
|
811
|
+
parent_prefix = parent_params.flatten.compact.uniq.map do |param|
|
|
812
|
+
map = (param.respond_to?(:map) && param.map ? param.map : param.to_s)
|
|
813
|
+
part = "#{map}/:#{param.to_s.singularize}_id/"
|
|
814
|
+
part = "(#{part})" if param.respond_to?(:optional) && param.optional?
|
|
815
|
+
part
|
|
798
816
|
end
|
|
799
817
|
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
#
|
|
803
|
-
# By default, if a non-provided mime-type is specified in a URL, the
|
|
804
|
-
# route will not match an thus return a 404.
|
|
805
|
-
#
|
|
806
|
-
# Setting the :treat_format_as_accept option to true allows treating
|
|
807
|
-
# missing mime types specified in the URL as if they were specified
|
|
808
|
-
# in the ACCEPT header and thus return 406.
|
|
809
|
-
#
|
|
810
|
-
# If no type is specified, the first in the provides-list will be
|
|
811
|
-
# returned.
|
|
812
|
-
#
|
|
813
|
-
# @example
|
|
814
|
-
# get "/a", :provides => [:html, :js]
|
|
815
|
-
# # => GET /a => :html
|
|
816
|
-
# # => GET /a.js => :js
|
|
817
|
-
# # => GET /a.xml => 404
|
|
818
|
-
#
|
|
819
|
-
# get "/b", :provides => [:html]
|
|
820
|
-
# # => GET /b; ACCEPT: html => html
|
|
821
|
-
# # => GET /b; ACCEPT: js => 406
|
|
822
|
-
#
|
|
823
|
-
# enable :treat_format_as_accept
|
|
824
|
-
# get "/c", :provides => [:html, :js]
|
|
825
|
-
# # => GET /c.xml => 406
|
|
826
|
-
#
|
|
827
|
-
def provides(*types)
|
|
828
|
-
@_use_format = true
|
|
829
|
-
condition do
|
|
830
|
-
mime_types = types.map { |t| mime_type(t) }.compact
|
|
831
|
-
url_format = params[:format].to_sym if params[:format]
|
|
832
|
-
accepts = request.accept.map { |a| a.to_str }
|
|
833
|
-
|
|
834
|
-
# per rfc2616-sec14:
|
|
835
|
-
# Assume */* if no ACCEPT header is given.
|
|
836
|
-
catch_all = (accepts.delete "*/*" || accepts.empty?)
|
|
837
|
-
matching_types = accepts.empty? ? mime_types.slice(0,1) : (accepts & mime_types)
|
|
838
|
-
if matching_types.empty? && types.include?(:any)
|
|
839
|
-
matching_types = accepts
|
|
840
|
-
end
|
|
818
|
+
[parent_prefix, path].flatten.join("")
|
|
819
|
+
end
|
|
841
820
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
821
|
+
##
|
|
822
|
+
# Processes the existing path and appends the 'format' suffix onto the route.
|
|
823
|
+
# Used for calculating path in route method.
|
|
824
|
+
#
|
|
825
|
+
def process_path_for_provides(path, format_params)
|
|
826
|
+
path << "(.:format)" unless path[-10, 10] == '(.:format)'
|
|
827
|
+
end
|
|
849
828
|
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
829
|
+
##
|
|
830
|
+
# Allows routing by MIME-types specified in the URL or ACCEPT header.
|
|
831
|
+
#
|
|
832
|
+
# By default, if a non-provided mime-type is specified in a URL, the
|
|
833
|
+
# route will not match an thus return a 404.
|
|
834
|
+
#
|
|
835
|
+
# Setting the :treat_format_as_accept option to true allows treating
|
|
836
|
+
# missing mime types specified in the URL as if they were specified
|
|
837
|
+
# in the ACCEPT header and thus return 406.
|
|
838
|
+
#
|
|
839
|
+
# If no type is specified, the first in the provides-list will be
|
|
840
|
+
# returned.
|
|
841
|
+
#
|
|
842
|
+
# @example
|
|
843
|
+
# get "/a", :provides => [:html, :js]
|
|
844
|
+
# # => GET /a => :html
|
|
845
|
+
# # => GET /a.js => :js
|
|
846
|
+
# # => GET /a.xml => 404
|
|
847
|
+
#
|
|
848
|
+
# get "/b", :provides => [:html]
|
|
849
|
+
# # => GET /b; ACCEPT: html => html
|
|
850
|
+
# # => GET /b; ACCEPT: js => 406
|
|
851
|
+
#
|
|
852
|
+
# enable :treat_format_as_accept
|
|
853
|
+
# get "/c", :provides => [:html, :js]
|
|
854
|
+
# # => GET /c.xml => 406
|
|
855
|
+
#
|
|
856
|
+
def provides(*types)
|
|
857
|
+
@_use_format = true
|
|
858
|
+
condition do
|
|
859
|
+
mime_types = types.map { |t| mime_type(t) }.compact
|
|
860
|
+
url_format = params[:format].to_sym if params[:format]
|
|
861
|
+
accepts = request.accept.map(&:to_str)
|
|
862
|
+
|
|
863
|
+
# Per rfc2616-sec14:
|
|
864
|
+
# Assume */* if no ACCEPT header is given.
|
|
865
|
+
catch_all = (accepts.delete "*/*" || accepts.empty?)
|
|
866
|
+
matching_types = accepts.empty? ? mime_types.slice(0,1) : (accepts & mime_types)
|
|
867
|
+
if matching_types.empty? && types.include?(:any)
|
|
868
|
+
matching_types = accepts
|
|
869
|
+
end
|
|
866
870
|
|
|
867
|
-
|
|
871
|
+
if !url_format && matching_types.first
|
|
872
|
+
type = ::Rack::Mime::MIME_TYPES.find { |k, v| v == matching_types.first }[0].sub(/\./,'').to_sym
|
|
873
|
+
accept_format = CONTENT_TYPE_ALIASES[type] || type
|
|
874
|
+
elsif catch_all && !types.include?(:any)
|
|
875
|
+
type = types.first
|
|
876
|
+
accept_format = CONTENT_TYPE_ALIASES[type] || type
|
|
868
877
|
end
|
|
869
|
-
end
|
|
870
878
|
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
879
|
+
matched_format = types.include?(:any) ||
|
|
880
|
+
types.include?(accept_format) ||
|
|
881
|
+
types.include?(url_format) ||
|
|
882
|
+
((!url_format) && request.accept.empty? && types.include?(:html))
|
|
883
|
+
|
|
884
|
+
# Per rfc2616-sec14:
|
|
885
|
+
# Answer with 406 if accept is given but types to not match any
|
|
886
|
+
# provided type.
|
|
887
|
+
halt 406 if
|
|
888
|
+
(!url_format && !accepts.empty? && !matched_format) ||
|
|
889
|
+
(settings.respond_to?(:treat_format_as_accept) && settings.treat_format_as_accept && url_format && !matched_format)
|
|
890
|
+
|
|
891
|
+
if matched_format
|
|
892
|
+
@_content_type = url_format || accept_format || :html
|
|
893
|
+
content_type(@_content_type, :charset => 'utf-8')
|
|
883
894
|
end
|
|
895
|
+
|
|
896
|
+
matched_format
|
|
884
897
|
end
|
|
898
|
+
end
|
|
899
|
+
|
|
900
|
+
##
|
|
901
|
+
# Implements CSRF checking when `allow_disabled_csrf` is set to true.
|
|
902
|
+
#
|
|
903
|
+
# This condition is always on, except when it is explicitly switched
|
|
904
|
+
# off.
|
|
905
|
+
#
|
|
906
|
+
# @example
|
|
907
|
+
# post("/", :csrf_protection => false)
|
|
908
|
+
#
|
|
909
|
+
def csrf_protection(on = true)
|
|
910
|
+
if on
|
|
911
|
+
condition { halt 403 if request.env['protection.csrf.failed'] }
|
|
912
|
+
end
|
|
913
|
+
end
|
|
885
914
|
end
|
|
886
915
|
|
|
887
916
|
##
|
|
@@ -889,7 +918,7 @@ module Padrino
|
|
|
889
918
|
#
|
|
890
919
|
module InstanceMethods
|
|
891
920
|
##
|
|
892
|
-
# Instance method for
|
|
921
|
+
# Instance method for URL generation.
|
|
893
922
|
#
|
|
894
923
|
# @example
|
|
895
924
|
# url(:show, :id => 1)
|
|
@@ -904,14 +933,22 @@ module Padrino
|
|
|
904
933
|
# http://www.sinatrarb.com/intro#Generating%20URLs
|
|
905
934
|
return super if args.first.is_a?(String) && !args[1].is_a?(Hash)
|
|
906
935
|
|
|
907
|
-
# Delegate to Padrino named route
|
|
936
|
+
# Delegate to Padrino named route URL generation.
|
|
908
937
|
settings.url(*args)
|
|
909
938
|
end
|
|
910
939
|
alias :url_for :url
|
|
911
940
|
|
|
912
941
|
##
|
|
913
|
-
# Returns
|
|
942
|
+
# Returns absolute url. Calls Sinatra::Helpers#uri to generate protocol version, hostname and port.
|
|
943
|
+
#
|
|
944
|
+
# @example
|
|
945
|
+
# absolute_url(:show, :id => 1) # => http://example.com/show?id=1
|
|
946
|
+
# absolute_url(:show, 24) # => https://example.com/admin/show/24
|
|
914
947
|
#
|
|
948
|
+
def absolute_url( *args )
|
|
949
|
+
uri url(*args), true, false
|
|
950
|
+
end
|
|
951
|
+
|
|
915
952
|
def recognize_path(path)
|
|
916
953
|
settings.recognize_path(path)
|
|
917
954
|
end
|
|
@@ -958,7 +995,7 @@ module Padrino
|
|
|
958
995
|
def static!
|
|
959
996
|
if path = static_file?(request.path_info)
|
|
960
997
|
env['sinatra.static_file'] = path
|
|
961
|
-
cache_control
|
|
998
|
+
cache_control(*settings.static_cache_control) if settings.static_cache_control?
|
|
962
999
|
send_file(path, :disposition => nil)
|
|
963
1000
|
end
|
|
964
1001
|
end
|
|
@@ -989,51 +1026,52 @@ module Padrino
|
|
|
989
1026
|
end
|
|
990
1027
|
|
|
991
1028
|
private
|
|
992
|
-
def filter!(type, base=settings)
|
|
993
|
-
base.filters[type].each { |block| instance_eval(&block) }
|
|
994
|
-
end
|
|
995
1029
|
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1030
|
+
def filter!(type, base=settings)
|
|
1031
|
+
base.filters[type].each { |block| instance_eval(&block) }
|
|
1032
|
+
end
|
|
1033
|
+
|
|
1034
|
+
def dispatch!
|
|
1035
|
+
invoke do
|
|
1036
|
+
static! if settings.static? && (request.get? || request.head?)
|
|
1037
|
+
route!
|
|
1038
|
+
end
|
|
1039
|
+
rescue ::Exception => boom
|
|
1040
|
+
filter! :before if boom.kind_of? ::Sinatra::NotFound
|
|
1041
|
+
invoke { @boom_handled = handle_exception!(boom) }
|
|
1042
|
+
ensure
|
|
1043
|
+
@boom_handled or begin
|
|
1044
|
+
filter! :after unless env['sinatra.static_file']
|
|
1001
1045
|
rescue ::Exception => boom
|
|
1002
|
-
|
|
1003
|
-
invoke { @boom_handled = handle_exception!(boom) }
|
|
1004
|
-
ensure
|
|
1005
|
-
@boom_handled or begin
|
|
1006
|
-
filter! :after unless env['sinatra.static_file']
|
|
1007
|
-
rescue ::Exception => boom
|
|
1008
|
-
invoke { handle_exception!(boom) } unless @env['sinatra.error']
|
|
1009
|
-
end
|
|
1046
|
+
invoke { handle_exception!(boom) } unless @env['sinatra.error']
|
|
1010
1047
|
end
|
|
1048
|
+
end
|
|
1011
1049
|
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
end
|
|
1050
|
+
def route!(base=settings, pass_block=nil)
|
|
1051
|
+
Thread.current['padrino.instance'] = self
|
|
1052
|
+
if base.compiled_router and match = base.compiled_router.call(@request.env)
|
|
1053
|
+
if match.respond_to?(:each)
|
|
1054
|
+
route_eval do
|
|
1055
|
+
match[1].each { |k,v| response[k] = v }
|
|
1056
|
+
status match[0]
|
|
1057
|
+
route_missing if match[0] == 404
|
|
1058
|
+
route_missing if allow = response['Allow'] and allow.include?(request.env['REQUEST_METHOD'])
|
|
1022
1059
|
end
|
|
1023
|
-
else
|
|
1024
|
-
filter! :before
|
|
1025
1060
|
end
|
|
1061
|
+
else
|
|
1062
|
+
filter! :before
|
|
1063
|
+
end
|
|
1026
1064
|
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1065
|
+
# Run routes defined in superclass.
|
|
1066
|
+
if base.superclass.respond_to?(:router)
|
|
1067
|
+
route!(base.superclass, pass_block)
|
|
1068
|
+
return
|
|
1069
|
+
end
|
|
1032
1070
|
|
|
1033
|
-
|
|
1071
|
+
route_eval(&pass_block) if pass_block
|
|
1034
1072
|
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
end
|
|
1038
|
-
end
|
|
1039
|
-
end
|
|
1073
|
+
route_missing
|
|
1074
|
+
end
|
|
1075
|
+
end
|
|
1076
|
+
end
|
|
1077
|
+
end
|