middleman-core 3.2.2 → 3.3.0
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/features/cli_init.feature +18 -8
- data/features/helpers_select_tag.feature +1 -1
- data/features/layouts_dir.feature +8 -0
- data/features/markdown_redcarpet.feature +2 -2
- data/fixtures/asciidoc-app/source/layouts/default.erb +0 -1
- data/fixtures/capture-html-app/source/capture_html_haml.html.haml +1 -1
- data/fixtures/content-for-app/source/content_for_haml.html.haml +1 -1
- data/fixtures/frontmatter-settings-app/source/layouts/override.erb +1 -2
- data/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb +1 -2
- data/fixtures/layouts-dir-app/source/ambiguous.html.erb +5 -0
- data/fixtures/layouts-dir-app/source/layouts/other.erb +3 -0
- data/fixtures/layouts-dir-app/source/other.erb +3 -0
- data/fixtures/link-to-app/source/link_to_haml.html.haml +1 -1
- data/fixtures/link-to-app/source/link_to_slim.html.slim +1 -1
- data/fixtures/nested-layout-app/source/layouts/inner_haml.haml +1 -1
- data/fixtures/nested-layout-app/source/layouts/inner_slim.slim +1 -1
- data/fixtures/nested-layout-app/source/layouts/outer_haml.haml +1 -1
- data/fixtures/nested-layout-app/source/layouts/outer_slim.slim +1 -1
- data/lib/middleman-core/application.rb +12 -3
- data/lib/middleman-core/cli/build.rb +5 -3
- data/lib/middleman-core/cli/console.rb +1 -1
- data/lib/middleman-core/cli/init.rb +1 -1
- data/lib/middleman-core/core_extensions.rb +0 -1
- data/lib/middleman-core/core_extensions/file_watcher.rb +11 -11
- data/lib/middleman-core/core_extensions/rendering.rb +40 -66
- data/lib/middleman-core/extension.rb +167 -0
- data/lib/middleman-core/extensions.rb +2 -151
- data/lib/middleman-core/logger.rb +2 -2
- data/lib/middleman-core/meta_pages/assets/config.css +13 -0
- data/lib/middleman-core/meta_pages/assets/meta.css +19 -3
- data/lib/middleman-core/meta_pages/assets/sitemap.css +18 -1
- data/lib/middleman-core/meta_pages/config_setting.rb +7 -9
- data/lib/middleman-core/meta_pages/sitemap_resource.rb +24 -15
- data/lib/middleman-core/meta_pages/sitemap_tree.rb +5 -1
- data/lib/middleman-core/meta_pages/templates/config.html.erb +2 -2
- data/lib/middleman-core/meta_pages/templates/index.html.erb +18 -8
- data/lib/middleman-core/meta_pages/templates/sitemap.html.erb +4 -5
- data/lib/middleman-core/preview_server.rb +6 -3
- data/lib/middleman-core/renderers/erb.rb +12 -14
- data/lib/middleman-core/renderers/haml.rb +10 -0
- data/lib/middleman-core/renderers/markdown.rb +5 -1
- data/lib/middleman-core/renderers/sass.rb +0 -4
- data/lib/middleman-core/renderers/slim.rb +16 -3
- data/lib/middleman-core/sitemap/resource.rb +1 -1
- data/lib/middleman-core/step_definitions.rb +2 -1
- data/lib/middleman-core/templates.rb +3 -1
- data/lib/middleman-core/templates/shared/Gemfile.tt +4 -1
- data/lib/middleman-core/templates/shared/config.tt +3 -1
- data/lib/middleman-core/templates/shared/gitignore +2 -1
- data/lib/middleman-core/util.rb +22 -16
- data/lib/middleman-core/version.rb +1 -1
- data/lib/middleman-more/core_extensions/compass.rb +3 -3
- data/lib/middleman-more/core_extensions/default_helpers.rb +18 -15
- data/lib/middleman-more/extensions/asset_hash.rb +1 -0
- data/middleman-core.gemspec +9 -6
- metadata +69 -227
- data/features/sass_cache_path.feature +0 -22
- data/fixtures/sass-cache-path-custom-app/config.rb +0 -3
- data/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass +0 -4
- data/fixtures/sass-cache-path-default-app/config.rb +0 -3
- data/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass +0 -4
- data/lib/vendored-middleman-deps/hooks-0.2.0/CHANGES.textile +0 -9
- data/lib/vendored-middleman-deps/hooks-0.2.0/Gemfile +0 -3
- data/lib/vendored-middleman-deps/hooks-0.2.0/README.rdoc +0 -107
- data/lib/vendored-middleman-deps/hooks-0.2.0/Rakefile +0 -12
- data/lib/vendored-middleman-deps/hooks-0.2.0/hooks.gemspec +0 -22
- data/lib/vendored-middleman-deps/hooks-0.2.0/lib/hooks.rb +0 -109
- data/lib/vendored-middleman-deps/hooks-0.2.0/lib/hooks/inheritable_attribute.rb +0 -33
- data/lib/vendored-middleman-deps/hooks-0.2.0/test/hooks_test.rb +0 -141
- data/lib/vendored-middleman-deps/hooks-0.2.0/test/inheritable_attribute_test.rb +0 -55
- data/lib/vendored-middleman-deps/hooks-0.2.0/test/test_helper.rb +0 -10
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/.document +0 -5
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/.gitignore +0 -22
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/.yardopts +0 -1
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/LICENSE.txt +0 -20
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/README.rdoc +0 -294
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/Rakefile +0 -5
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/bin/padrino +0 -9
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core.rb +0 -200
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application.rb +0 -297
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/flash.rb +0 -229
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering.rb +0 -317
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/erubis.rb +0 -64
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/haml.rb +0 -28
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/slim.rb +0 -14
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/routing.rb +0 -1077
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/showexceptions.rb +0 -21
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/caller.rb +0 -53
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/adapter.rb +0 -24
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/base.rb +0 -159
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/console.rb +0 -20
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/rake.rb +0 -47
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/rake_tasks.rb +0 -52
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/command.rb +0 -38
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/images/404.png +0 -0
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/images/500.png +0 -0
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/loader.rb +0 -224
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/cs.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/da.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/de.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/en.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/es.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/fr.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/hu.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/it.yml +0 -39
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ja.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/lv.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/nl.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/no.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/pl.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/pt_br.yml +0 -39
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ro.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ru.yml +0 -34
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/sv.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/tr.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/uk.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/zh_cn.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/zh_tw.yml +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/logger.rb +0 -438
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/module.rb +0 -58
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/mounter.rb +0 -234
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/reloader.rb +0 -341
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/router.rb +0 -95
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/server.rb +0 -77
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/support_lite.rb +0 -260
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/tasks.rb +0 -21
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/version.rb +0 -20
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/padrino-core.gemspec +0 -43
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/Gemfile +0 -4
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/app/app.rb +0 -3
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/app_gem.gemspec +0 -17
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/lib/app_gem.rb +0 -7
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/lib/app_gem/version.rb +0 -3
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/.components +0 -6
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/.gitignore +0 -7
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/complex.rb +0 -32
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/simple.rb +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/a.rb +0 -9
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/b.rb +0 -4
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/c.rb +0 -1
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/e.rb +0 -13
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/f.rb +0 -2
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/g.rb +0 -2
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/d.rb +0 -4
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/helper.rb +0 -83
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/mini_shoulda.rb +0 -45
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_application.rb +0 -125
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_core.rb +0 -77
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_csrf_protection.rb +0 -80
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_dependencies.rb +0 -44
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_filters.rb +0 -348
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_flash.rb +0 -168
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_locale.rb +0 -21
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_logger.rb +0 -210
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_mounter.rb +0 -199
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_complex.rb +0 -75
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_simple.rb +0 -98
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering.rb +0 -545
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering_extensions.rb +0 -14
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_restful_routing.rb +0 -33
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_router.rb +0 -146
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_routing.rb +0 -1927
- data/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_support_lite.rb +0 -56
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.document +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.gitignore +0 -21
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.yardopts +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/LICENSE.txt +0 -20
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/README.rdoc +0 -239
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/Rakefile +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers.rb +0 -57
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/asset_tag_helpers.rb +0 -401
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/breadcrumb_helpers.rb +0 -183
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_builder/abstract_form_builder.rb +0 -317
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_builder/standard_form_builder.rb +0 -40
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_helpers.rb +0 -919
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/format_helpers.rb +0 -372
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/cs.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/da.yml +0 -91
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/de.yml +0 -81
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/en.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/es.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/fr.yml +0 -79
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/hu.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/it.yml +0 -89
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ja.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/lv.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/nl.yml +0 -82
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/no.yml +0 -91
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/pl.yml +0 -95
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/pt_br.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ro.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ru.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/sv.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/tr.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/uk.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/zh_cn.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/zh_tw.yml +0 -103
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/number_helpers.rb +0 -283
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers.rb +0 -207
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/abstract_handler.rb +0 -96
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/erb_handler.rb +0 -78
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/haml_handler.rb +0 -63
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/slim_handler.rb +0 -78
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/render_helpers.rb +0 -59
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/tag_helpers.rb +0 -292
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/translation_helpers.rb +0 -36
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/padrino-helpers.gemspec +0 -27
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/app.rb +0 -84
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.erb +0 -8
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.haml +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.slim +0 -6
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.erb +0 -14
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.haml +0 -12
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.slim +0 -12
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.erb +0 -14
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.haml +0 -12
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.slim +0 -12
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.erb +0 -11
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.haml +0 -9
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.slim +0 -9
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.erb +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.haml +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.slim +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.erb +0 -20
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.haml +0 -15
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.slim +0 -15
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.erb +0 -72
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.haml +0 -59
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.slim +0 -59
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.erb +0 -95
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.haml +0 -78
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.slim +0 -79
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.erb +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.haml +0 -4
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.slim +0 -4
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.erb +0 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.haml +0 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.slim +0 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.erb +0 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.haml +0 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.slim +0 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_erb.erb +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_haml.haml +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_slim.slim +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.erb +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.haml +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.slim +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/app.rb +0 -58
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engine.haml +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_erb.erb +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_haml.haml +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_slim.slim +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_erb.erb +0 -3
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_haml.haml +0 -2
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_slim.slim +0 -2
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/erb/test.erb +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/explicit_engine.haml +0 -5
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/haml/test.haml +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/_user.haml +0 -7
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/haml_template.haml +0 -1
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/some_template.haml +0 -2
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/helper.rb +0 -67
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_asset_tag_helpers.rb +0 -359
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_breadcrumb_helpers.rb +0 -134
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_builder.rb +0 -1178
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_helpers.rb +0 -1030
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_format_helpers.rb +0 -241
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_locale.rb +0 -20
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_number_helpers.rb +0 -143
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_output_helpers.rb +0 -154
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_render_helpers.rb +0 -94
- data/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_tag_helpers.rb +0 -117
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/abstract_form_builder') unless defined?(AbstractFormBuilder)
|
|
2
|
-
|
|
3
|
-
module Padrino
|
|
4
|
-
module Helpers
|
|
5
|
-
module FormBuilder
|
|
6
|
-
class StandardFormBuilder < AbstractFormBuilder
|
|
7
|
-
##
|
|
8
|
-
# StandardFormBuilder
|
|
9
|
-
#
|
|
10
|
-
# text_field_block(:username, { :class => 'long' }, { :class => 'wide-label' })
|
|
11
|
-
# text_area_block(:summary, { :class => 'long' }, { :class => 'wide-label' })
|
|
12
|
-
# password_field_block(:password, { :class => 'long' }, { :class => 'wide-label' })
|
|
13
|
-
# file_field_block(:photo, { :class => 'long' }, { :class => 'wide-label' })
|
|
14
|
-
# check_box_block(:remember_me, { :class => 'long' }, { :class => 'wide-label' })
|
|
15
|
-
# select_block(:color, :options => ['green', 'black'])
|
|
16
|
-
#
|
|
17
|
-
(self.field_types - [ :hidden_field, :radio_button ]).each do |field_type|
|
|
18
|
-
class_eval <<-EOF
|
|
19
|
-
def #{field_type}_block(field, options={}, label_options={})
|
|
20
|
-
label_options.reverse_merge!(:caption => options.delete(:caption)) if options[:caption]
|
|
21
|
-
field_html = label(field, label_options)
|
|
22
|
-
field_html << #{field_type}(field, options)
|
|
23
|
-
@template.content_tag(:p, field_html)
|
|
24
|
-
end
|
|
25
|
-
EOF
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def submit_block(caption, options={})
|
|
29
|
-
submit_html = self.submit(caption, options)
|
|
30
|
-
@template.content_tag(:p, submit_html)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def image_submit_block(source, options={})
|
|
34
|
-
submit_html = self.image_submit(source, options)
|
|
35
|
-
@template.content_tag(:p, submit_html)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,919 +0,0 @@
|
|
|
1
|
-
require 'securerandom'
|
|
2
|
-
|
|
3
|
-
module Padrino
|
|
4
|
-
module Helpers
|
|
5
|
-
##
|
|
6
|
-
# Helpers related to producing form related tags and inputs into templates.
|
|
7
|
-
#
|
|
8
|
-
module FormHelpers
|
|
9
|
-
##
|
|
10
|
-
# Constructs a form for object using given or default form_builder.
|
|
11
|
-
#
|
|
12
|
-
# @param [Object] object
|
|
13
|
-
# The object for which the form is being built.
|
|
14
|
-
# @param [String] URL
|
|
15
|
-
# The url this form will submit to.
|
|
16
|
-
# @param [Hash] settings
|
|
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.
|
|
20
|
-
# @option settings [String] :builder ("StandardFormBuilder")
|
|
21
|
-
# The FormBuilder class to use such as StandardFormBuilder.
|
|
22
|
-
# @param [Proc] block
|
|
23
|
-
# The fields and content inside this form.
|
|
24
|
-
#
|
|
25
|
-
# @yield [AbstractFormBuilder] The form builder used to compose fields.
|
|
26
|
-
#
|
|
27
|
-
# @return [String] The html object-backed form with the specified options and input fields.
|
|
28
|
-
#
|
|
29
|
-
# @example
|
|
30
|
-
# form_for :user, '/register' do |f| ... end
|
|
31
|
-
# form_for @user, '/register', :id => 'register' do |f| ... end
|
|
32
|
-
#
|
|
33
|
-
def form_for(object, url, settings={}, &block)
|
|
34
|
-
instance = builder_instance(object, settings)
|
|
35
|
-
html = capture_html(instance, &block)
|
|
36
|
-
settings[:multipart] = instance.multipart unless settings.include?(:multipart)
|
|
37
|
-
settings.delete(:namespace)
|
|
38
|
-
form_tag(url, settings) { html }
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
##
|
|
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.
|
|
44
|
-
#
|
|
45
|
-
# @param [Object] object
|
|
46
|
-
# The object for which the fields are being built.
|
|
47
|
-
# @param [Hash] settings
|
|
48
|
-
# The settings associated with these fields. Accepts HTML options.
|
|
49
|
-
# @param [Proc] block
|
|
50
|
-
# The content inside this set of fields.
|
|
51
|
-
#
|
|
52
|
-
# @return [String] The html fields with the specified options.
|
|
53
|
-
#
|
|
54
|
-
# @example
|
|
55
|
-
# fields_for @user.assignment do |assignment| ... end
|
|
56
|
-
# fields_for :assignment do |assigment| ... end
|
|
57
|
-
#
|
|
58
|
-
def fields_for(object, settings={}, &block)
|
|
59
|
-
instance = builder_instance(object, settings)
|
|
60
|
-
fields_html = capture_html(instance, &block)
|
|
61
|
-
fields_html << instance.hidden_field(:id) if instance.send(:nested_object_id)
|
|
62
|
-
concat_safe_content fields_html
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
##
|
|
66
|
-
# Constructs a form without object based on options.
|
|
67
|
-
#
|
|
68
|
-
# @param [String] url
|
|
69
|
-
# The URL this form will submit to.
|
|
70
|
-
# @param [Hash] options
|
|
71
|
-
# The html options associated with this form.
|
|
72
|
-
# @param [Proc] block
|
|
73
|
-
# The fields and content inside this form.
|
|
74
|
-
#
|
|
75
|
-
# @return [String] The HTML form with the specified options and input fields.
|
|
76
|
-
#
|
|
77
|
-
# @example
|
|
78
|
-
# form_tag '/register', :class => "registration_form" do ... end
|
|
79
|
-
#
|
|
80
|
-
def form_tag(url, options={}, &block)
|
|
81
|
-
desired_method = options[:method].to_s
|
|
82
|
-
options.delete(:method) unless desired_method =~ /get|post/i
|
|
83
|
-
options.reverse_merge!(:method => 'post',
|
|
84
|
-
:action => url,
|
|
85
|
-
:protect_from_csrf => is_protected_from_csrf? )
|
|
86
|
-
options[:enctype] = 'multipart/form-data' if options.delete(:multipart)
|
|
87
|
-
options['accept-charset'] ||= 'UTF-8'
|
|
88
|
-
inner_form_html = hidden_form_method_field(desired_method)
|
|
89
|
-
if options[:protect_from_csrf] == true && !(desired_method =~ /get/i)
|
|
90
|
-
inner_form_html << csrf_token_field
|
|
91
|
-
end
|
|
92
|
-
inner_form_html << mark_safe(capture_html(&block))
|
|
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)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
##
|
|
99
|
-
# Returns the hidden method field for 'put' and 'delete' forms.
|
|
100
|
-
# Only 'get' and 'post' are allowed within browsers;
|
|
101
|
-
# 'put' and 'delete' are just specified using hidden fields with form action still 'put'.
|
|
102
|
-
#
|
|
103
|
-
# @param [String] desired_method
|
|
104
|
-
# The method this hidden field represents (i.e put or delete).
|
|
105
|
-
#
|
|
106
|
-
# @return [String] The hidden field representing the +desired_method+ for the form.
|
|
107
|
-
#
|
|
108
|
-
# @example
|
|
109
|
-
# # Generate: <input name="_method" value="delete" />
|
|
110
|
-
# hidden_form_method_field('delete')
|
|
111
|
-
#
|
|
112
|
-
def hidden_form_method_field(desired_method)
|
|
113
|
-
return ActiveSupport::SafeBuffer.new if desired_method.blank? || desired_method.to_s =~ /get|post/i
|
|
114
|
-
hidden_field_tag(:_method, :value => desired_method)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
##
|
|
118
|
-
# Constructs a field_set to group fields with given options.
|
|
119
|
-
#
|
|
120
|
-
# @overload field_set_tag(legend=nil, options={}, &block)
|
|
121
|
-
# @param [String] legend The legend caption for the fieldset
|
|
122
|
-
# @param [Hash] options The html options for the fieldset.
|
|
123
|
-
# @param [Proc] block The content inside the fieldset.
|
|
124
|
-
# @overload field_set_tag(options={}, &block)
|
|
125
|
-
# @param [Hash] options The html options for the fieldset.
|
|
126
|
-
# @param [Proc] block The content inside the fieldset.
|
|
127
|
-
#
|
|
128
|
-
# @return [String] The html for the fieldset tag based on given +options+.
|
|
129
|
-
#
|
|
130
|
-
# @example
|
|
131
|
-
# field_set_tag(:class => "office-set") { }
|
|
132
|
-
# field_set_tag("Office", :class => 'office-set') { }
|
|
133
|
-
#
|
|
134
|
-
def field_set_tag(*args, &block)
|
|
135
|
-
options = args.extract_options!
|
|
136
|
-
legend_text = args[0].is_a?(String) ? args.first : nil
|
|
137
|
-
legend_html = legend_text.blank? ? ActiveSupport::SafeBuffer.new : content_tag(:legend, legend_text)
|
|
138
|
-
field_set_content = legend_html + mark_safe(capture_html(&block))
|
|
139
|
-
concat_content content_tag(:fieldset, field_set_content, options)
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
##
|
|
143
|
-
# Constructs list HTML for the errors for a given symbol.
|
|
144
|
-
#
|
|
145
|
-
# @overload error_messages_for(*objects, options = {})
|
|
146
|
-
# @param [Array<Object>] object Splat of objects to display errors for.
|
|
147
|
-
# @param [Hash] options Error message display options.
|
|
148
|
-
# @option options [String] :header_tag ("h2")
|
|
149
|
-
# Used for the header of the error div.
|
|
150
|
-
# @option options [String] :id ("field-errors")
|
|
151
|
-
# The id of the error div.
|
|
152
|
-
# @option options [String] :class ("field-errors")
|
|
153
|
-
# The class of the error div.
|
|
154
|
-
# @option options [Array<Object>] :object
|
|
155
|
-
# The object (or array of objects) for which to display errors,
|
|
156
|
-
# if you need to escape the instance variable convention.
|
|
157
|
-
# @option options [String] :object_name
|
|
158
|
-
# The object name to use in the header, or any text that you prefer.
|
|
159
|
-
# If +:object_name+ is not set, the name of the first object will be used.
|
|
160
|
-
# @option options [String] :header_message ("X errors prohibited this object from being saved")
|
|
161
|
-
# The message in the header of the error div. Pass +nil+ or an empty string
|
|
162
|
-
# to avoid the header message altogether.
|
|
163
|
-
# @option options [String] :message ("There were problems with the following fields:")
|
|
164
|
-
# The explanation message after the header message and before
|
|
165
|
-
# the error list. Pass +nil+ or an empty string to avoid the explanation message
|
|
166
|
-
# altogether.
|
|
167
|
-
#
|
|
168
|
-
# @return [String] The html section with all errors for the specified +objects+
|
|
169
|
-
#
|
|
170
|
-
# @example
|
|
171
|
-
# error_messages_for :user
|
|
172
|
-
#
|
|
173
|
-
def error_messages_for(*objects)
|
|
174
|
-
options = objects.extract_options!.symbolize_keys
|
|
175
|
-
objects = objects.map { |object_name|
|
|
176
|
-
object_name.is_a?(Symbol) ? instance_variable_get("@#{object_name}") : object_name
|
|
177
|
-
}.compact
|
|
178
|
-
count = objects.inject(0) { |sum, object| sum + object.errors.count }
|
|
179
|
-
|
|
180
|
-
unless count.zero?
|
|
181
|
-
html = {}
|
|
182
|
-
[:id, :class, :style].each do |key|
|
|
183
|
-
if options.include?(key)
|
|
184
|
-
value = options[key]
|
|
185
|
-
html[key] = value unless value.blank?
|
|
186
|
-
else
|
|
187
|
-
html[key] = 'field-errors' unless key == :style
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
options[:object_name] ||= objects.first.class.to_s.underscore.gsub(/\//, ' ')
|
|
192
|
-
|
|
193
|
-
I18n.with_options :locale => options[:locale], :scope => [:models, :errors, :template] do |locale|
|
|
194
|
-
header_message = if options.include?(:header_message)
|
|
195
|
-
options[:header_message]
|
|
196
|
-
else
|
|
197
|
-
object_name = options[:object_name]
|
|
198
|
-
object_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1)
|
|
199
|
-
locale.t :header, :count => count, :model => object_name
|
|
200
|
-
end
|
|
201
|
-
message = options.include?(:message) ? options[:message] : locale.t(:body)
|
|
202
|
-
error_messages = objects.map { |object|
|
|
203
|
-
object_name = options[:object_name]
|
|
204
|
-
object.errors.map { |f, msg|
|
|
205
|
-
field = I18n.t(f, :default => f.to_s.humanize, :scope => [:models, object_name, :attributes])
|
|
206
|
-
content_tag(:li, "%s %s" % [field, msg])
|
|
207
|
-
}
|
|
208
|
-
}.join
|
|
209
|
-
|
|
210
|
-
contents = ActiveSupport::SafeBuffer.new
|
|
211
|
-
contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
|
|
212
|
-
contents << content_tag(:p, message) unless message.blank?
|
|
213
|
-
contents << safe_content_tag(:ul, error_messages)
|
|
214
|
-
|
|
215
|
-
content_tag(:div, contents, html)
|
|
216
|
-
end
|
|
217
|
-
else
|
|
218
|
-
''
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
##
|
|
223
|
-
# Returns a string containing the error message attached to the
|
|
224
|
-
# +method+ on the +object+ if one exists.
|
|
225
|
-
#
|
|
226
|
-
# @param [Object] object
|
|
227
|
-
# The object to display the error for.
|
|
228
|
-
# @param [Symbol] field
|
|
229
|
-
# The field on the +object+ to display the error for.
|
|
230
|
-
# @param [Hash] options
|
|
231
|
-
# The options to control the error display.
|
|
232
|
-
# @option options [String] :tag ("span")
|
|
233
|
-
# The tag that encloses the error.
|
|
234
|
-
# @option options [String] :prepend ("")
|
|
235
|
-
# The text to prepend before the field error.
|
|
236
|
-
# @option options [String] :append ("")
|
|
237
|
-
# The text to append after the field error.
|
|
238
|
-
#
|
|
239
|
-
# @example
|
|
240
|
-
# # => <span class="error">can't be blank</div>
|
|
241
|
-
# error_message_on :post, :title
|
|
242
|
-
# error_message_on @post, :title
|
|
243
|
-
#
|
|
244
|
-
# # => <div class="custom" style="border:1px solid red">can't be blank</div>
|
|
245
|
-
# error_message_on :post, :title, :tag => :id, :class => :custom, :style => "border:1px solid red"
|
|
246
|
-
#
|
|
247
|
-
# # => <div class="error">This title can't be blank (or it won't work)</div>
|
|
248
|
-
# error_message_on :post, :title, :prepend => "This title", :append => "(or it won't work)"
|
|
249
|
-
#
|
|
250
|
-
# @return [String] The html display of an error for a particular +object+ and +field+.
|
|
251
|
-
#
|
|
252
|
-
# @api public
|
|
253
|
-
def error_message_on(object, field, options={})
|
|
254
|
-
object = object.is_a?(Symbol) ? instance_variable_get("@#{object}") : object
|
|
255
|
-
error = object.errors[field] rescue nil
|
|
256
|
-
error = if defined?(Ohm::Model) && object.is_a?(Ohm::Model)
|
|
257
|
-
I18n.t("ohm.errors.messages.#{error[0]}", :default => error[0].to_s)
|
|
258
|
-
else
|
|
259
|
-
# Array(error).first is necessary because some ORMs
|
|
260
|
-
# give us an array others directly a value.
|
|
261
|
-
Array(error)[0]
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
if error = Array(error)[0]
|
|
265
|
-
options.reverse_merge!(:tag => :span, :class => :error)
|
|
266
|
-
tag = options.delete(:tag)
|
|
267
|
-
error = [options.delete(:prepend), error, options.delete(:append)].compact.join(" ")
|
|
268
|
-
content_tag(tag, error, options)
|
|
269
|
-
else
|
|
270
|
-
''
|
|
271
|
-
end
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
##
|
|
275
|
-
# Constructs a label tag from the given options.
|
|
276
|
-
#
|
|
277
|
-
# @param [String] name
|
|
278
|
-
# The name of the field to label.
|
|
279
|
-
# @param [Hash] options
|
|
280
|
-
# The html options for this label.
|
|
281
|
-
# @option options :caption
|
|
282
|
-
# The caption for this label.
|
|
283
|
-
# @param [Proc] block
|
|
284
|
-
# The content to be inserted into the label.
|
|
285
|
-
#
|
|
286
|
-
# @return [String] The html for this label with the given +options+.
|
|
287
|
-
#
|
|
288
|
-
# @example
|
|
289
|
-
# label_tag :username, :class => 'long-label'
|
|
290
|
-
# label_tag :username, :class => 'long-label' do ... end
|
|
291
|
-
#
|
|
292
|
-
def label_tag(name, options={}, &block)
|
|
293
|
-
options.reverse_merge!(:caption => "#{name.to_s.humanize}: ", :for => name)
|
|
294
|
-
caption_text = options.delete(:caption).html_safe
|
|
295
|
-
caption_text.safe_concat "<span class='required'>*</span> " if options.delete(:required)
|
|
296
|
-
|
|
297
|
-
if block_given? # label with inner content
|
|
298
|
-
label_content = caption_text.concat capture_html(&block)
|
|
299
|
-
concat_content(content_tag(:label, label_content, options))
|
|
300
|
-
else # regular label
|
|
301
|
-
content_tag(:label, caption_text, options)
|
|
302
|
-
end
|
|
303
|
-
end
|
|
304
|
-
|
|
305
|
-
##
|
|
306
|
-
# Creates a text field input with the given name and options.
|
|
307
|
-
#
|
|
308
|
-
# @macro [new] text_field
|
|
309
|
-
# @param [Symbol] name
|
|
310
|
-
# The name of the input to create.
|
|
311
|
-
# @param [Hash] options
|
|
312
|
-
# The HTML options to include in this field.
|
|
313
|
-
#
|
|
314
|
-
# @option options [String] :id
|
|
315
|
-
# Specifies a unique identifier for the field.
|
|
316
|
-
# @option options [String] :class
|
|
317
|
-
# Specifies the stylesheet class of the field.
|
|
318
|
-
# @option options [String] :name
|
|
319
|
-
# Specifies the name of the field.
|
|
320
|
-
# @option options [String] :accesskey
|
|
321
|
-
# Specifies a shortcut key to access the field.
|
|
322
|
-
# @option options [Integer] :tabindex
|
|
323
|
-
# Specifies the tab order of the field.
|
|
324
|
-
# @option options [Integer] :maxlength
|
|
325
|
-
# Specifies the maximum length, in characters, of the field.
|
|
326
|
-
# @option options [Integer] :size
|
|
327
|
-
# Specifies the width, in characters, of the field.
|
|
328
|
-
# @option options [String] :placeholder
|
|
329
|
-
# Specifies a short hint that describes the expected value of the field.
|
|
330
|
-
# @option options [Boolean] :hidden
|
|
331
|
-
# Specifies whether or not the field is hidden from view.
|
|
332
|
-
# @option options [Boolean] :spellcheck
|
|
333
|
-
# Specifies whether or not the field should have it's spelling and grammar checked for errors.
|
|
334
|
-
# @option options [Boolean] :draggable
|
|
335
|
-
# Specifies whether or not the field is draggable. (true, false, :auto).
|
|
336
|
-
# @option options [String] :pattern
|
|
337
|
-
# Specifies the regular expression pattern that the field's value is checked against.
|
|
338
|
-
# @option options [Symbol] :autocomplete
|
|
339
|
-
# Specifies whether or not the field should have autocomplete enabled. (:on, :off).
|
|
340
|
-
# @option options [Boolean] :autofocus
|
|
341
|
-
# Specifies whether or not the field should automatically get focus when the page loads.
|
|
342
|
-
# @option options [Boolean] :required
|
|
343
|
-
# Specifies whether or not the field is required to be completed before the form is submitted.
|
|
344
|
-
# @option options [Boolean] :readonly
|
|
345
|
-
# Specifies whether or not the field is read only.
|
|
346
|
-
# @option options [Boolean] :disabled
|
|
347
|
-
# Specifies whether or not the field is disabled.
|
|
348
|
-
#
|
|
349
|
-
# @return [String]
|
|
350
|
-
# Generated HTML with specified +options+.
|
|
351
|
-
#
|
|
352
|
-
# @example
|
|
353
|
-
# text_field_tag :first_name, :maxlength => 40, :required => true
|
|
354
|
-
# # => <input name="first_name" maxlength="40" required type="text" />
|
|
355
|
-
#
|
|
356
|
-
# text_field_tag :last_name, :class => 'string', :size => 40
|
|
357
|
-
# # => <input name="last_name" class="string" size="40" type="text" />
|
|
358
|
-
#
|
|
359
|
-
# text_field_tag :username, :placeholder => 'Your Username'
|
|
360
|
-
# # => <input name="username" placeholder="Your Username" type="text" />
|
|
361
|
-
#
|
|
362
|
-
def text_field_tag(name, options={})
|
|
363
|
-
input_tag(:text, options.reverse_merge!(:name => name))
|
|
364
|
-
end
|
|
365
|
-
|
|
366
|
-
##
|
|
367
|
-
# Creates a number field input with the given name and options.
|
|
368
|
-
#
|
|
369
|
-
# @macro [new] number_field
|
|
370
|
-
# @param [Symbol] name
|
|
371
|
-
# The name of the input to create.
|
|
372
|
-
# @param [Hash] options
|
|
373
|
-
# The HTML options to include in this field.
|
|
374
|
-
#
|
|
375
|
-
# @option options [String] :id
|
|
376
|
-
# Specifies a unique identifier for the field.
|
|
377
|
-
# @option options [String] :class
|
|
378
|
-
# Specifies the stylesheet class of the field.
|
|
379
|
-
# @option options [String] :name
|
|
380
|
-
# Specifies the name of the field.
|
|
381
|
-
# @option options [String] :accesskey
|
|
382
|
-
# Specifies a shortcut key to access the field.
|
|
383
|
-
# @option options [Integer] :tabindex
|
|
384
|
-
# Specifies the tab order of the field.
|
|
385
|
-
# @option options [Integer] :min
|
|
386
|
-
# Specifies the minimum value of the field.
|
|
387
|
-
# @option options [Integer] :max
|
|
388
|
-
# Specifies the maximum value of the field.
|
|
389
|
-
# @option options [Integer] :step
|
|
390
|
-
# Specifies the legal number intervals of the field.
|
|
391
|
-
# @option options [Boolean] :hidden
|
|
392
|
-
# Specifies whether or not the field is hidden from view.
|
|
393
|
-
# @option options [Boolean] :spellcheck
|
|
394
|
-
# Specifies whether or not the field should have it's spelling and grammar checked for errors.
|
|
395
|
-
# @option options [Boolean] :draggable
|
|
396
|
-
# Specifies whether or not the field is draggable. (true, false, :auto).
|
|
397
|
-
# @option options [String] :pattern
|
|
398
|
-
# Specifies the regular expression pattern that the field's value is checked against.
|
|
399
|
-
# @option options [Symbol] :autocomplete
|
|
400
|
-
# Specifies whether or not the field should have autocomplete enabled. (:on, :off).
|
|
401
|
-
# @option options [Boolean] :autofocus
|
|
402
|
-
# Specifies whether or not the field should automatically get focus when the page loads.
|
|
403
|
-
# @option options [Boolean] :required
|
|
404
|
-
# Specifies whether or not the field is required to be completeled before the form is submitted.
|
|
405
|
-
# @option options [Boolean] :readonly
|
|
406
|
-
# Specifies whether or not the field is read only.
|
|
407
|
-
# @option options [Boolean] :disabled
|
|
408
|
-
# Specifies whether or not the field is disabled.
|
|
409
|
-
#
|
|
410
|
-
# @return [String]
|
|
411
|
-
# Generated HTML with specified +options+.
|
|
412
|
-
#
|
|
413
|
-
# @example
|
|
414
|
-
# number_field_tag :quantity, :class => 'numeric'
|
|
415
|
-
# # => <input name="quantity" class="numeric" type="number" />
|
|
416
|
-
#
|
|
417
|
-
# number_field_tag :zip_code, :pattern => /[0-9]{5}/
|
|
418
|
-
# # => <input name="zip_code" pattern="[0-9]{5}" type="number" />
|
|
419
|
-
#
|
|
420
|
-
# number_field_tag :credit_card, :autocomplete => :off
|
|
421
|
-
# # => <input name="credit_card" autocomplete="off" type="number" />
|
|
422
|
-
#
|
|
423
|
-
# number_field_tag :age, :min => 18, :max => 120, :step => 1
|
|
424
|
-
# # => <input name="age" min="18" max="120" step="1" type="number" />
|
|
425
|
-
#
|
|
426
|
-
def number_field_tag(name, options={})
|
|
427
|
-
input_tag(:number, options.reverse_merge(:name => name))
|
|
428
|
-
end
|
|
429
|
-
|
|
430
|
-
##
|
|
431
|
-
# Creates a telephone field input with the given name and options.
|
|
432
|
-
#
|
|
433
|
-
# @macro text_field
|
|
434
|
-
#
|
|
435
|
-
# @example
|
|
436
|
-
# telephone_field_tag :phone_number, :class => 'string'
|
|
437
|
-
# # => <input name="phone_number" class="string" type="tel" />
|
|
438
|
-
#
|
|
439
|
-
# telephone_field_tag :cell_phone, :tabindex => 1
|
|
440
|
-
# telephone_field_tag :work_phone, :tabindex => 2
|
|
441
|
-
# telephone_field_tag :home_phone, :tabindex => 3
|
|
442
|
-
#
|
|
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" />
|
|
446
|
-
#
|
|
447
|
-
def telephone_field_tag(name, options={})
|
|
448
|
-
input_tag(:tel, options.reverse_merge(:name => name))
|
|
449
|
-
end
|
|
450
|
-
alias_method :phone_field_tag, :telephone_field_tag
|
|
451
|
-
|
|
452
|
-
##
|
|
453
|
-
# Creates an email field input with the given name and options.
|
|
454
|
-
#
|
|
455
|
-
# @macro text_field
|
|
456
|
-
#
|
|
457
|
-
# @example
|
|
458
|
-
# email_field_tag :email, :placeholder => 'you@example.com'
|
|
459
|
-
# # => <input name="email" placeholder="you@example.com" type="email" />
|
|
460
|
-
#
|
|
461
|
-
# email_field_tag :email, :value => 'padrinorb@gmail.com', :readonly => true
|
|
462
|
-
# # => <input name="email" value="padrinorb@gmail.com" readonly type="email" />
|
|
463
|
-
#
|
|
464
|
-
def email_field_tag(name, options={})
|
|
465
|
-
input_tag(:email, options.reverse_merge(:name => name))
|
|
466
|
-
end
|
|
467
|
-
|
|
468
|
-
##
|
|
469
|
-
# Creates a search field input with the given name and options.
|
|
470
|
-
#
|
|
471
|
-
# @macro text_field
|
|
472
|
-
#
|
|
473
|
-
# @example
|
|
474
|
-
# search_field_tag :search, :placeholder => 'Search this website...'
|
|
475
|
-
# # => <input name="search" placeholder="Search this website..." type="search" />
|
|
476
|
-
#
|
|
477
|
-
# search_field_tag :search, :maxlength => 15, :class => ['search', 'string']
|
|
478
|
-
# # => <input name="search" maxlength="15" class="search string" />
|
|
479
|
-
#
|
|
480
|
-
# search_field_tag :search, :id => 'search'
|
|
481
|
-
# # => <input name="search" id="search" type="search" />
|
|
482
|
-
#
|
|
483
|
-
# search_field_tag :search, :autofocus => true
|
|
484
|
-
# # => <input name="search" autofocus type="search" />
|
|
485
|
-
#
|
|
486
|
-
def search_field_tag(name, options={})
|
|
487
|
-
input_tag(:search, options.reverse_merge(:name => name))
|
|
488
|
-
end
|
|
489
|
-
|
|
490
|
-
##
|
|
491
|
-
# Creates a URL field input with the given name and options.
|
|
492
|
-
#
|
|
493
|
-
# @macro text_field
|
|
494
|
-
#
|
|
495
|
-
# @example
|
|
496
|
-
# url_field_tag :favorite_website, :placeholder => 'http://padrinorb.com'
|
|
497
|
-
# <input name="favorite_website" placeholder="http://padrinorb.com." type="url" />
|
|
498
|
-
#
|
|
499
|
-
# url_field_tag :home_page, :class => 'string url'
|
|
500
|
-
# <input name="home_page" class="string url", type="url" />
|
|
501
|
-
#
|
|
502
|
-
def url_field_tag(name, options={})
|
|
503
|
-
input_tag(:url, options.reverse_merge(:name => name))
|
|
504
|
-
end
|
|
505
|
-
|
|
506
|
-
##
|
|
507
|
-
# Constructs a hidden field input from the given options.
|
|
508
|
-
#
|
|
509
|
-
# @example
|
|
510
|
-
# hidden_field_tag :session_key, :value => "__secret__"
|
|
511
|
-
#
|
|
512
|
-
def hidden_field_tag(name, options={})
|
|
513
|
-
options.reverse_merge!(:name => name)
|
|
514
|
-
input_tag(:hidden, options)
|
|
515
|
-
end
|
|
516
|
-
|
|
517
|
-
##
|
|
518
|
-
# Constructs a text area input from the given options.
|
|
519
|
-
#
|
|
520
|
-
# @example
|
|
521
|
-
# text_area_tag :username, :class => 'long', :value => "Demo?"
|
|
522
|
-
#
|
|
523
|
-
def text_area_tag(name, options={})
|
|
524
|
-
options.reverse_merge!(:name => name, :rows => "", :cols => "")
|
|
525
|
-
content_tag(:textarea, options.delete(:value).to_s, options)
|
|
526
|
-
end
|
|
527
|
-
|
|
528
|
-
##
|
|
529
|
-
# Constructs a password field input from the given options.
|
|
530
|
-
#
|
|
531
|
-
# @example
|
|
532
|
-
# password_field_tag :password, :class => 'long'
|
|
533
|
-
#
|
|
534
|
-
# @api public
|
|
535
|
-
def password_field_tag(name, options={})
|
|
536
|
-
options.reverse_merge!(:name => name)
|
|
537
|
-
input_tag(:password, options)
|
|
538
|
-
end
|
|
539
|
-
|
|
540
|
-
##
|
|
541
|
-
# Constructs a check_box from the given options.
|
|
542
|
-
#
|
|
543
|
-
# @example
|
|
544
|
-
# check_box_tag :remember_me, :value => 'Yes'
|
|
545
|
-
#
|
|
546
|
-
def check_box_tag(name, options={})
|
|
547
|
-
options.reverse_merge!(:name => name, :value => '1')
|
|
548
|
-
input_tag(:checkbox, options)
|
|
549
|
-
end
|
|
550
|
-
|
|
551
|
-
##
|
|
552
|
-
# Constructs a radio_button from the given options.
|
|
553
|
-
#
|
|
554
|
-
# @example
|
|
555
|
-
# radio_button_tag :remember_me, :value => 'true'
|
|
556
|
-
#
|
|
557
|
-
def radio_button_tag(name, options={})
|
|
558
|
-
options.reverse_merge!(:name => name)
|
|
559
|
-
input_tag(:radio, options)
|
|
560
|
-
end
|
|
561
|
-
|
|
562
|
-
##
|
|
563
|
-
# Constructs a file field input from the given options.
|
|
564
|
-
#
|
|
565
|
-
# @example
|
|
566
|
-
# file_field_tag :photo, :class => 'long'
|
|
567
|
-
#
|
|
568
|
-
# @api public
|
|
569
|
-
def file_field_tag(name, options={})
|
|
570
|
-
name = "#{name}[]" if options[:multiple]
|
|
571
|
-
options.reverse_merge!(:name => name)
|
|
572
|
-
input_tag(:file, options)
|
|
573
|
-
end
|
|
574
|
-
|
|
575
|
-
##
|
|
576
|
-
# Constructs a select from the given options.
|
|
577
|
-
#
|
|
578
|
-
# @example
|
|
579
|
-
# options = [['caption', 'value'], ['Green', 'green1'], ['Blue', 'blue1'], ['Black', "black1"]]
|
|
580
|
-
# options = ['option', 'red', 'yellow' ]
|
|
581
|
-
# select_tag(:favorite_color, :options => ['red', 'yellow'], :selected => 'green1')
|
|
582
|
-
# select_tag(:country, :collection => @countries, :fields => [:name, :code], :include_blank => 'None')
|
|
583
|
-
#
|
|
584
|
-
# # Optgroups can be generated using :grouped_options => (Hash or nested Array)
|
|
585
|
-
# grouped_options = [['Friends',['Yoda',['Obiwan',1]]],['Enemies',['Palpatine',['Darth Vader',3]]]]
|
|
586
|
-
# grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
|
|
587
|
-
# select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])
|
|
588
|
-
#
|
|
589
|
-
# # Optgroups can be generated using :grouped_options => (Hash or nested Array)
|
|
590
|
-
# grouped_options = [['Friends',['Yoda',['Obiwan',1]]],['Enemies',['Palpatine',['Darth Vader',3]]]]
|
|
591
|
-
# grouped_options = {'Friends' => ['Yoda',['Obiwan',1]],'Enemies' => ['Palpatine',['Darth Vader',3]]}
|
|
592
|
-
# select_tag(:color, :grouped_options => [['warm',['red','yellow']],['cool',['blue', 'purple']]])
|
|
593
|
-
#
|
|
594
|
-
# @param [String] name
|
|
595
|
-
# The name of the input field.
|
|
596
|
-
# @param [Hash] options
|
|
597
|
-
# The html options for the input field.
|
|
598
|
-
# @option options [Array<String, Array>] :options
|
|
599
|
-
# Explicit options to display in the select. Can be strings or string tuples.
|
|
600
|
-
# @option options [Array<Array>] :grouped_options
|
|
601
|
-
# List of options for each group in the select. See examples for details.
|
|
602
|
-
# @option options [Array<Object>] :collection
|
|
603
|
-
# Collection of objects used as options in the select.
|
|
604
|
-
# @option options [Array<Symbol>] :fields
|
|
605
|
-
# The attributes used as "label" and "value" for each +collection+ object.
|
|
606
|
-
# @option options [String] :selected (nil)
|
|
607
|
-
# The option value initially selected.
|
|
608
|
-
# @option options [Boolean] :include_blank (false)
|
|
609
|
-
# Include a blank option in the select.
|
|
610
|
-
# @option options [Boolean] :multiple (false)
|
|
611
|
-
# Allow multiple options to be selected at once.
|
|
612
|
-
#
|
|
613
|
-
# @return [String] The HTML input field based on the +options+ specified.
|
|
614
|
-
#
|
|
615
|
-
def select_tag(name, options={})
|
|
616
|
-
options.reverse_merge!(:name => name)
|
|
617
|
-
collection, fields = options.delete(:collection), options.delete(:fields)
|
|
618
|
-
options[:options] = options_from_collection(collection, fields) if collection
|
|
619
|
-
prompt = options.delete(:include_blank)
|
|
620
|
-
select_options_html = if options[:options]
|
|
621
|
-
options_for_select(options.delete(:options), options.delete(:selected))
|
|
622
|
-
elsif options[:grouped_options]
|
|
623
|
-
grouped_options_for_select(options.delete(:grouped_options), options.delete(:selected), prompt)
|
|
624
|
-
end
|
|
625
|
-
select_options_html = select_options_html.unshift(blank_option(prompt)) if select_options_html.is_a?(Array)
|
|
626
|
-
options.merge!(:name => "#{options[:name]}[]") if options[:multiple]
|
|
627
|
-
safe_content_tag(:select, select_options_html, options)
|
|
628
|
-
end
|
|
629
|
-
|
|
630
|
-
##
|
|
631
|
-
# Constructs a button input from the given options.
|
|
632
|
-
#
|
|
633
|
-
# @param [String] caption
|
|
634
|
-
# The caption for the button.
|
|
635
|
-
# @param [Hash] options
|
|
636
|
-
# The html options for the input field.
|
|
637
|
-
#
|
|
638
|
-
# @return [String] The html button based on the +options+ specified.
|
|
639
|
-
#
|
|
640
|
-
# @example
|
|
641
|
-
# button_tag "Cancel", :class => 'clear'
|
|
642
|
-
#
|
|
643
|
-
def button_tag(caption, options = {})
|
|
644
|
-
options.reverse_merge!(:value => caption)
|
|
645
|
-
input_tag(:button, options)
|
|
646
|
-
end
|
|
647
|
-
|
|
648
|
-
##
|
|
649
|
-
# Constructs a submit button from the given options.
|
|
650
|
-
#
|
|
651
|
-
# @param [String] caption (defaults to: +Submit+)
|
|
652
|
-
# The caption for the submit button.
|
|
653
|
-
# @param [Hash] options
|
|
654
|
-
# The html options for the input field.
|
|
655
|
-
#
|
|
656
|
-
# @return [String] The html submit button based on the +options+ specified.
|
|
657
|
-
#
|
|
658
|
-
# @example
|
|
659
|
-
# submit_tag "Create", :class => 'success'
|
|
660
|
-
# submit_tag :class => 'btn'
|
|
661
|
-
#
|
|
662
|
-
def submit_tag(*args)
|
|
663
|
-
options = args[-1].is_a?(Hash) ? args.pop : {}
|
|
664
|
-
caption = args.length >= 1 ? args.shift : "Submit"
|
|
665
|
-
options.reverse_merge!(:value => caption)
|
|
666
|
-
input_tag(:submit, options)
|
|
667
|
-
end
|
|
668
|
-
|
|
669
|
-
##
|
|
670
|
-
# Constructs a submit button from the given options.
|
|
671
|
-
#
|
|
672
|
-
# @param [String] source
|
|
673
|
-
# The source image path for the button.
|
|
674
|
-
# @param [Hash] options
|
|
675
|
-
# The html options for the input field.
|
|
676
|
-
#
|
|
677
|
-
# @return [String] The html image button based on the +options+ specified.
|
|
678
|
-
#
|
|
679
|
-
# @example
|
|
680
|
-
# submit_tag "Create", :class => 'success'
|
|
681
|
-
#
|
|
682
|
-
def image_submit_tag(source, options={})
|
|
683
|
-
options.reverse_merge!(:src => image_path(source))
|
|
684
|
-
input_tag(:image, options)
|
|
685
|
-
end
|
|
686
|
-
|
|
687
|
-
##
|
|
688
|
-
# Constructs a hidden field containing a CSRF token.
|
|
689
|
-
#
|
|
690
|
-
# @param [String] token
|
|
691
|
-
# The token to use. Will be read from the session by default.
|
|
692
|
-
#
|
|
693
|
-
# @return [String] The hidden field with CSRF token as value.
|
|
694
|
-
#
|
|
695
|
-
# @example
|
|
696
|
-
# csrf_token_field
|
|
697
|
-
#
|
|
698
|
-
def csrf_token_field(token = nil)
|
|
699
|
-
hidden_field_tag csrf_param, :value => csrf_token
|
|
700
|
-
end
|
|
701
|
-
|
|
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
|
|
716
|
-
end
|
|
717
|
-
|
|
718
|
-
##
|
|
719
|
-
# Creates a form containing a single button that submits to the URL.
|
|
720
|
-
#
|
|
721
|
-
# @overload button_to(name, url, options={})
|
|
722
|
-
# @param [String] caption The text caption.
|
|
723
|
-
# @param [String] url The url href.
|
|
724
|
-
# @param [Hash] options The html options.
|
|
725
|
-
# @overload button_to(name, options={}, &block)
|
|
726
|
-
# @param [String] url The url href.
|
|
727
|
-
# @param [Hash] options The html options.
|
|
728
|
-
# @param [Proc] block The button content.
|
|
729
|
-
#
|
|
730
|
-
# @option options [Boolean] :multipart
|
|
731
|
-
# If true, this form will support multipart encoding.
|
|
732
|
-
# @option options [String] :remote
|
|
733
|
-
# Instructs ujs handler to handle the submit as ajax.
|
|
734
|
-
# @option options [Symbol] :method
|
|
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)
|
|
738
|
-
#
|
|
739
|
-
# @return [String] Form and button html with specified +options+.
|
|
740
|
-
#
|
|
741
|
-
# @example
|
|
742
|
-
# button_to 'Delete', url(:accounts_destroy, :id => account), :method => :delete, :class => :form
|
|
743
|
-
# # Generates:
|
|
744
|
-
# # <form class="form" action="/admin/accounts/destroy/2" method="post">
|
|
745
|
-
# # <input type="hidden" value="delete" name="_method" />
|
|
746
|
-
# # <input type="submit" value="Delete" />
|
|
747
|
-
# # </form>
|
|
748
|
-
#
|
|
749
|
-
def button_to(*args, &block)
|
|
750
|
-
name, url = args[0], args[1]
|
|
751
|
-
options = args.extract_options!
|
|
752
|
-
options['data-remote'] = 'true' if options.delete(:remote)
|
|
753
|
-
submit_options = options.delete(:submit_options) || {}
|
|
754
|
-
if block_given?
|
|
755
|
-
form_tag(url, options, &block)
|
|
756
|
-
else
|
|
757
|
-
form_tag(url, options.merge!(:not_concat => true)) do
|
|
758
|
-
submit_tag(name, submit_options)
|
|
759
|
-
end
|
|
760
|
-
end
|
|
761
|
-
end
|
|
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
|
-
|
|
790
|
-
protected
|
|
791
|
-
|
|
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
|
|
801
|
-
|
|
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)
|
|
811
|
-
end
|
|
812
|
-
end
|
|
813
|
-
|
|
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
|
|
837
|
-
end
|
|
838
|
-
end
|
|
839
|
-
end
|
|
840
|
-
|
|
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 => '')
|
|
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
|
|
878
|
-
|
|
879
|
-
private
|
|
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
|
|
893
|
-
|
|
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
|
|
904
|
-
|
|
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)
|
|
915
|
-
end
|
|
916
|
-
end
|
|
917
|
-
end
|
|
918
|
-
end
|
|
919
|
-
end
|