middleman-core 3.2.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -2,9 +2,8 @@ require File.expand_path(File.dirname(__FILE__) + '/abstract_form_builder') unle
|
|
2
2
|
|
3
3
|
module Padrino
|
4
4
|
module Helpers
|
5
|
-
module FormBuilder
|
6
|
-
class StandardFormBuilder < AbstractFormBuilder
|
7
|
-
|
5
|
+
module FormBuilder
|
6
|
+
class StandardFormBuilder < AbstractFormBuilder
|
8
7
|
##
|
9
8
|
# StandardFormBuilder
|
10
9
|
#
|
@@ -26,18 +25,16 @@ module Padrino
|
|
26
25
|
EOF
|
27
26
|
end
|
28
27
|
|
29
|
-
# submit_block("Update")
|
30
28
|
def submit_block(caption, options={})
|
31
29
|
submit_html = self.submit(caption, options)
|
32
30
|
@template.content_tag(:p, submit_html)
|
33
31
|
end
|
34
32
|
|
35
|
-
# image_submit_block("submit.png")
|
36
33
|
def image_submit_block(source, options={})
|
37
34
|
submit_html = self.image_submit(source, options)
|
38
35
|
@template.content_tag(:p, submit_html)
|
39
36
|
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -7,14 +7,16 @@ module Padrino
|
|
7
7
|
#
|
8
8
|
module FormHelpers
|
9
9
|
##
|
10
|
-
# Constructs a form for object using given or default form_builder
|
10
|
+
# Constructs a form for object using given or default form_builder.
|
11
11
|
#
|
12
12
|
# @param [Object] object
|
13
13
|
# The object for which the form is being built.
|
14
|
-
# @param [String]
|
14
|
+
# @param [String] URL
|
15
15
|
# The url this form will submit to.
|
16
16
|
# @param [Hash] settings
|
17
|
-
# The settings associated with this form.
|
17
|
+
# The settings associated with this form.
|
18
|
+
# Accepts a :namespace option that will be prepended to the id attributes of the form's elements.
|
19
|
+
# Also accepts HTML options.
|
18
20
|
# @option settings [String] :builder ("StandardFormBuilder")
|
19
21
|
# The FormBuilder class to use such as StandardFormBuilder.
|
20
22
|
# @param [Proc] block
|
@@ -28,21 +30,22 @@ module Padrino
|
|
28
30
|
# form_for :user, '/register' do |f| ... end
|
29
31
|
# form_for @user, '/register', :id => 'register' do |f| ... end
|
30
32
|
#
|
31
|
-
# @api public
|
32
33
|
def form_for(object, url, settings={}, &block)
|
33
34
|
instance = builder_instance(object, settings)
|
34
35
|
html = capture_html(instance, &block)
|
36
|
+
settings[:multipart] = instance.multipart unless settings.include?(:multipart)
|
37
|
+
settings.delete(:namespace)
|
35
38
|
form_tag(url, settings) { html }
|
36
39
|
end
|
37
40
|
|
38
41
|
##
|
39
|
-
# Constructs form fields for an object using given or default form_builder
|
40
|
-
# Used within an existing form to allow alternate objects within one form
|
42
|
+
# Constructs form fields for an object using given or default form_builder.
|
43
|
+
# Used within an existing form to allow alternate objects within one form.
|
41
44
|
#
|
42
45
|
# @param [Object] object
|
43
46
|
# The object for which the fields are being built.
|
44
47
|
# @param [Hash] settings
|
45
|
-
# The settings associated with these fields. Accepts
|
48
|
+
# The settings associated with these fields. Accepts HTML options.
|
46
49
|
# @param [Proc] block
|
47
50
|
# The content inside this set of fields.
|
48
51
|
#
|
@@ -52,7 +55,6 @@ module Padrino
|
|
52
55
|
# fields_for @user.assignment do |assignment| ... end
|
53
56
|
# fields_for :assignment do |assigment| ... end
|
54
57
|
#
|
55
|
-
# @api public
|
56
58
|
def fields_for(object, settings={}, &block)
|
57
59
|
instance = builder_instance(object, settings)
|
58
60
|
fields_html = capture_html(instance, &block)
|
@@ -61,40 +63,45 @@ module Padrino
|
|
61
63
|
end
|
62
64
|
|
63
65
|
##
|
64
|
-
# Constructs a form without object based on options
|
66
|
+
# Constructs a form without object based on options.
|
65
67
|
#
|
66
68
|
# @param [String] url
|
67
|
-
# The
|
69
|
+
# The URL this form will submit to.
|
68
70
|
# @param [Hash] options
|
69
71
|
# The html options associated with this form.
|
70
72
|
# @param [Proc] block
|
71
73
|
# The fields and content inside this form.
|
72
74
|
#
|
73
|
-
# @return [String] The
|
75
|
+
# @return [String] The HTML form with the specified options and input fields.
|
74
76
|
#
|
75
77
|
# @example
|
76
78
|
# form_tag '/register', :class => "registration_form" do ... end
|
77
79
|
#
|
78
|
-
# @api public
|
79
80
|
def form_tag(url, options={}, &block)
|
80
81
|
desired_method = options[:method].to_s
|
81
82
|
options.delete(:method) unless desired_method =~ /get|post/i
|
82
|
-
options.reverse_merge!(:method => 'post',
|
83
|
+
options.reverse_merge!(:method => 'post',
|
84
|
+
:action => url,
|
85
|
+
:protect_from_csrf => is_protected_from_csrf? )
|
83
86
|
options[:enctype] = 'multipart/form-data' if options.delete(:multipart)
|
84
87
|
options['accept-charset'] ||= 'UTF-8'
|
85
88
|
inner_form_html = hidden_form_method_field(desired_method)
|
86
|
-
|
89
|
+
if options[:protect_from_csrf] == true && !(desired_method =~ /get/i)
|
90
|
+
inner_form_html << csrf_token_field
|
91
|
+
end
|
87
92
|
inner_form_html << mark_safe(capture_html(&block))
|
88
|
-
|
93
|
+
not_concat = options.delete(:not_concat)
|
94
|
+
form_html = content_tag(:form, inner_form_html, options)
|
95
|
+
not_concat ? form_html : concat_content(form_html)
|
89
96
|
end
|
90
97
|
|
91
98
|
##
|
92
|
-
# Returns the hidden method field for 'put' and 'delete' forms
|
99
|
+
# Returns the hidden method field for 'put' and 'delete' forms.
|
93
100
|
# Only 'get' and 'post' are allowed within browsers;
|
94
101
|
# 'put' and 'delete' are just specified using hidden fields with form action still 'put'.
|
95
102
|
#
|
96
103
|
# @param [String] desired_method
|
97
|
-
# The method this hidden field represents (i.e put or delete)
|
104
|
+
# The method this hidden field represents (i.e put or delete).
|
98
105
|
#
|
99
106
|
# @return [String] The hidden field representing the +desired_method+ for the form.
|
100
107
|
#
|
@@ -102,14 +109,13 @@ module Padrino
|
|
102
109
|
# # Generate: <input name="_method" value="delete" />
|
103
110
|
# hidden_form_method_field('delete')
|
104
111
|
#
|
105
|
-
# @api semipublic
|
106
112
|
def hidden_form_method_field(desired_method)
|
107
113
|
return ActiveSupport::SafeBuffer.new if desired_method.blank? || desired_method.to_s =~ /get|post/i
|
108
114
|
hidden_field_tag(:_method, :value => desired_method)
|
109
115
|
end
|
110
116
|
|
111
117
|
##
|
112
|
-
# Constructs a field_set to group fields with given options
|
118
|
+
# Constructs a field_set to group fields with given options.
|
113
119
|
#
|
114
120
|
# @overload field_set_tag(legend=nil, options={}, &block)
|
115
121
|
# @param [String] legend The legend caption for the fieldset
|
@@ -125,7 +131,6 @@ module Padrino
|
|
125
131
|
# field_set_tag(:class => "office-set") { }
|
126
132
|
# field_set_tag("Office", :class => 'office-set') { }
|
127
133
|
#
|
128
|
-
# @api public
|
129
134
|
def field_set_tag(*args, &block)
|
130
135
|
options = args.extract_options!
|
131
136
|
legend_text = args[0].is_a?(String) ? args.first : nil
|
@@ -135,13 +140,13 @@ module Padrino
|
|
135
140
|
end
|
136
141
|
|
137
142
|
##
|
138
|
-
# Constructs list
|
143
|
+
# Constructs list HTML for the errors for a given symbol.
|
139
144
|
#
|
140
145
|
# @overload error_messages_for(*objects, options = {})
|
141
146
|
# @param [Array<Object>] object Splat of objects to display errors for.
|
142
147
|
# @param [Hash] options Error message display options.
|
143
148
|
# @option options [String] :header_tag ("h2")
|
144
|
-
# Used for the header of the error div
|
149
|
+
# Used for the header of the error div.
|
145
150
|
# @option options [String] :id ("field-errors")
|
146
151
|
# The id of the error div.
|
147
152
|
# @option options [String] :class ("field-errors")
|
@@ -153,7 +158,7 @@ module Padrino
|
|
153
158
|
# The object name to use in the header, or any text that you prefer.
|
154
159
|
# If +:object_name+ is not set, the name of the first object will be used.
|
155
160
|
# @option options [String] :header_message ("X errors prohibited this object from being saved")
|
156
|
-
# The message in the header of the error div.
|
161
|
+
# The message in the header of the error div. Pass +nil+ or an empty string
|
157
162
|
# to avoid the header message altogether.
|
158
163
|
# @option options [String] :message ("There were problems with the following fields:")
|
159
164
|
# The explanation message after the header message and before
|
@@ -165,7 +170,6 @@ module Padrino
|
|
165
170
|
# @example
|
166
171
|
# error_messages_for :user
|
167
172
|
#
|
168
|
-
# @api public
|
169
173
|
def error_messages_for(*objects)
|
170
174
|
options = objects.extract_options!.symbolize_keys
|
171
175
|
objects = objects.map { |object_name|
|
@@ -184,19 +188,19 @@ module Padrino
|
|
184
188
|
end
|
185
189
|
end
|
186
190
|
|
187
|
-
options[:object_name] ||= objects.first.class
|
191
|
+
options[:object_name] ||= objects.first.class.to_s.underscore.gsub(/\//, ' ')
|
188
192
|
|
189
193
|
I18n.with_options :locale => options[:locale], :scope => [:models, :errors, :template] do |locale|
|
190
194
|
header_message = if options.include?(:header_message)
|
191
195
|
options[:header_message]
|
192
196
|
else
|
193
|
-
object_name = options[:object_name]
|
197
|
+
object_name = options[:object_name]
|
194
198
|
object_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1)
|
195
199
|
locale.t :header, :count => count, :model => object_name
|
196
200
|
end
|
197
201
|
message = options.include?(:message) ? options[:message] : locale.t(:body)
|
198
202
|
error_messages = objects.map { |object|
|
199
|
-
object_name = options[:object_name]
|
203
|
+
object_name = options[:object_name]
|
200
204
|
object.errors.map { |f, msg|
|
201
205
|
field = I18n.t(f, :default => f.to_s.humanize, :scope => [:models, object_name, :attributes])
|
202
206
|
content_tag(:li, "%s %s" % [field, msg])
|
@@ -216,7 +220,8 @@ module Padrino
|
|
216
220
|
end
|
217
221
|
|
218
222
|
##
|
219
|
-
# Returns a string containing the error message attached to the
|
223
|
+
# Returns a string containing the error message attached to the
|
224
|
+
# +method+ on the +object+ if one exists.
|
220
225
|
#
|
221
226
|
# @param [Object] object
|
222
227
|
# The object to display the error for.
|
@@ -251,8 +256,8 @@ module Padrino
|
|
251
256
|
error = if defined?(Ohm::Model) && object.is_a?(Ohm::Model)
|
252
257
|
I18n.t("ohm.errors.messages.#{error[0]}", :default => error[0].to_s)
|
253
258
|
else
|
254
|
-
# Array(error).first is necessary because some ORMs
|
255
|
-
# give us an array others directly a value
|
259
|
+
# Array(error).first is necessary because some ORMs
|
260
|
+
# give us an array others directly a value.
|
256
261
|
Array(error)[0]
|
257
262
|
end
|
258
263
|
|
@@ -267,7 +272,7 @@ module Padrino
|
|
267
272
|
end
|
268
273
|
|
269
274
|
##
|
270
|
-
# Constructs a label tag from the given options
|
275
|
+
# Constructs a label tag from the given options.
|
271
276
|
#
|
272
277
|
# @param [String] name
|
273
278
|
# The name of the field to label.
|
@@ -284,7 +289,6 @@ module Padrino
|
|
284
289
|
# label_tag :username, :class => 'long-label'
|
285
290
|
# label_tag :username, :class => 'long-label' do ... end
|
286
291
|
#
|
287
|
-
# @api public
|
288
292
|
def label_tag(name, options={}, &block)
|
289
293
|
options.reverse_merge!(:caption => "#{name.to_s.humanize}: ", :for => name)
|
290
294
|
caption_text = options.delete(:caption).html_safe
|
@@ -299,7 +303,7 @@ module Padrino
|
|
299
303
|
end
|
300
304
|
|
301
305
|
##
|
302
|
-
# Creates a text field input with the given name and options
|
306
|
+
# Creates a text field input with the given name and options.
|
303
307
|
#
|
304
308
|
# @macro [new] text_field
|
305
309
|
# @param [Symbol] name
|
@@ -328,40 +332,39 @@ module Padrino
|
|
328
332
|
# @option options [Boolean] :spellcheck
|
329
333
|
# Specifies whether or not the field should have it's spelling and grammar checked for errors.
|
330
334
|
# @option options [Boolean] :draggable
|
331
|
-
# Specifies whether or not the field is draggable. (true, false, :auto)
|
335
|
+
# Specifies whether or not the field is draggable. (true, false, :auto).
|
332
336
|
# @option options [String] :pattern
|
333
337
|
# Specifies the regular expression pattern that the field's value is checked against.
|
334
338
|
# @option options [Symbol] :autocomplete
|
335
|
-
# Specifies whether or not the field should have autocomplete enabled. (:on, :off)
|
339
|
+
# Specifies whether or not the field should have autocomplete enabled. (:on, :off).
|
336
340
|
# @option options [Boolean] :autofocus
|
337
341
|
# Specifies whether or not the field should automatically get focus when the page loads.
|
338
342
|
# @option options [Boolean] :required
|
339
|
-
# Specifies whether or not the field is required to be
|
343
|
+
# Specifies whether or not the field is required to be completed before the form is submitted.
|
340
344
|
# @option options [Boolean] :readonly
|
341
345
|
# Specifies whether or not the field is read only.
|
342
346
|
# @option options [Boolean] :disabled
|
343
347
|
# Specifies whether or not the field is disabled.
|
344
348
|
#
|
345
349
|
# @return [String]
|
346
|
-
# Generated HTML with specified +options
|
350
|
+
# Generated HTML with specified +options+.
|
347
351
|
#
|
348
352
|
# @example
|
349
353
|
# text_field_tag :first_name, :maxlength => 40, :required => true
|
350
|
-
# # => <input name="first_name" maxlength="40" required type="text"
|
354
|
+
# # => <input name="first_name" maxlength="40" required type="text" />
|
351
355
|
#
|
352
356
|
# text_field_tag :last_name, :class => 'string', :size => 40
|
353
|
-
# # => <input name="last_name" class="string" size="40" type="text"
|
357
|
+
# # => <input name="last_name" class="string" size="40" type="text" />
|
354
358
|
#
|
355
359
|
# text_field_tag :username, :placeholder => 'Your Username'
|
356
|
-
# # => <input name="username" placeholder="Your Username" type="text"
|
360
|
+
# # => <input name="username" placeholder="Your Username" type="text" />
|
357
361
|
#
|
358
|
-
# @api public
|
359
362
|
def text_field_tag(name, options={})
|
360
363
|
input_tag(:text, options.reverse_merge!(:name => name))
|
361
364
|
end
|
362
365
|
|
363
366
|
##
|
364
|
-
# Creates a number field input with the given name and options
|
367
|
+
# Creates a number field input with the given name and options.
|
365
368
|
#
|
366
369
|
# @macro [new] number_field
|
367
370
|
# @param [Symbol] name
|
@@ -390,11 +393,11 @@ module Padrino
|
|
390
393
|
# @option options [Boolean] :spellcheck
|
391
394
|
# Specifies whether or not the field should have it's spelling and grammar checked for errors.
|
392
395
|
# @option options [Boolean] :draggable
|
393
|
-
# Specifies whether or not the field is draggable. (true, false, :auto)
|
396
|
+
# Specifies whether or not the field is draggable. (true, false, :auto).
|
394
397
|
# @option options [String] :pattern
|
395
398
|
# Specifies the regular expression pattern that the field's value is checked against.
|
396
399
|
# @option options [Symbol] :autocomplete
|
397
|
-
# Specifies whether or not the field should have autocomplete enabled. (:on, :off)
|
400
|
+
# Specifies whether or not the field should have autocomplete enabled. (:on, :off).
|
398
401
|
# @option options [Boolean] :autofocus
|
399
402
|
# Specifies whether or not the field should automatically get focus when the page loads.
|
400
403
|
# @option options [Boolean] :required
|
@@ -405,138 +408,125 @@ module Padrino
|
|
405
408
|
# Specifies whether or not the field is disabled.
|
406
409
|
#
|
407
410
|
# @return [String]
|
408
|
-
# Generated HTML with specified +options
|
411
|
+
# Generated HTML with specified +options+.
|
409
412
|
#
|
410
413
|
# @example
|
411
|
-
# number_field_tag :
|
412
|
-
# # => <input name="
|
414
|
+
# number_field_tag :quantity, :class => 'numeric'
|
415
|
+
# # => <input name="quantity" class="numeric" type="number" />
|
413
416
|
#
|
414
417
|
# number_field_tag :zip_code, :pattern => /[0-9]{5}/
|
415
|
-
# # => <input name="zip_code" pattern="[0-9]{5}" type="number"
|
418
|
+
# # => <input name="zip_code" pattern="[0-9]{5}" type="number" />
|
416
419
|
#
|
417
420
|
# number_field_tag :credit_card, :autocomplete => :off
|
418
|
-
# # => <input name="credit_card" autocomplete="off" type="number"
|
421
|
+
# # => <input name="credit_card" autocomplete="off" type="number" />
|
419
422
|
#
|
420
423
|
# number_field_tag :age, :min => 18, :max => 120, :step => 1
|
421
|
-
# # => <input name="age" min="18" max="120" step="1" type="number"
|
424
|
+
# # => <input name="age" min="18" max="120" step="1" type="number" />
|
422
425
|
#
|
423
|
-
# @api public
|
424
426
|
def number_field_tag(name, options={})
|
425
427
|
input_tag(:number, options.reverse_merge(:name => name))
|
426
428
|
end
|
427
429
|
|
428
430
|
##
|
429
|
-
# Creates a telephone field input with the given name and options
|
431
|
+
# Creates a telephone field input with the given name and options.
|
430
432
|
#
|
431
433
|
# @macro text_field
|
432
434
|
#
|
433
435
|
# @example
|
434
436
|
# telephone_field_tag :phone_number, :class => 'string'
|
435
|
-
# # => <input name="phone_number" class="string" type="tel"
|
437
|
+
# # => <input name="phone_number" class="string" type="tel" />
|
436
438
|
#
|
437
439
|
# telephone_field_tag :cell_phone, :tabindex => 1
|
438
440
|
# telephone_field_tag :work_phone, :tabindex => 2
|
439
441
|
# telephone_field_tag :home_phone, :tabindex => 3
|
440
442
|
#
|
441
|
-
# # => <input name="cell_phone" tabindex="1" type="tel"
|
442
|
-
# # => <input name="work_phone" tabindex="2" type="tel"
|
443
|
-
# # => <input name="home_phone" tabindex="3" type="tel"
|
443
|
+
# # => <input name="cell_phone" tabindex="1" type="tel" />
|
444
|
+
# # => <input name="work_phone" tabindex="2" type="tel" />
|
445
|
+
# # => <input name="home_phone" tabindex="3" type="tel" />
|
444
446
|
#
|
445
|
-
# @api public
|
446
447
|
def telephone_field_tag(name, options={})
|
447
448
|
input_tag(:tel, options.reverse_merge(:name => name))
|
448
449
|
end
|
449
450
|
alias_method :phone_field_tag, :telephone_field_tag
|
450
451
|
|
451
452
|
##
|
452
|
-
# Creates an email field input with the given name and options
|
453
|
+
# Creates an email field input with the given name and options.
|
453
454
|
#
|
454
455
|
# @macro text_field
|
455
456
|
#
|
456
457
|
# @example
|
457
458
|
# email_field_tag :email, :placeholder => 'you@example.com'
|
458
|
-
# # => <input name="email" placeholder="you@example.com" type="email"
|
459
|
+
# # => <input name="email" placeholder="you@example.com" type="email" />
|
459
460
|
#
|
460
461
|
# email_field_tag :email, :value => 'padrinorb@gmail.com', :readonly => true
|
461
|
-
# # => <input name="email" value="padrinorb@gmail.com" readonly type="email"
|
462
|
+
# # => <input name="email" value="padrinorb@gmail.com" readonly type="email" />
|
462
463
|
#
|
463
|
-
# @api public
|
464
464
|
def email_field_tag(name, options={})
|
465
465
|
input_tag(:email, options.reverse_merge(:name => name))
|
466
466
|
end
|
467
467
|
|
468
468
|
##
|
469
|
-
# Creates a search field input with the given name and options
|
469
|
+
# Creates a search field input with the given name and options.
|
470
470
|
#
|
471
471
|
# @macro text_field
|
472
472
|
#
|
473
473
|
# @example
|
474
474
|
# search_field_tag :search, :placeholder => 'Search this website...'
|
475
|
-
# # => <input name="search" placeholder="Search this website..." type="search"
|
475
|
+
# # => <input name="search" placeholder="Search this website..." type="search" />
|
476
476
|
#
|
477
477
|
# search_field_tag :search, :maxlength => 15, :class => ['search', 'string']
|
478
|
-
# # => <input name="search" maxlength="15" class="search string"
|
478
|
+
# # => <input name="search" maxlength="15" class="search string" />
|
479
479
|
#
|
480
480
|
# search_field_tag :search, :id => 'search'
|
481
|
-
# # => <input name="search" id="search" type="search"
|
481
|
+
# # => <input name="search" id="search" type="search" />
|
482
482
|
#
|
483
483
|
# search_field_tag :search, :autofocus => true
|
484
|
-
# # => <input name="search" autofocus type="search"
|
484
|
+
# # => <input name="search" autofocus type="search" />
|
485
485
|
#
|
486
|
-
# @api public
|
487
486
|
def search_field_tag(name, options={})
|
488
487
|
input_tag(:search, options.reverse_merge(:name => name))
|
489
488
|
end
|
490
489
|
|
491
490
|
##
|
492
|
-
# Creates a
|
491
|
+
# Creates a URL field input with the given name and options.
|
493
492
|
#
|
494
493
|
# @macro text_field
|
495
494
|
#
|
496
495
|
# @example
|
497
496
|
# url_field_tag :favorite_website, :placeholder => 'http://padrinorb.com'
|
498
|
-
# <input name="favorite_website" placeholder="http://padrinorb.com." type="url"
|
497
|
+
# <input name="favorite_website" placeholder="http://padrinorb.com." type="url" />
|
499
498
|
#
|
500
499
|
# url_field_tag :home_page, :class => 'string url'
|
501
|
-
# <input name="home_page" class="string url", type="url"
|
500
|
+
# <input name="home_page" class="string url", type="url" />
|
502
501
|
#
|
503
|
-
# @api public
|
504
502
|
def url_field_tag(name, options={})
|
505
503
|
input_tag(:url, options.reverse_merge(:name => name))
|
506
504
|
end
|
507
505
|
|
508
506
|
##
|
509
|
-
# Constructs a hidden field input from the given options
|
510
|
-
#
|
511
|
-
# @macro text_field
|
507
|
+
# Constructs a hidden field input from the given options.
|
512
508
|
#
|
513
509
|
# @example
|
514
510
|
# hidden_field_tag :session_key, :value => "__secret__"
|
515
511
|
#
|
516
|
-
# @api public
|
517
512
|
def hidden_field_tag(name, options={})
|
518
513
|
options.reverse_merge!(:name => name)
|
519
514
|
input_tag(:hidden, options)
|
520
515
|
end
|
521
516
|
|
522
517
|
##
|
523
|
-
# Constructs a text area input from the given options
|
524
|
-
#
|
525
|
-
# @macro text_field
|
518
|
+
# Constructs a text area input from the given options.
|
526
519
|
#
|
527
520
|
# @example
|
528
521
|
# text_area_tag :username, :class => 'long', :value => "Demo?"
|
529
522
|
#
|
530
|
-
# @api public
|
531
523
|
def text_area_tag(name, options={})
|
532
524
|
options.reverse_merge!(:name => name, :rows => "", :cols => "")
|
533
525
|
content_tag(:textarea, options.delete(:value).to_s, options)
|
534
526
|
end
|
535
527
|
|
536
528
|
##
|
537
|
-
# Constructs a password field input from the given options
|
538
|
-
#
|
539
|
-
# @macro text_field
|
529
|
+
# Constructs a password field input from the given options.
|
540
530
|
#
|
541
531
|
# @example
|
542
532
|
# password_field_tag :password, :class => 'long'
|
@@ -548,37 +538,29 @@ module Padrino
|
|
548
538
|
end
|
549
539
|
|
550
540
|
##
|
551
|
-
# Constructs a check_box from the given options
|
552
|
-
#
|
553
|
-
# @macro text_field
|
541
|
+
# Constructs a check_box from the given options.
|
554
542
|
#
|
555
543
|
# @example
|
556
544
|
# check_box_tag :remember_me, :value => 'Yes'
|
557
545
|
#
|
558
|
-
# @api public
|
559
546
|
def check_box_tag(name, options={})
|
560
547
|
options.reverse_merge!(:name => name, :value => '1')
|
561
548
|
input_tag(:checkbox, options)
|
562
549
|
end
|
563
550
|
|
564
551
|
##
|
565
|
-
# Constructs a radio_button from the given options
|
566
|
-
#
|
567
|
-
# @macro text_field
|
552
|
+
# Constructs a radio_button from the given options.
|
568
553
|
#
|
569
554
|
# @example
|
570
555
|
# radio_button_tag :remember_me, :value => 'true'
|
571
556
|
#
|
572
|
-
# @api public
|
573
557
|
def radio_button_tag(name, options={})
|
574
558
|
options.reverse_merge!(:name => name)
|
575
559
|
input_tag(:radio, options)
|
576
560
|
end
|
577
561
|
|
578
562
|
##
|
579
|
-
# Constructs a file field input from the given options
|
580
|
-
#
|
581
|
-
# @macro text_field
|
563
|
+
# Constructs a file field input from the given options.
|
582
564
|
#
|
583
565
|
# @example
|
584
566
|
# file_field_tag :photo, :class => 'long'
|
@@ -591,7 +573,7 @@ module Padrino
|
|
591
573
|
end
|
592
574
|
|
593
575
|
##
|
594
|
-
# Constructs a select from the given options
|
576
|
+
# Constructs a select from the given options.
|
595
577
|
#
|
596
578
|
# @example
|
597
579
|
# options = [['caption', 'value'], ['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
|
@@ -628,9 +610,8 @@ module Padrino
|
|
628
610
|
# @option options [Boolean] :multiple (false)
|
629
611
|
# Allow multiple options to be selected at once.
|
630
612
|
#
|
631
|
-
# @return [String] The
|
613
|
+
# @return [String] The HTML input field based on the +options+ specified.
|
632
614
|
#
|
633
|
-
# @api public
|
634
615
|
def select_tag(name, options={})
|
635
616
|
options.reverse_merge!(:name => name)
|
636
617
|
collection, fields = options.delete(:collection), options.delete(:fields)
|
@@ -647,7 +628,7 @@ module Padrino
|
|
647
628
|
end
|
648
629
|
|
649
630
|
##
|
650
|
-
# Constructs a button input from the given options
|
631
|
+
# Constructs a button input from the given options.
|
651
632
|
#
|
652
633
|
# @param [String] caption
|
653
634
|
# The caption for the button.
|
@@ -659,16 +640,15 @@ module Padrino
|
|
659
640
|
# @example
|
660
641
|
# button_tag "Cancel", :class => 'clear'
|
661
642
|
#
|
662
|
-
# @api public
|
663
643
|
def button_tag(caption, options = {})
|
664
644
|
options.reverse_merge!(:value => caption)
|
665
645
|
input_tag(:button, options)
|
666
646
|
end
|
667
647
|
|
668
648
|
##
|
669
|
-
# Constructs a submit button from the given options
|
649
|
+
# Constructs a submit button from the given options.
|
670
650
|
#
|
671
|
-
# @param [String] caption
|
651
|
+
# @param [String] caption (defaults to: +Submit+)
|
672
652
|
# The caption for the submit button.
|
673
653
|
# @param [Hash] options
|
674
654
|
# The html options for the input field.
|
@@ -677,14 +657,17 @@ module Padrino
|
|
677
657
|
#
|
678
658
|
# @example
|
679
659
|
# submit_tag "Create", :class => 'success'
|
660
|
+
# submit_tag :class => 'btn'
|
680
661
|
#
|
681
|
-
|
682
|
-
|
662
|
+
def submit_tag(*args)
|
663
|
+
options = args[-1].is_a?(Hash) ? args.pop : {}
|
664
|
+
caption = args.length >= 1 ? args.shift : "Submit"
|
683
665
|
options.reverse_merge!(:value => caption)
|
684
666
|
input_tag(:submit, options)
|
685
667
|
end
|
686
668
|
|
687
|
-
|
669
|
+
##
|
670
|
+
# Constructs a submit button from the given options.
|
688
671
|
#
|
689
672
|
# @param [String] source
|
690
673
|
# The source image path for the button.
|
@@ -696,12 +679,12 @@ module Padrino
|
|
696
679
|
# @example
|
697
680
|
# submit_tag "Create", :class => 'success'
|
698
681
|
#
|
699
|
-
# @api public
|
700
682
|
def image_submit_tag(source, options={})
|
701
683
|
options.reverse_merge!(:src => image_path(source))
|
702
684
|
input_tag(:image, options)
|
703
685
|
end
|
704
686
|
|
687
|
+
##
|
705
688
|
# Constructs a hidden field containing a CSRF token.
|
706
689
|
#
|
707
690
|
# @param [String] token
|
@@ -712,17 +695,28 @@ module Padrino
|
|
712
695
|
# @example
|
713
696
|
# csrf_token_field
|
714
697
|
#
|
715
|
-
# @api public
|
716
698
|
def csrf_token_field(token = nil)
|
717
|
-
|
718
|
-
|
719
|
-
end
|
699
|
+
hidden_field_tag csrf_param, :value => csrf_token
|
700
|
+
end
|
720
701
|
|
721
|
-
|
702
|
+
##
|
703
|
+
# Constructs meta tags `csrf-param` and `csrf-token` with the name of the
|
704
|
+
# cross-site request forgery protection parameter and token, respectively.
|
705
|
+
#
|
706
|
+
# @return [String] The meta tags with the CSRF token and the param your app expects it in.
|
707
|
+
#
|
708
|
+
# @example
|
709
|
+
# csrf_meta_tags
|
710
|
+
#
|
711
|
+
def csrf_meta_tags
|
712
|
+
if is_protected_from_csrf?
|
713
|
+
meta_tag(csrf_param, :name => 'csrf-param') <<
|
714
|
+
meta_tag(csrf_token, :name => 'csrf-token')
|
715
|
+
end
|
722
716
|
end
|
723
717
|
|
724
718
|
##
|
725
|
-
# Creates a form containing a single button that submits to the
|
719
|
+
# Creates a form containing a single button that submits to the URL.
|
726
720
|
#
|
727
721
|
# @overload button_to(name, url, options={})
|
728
722
|
# @param [String] caption The text caption.
|
@@ -739,6 +733,8 @@ module Padrino
|
|
739
733
|
# Instructs ujs handler to handle the submit as ajax.
|
740
734
|
# @option options [Symbol] :method
|
741
735
|
# Instructs ujs handler to use different http method (i.e :post, :delete).
|
736
|
+
# @option options [Hash] :submit_options
|
737
|
+
# Hash of any options, that you want to pass to submit_tag (i.e :id, :class)
|
742
738
|
#
|
743
739
|
# @return [String] Form and button html with specified +options+.
|
744
740
|
#
|
@@ -750,113 +746,174 @@ module Padrino
|
|
750
746
|
# # <input type="submit" value="Delete" />
|
751
747
|
# # </form>
|
752
748
|
#
|
753
|
-
# @api public
|
754
749
|
def button_to(*args, &block)
|
755
750
|
name, url = args[0], args[1]
|
756
751
|
options = args.extract_options!
|
757
752
|
options['data-remote'] = 'true' if options.delete(:remote)
|
753
|
+
submit_options = options.delete(:submit_options) || {}
|
758
754
|
if block_given?
|
759
755
|
form_tag(url, options, &block)
|
760
756
|
else
|
761
|
-
form_tag(url, options) do
|
762
|
-
submit_tag(name)
|
757
|
+
form_tag(url, options.merge!(:not_concat => true)) do
|
758
|
+
submit_tag(name, submit_options)
|
763
759
|
end
|
764
760
|
end
|
765
761
|
end
|
766
762
|
|
763
|
+
##
|
764
|
+
# Constructs a range tag from the given options.
|
765
|
+
#
|
766
|
+
# @example
|
767
|
+
# range_field_tag('ranger_with_min_max', :min => 1, :max => 50)
|
768
|
+
# range_field_tag('ranger_with_range', :range => 1..5)
|
769
|
+
#
|
770
|
+
# @param [String] name
|
771
|
+
# The name of the range field.
|
772
|
+
# @param [Hash] options
|
773
|
+
# The html options for the range field.
|
774
|
+
# @option options [Integer] :min
|
775
|
+
# The min range of the range field.
|
776
|
+
# @option options [Integer] :max
|
777
|
+
# The max range of the range field.
|
778
|
+
# @option options [range] :range
|
779
|
+
# The range, in lieu of :min and :max. See examples for details.
|
780
|
+
# @return [String] The html range field
|
781
|
+
#
|
782
|
+
def range_field_tag(name, options = {})
|
783
|
+
options.reverse_merge!(:name => name)
|
784
|
+
if range = options.delete(:range)
|
785
|
+
options[:min], options[:max] = range.min, range.max
|
786
|
+
end
|
787
|
+
input_tag(:range, options)
|
788
|
+
end
|
789
|
+
|
767
790
|
protected
|
768
791
|
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
792
|
+
##
|
793
|
+
# Returns an array of option items for a select field based on the given collection.
|
794
|
+
#
|
795
|
+
# @param [Array] fields
|
796
|
+
# fields is an array containing the fields to display from each item in the collection.
|
797
|
+
#
|
798
|
+
def options_from_collection(collection, fields)
|
799
|
+
collection.map { |item| [ item.send(fields.first), item.send(fields.last) ] }
|
800
|
+
end
|
776
801
|
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
802
|
+
##
|
803
|
+
# Returns the options tags for a select based on the given option items.
|
804
|
+
#
|
805
|
+
def options_for_select(option_items, selected_value=nil)
|
806
|
+
return [] if option_items.blank?
|
807
|
+
option_items.map do |caption, value, disabled|
|
808
|
+
value ||= caption
|
809
|
+
disabled ||= false
|
810
|
+
content_tag(:option, caption, :value => value, :selected => option_is_selected?(value, caption, selected_value), :disabled => disabled)
|
786
811
|
end
|
812
|
+
end
|
787
813
|
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
814
|
+
##
|
815
|
+
# Returns the optgroups with options tags for a select based on the given :grouped_options items.
|
816
|
+
#
|
817
|
+
def grouped_options_for_select(collection, selected=nil, prompt=false)
|
818
|
+
if collection.is_a?(Hash)
|
819
|
+
collection.map do |key, value|
|
820
|
+
# Hash format:
|
821
|
+
# {:first => [1,2,3], :second => [4,5,6]}
|
822
|
+
# or:
|
823
|
+
# {:first => [[1,2,3], {:disabled => true}], :second => [4,5,6]}
|
824
|
+
attributes_hash = value.last.is_a?(Hash) ? value.pop : nil
|
825
|
+
disabled ||= attributes_hash && attributes_hash.include?(:disabled) ? attributes_hash[:disabled] : false
|
826
|
+
content_tag :optgroup, options_for_select(value, selected), :label => key, :disabled => disabled
|
827
|
+
end
|
828
|
+
elsif collection.is_a?(Array)
|
829
|
+
# Array format:
|
830
|
+
# ["Option Label", [:option1, :option2, ...]]
|
831
|
+
# or:
|
832
|
+
# ["Option Label", [:option1, :option2, ...], true]
|
833
|
+
# the last item tells if it is disabled or not. This is keeps it backwards compatible.
|
834
|
+
collection.map do |optgroup|
|
835
|
+
disabled ||= optgroup.count > 2 ? optgroup.pop : false
|
836
|
+
content_tag :optgroup, options_for_select(optgroup.last, selected), :label => optgroup.first, :disabled => disabled
|
804
837
|
end
|
805
838
|
end
|
839
|
+
end
|
806
840
|
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
end
|
841
|
+
##
|
842
|
+
# Returns the blank option serving as a prompt if passed.
|
843
|
+
#
|
844
|
+
def blank_option(prompt)
|
845
|
+
return unless prompt
|
846
|
+
case prompt
|
847
|
+
when String then content_tag(:option, prompt, :value => '')
|
848
|
+
when Array then content_tag(:option, prompt.first, :value => prompt.last)
|
849
|
+
else content_tag(:option, '', :value => '')
|
817
850
|
end
|
851
|
+
end
|
852
|
+
|
853
|
+
##
|
854
|
+
# Returns whether the application is being protected from CSRF. Defaults to true.
|
855
|
+
#
|
856
|
+
def is_protected_from_csrf?
|
857
|
+
defined?(settings) ? settings.protect_from_csrf : true
|
858
|
+
end
|
859
|
+
|
860
|
+
##
|
861
|
+
# Returns the current CSRF token (based on the session). If it doesn't exist,
|
862
|
+
# it will create one and assign it to the session's `csrf` key.
|
863
|
+
#
|
864
|
+
def csrf_token
|
865
|
+
session[:csrf] ||= SecureRandom.hex(32) if defined?(session)
|
866
|
+
end
|
867
|
+
|
868
|
+
##
|
869
|
+
# Returns the param/field name in which your CSRF token should be expected by your
|
870
|
+
# controllers. Defaults to `authenticity_token`.
|
871
|
+
#
|
872
|
+
# Set this in your application with `set :csrf_param, :something_else`.
|
873
|
+
#
|
874
|
+
def csrf_param
|
875
|
+
defined?(settings) && settings.respond_to?(:csrf_param) ?
|
876
|
+
settings.csrf_param : :authenticity_token
|
877
|
+
end
|
818
878
|
|
819
879
|
private
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
end
|
880
|
+
##
|
881
|
+
# Returns the FormBuilder class to use based on all available setting sources
|
882
|
+
# If explicitly defined, returns that, otherwise returns defaults.
|
883
|
+
#
|
884
|
+
# @example
|
885
|
+
# configured_form_builder_class(nil) => StandardFormBuilder
|
886
|
+
#
|
887
|
+
def configured_form_builder_class(explicit_builder=nil)
|
888
|
+
default_builder = self.respond_to?(:settings) && self.settings.default_builder
|
889
|
+
configured_builder = explicit_builder || default_builder || 'StandardFormBuilder'
|
890
|
+
configured_builder = "Padrino::Helpers::FormBuilder::#{configured_builder}".constantize if configured_builder.is_a?(String)
|
891
|
+
configured_builder
|
892
|
+
end
|
834
893
|
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
end
|
894
|
+
##
|
895
|
+
# Returns an initialized builder instance for the given object and settings.
|
896
|
+
#
|
897
|
+
# @example
|
898
|
+
# builder_instance(@account, :nested => { ... }) => <FormBuilder>
|
899
|
+
#
|
900
|
+
def builder_instance(object, settings={})
|
901
|
+
builder_class = configured_form_builder_class(settings.delete(:builder))
|
902
|
+
builder_class.new(self, object, settings)
|
903
|
+
end
|
846
904
|
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
[value.to_s, caption.to_s].include?(selected.to_s)
|
858
|
-
end
|
905
|
+
##
|
906
|
+
# Returns whether the option should be selected or not.
|
907
|
+
#
|
908
|
+
# @example
|
909
|
+
# option_is_selected?("red", "Red", ["red", "blue"]) => true
|
910
|
+
# option_is_selected?("red", "Red", ["green", "blue"]) => false
|
911
|
+
#
|
912
|
+
def option_is_selected?(value, caption, selected_values)
|
913
|
+
Array(selected_values).any? do |selected|
|
914
|
+
[value.to_s, caption.to_s].include?(selected.to_s)
|
859
915
|
end
|
860
|
-
|
861
|
-
|
862
|
-
end
|
916
|
+
end
|
917
|
+
end
|
918
|
+
end
|
919
|
+
end
|