middleman-core 3.0.0.beta.2 → 3.0.0.beta.3
Sign up to get free protection for your applications and to get access to all the features.
- data/features/cli_extension.feature +13 -0
- data/features/{cli.feature → cli_init.feature} +1 -10
- data/features/directory_index.feature +29 -1
- data/features/dynamic_pages.feature +1 -0
- data/features/extensionless_text_files.feature +0 -2
- data/features/front-matter.feature +17 -1
- data/features/frontmatter_page_settings.feature +16 -1
- data/features/helpers_relative_link_to.feature +68 -0
- data/features/unicode_filenames.feature +14 -0
- data/fixtures/csspie/config.rb +0 -0
- data/fixtures/csspie/source/stylesheets/PIE.htc +96 -0
- data/fixtures/dynamic-pages-app/config.rb +3 -0
- data/fixtures/frontmatter-app/source/front-matter-auto.erb +6 -0
- data/fixtures/frontmatter-app/source/front-matter.html.erb +2 -0
- data/fixtures/frontmatter-app/source/json-front-matter-2.php.erb +7 -0
- data/fixtures/frontmatter-app/source/json-front-matter-auto.erb +6 -0
- data/fixtures/frontmatter-app/source/json-front-matter.html.erb +6 -0
- data/fixtures/unicode-filenames-app/config.rb +1 -0
- data/fixtures/unicode-filenames-app/source/snowmen-rule-/342/230/203.html +4 -0
- data/lib/middleman-core/application.rb +43 -335
- data/lib/middleman-core/cli/build.rb +11 -4
- data/lib/middleman-core/cli/bundler.rb +40 -0
- data/lib/middleman-core/cli/extension.rb +36 -0
- data/lib/middleman-core/cli/server.rb +2 -2
- data/lib/middleman-core/cli.rb +2 -6
- data/lib/middleman-core/core_extensions/assets.rb +35 -31
- data/lib/middleman-core/core_extensions/builder.rb +14 -9
- data/lib/middleman-core/core_extensions/data.rb +150 -145
- data/lib/middleman-core/core_extensions/default_helpers.rb +159 -97
- data/lib/middleman-core/core_extensions/extensions.rb +103 -97
- data/lib/middleman-core/core_extensions/external_helpers.rb +27 -23
- data/lib/middleman-core/core_extensions/file_watcher.rb +140 -110
- data/lib/middleman-core/core_extensions/front_matter.rb +155 -175
- data/lib/middleman-core/core_extensions/i18n.rb +111 -102
- data/lib/middleman-core/core_extensions/rendering.rb +293 -295
- data/lib/middleman-core/core_extensions/request.rb +338 -0
- data/lib/middleman-core/core_extensions/routing.rb +72 -68
- data/lib/middleman-core/core_extensions/show_exceptions.rb +23 -18
- data/lib/middleman-core/core_extensions.rb +39 -0
- data/lib/middleman-core/extensions/directory_indexes.rb +1 -4
- data/lib/middleman-core/extensions/lorem.rb +10 -3
- data/lib/middleman-core/extensions.rb +2 -64
- data/lib/middleman-core/preview_server.rb +157 -0
- data/lib/middleman-core/sitemap/extensions/ignores.rb +73 -68
- data/lib/middleman-core/sitemap/extensions/on_disk.rb +65 -58
- data/lib/middleman-core/sitemap/extensions/proxies.rb +86 -75
- data/lib/middleman-core/sitemap/extensions/traversal.rb +68 -61
- data/lib/middleman-core/sitemap/resource.rb +123 -102
- data/lib/middleman-core/sitemap/store.rb +170 -149
- data/lib/middleman-core/sitemap.rb +57 -57
- data/lib/middleman-core/step_definitions/server_steps.rb +13 -3
- data/lib/middleman-core/templates/extension/Gemfile +4 -0
- data/lib/middleman-core/templates/extension/Rakefile +12 -0
- data/lib/middleman-core/templates/extension/features/support/env.rb +4 -0
- data/lib/middleman-core/templates/extension/gemspec +24 -0
- data/lib/middleman-core/templates/extension/lib/lib.rb +49 -0
- data/lib/middleman-core/templates/extension/lib/middleman_extension.rb +1 -0
- data/lib/middleman-core/templates/shared/gitignore +14 -0
- data/lib/middleman-core/templates.rb +14 -8
- data/lib/middleman-core/util.rb +31 -9
- data/lib/middleman-core/version.rb +1 -1
- data/lib/middleman-core.rb +6 -4
- data/middleman-core.gemspec +4 -6
- metadata +62 -203
- data/lib/middleman-core/vendor/padrino-core-0.10.6/.document +0 -5
- data/lib/middleman-core/vendor/padrino-core-0.10.6/.gitignore +0 -22
- data/lib/middleman-core/vendor/padrino-core-0.10.6/.yardopts +0 -1
- data/lib/middleman-core/vendor/padrino-core-0.10.6/LICENSE.txt +0 -20
- data/lib/middleman-core/vendor/padrino-core-0.10.6/README.rdoc +0 -294
- data/lib/middleman-core/vendor/padrino-core-0.10.6/Rakefile +0 -5
- data/lib/middleman-core/vendor/padrino-core-0.10.6/bin/padrino +0 -9
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/rendering.rb +0 -292
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/routing.rb +0 -943
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application/showexceptions.rb +0 -20
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/application.rb +0 -269
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/caller.rb +0 -53
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/adapter.rb +0 -24
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/base.rb +0 -150
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/console.rb +0 -20
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/rake.rb +0 -24
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/cli/rake_tasks.rb +0 -59
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/command.rb +0 -38
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/images/404.png +0 -0
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/images/500.png +0 -0
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/loader.rb +0 -211
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/cs.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/da.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/de.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/en.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/es.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/fr.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/hu.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/it.yml +0 -40
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/ja.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/lv.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/nl.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/no.yml +0 -35
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/pl.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/pt_br.yml +0 -40
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/ru.yml +0 -35
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/tr.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/uk.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/zh_cn.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/locale/zh_tw.yml +0 -34
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/logger.rb +0 -428
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/mounter.rb +0 -224
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/reloader.rb +0 -254
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/router.rb +0 -98
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/server.rb +0 -79
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/support_lite.rb +0 -199
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/tasks.rb +0 -21
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core/version.rb +0 -20
- data/lib/middleman-core/vendor/padrino-core-0.10.6/lib/padrino-core.rb +0 -152
- data/lib/middleman-core/vendor/padrino-core-0.10.6/padrino-core.gemspec +0 -38
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/.components +0 -6
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/.gitignore +0 -7
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/complex.rb +0 -32
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/apps/simple.rb +0 -33
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/a.rb +0 -9
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/b.rb +0 -4
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/c.rb +0 -1
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/e.rb +0 -13
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/f.rb +0 -2
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/circular/g.rb +0 -2
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/fixtures/dependencies/d.rb +0 -4
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/helper.rb +0 -83
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/mini_shoulda.rb +0 -45
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_application.rb +0 -108
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_core.rb +0 -77
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_dependencies.rb +0 -44
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_filters.rb +0 -278
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_locale.rb +0 -21
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_logger.rb +0 -154
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_mounter.rb +0 -177
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_reloader_complex.rb +0 -75
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_reloader_simple.rb +0 -98
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_rendering.rb +0 -461
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_restful_routing.rb +0 -33
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_router.rb +0 -146
- data/lib/middleman-core/vendor/padrino-core-0.10.6/test/test_routing.rb +0 -1680
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.document +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.gitignore +0 -21
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/.yardopts +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/LICENSE.txt +0 -20
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/README.rdoc +0 -239
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/Rakefile +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/asset_tag_helpers.rb +0 -417
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_builder/abstract_form_builder.rb +0 -251
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_builder/standard_form_builder.rb +0 -43
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/form_helpers.rb +0 -787
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/format_helpers.rb +0 -381
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/cs.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/da.yml +0 -91
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/de.yml +0 -81
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/en.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/es.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/fr.yml +0 -80
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/hu.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/it.yml +0 -89
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/ja.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/lv.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/nl.yml +0 -82
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/no.yml +0 -91
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/pl.yml +0 -95
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/pt_br.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/ru.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/tr.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/uk.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/zh_cn.yml +0 -104
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/locale/zh_tw.yml +0 -103
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/number_helpers.rb +0 -288
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/abstract_handler.rb +0 -98
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/erb_handler.rb +0 -79
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/haml_handler.rb +0 -63
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers/slim_handler.rb +0 -81
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/output_helpers.rb +0 -175
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/render_helpers.rb +0 -60
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/tag_helpers.rb +0 -260
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/translation_helpers.rb +0 -38
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers.rb +0 -59
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/padrino-helpers.gemspec +0 -27
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/app.rb +0 -73
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.erb +0 -14
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.haml +0 -12
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/capture_concat.slim +0 -13
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.erb +0 -14
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.haml +0 -12
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_for.slim +0 -12
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.erb +0 -11
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.haml +0 -9
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/content_tag.slim +0 -9
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.erb +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.haml +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/current_engine.slim +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.erb +0 -20
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.haml +0 -15
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/fields_for.slim +0 -15
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.erb +0 -72
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.haml +0 -59
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_for.slim +0 -59
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.erb +0 -86
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.haml +0 -70
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/form_tag.slim +0 -70
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.erb +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.haml +0 -4
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/link_to.slim +0 -4
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.erb +0 -3
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.haml +0 -3
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/mail_to.slim +0 -3
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.erb +0 -3
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.haml +0 -3
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/meta_tag.slim +0 -3
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_erb.erb +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_haml.haml +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/partials/_slim.slim +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.erb +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.haml +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/markup_app/views/simple_partial.slim +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/app.rb +0 -50
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engine.haml +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_erb.erb +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_haml.haml +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/current_engines/_slim.slim +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/erb/test.erb +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/explicit_engine.haml +0 -5
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/haml/test.haml +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/_user.haml +0 -7
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/haml_template.haml +0 -1
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/fixtures/render_app/views/template/some_template.haml +0 -2
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/helper.rb +0 -66
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_asset_tag_helpers.rb +0 -328
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_form_builder.rb +0 -1106
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_form_helpers.rb +0 -770
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_format_helpers.rb +0 -227
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_locale.rb +0 -20
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_number_helpers.rb +0 -139
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_output_helpers.rb +0 -153
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_render_helpers.rb +0 -76
- data/lib/middleman-core/vendor/padrino-helpers-0.10.6/test/test_tag_helpers.rb +0 -106
- data/lib/middleman-core/watcher.rb +0 -196
data/lib/middleman-core/vendor/padrino-helpers-0.10.6/lib/padrino-helpers/asset_tag_helpers.rb
DELETED
@@ -1,417 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
module Helpers
|
3
|
-
###
|
4
|
-
# Helpers related to producing assets (images,stylesheets,js,etc) within templates.
|
5
|
-
#
|
6
|
-
module AssetTagHelpers
|
7
|
-
##
|
8
|
-
# Creates a div to display the flash of given type if it exists
|
9
|
-
#
|
10
|
-
# @param [Symbol] kind
|
11
|
-
# The type of flash to display in the tag.
|
12
|
-
# @param [Hash] options
|
13
|
-
# The html options for this section.
|
14
|
-
#
|
15
|
-
# @return [String] Flash tag html with specified +options+.
|
16
|
-
#
|
17
|
-
# @example
|
18
|
-
# flash_tag(:notice, :id => 'flash-notice')
|
19
|
-
# # Generates: <div class="notice">flash-notice</div>
|
20
|
-
# flash_tag(:error, :success)
|
21
|
-
# # Generates: <div class="error">flash-error</div>
|
22
|
-
# # <div class="success">flash-success</div>
|
23
|
-
#
|
24
|
-
# @api public
|
25
|
-
def flash_tag(*args)
|
26
|
-
options = args.extract_options!
|
27
|
-
args.map do |kind|
|
28
|
-
flash_text = flash[kind]
|
29
|
-
next if flash_text.blank?
|
30
|
-
content_tag(:div, flash_text, options.reverse_merge(:class => kind))
|
31
|
-
end.compact * "\n"
|
32
|
-
end
|
33
|
-
|
34
|
-
##
|
35
|
-
# Creates a link element with given name, url and options
|
36
|
-
#
|
37
|
-
# @overload link_to(caption, url, options={})
|
38
|
-
# @param [String] caption The text caption.
|
39
|
-
# @param [String] url The url href.
|
40
|
-
# @param [Hash] options The html options.
|
41
|
-
# @overload link_to(url, options={}, &block)
|
42
|
-
# @param [String] url The url href.
|
43
|
-
# @param [Hash] options The html options.
|
44
|
-
# @param [Proc] block The link content.
|
45
|
-
#
|
46
|
-
# @option options [String] :anchor
|
47
|
-
# The anchor for the link (i.e #something)
|
48
|
-
# @option options [Boolean] :if
|
49
|
-
# If true, the link will appear, otherwise not;
|
50
|
-
# @option options [Boolean] :unless
|
51
|
-
# If false, the link will appear, otherwise not;
|
52
|
-
# @option options [Boolean] :remote
|
53
|
-
# If true, this link should be handled by a ajax ujs handler.
|
54
|
-
# @option options [String] :confirm
|
55
|
-
# Instructs ujs handler to alert confirm message.
|
56
|
-
# @option options [Symbol] :method
|
57
|
-
# Instructs ujs handler to use different http method (i.e :post, :delete).
|
58
|
-
#
|
59
|
-
# @return [String] Link tag html with specified +options+.
|
60
|
-
#
|
61
|
-
# @example
|
62
|
-
# link_to('click me', '/dashboard', :class => 'linky')
|
63
|
-
# link_to('click me', '/dashboard', :remote => true)
|
64
|
-
# link_to('click me', '/dashboard', :method => :delete)
|
65
|
-
# link_to('click me', :class => 'blocky') do; end
|
66
|
-
#
|
67
|
-
# Note that you can pass :+if+ or :+unless+ conditions, but if you provide :current as
|
68
|
-
# condition padrino return true/false if the request.path_info match the given url
|
69
|
-
#
|
70
|
-
# @api public
|
71
|
-
def link_to(*args, &block)
|
72
|
-
options = args.extract_options!
|
73
|
-
anchor = "##{CGI.escape options.delete(:anchor).to_s}" if options[:anchor]
|
74
|
-
|
75
|
-
if block_given?
|
76
|
-
url = args[0] ? args[0] + anchor.to_s : anchor || '#'
|
77
|
-
options.reverse_merge!(:href => url)
|
78
|
-
link_content = capture_html(&block)
|
79
|
-
return '' unless parse_conditions(url, options)
|
80
|
-
result_link = content_tag(:a, link_content, options)
|
81
|
-
block_is_template?(block) ? concat_content(result_link) : result_link
|
82
|
-
else
|
83
|
-
name, url = args[0], (args[1] ? args[1] + anchor.to_s : anchor || '#')
|
84
|
-
return name unless parse_conditions(url, options)
|
85
|
-
options.reverse_merge!(:href => url)
|
86
|
-
content_tag(:a, name, options)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
##
|
91
|
-
# Creates a form containing a single button that submits to the url.
|
92
|
-
#
|
93
|
-
# @overload button_to(name, url, options={})
|
94
|
-
# @param [String] caption The text caption.
|
95
|
-
# @param [String] url The url href.
|
96
|
-
# @param [Hash] options The html options.
|
97
|
-
# @overload button_to(name, options={}, &block)
|
98
|
-
# @param [String] url The url href.
|
99
|
-
# @param [Hash] options The html options.
|
100
|
-
# @param [Proc] block The button content.
|
101
|
-
#
|
102
|
-
# @option options [Boolean] :multipart
|
103
|
-
# If true, this form will support multipart encoding.
|
104
|
-
# @option options [String] :remote
|
105
|
-
# Instructs ujs handler to handle the submit as ajax.
|
106
|
-
# @option options [Symbol] :method
|
107
|
-
# Instructs ujs handler to use different http method (i.e :post, :delete).
|
108
|
-
#
|
109
|
-
# @return [String] Form and button html with specified +options+.
|
110
|
-
#
|
111
|
-
# @example
|
112
|
-
# button_to 'Delete', url(:accounts_destroy, :id => account), :method => :delete, :class => :form
|
113
|
-
# # Generates:
|
114
|
-
# # <form class="form" action="/admin/accounts/destroy/2" method="post">
|
115
|
-
# # <input type="hidden" value="delete" name="_method" />
|
116
|
-
# # <input type="submit" value="Delete" />
|
117
|
-
# # </form>
|
118
|
-
#
|
119
|
-
# @api public
|
120
|
-
def button_to(*args, &block)
|
121
|
-
name, url = args[0], args[1]
|
122
|
-
options = args.extract_options!
|
123
|
-
desired_method = options[:method]
|
124
|
-
options.delete(:method) if options[:method].to_s !~ /get|post/i
|
125
|
-
options.reverse_merge!(:method => 'post', :action => url)
|
126
|
-
options[:enctype] = 'multipart/form-data' if options.delete(:multipart)
|
127
|
-
options['data-remote'] = 'true' if options.delete(:remote)
|
128
|
-
inner_form_html = hidden_form_method_field(desired_method)
|
129
|
-
inner_form_html += block_given? ? capture_html(&block) : submit_tag(name)
|
130
|
-
content_tag('form', inner_form_html, options)
|
131
|
-
end
|
132
|
-
|
133
|
-
##
|
134
|
-
# Creates a link tag that browsers and news readers can use to auto-detect an RSS or ATOM feed.
|
135
|
-
#
|
136
|
-
# @param [Symbol] mime
|
137
|
-
# The mime type of the feed (i.e :atom or :rss).
|
138
|
-
# @param [String] url
|
139
|
-
# The url for the feed tag to reference.
|
140
|
-
# @param[Hash] options
|
141
|
-
# The options for the feed tag.
|
142
|
-
# @option options [String] :rel ("alternate")
|
143
|
-
# Specify the relation of this link
|
144
|
-
# @option options [String] :type
|
145
|
-
# Override the auto-generated mime type
|
146
|
-
# @option options [String] :title
|
147
|
-
# Specify the title of the link, defaults to the type
|
148
|
-
#
|
149
|
-
# @return [String] Feed link html tag with specified +options+.
|
150
|
-
#
|
151
|
-
# @example
|
152
|
-
# feed_tag :atom, url(:blog, :posts, :format => :atom), :title => "ATOM"
|
153
|
-
# # Generates: <link type="application/atom+xml" rel="alternate" href="/blog/posts.atom" title="ATOM" />
|
154
|
-
# feed_tag :rss, url(:blog, :posts, :format => :rss)
|
155
|
-
# # Generates: <link type="application/rss+xml" rel="alternate" href="/blog/posts.rss" title="rss" />
|
156
|
-
#
|
157
|
-
# @api public
|
158
|
-
def feed_tag(mime, url, options={})
|
159
|
-
full_mime = (mime == :atom) ? 'application/atom+xml' : 'application/rss+xml'
|
160
|
-
tag(:link, options.reverse_merge(:rel => 'alternate', :type => full_mime, :title => mime, :href => url))
|
161
|
-
end
|
162
|
-
|
163
|
-
##
|
164
|
-
# Creates a mail link element with given name and caption.
|
165
|
-
#
|
166
|
-
# @param [String] email
|
167
|
-
# The email address for the link.
|
168
|
-
# @param [String] caption
|
169
|
-
# The caption for the link.
|
170
|
-
# @param [Hash] mail_options
|
171
|
-
# The options for the mail link. Accepts html options.
|
172
|
-
# @option mail_options [String] cc The cc recipients.
|
173
|
-
# @option mail_options [String] bcc The bcc recipients.
|
174
|
-
# @option mail_options [String] subject The subject line.
|
175
|
-
# @option mail_options [String] body The email body.
|
176
|
-
#
|
177
|
-
# @return [String] Mail link html tag with specified +options+.
|
178
|
-
#
|
179
|
-
# @example
|
180
|
-
# # Generates: <a href="mailto:me@demo.com">me@demo.com</a>
|
181
|
-
# mail_to "me@demo.com"
|
182
|
-
# # Generates: <a href="mailto:me@demo.com">My Email</a>
|
183
|
-
# mail_to "me@demo.com", "My Email"
|
184
|
-
#
|
185
|
-
# @api public
|
186
|
-
def mail_to(email, caption=nil, mail_options={})
|
187
|
-
html_options = mail_options.slice!(:cc, :bcc, :subject, :body)
|
188
|
-
mail_query = Rack::Utils.build_query(mail_options).gsub(/\+/, '%20').gsub('%40', '@')
|
189
|
-
mail_href = "mailto:#{email}"; mail_href << "?#{mail_query}" if mail_query.present?
|
190
|
-
link_to((caption || email), mail_href, html_options)
|
191
|
-
end
|
192
|
-
|
193
|
-
##
|
194
|
-
# Creates a meta element with the content and given options.
|
195
|
-
#
|
196
|
-
# @param [String] content
|
197
|
-
# The content for the meta tag.
|
198
|
-
# @param [Hash] options
|
199
|
-
# The html options for the meta tag.
|
200
|
-
#
|
201
|
-
# @return [String] Meta html tag with specified +options+.
|
202
|
-
#
|
203
|
-
# @example
|
204
|
-
# # Generates: <meta name="keywords" content="weblog,news">
|
205
|
-
# meta_tag "weblog,news", :name => "keywords"
|
206
|
-
#
|
207
|
-
# # Generates: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
208
|
-
# meta_tag "text/html; charset=UTF-8", 'http-equiv' => "Content-Type"
|
209
|
-
#
|
210
|
-
# @api public
|
211
|
-
def meta_tag(content, options={})
|
212
|
-
options.reverse_merge!("content" => content)
|
213
|
-
tag(:meta, options)
|
214
|
-
end
|
215
|
-
|
216
|
-
##
|
217
|
-
# Generates a favicon link. looks inside images folder
|
218
|
-
#
|
219
|
-
# @param [String] source
|
220
|
-
# The source image path for the favicon link tag.
|
221
|
-
# @param [Hash] options
|
222
|
-
# The html options for the favicon link tag.
|
223
|
-
#
|
224
|
-
# @return [String] The favicon link html tag with specified +options+.
|
225
|
-
#
|
226
|
-
# @example
|
227
|
-
# favicon_tag 'favicon.png'
|
228
|
-
# favicon_tag 'icons/favicon.png'
|
229
|
-
# # or override some options
|
230
|
-
# favicon_tag 'favicon.png', :type => 'image/ico'
|
231
|
-
#
|
232
|
-
# @api public
|
233
|
-
def favicon_tag(source, options={})
|
234
|
-
type = File.extname(source).gsub('.','')
|
235
|
-
options = options.dup.reverse_merge!(:href => image_path(source), :rel => 'icon', :type => "image/#{type}")
|
236
|
-
tag(:link, options)
|
237
|
-
end
|
238
|
-
|
239
|
-
##
|
240
|
-
# Creates an image element with given url and options
|
241
|
-
#
|
242
|
-
# @param [String] url
|
243
|
-
# The source path for the image tag.
|
244
|
-
# @param [Hash] options
|
245
|
-
# The html options for the image tag.
|
246
|
-
#
|
247
|
-
# @return [String] Image html tag with +url+ and specified +options+.
|
248
|
-
#
|
249
|
-
# @example
|
250
|
-
# image_tag('icons/avatar.png')
|
251
|
-
#
|
252
|
-
# @api public
|
253
|
-
def image_tag(url, options={})
|
254
|
-
options.reverse_merge!(:src => image_path(url))
|
255
|
-
tag(:img, options)
|
256
|
-
end
|
257
|
-
|
258
|
-
##
|
259
|
-
# Returns an html script tag for each of the sources provided.
|
260
|
-
# You can pass in the filename without extension or a symbol and we search it in your +appname.public_folder+
|
261
|
-
# like app/public/stylesheets for inclusion. You can provide also a full path.
|
262
|
-
#
|
263
|
-
# @overload stylesheet_link_tag(*sources, options={})
|
264
|
-
# @param [Array<String>] sources Splat of css source paths
|
265
|
-
# @param [Hash] options The html options for the link tag
|
266
|
-
#
|
267
|
-
# @return [String] Stylesheet link html tag for +sources+ with specified +options+.
|
268
|
-
#
|
269
|
-
# @example
|
270
|
-
# stylesheet_link_tag 'style', 'application', 'layout'
|
271
|
-
#
|
272
|
-
# @api public
|
273
|
-
def stylesheet_link_tag(*sources)
|
274
|
-
options = sources.extract_options!.symbolize_keys
|
275
|
-
options.reverse_merge!(:media => 'screen', :rel => 'stylesheet', :type => 'text/css')
|
276
|
-
sources.flatten.map { |source|
|
277
|
-
tag(:link, options.reverse_merge(:href => asset_path(:css, source)))
|
278
|
-
}.join("\n")
|
279
|
-
end
|
280
|
-
|
281
|
-
##
|
282
|
-
# Returns an html script tag for each of the sources provided.
|
283
|
-
# You can pass in the filename without extension or a symbol and we search it in your +appname.public_folder+
|
284
|
-
# like app/public/javascript for inclusion. You can provide also a full path.
|
285
|
-
#
|
286
|
-
# @overload javascript_include_tag(*sources, options={})
|
287
|
-
# @param [Array<String>] sources Splat of js source paths
|
288
|
-
# @param [Hash] options The html options for the script tag
|
289
|
-
#
|
290
|
-
# @return [String] Script tag for +sources+ with specified +options+.
|
291
|
-
#
|
292
|
-
# @example
|
293
|
-
# javascript_include_tag 'application', :extjs
|
294
|
-
#
|
295
|
-
# @api public
|
296
|
-
def javascript_include_tag(*sources)
|
297
|
-
options = sources.extract_options!.symbolize_keys
|
298
|
-
options.reverse_merge!(:type => 'text/javascript')
|
299
|
-
sources.flatten.map { |source|
|
300
|
-
content_tag(:script, nil, options.reverse_merge(:src => asset_path(:js, source)))
|
301
|
-
}.join("\n")
|
302
|
-
end
|
303
|
-
|
304
|
-
##
|
305
|
-
# Returns the path to the image, either relative or absolute. We search it in your +appname.public_folder+
|
306
|
-
# like app/public/images for inclusion. You can provide also a full path.
|
307
|
-
#
|
308
|
-
# @param [String] src
|
309
|
-
# The path to the image file (relative or absolute)
|
310
|
-
#
|
311
|
-
# @return [String] Path to an image given the +kind+ and +source+.
|
312
|
-
#
|
313
|
-
# @example
|
314
|
-
# # Generates: /images/foo.jpg?1269008689
|
315
|
-
# image_path("foo.jpg")
|
316
|
-
#
|
317
|
-
# @api public
|
318
|
-
def image_path(src)
|
319
|
-
asset_path(:images, src)
|
320
|
-
end
|
321
|
-
|
322
|
-
##
|
323
|
-
# Returns the path to the specified asset (css or javascript)
|
324
|
-
#
|
325
|
-
# @param [String] kind
|
326
|
-
# The kind of asset (i.e :images, :js, :css)
|
327
|
-
# @param [String] source
|
328
|
-
# The path to the asset (relative or absolute).
|
329
|
-
#
|
330
|
-
# @return [String] Path for the asset given the +kind+ and +source+.
|
331
|
-
#
|
332
|
-
# @example
|
333
|
-
# # Generates: /javascripts/application.js?1269008689
|
334
|
-
# asset_path :js, :application
|
335
|
-
#
|
336
|
-
# # Generates: /stylesheets/application.css?1269008689
|
337
|
-
# asset_path :css, :application
|
338
|
-
#
|
339
|
-
# # Generates: /images/example.jpg?1269008689
|
340
|
-
# asset_path :images, 'example.jpg'
|
341
|
-
#
|
342
|
-
# @api semipublic
|
343
|
-
def asset_path(kind, source)
|
344
|
-
return source if source =~ /^http/
|
345
|
-
is_absolute = source =~ %r{^/}
|
346
|
-
asset_folder = asset_folder_name(kind)
|
347
|
-
source = source.to_s.gsub(/\s/, '%20')
|
348
|
-
ignore_extension = (asset_folder.to_s == kind.to_s) # don't append an extension
|
349
|
-
source << ".#{kind}" unless ignore_extension or source =~ /\.#{kind}/
|
350
|
-
result_path = is_absolute ? source : uri_root_path(asset_folder, source)
|
351
|
-
timestamp = asset_timestamp(result_path, is_absolute)
|
352
|
-
"#{result_path}#{timestamp}"
|
353
|
-
end
|
354
|
-
|
355
|
-
private
|
356
|
-
##
|
357
|
-
# Returns the uri root of the application with optional paths appended.
|
358
|
-
#
|
359
|
-
# @example
|
360
|
-
# uri_root_path("/some/path") => "/root/some/path"
|
361
|
-
# uri_root_path("javascripts", "test.js") => "/uri/root/javascripts/test.js"
|
362
|
-
#
|
363
|
-
def uri_root_path(*paths)
|
364
|
-
root_uri = self.class.uri_root if self.class.respond_to?(:uri_root)
|
365
|
-
File.join(ENV['RACK_BASE_URI'].to_s, root_uri || '/', *paths)
|
366
|
-
end
|
367
|
-
|
368
|
-
##
|
369
|
-
# Returns the timestamp mtime for an asset
|
370
|
-
#
|
371
|
-
# @example
|
372
|
-
# asset_timestamp("some/path/to/file.png") => "?154543678"
|
373
|
-
# asset_timestamp("/some/absolute/path.png", true) => nil
|
374
|
-
#
|
375
|
-
def asset_timestamp(file_path, absolute=false)
|
376
|
-
return nil if file_path =~ /\?/ || (self.class.respond_to?(:asset_stamp) && !self.class.asset_stamp)
|
377
|
-
public_file_path = Padrino.root("public", file_path) if Padrino.respond_to?(:root)
|
378
|
-
stamp = File.mtime(public_file_path).to_i if public_file_path && File.exist?(public_file_path)
|
379
|
-
stamp ||= Time.now.to_i unless absolute
|
380
|
-
"?#{stamp}" if stamp
|
381
|
-
end
|
382
|
-
|
383
|
-
###
|
384
|
-
# Returns the asset folder given a kind.
|
385
|
-
#
|
386
|
-
# @example
|
387
|
-
# asset_folder_name(:css) => 'stylesheets'
|
388
|
-
# asset_folder_name(:js) => 'javascripts'
|
389
|
-
# asset_folder_name(:images) => 'images'
|
390
|
-
#
|
391
|
-
def asset_folder_name(kind)
|
392
|
-
case kind
|
393
|
-
when :css then 'stylesheets'
|
394
|
-
when :js then 'javascripts'
|
395
|
-
else kind.to_s
|
396
|
-
end
|
397
|
-
end
|
398
|
-
|
399
|
-
##
|
400
|
-
# Parses link_to options for given correct conditions
|
401
|
-
#
|
402
|
-
# @example
|
403
|
-
# parse_conditions("/some/url", :if => false) => true
|
404
|
-
#
|
405
|
-
def parse_conditions(url, options)
|
406
|
-
if options.has_key?(:if)
|
407
|
-
condition = options.delete(:if)
|
408
|
-
condition == :current ? url == request.path_info : condition
|
409
|
-
elsif condition = options.delete(:unless)
|
410
|
-
condition == :current ? url != request.path_info : !condition
|
411
|
-
else
|
412
|
-
true
|
413
|
-
end
|
414
|
-
end
|
415
|
-
end # AssetTagHelpers
|
416
|
-
end # Helpers
|
417
|
-
end # Padrino
|
@@ -1,251 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
module Helpers
|
3
|
-
module FormBuilder # @private
|
4
|
-
class AbstractFormBuilder # @private
|
5
|
-
attr_accessor :template, :object
|
6
|
-
|
7
|
-
def initialize(template, object, options={})
|
8
|
-
@template = template
|
9
|
-
@object = build_object(object)
|
10
|
-
@options = options
|
11
|
-
raise "FormBuilder template must be initialized!" unless template
|
12
|
-
raise "FormBuilder object must not be a nil value. If there's no object, use a symbol instead! (i.e :user)" unless object
|
13
|
-
end
|
14
|
-
|
15
|
-
# f.error_messages
|
16
|
-
def error_messages(*params)
|
17
|
-
params.unshift object
|
18
|
-
@template.error_messages_for(*params)
|
19
|
-
end
|
20
|
-
|
21
|
-
# f.error_message_on(field)
|
22
|
-
def error_message_on(field, options={})
|
23
|
-
@template.error_message_on(object, field, options)
|
24
|
-
end
|
25
|
-
|
26
|
-
# f.label :username, :caption => "Nickname"
|
27
|
-
def label(field, options={})
|
28
|
-
options.reverse_merge!(:caption => "#{field_human_name(field)}: ")
|
29
|
-
@template.label_tag(field_id(field), options)
|
30
|
-
end
|
31
|
-
|
32
|
-
# f.hidden_field :session_id, :value => "45"
|
33
|
-
def hidden_field(field, options={})
|
34
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
35
|
-
@template.hidden_field_tag field_name(field), options
|
36
|
-
end
|
37
|
-
|
38
|
-
# f.text_field :username, :value => "(blank)", :id => 'username'
|
39
|
-
def text_field(field, options={})
|
40
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
41
|
-
options.merge!(:class => field_error(field, options))
|
42
|
-
@template.text_field_tag field_name(field), options
|
43
|
-
end
|
44
|
-
|
45
|
-
def number_field(field, options={})
|
46
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
47
|
-
options.merge!(:class => field_error(field, options))
|
48
|
-
@template.number_field_tag field_name(field), options
|
49
|
-
end
|
50
|
-
|
51
|
-
def telephone_field(field, options={})
|
52
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
53
|
-
options.merge!(:class => field_error(field, options))
|
54
|
-
@template.telephone_field_tag field_name(field), options
|
55
|
-
end
|
56
|
-
alias_method :phone_field, :telephone_field
|
57
|
-
|
58
|
-
def email_field(field, options={})
|
59
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
60
|
-
options.merge!(:class => field_error(field, options))
|
61
|
-
@template.email_field_tag field_name(field), options
|
62
|
-
end
|
63
|
-
|
64
|
-
def search_field(field, options={})
|
65
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
66
|
-
options.merge!(:class => field_error(field, options))
|
67
|
-
@template.search_field_tag field_name(field), options
|
68
|
-
end
|
69
|
-
|
70
|
-
def url_field(field, options={})
|
71
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
72
|
-
options.merge!(:class => field_error(field, options))
|
73
|
-
@template.url_field_tag field_name(field), options
|
74
|
-
end
|
75
|
-
|
76
|
-
# f.text_area :summary, :value => "(enter summary)", :id => 'summary'
|
77
|
-
def text_area(field, options={})
|
78
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
79
|
-
options.merge!(:class => field_error(field, options))
|
80
|
-
@template.text_area_tag field_name(field), options
|
81
|
-
end
|
82
|
-
|
83
|
-
# f.password_field :password, :id => 'password'
|
84
|
-
def password_field(field, options={})
|
85
|
-
options.reverse_merge!(:value => field_value(field), :id => field_id(field))
|
86
|
-
options.merge!(:class => field_error(field, options))
|
87
|
-
@template.password_field_tag field_name(field), options
|
88
|
-
end
|
89
|
-
|
90
|
-
# f.select :color, :options => ['red', 'green'], :include_blank => true
|
91
|
-
# f.select :color, :collection => @colors, :fields => [:name, :id]
|
92
|
-
def select(field, options={})
|
93
|
-
options.reverse_merge!(:id => field_id(field), :selected => field_value(field))
|
94
|
-
options.merge!(:class => field_error(field, options))
|
95
|
-
@template.select_tag field_name(field), options
|
96
|
-
end
|
97
|
-
|
98
|
-
# f.check_box :remember_me, :value => 'true', :uncheck_value => '0'
|
99
|
-
def check_box(field, options={})
|
100
|
-
unchecked_value = options.delete(:uncheck_value) || '0'
|
101
|
-
options.reverse_merge!(:id => field_id(field), :value => '1')
|
102
|
-
options.reverse_merge!(:checked => true) if values_matches_field?(field, options[:value])
|
103
|
-
html = @template.hidden_field_tag(options[:name] || field_name(field), :value => unchecked_value, :id => nil)
|
104
|
-
html << @template.check_box_tag(field_name(field), options)
|
105
|
-
end
|
106
|
-
|
107
|
-
# f.radio_button :gender, :value => 'male'
|
108
|
-
def radio_button(field, options={})
|
109
|
-
options.reverse_merge!(:id => field_id(field, options[:value]))
|
110
|
-
options.reverse_merge!(:checked => true) if values_matches_field?(field, options[:value])
|
111
|
-
@template.radio_button_tag field_name(field), options
|
112
|
-
end
|
113
|
-
|
114
|
-
# f.file_field :photo, :class => 'avatar'
|
115
|
-
def file_field(field, options={})
|
116
|
-
options.reverse_merge!(:id => field_id(field))
|
117
|
-
options.merge!(:class => field_error(field, options))
|
118
|
-
@template.file_field_tag field_name(field), options
|
119
|
-
end
|
120
|
-
|
121
|
-
# f.submit "Update", :class => 'large'
|
122
|
-
def submit(caption="Submit", options={})
|
123
|
-
@template.submit_tag caption, options
|
124
|
-
end
|
125
|
-
|
126
|
-
# f.image_submit "buttons/submit.png", :class => 'large'
|
127
|
-
def image_submit(source, options={})
|
128
|
-
@template.image_submit_tag source, options
|
129
|
-
end
|
130
|
-
|
131
|
-
# Supports nested fields for a child model within a form
|
132
|
-
# f.fields_for :addresses
|
133
|
-
# f.fields_for :addresses, address
|
134
|
-
# f.fields_for :addresses, @addresses
|
135
|
-
def fields_for(child_association, instance_or_collection=nil, &block)
|
136
|
-
default_collection = self.object.send(child_association)
|
137
|
-
include_index = default_collection.respond_to?(:each)
|
138
|
-
nested_options = { :parent => self, :association => child_association }
|
139
|
-
nested_objects = instance_or_collection ? Array(instance_or_collection) : Array(default_collection)
|
140
|
-
result = nested_objects.each_with_index.map do |child_instance, index|
|
141
|
-
nested_options[:index] = include_index ? index : nil
|
142
|
-
@template.fields_for(child_instance, { :nested => nested_options }, &block)
|
143
|
-
end.join("\n")
|
144
|
-
end
|
145
|
-
|
146
|
-
protected
|
147
|
-
# Returns the known field types for a formbuilder
|
148
|
-
def self.field_types
|
149
|
-
[:hidden_field, :text_field, :text_area, :password_field, :file_field, :radio_button, :check_box, :select]
|
150
|
-
end
|
151
|
-
|
152
|
-
# Returns true if the value matches the value in the field
|
153
|
-
# field_has_value?(:gender, 'male')
|
154
|
-
def values_matches_field?(field, value)
|
155
|
-
value.present? && (field_value(field).to_s == value.to_s || field_value(field).to_s == 'true')
|
156
|
-
end
|
157
|
-
|
158
|
-
# Add a :invalid css class to the field if it contain an error
|
159
|
-
def field_error(field, options)
|
160
|
-
error = @object.errors[field] rescue nil
|
161
|
-
error.blank? ? options[:class] : [options[:class], :invalid].flatten.compact.join(" ")
|
162
|
-
end
|
163
|
-
|
164
|
-
# Returns the human name of the field. Look that use builtin I18n.
|
165
|
-
def field_human_name(field)
|
166
|
-
I18n.translate("#{object_model_name}.attributes.#{field}", :count => 1, :default => field.to_s.humanize, :scope => :models)
|
167
|
-
end
|
168
|
-
|
169
|
-
# Returns the name for the given field
|
170
|
-
# field_name(:username) => "user[username]"
|
171
|
-
# field_name(:number) => "user[telephone_attributes][number]"
|
172
|
-
# field_name(:street) => "user[addresses_attributes][0][street]"
|
173
|
-
def field_name(field=nil)
|
174
|
-
result = []
|
175
|
-
if root_form?
|
176
|
-
result << object_model_name
|
177
|
-
elsif nested_form?
|
178
|
-
parent_form = @options[:nested][:parent]
|
179
|
-
attributes_name = "#{@options[:nested][:association]}_attributes"
|
180
|
-
nested_index = @options[:nested][:index]
|
181
|
-
fragment = [parent_form.field_name, "[#{attributes_name}", "]"]
|
182
|
-
fragment.insert(2, "][#{nested_index}") if nested_index
|
183
|
-
result << fragment
|
184
|
-
end
|
185
|
-
result << "[#{field}]" unless field.blank?
|
186
|
-
result.flatten.join
|
187
|
-
end
|
188
|
-
|
189
|
-
# Returns the id for the given field
|
190
|
-
# field_id(:username) => "user_username"
|
191
|
-
# field_id(:gender, :male) => "user_gender_male"
|
192
|
-
# field_name(:number) => "user_telephone_attributes_number"
|
193
|
-
# field_name(:street) => "user_addresses_attributes_0_street"
|
194
|
-
def field_id(field=nil, value=nil)
|
195
|
-
result = []
|
196
|
-
if root_form?
|
197
|
-
result << object_model_name
|
198
|
-
elsif nested_form?
|
199
|
-
parent_form = @options[:nested][:parent]
|
200
|
-
attributes_name = "#{@options[:nested][:association]}_attributes"
|
201
|
-
nested_index = @options[:nested][:index]
|
202
|
-
fragment = [parent_form.field_id, "_#{attributes_name}"]
|
203
|
-
fragment.push("_#{nested_index}") if nested_index
|
204
|
-
result << fragment
|
205
|
-
end
|
206
|
-
result << "_#{field}" unless field.blank?
|
207
|
-
result << "_#{value}" unless value.blank?
|
208
|
-
result.flatten.join
|
209
|
-
end
|
210
|
-
|
211
|
-
# Returns the child object if it exists
|
212
|
-
def nested_object_id
|
213
|
-
nested_form? && object.respond_to?(:new_record?) && !object.new_record? && object.id
|
214
|
-
end
|
215
|
-
|
216
|
-
# Returns true if this form object is nested in a parent form
|
217
|
-
def nested_form?
|
218
|
-
@options[:nested] && @options[:nested][:parent] && @options[:nested][:parent].respond_to?(:object)
|
219
|
-
end
|
220
|
-
|
221
|
-
# Returns the value for the object's field
|
222
|
-
# field_value(:username) => "Joey"
|
223
|
-
def field_value(field)
|
224
|
-
@object && @object.respond_to?(field) ? @object.send(field) : ""
|
225
|
-
end
|
226
|
-
|
227
|
-
# explicit_object is either a symbol or a record
|
228
|
-
# Returns a new record of the type specified in the object
|
229
|
-
def build_object(object_or_symbol)
|
230
|
-
object_or_symbol.is_a?(Symbol) ? @template.instance_variable_get("@#{object_or_symbol}") || object_class(object_or_symbol).new : object_or_symbol
|
231
|
-
end
|
232
|
-
|
233
|
-
# Returns the object's models name
|
234
|
-
# => user_assignment
|
235
|
-
def object_model_name(explicit_object=object)
|
236
|
-
explicit_object.is_a?(Symbol) ? explicit_object : explicit_object.class.to_s.underscore.gsub(/\//, '_')
|
237
|
-
end
|
238
|
-
|
239
|
-
# Returns the class type for the given object
|
240
|
-
def object_class(explicit_object)
|
241
|
-
explicit_object.is_a?(Symbol) ? explicit_object.to_s.camelize.constantize : explicit_object.class
|
242
|
-
end
|
243
|
-
|
244
|
-
# Returns true if this form is the top-level (not nested)
|
245
|
-
def root_form?
|
246
|
-
!nested_form?
|
247
|
-
end
|
248
|
-
end # AbstractFormBuilder
|
249
|
-
end # FormBuilder
|
250
|
-
end # Helpers
|
251
|
-
end # Padrino
|