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
@@ -1,224 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
##
|
3
|
-
# Represents a particular mounted padrino application
|
4
|
-
# Stores the name of the application (app folder name) and url mount path
|
5
|
-
#
|
6
|
-
# @example
|
7
|
-
# Mounter.new("blog_app", :app_class => "Blog").to("/blog")
|
8
|
-
# Mounter.new("blog_app", :app_file => "/path/to/blog/app.rb").to("/blog")
|
9
|
-
#
|
10
|
-
class Mounter
|
11
|
-
class MounterException < RuntimeError # @private
|
12
|
-
end
|
13
|
-
|
14
|
-
attr_accessor :name, :uri_root, :app_file, :app_class, :app_root, :app_obj, :app_host
|
15
|
-
|
16
|
-
##
|
17
|
-
# @param [String, Padrino::Application] name
|
18
|
-
# The app name or the {Padrino::Application} class
|
19
|
-
#
|
20
|
-
# @param [Hash] options
|
21
|
-
# @option options [Symbol] :app_class (Detected from name)
|
22
|
-
# @option options [Symbol] :app_file (Automatically detected)
|
23
|
-
# @option options [Symbol] :app_obj (Detected)
|
24
|
-
# @option options [Symbol] :app_root (Directory of :app_file)
|
25
|
-
#
|
26
|
-
def initialize(name, options={})
|
27
|
-
@name = name.to_s
|
28
|
-
@app_class = options[:app_class] || @name.camelize
|
29
|
-
@app_file = options[:app_file] || locate_app_file
|
30
|
-
@app_obj = options[:app_obj] || app_constant || locate_app_object
|
31
|
-
ensure_app_file! || ensure_app_object!
|
32
|
-
@app_root = options[:app_root] || File.dirname(@app_file)
|
33
|
-
@uri_root = "/"
|
34
|
-
Padrino::Reloader.exclude_constants << @app_class
|
35
|
-
end
|
36
|
-
|
37
|
-
##
|
38
|
-
# Registers the mounted application onto Padrino
|
39
|
-
#
|
40
|
-
# @param [String] mount_url
|
41
|
-
# Path where we mount the app
|
42
|
-
#
|
43
|
-
# @example
|
44
|
-
# Mounter.new("blog_app").to("/blog")
|
45
|
-
#
|
46
|
-
def to(mount_url)
|
47
|
-
@uri_root = mount_url
|
48
|
-
Padrino.insert_mounted_app(self)
|
49
|
-
self
|
50
|
-
end
|
51
|
-
|
52
|
-
##
|
53
|
-
# Registers the mounted application onto Padrino for the given host
|
54
|
-
#
|
55
|
-
# @param [String] mount_host
|
56
|
-
# Host name
|
57
|
-
#
|
58
|
-
# @example
|
59
|
-
# Mounter.new("blog_app").to("/blog").host("blog.padrino.org")
|
60
|
-
# Mounter.new("blog_app").host("blog.padrino.org")
|
61
|
-
# Mounter.new("catch_all").host(/.*\.padrino.org/)
|
62
|
-
#
|
63
|
-
def host(mount_host)
|
64
|
-
@app_host = mount_host
|
65
|
-
Padrino.insert_mounted_app(self)
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
##
|
70
|
-
# Maps Padrino application onto a Padrino::Router
|
71
|
-
# For use in constructing a Rack application
|
72
|
-
#
|
73
|
-
# @param [Padrino::Router]
|
74
|
-
#
|
75
|
-
# @return [Padrino::Router]
|
76
|
-
#
|
77
|
-
# @example
|
78
|
-
# @app.map_onto(router)
|
79
|
-
#
|
80
|
-
def map_onto(router)
|
81
|
-
app_data, app_obj = self, @app_obj
|
82
|
-
app_obj.set :uri_root, app_data.uri_root
|
83
|
-
app_obj.set :app_name, app_data.name
|
84
|
-
app_obj.set :app_file, app_data.app_file unless ::File.exist?(app_obj.app_file)
|
85
|
-
app_obj.set :root, app_data.app_root unless app_data.app_root.blank?
|
86
|
-
app_obj.set :public_folder, Padrino.root('public', app_data.uri_root) unless File.exists?(app_obj.public_folder)
|
87
|
-
app_obj.set :static, File.exist?(app_obj.public_folder) if app_obj.nil?
|
88
|
-
app_obj.setup_application! # Initializes the app here with above settings.
|
89
|
-
router.map(:to => app_obj, :path => app_data.uri_root, :host => app_data.app_host)
|
90
|
-
end
|
91
|
-
|
92
|
-
###
|
93
|
-
# Returns the route objects for the mounted application
|
94
|
-
#
|
95
|
-
def routes
|
96
|
-
app_obj.routes
|
97
|
-
end
|
98
|
-
|
99
|
-
###
|
100
|
-
# Returns the basic route information for each named route
|
101
|
-
#
|
102
|
-
# @return [Array]
|
103
|
-
# Array of routes
|
104
|
-
#
|
105
|
-
def named_routes
|
106
|
-
app_obj.routes.map { |route|
|
107
|
-
name_array = "(#{route.named.to_s.split("_").map { |piece| %Q[:#{piece}] }.join(", ")})"
|
108
|
-
request_method = route.conditions[:request_method][0]
|
109
|
-
full_path = File.join(uri_root, route.original_path)
|
110
|
-
next if route.named.blank? || request_method == 'HEAD'
|
111
|
-
OpenStruct.new(:verb => request_method, :identifier => route.named, :name => name_array, :path => full_path)
|
112
|
-
}.compact
|
113
|
-
end
|
114
|
-
|
115
|
-
##
|
116
|
-
# Makes two Mounters equal if they have the same name and uri_root
|
117
|
-
#
|
118
|
-
# @param [Padrino::Mounter] other
|
119
|
-
#
|
120
|
-
def ==(other)
|
121
|
-
other.is_a?(Mounter) && self.app_class == other.app_class && self.uri_root == other.uri_root
|
122
|
-
end
|
123
|
-
|
124
|
-
##
|
125
|
-
# @return [Padrino::Application]
|
126
|
-
# the class object for the app if defined, nil otherwise
|
127
|
-
#
|
128
|
-
def app_constant
|
129
|
-
klass = Object
|
130
|
-
for piece in app_class.split("::")
|
131
|
-
piece = piece.to_sym
|
132
|
-
if klass.const_defined?(piece)
|
133
|
-
klass = klass.const_get(piece)
|
134
|
-
else
|
135
|
-
return
|
136
|
-
end
|
137
|
-
end
|
138
|
-
klass
|
139
|
-
end
|
140
|
-
|
141
|
-
protected
|
142
|
-
##
|
143
|
-
# Locates and requires the file to load the app constant
|
144
|
-
#
|
145
|
-
def locate_app_object
|
146
|
-
@_app_object ||= begin
|
147
|
-
ensure_app_file!
|
148
|
-
Padrino.require_dependencies(app_file)
|
149
|
-
app_constant
|
150
|
-
end
|
151
|
-
end
|
152
|
-
|
153
|
-
##
|
154
|
-
# Returns the determined location of the mounted application main file
|
155
|
-
#
|
156
|
-
def locate_app_file
|
157
|
-
candidates = []
|
158
|
-
candidates << app_constant.app_file if app_constant.respond_to?(:app_file) && File.exist?(app_constant.app_file.to_s)
|
159
|
-
candidates << Padrino.first_caller if File.identical?(Padrino.first_caller.to_s, Padrino.called_from.to_s)
|
160
|
-
candidates << Padrino.mounted_root(name.downcase, "app.rb")
|
161
|
-
candidates << Padrino.root("app", "app.rb")
|
162
|
-
candidates.find { |candidate| File.exist?(candidate) }
|
163
|
-
end
|
164
|
-
|
165
|
-
###
|
166
|
-
# Raises an exception unless app_file is located properly
|
167
|
-
#
|
168
|
-
def ensure_app_file!
|
169
|
-
message = "Unable to locate source file for app '#{app_class}', try with :app_file => '/path/app.rb'"
|
170
|
-
raise MounterException, message unless @app_file
|
171
|
-
end
|
172
|
-
|
173
|
-
###
|
174
|
-
# Raises an exception unless app_obj is defined properly
|
175
|
-
#
|
176
|
-
def ensure_app_object!
|
177
|
-
message = "Unable to locate app for '#{app_class}', try with :app_class => 'MyAppClass'"
|
178
|
-
raise MounterException, message unless @app_obj
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
class << self
|
183
|
-
attr_writer :mounted_root # Set root directory where padrino searches mounted apps
|
184
|
-
|
185
|
-
##
|
186
|
-
# @param [Array] args
|
187
|
-
#
|
188
|
-
# @return [String]
|
189
|
-
# the root to the mounted apps base directory
|
190
|
-
#
|
191
|
-
def mounted_root(*args)
|
192
|
-
Padrino.root(@mounted_root ||= "", *args)
|
193
|
-
end
|
194
|
-
|
195
|
-
##
|
196
|
-
# @return [Array]
|
197
|
-
# the mounted padrino applications (MountedApp objects)
|
198
|
-
#
|
199
|
-
def mounted_apps
|
200
|
-
@mounted_apps ||= []
|
201
|
-
end
|
202
|
-
|
203
|
-
##
|
204
|
-
# Inserts a Mounter object into the mounted applications (avoids duplicates)
|
205
|
-
#
|
206
|
-
# @param [Padrino::Mounter] mounter
|
207
|
-
#
|
208
|
-
def insert_mounted_app(mounter)
|
209
|
-
Padrino.mounted_apps.push(mounter) unless Padrino.mounted_apps.include?(mounter)
|
210
|
-
end
|
211
|
-
|
212
|
-
##
|
213
|
-
# Mounts a new sub-application onto Padrino project
|
214
|
-
#
|
215
|
-
# @see Padrino::Mounter#new
|
216
|
-
#
|
217
|
-
# @example
|
218
|
-
# Padrino.mount("blog_app").to("/blog")
|
219
|
-
#
|
220
|
-
def mount(name, options={})
|
221
|
-
Mounter.new(name, options)
|
222
|
-
end
|
223
|
-
end # Mounter
|
224
|
-
end # Padrino
|
@@ -1,254 +0,0 @@
|
|
1
|
-
require 'pathname'
|
2
|
-
|
3
|
-
module Padrino
|
4
|
-
##
|
5
|
-
# High performance source code reloader middleware
|
6
|
-
#
|
7
|
-
module Reloader
|
8
|
-
##
|
9
|
-
# This reloader is suited for use in a many environments because each file
|
10
|
-
# will only be checked once and only one system call to stat(2) is made.
|
11
|
-
#
|
12
|
-
# Please note that this will not reload files in the background, and does so
|
13
|
-
# only when explicitly invoked.
|
14
|
-
#
|
15
|
-
|
16
|
-
# The modification times for every file in a project.
|
17
|
-
MTIMES = {}
|
18
|
-
# The list of files loaded as part of a project.
|
19
|
-
LOADED_FILES = {}
|
20
|
-
# The list of object constants and classes loaded as part of the project.
|
21
|
-
LOADED_CLASSES = {}
|
22
|
-
|
23
|
-
class << self
|
24
|
-
##
|
25
|
-
# Specified folders can be excluded from the code reload detection process.
|
26
|
-
# Default excluded directories at Padrino.root are: test, spec, features, tmp, config, db and public
|
27
|
-
#
|
28
|
-
def exclude
|
29
|
-
@_exclude ||= %w(test spec tmp features config public db).map { |path| Padrino.root(path) }
|
30
|
-
end
|
31
|
-
|
32
|
-
##
|
33
|
-
# Specified constants can be excluded from the code unloading process.
|
34
|
-
#
|
35
|
-
def exclude_constants
|
36
|
-
@_exclude_constants ||= []
|
37
|
-
end
|
38
|
-
|
39
|
-
##
|
40
|
-
# Specified constants can be configured to be reloaded on every request.
|
41
|
-
# Default included constants are: [none]
|
42
|
-
#
|
43
|
-
def include_constants
|
44
|
-
@_include_constants ||= []
|
45
|
-
end
|
46
|
-
|
47
|
-
##
|
48
|
-
# Reload all files with changes detected.
|
49
|
-
#
|
50
|
-
def reload!
|
51
|
-
# Detect changed files
|
52
|
-
rotation do |file, mtime|
|
53
|
-
# Retrive the last modified time
|
54
|
-
new_file = MTIMES[file].nil?
|
55
|
-
previous_mtime = MTIMES[file] ||= mtime
|
56
|
-
logger.devel "Detected a new file #{file}" if new_file
|
57
|
-
# We skip to next file if it is not new and not modified
|
58
|
-
next unless new_file || mtime > previous_mtime
|
59
|
-
# Now we can reload our file
|
60
|
-
apps = mounted_apps_of(file)
|
61
|
-
if apps.present?
|
62
|
-
apps.each { |app| app.app_obj.reload! }
|
63
|
-
else
|
64
|
-
safe_load(file, :force => new_file)
|
65
|
-
# Reload also apps
|
66
|
-
Padrino.mounted_apps.each do |app|
|
67
|
-
app.app_obj.reload! if app.app_obj.dependencies.include?(file)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
##
|
74
|
-
# Remove files and classes loaded with stat
|
75
|
-
#
|
76
|
-
def clear!
|
77
|
-
MTIMES.clear
|
78
|
-
LOADED_CLASSES.each do |file, klasses|
|
79
|
-
klasses.each { |klass| remove_constant(klass) }
|
80
|
-
LOADED_CLASSES.delete(file)
|
81
|
-
end
|
82
|
-
LOADED_FILES.each do |file, dependencies|
|
83
|
-
dependencies.each { |dependency| $LOADED_FEATURES.delete(dependency) }
|
84
|
-
$LOADED_FEATURES.delete(file)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
##
|
89
|
-
# Returns true if any file changes are detected and populates the MTIMES cache
|
90
|
-
#
|
91
|
-
def changed?
|
92
|
-
changed = false
|
93
|
-
rotation do |file, mtime|
|
94
|
-
new_file = MTIMES[file].nil?
|
95
|
-
previous_mtime = MTIMES[file]
|
96
|
-
changed = true if new_file || mtime > previous_mtime
|
97
|
-
end
|
98
|
-
changed
|
99
|
-
end
|
100
|
-
alias :run! :changed?
|
101
|
-
|
102
|
-
##
|
103
|
-
# We lock dependencies sets to prevent reloading of protected constants
|
104
|
-
#
|
105
|
-
def lock!
|
106
|
-
klasses = ObjectSpace.classes.map { |klass| klass.name.split('::')[0] }.uniq
|
107
|
-
klasses = klasses | Padrino.mounted_apps.map { |app| app.app_class }
|
108
|
-
Padrino::Reloader.exclude_constants.concat(klasses)
|
109
|
-
end
|
110
|
-
|
111
|
-
##
|
112
|
-
# A safe Kernel::require which issues the necessary hooks depending on results
|
113
|
-
#
|
114
|
-
def safe_load(file, options={})
|
115
|
-
began_at = Time.now
|
116
|
-
force, file = options[:force], figure_path(file)
|
117
|
-
|
118
|
-
# Check if file was changed or if force a reload
|
119
|
-
reload = MTIMES[file] && File.mtime(file) > MTIMES[file]
|
120
|
-
return if !force && !reload && MTIMES[file]
|
121
|
-
|
122
|
-
# Removes all classes declared in the specified file
|
123
|
-
if klasses = LOADED_CLASSES.delete(file)
|
124
|
-
klasses.each { |klass| remove_constant(klass) }
|
125
|
-
end
|
126
|
-
|
127
|
-
# Remove all loaded fatures with our file
|
128
|
-
if features = LOADED_FILES[file]
|
129
|
-
features.each { |feature| $LOADED_FEATURES.delete(feature) }
|
130
|
-
end
|
131
|
-
|
132
|
-
# Duplicate objects and loaded features before load file
|
133
|
-
klasses = ObjectSpace.classes.dup
|
134
|
-
files = $LOADED_FEATURES.dup
|
135
|
-
|
136
|
-
# Now we can reload dependencies of our file
|
137
|
-
if features = LOADED_FILES.delete(file)
|
138
|
-
features.each { |feature| safe_load(feature, :force => true) }
|
139
|
-
end
|
140
|
-
|
141
|
-
# And finally load the specified file
|
142
|
-
begin
|
143
|
-
logger.devel :loading, began_at, file if !reload
|
144
|
-
logger.debug :reload, began_at, file if reload
|
145
|
-
$LOADED_FEATURES.delete(file)
|
146
|
-
verbosity_was, $-v = $-v, nil
|
147
|
-
loaded = false
|
148
|
-
require(file)
|
149
|
-
loaded = true
|
150
|
-
MTIMES[file] = File.mtime(file)
|
151
|
-
rescue SyntaxError => e
|
152
|
-
logger.error "Cannot require #{file} due to a syntax error: #{e.message}"
|
153
|
-
ensure
|
154
|
-
$-v = verbosity_was
|
155
|
-
new_constants = (ObjectSpace.classes - klasses).uniq
|
156
|
-
if loaded
|
157
|
-
# Store the file details
|
158
|
-
LOADED_CLASSES[file] = new_constants
|
159
|
-
LOADED_FILES[file] = ($LOADED_FEATURES - files - [file]).uniq
|
160
|
-
# Track only features in our Padrino.root
|
161
|
-
LOADED_FILES[file].delete_if { |feature| !in_root?(feature) }
|
162
|
-
else
|
163
|
-
logger.devel "Failed to load #{file}; removing partially defined constants"
|
164
|
-
new_constants.each { |klass| remove_constant(klass) }
|
165
|
-
end
|
166
|
-
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
##
|
171
|
-
# Returns true if the file is defined in our padrino root
|
172
|
-
#
|
173
|
-
def figure_path(file)
|
174
|
-
return file if Pathname.new(file).absolute?
|
175
|
-
$:.each do |path|
|
176
|
-
found = File.join(path, file)
|
177
|
-
return File.expand_path(found) if File.exist?(found)
|
178
|
-
end
|
179
|
-
file
|
180
|
-
end
|
181
|
-
|
182
|
-
##
|
183
|
-
# Removes the specified class and constant.
|
184
|
-
#
|
185
|
-
def remove_constant(const)
|
186
|
-
return if exclude_constants.compact.uniq.any? { |c| const.name.index(c) == 0 } &&
|
187
|
-
!include_constants.compact.uniq.any? { |c| const.name.index(c) == 0 }
|
188
|
-
begin
|
189
|
-
parts = const.to_s.sub(/^::(Object)?/, 'Object::').split('::')
|
190
|
-
object = parts.pop
|
191
|
-
base = parts.empty? ? Object : Inflector.constantize(parts * '::')
|
192
|
-
base.send :remove_const, object
|
193
|
-
logger.devel "Removed constant: #{const} from #{base}"
|
194
|
-
rescue NameError; end
|
195
|
-
end
|
196
|
-
|
197
|
-
private
|
198
|
-
##
|
199
|
-
# Return the mounted_apps providing the app location
|
200
|
-
# Can be an array because in one app.rb we can define multiple Padrino::Appplications
|
201
|
-
#
|
202
|
-
def mounted_apps_of(file)
|
203
|
-
file = figure_path(file)
|
204
|
-
Padrino.mounted_apps.find_all { |app| File.identical?(file, app.app_file) }
|
205
|
-
end
|
206
|
-
|
207
|
-
##
|
208
|
-
# Returns true if file is in our Padrino.root
|
209
|
-
#
|
210
|
-
def in_root?(file)
|
211
|
-
# This is better but slow:
|
212
|
-
# Pathname.new(Padrino.root).find { |f| File.identical?(Padrino.root(f), figure_path(file)) }
|
213
|
-
figure_path(file).index(Padrino.root) == 0
|
214
|
-
end
|
215
|
-
|
216
|
-
##
|
217
|
-
# Searches Ruby files in your +Padrino.load_paths+ , Padrino::Application.load_paths
|
218
|
-
# and monitors them for any changes.
|
219
|
-
#
|
220
|
-
def rotation
|
221
|
-
files = Padrino.load_paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten
|
222
|
-
files = files | Padrino.mounted_apps.map { |app| app.app_file }
|
223
|
-
files = files | Padrino.mounted_apps.map { |app| app.app_obj.dependencies }.flatten
|
224
|
-
files.uniq.map do |file|
|
225
|
-
file = File.expand_path(file)
|
226
|
-
next if Padrino::Reloader.exclude.any? { |base| file.index(base) == 0 } || !File.exist?(file)
|
227
|
-
yield file, File.mtime(file)
|
228
|
-
end.compact
|
229
|
-
end
|
230
|
-
end # self
|
231
|
-
|
232
|
-
##
|
233
|
-
# This class acts as a Rack middleware to be added to the application stack. This middleware performs a
|
234
|
-
# check and reload for source files at the start of each request, but also respects a specified cool down time
|
235
|
-
# during which no further action will be taken.
|
236
|
-
#
|
237
|
-
class Rack
|
238
|
-
def initialize(app, cooldown=1)
|
239
|
-
@app = app
|
240
|
-
@cooldown = cooldown
|
241
|
-
@last = (Time.now - cooldown)
|
242
|
-
end
|
243
|
-
|
244
|
-
# Invoked in order to perform the reload as part of the request stack.
|
245
|
-
def call(env)
|
246
|
-
if @cooldown && Time.now > @last + @cooldown
|
247
|
-
Thread.list.size > 1 ? Thread.exclusive { Padrino.reload! } : Padrino.reload!
|
248
|
-
@last = Time.now
|
249
|
-
end
|
250
|
-
@app.call(env)
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end # Reloader
|
254
|
-
end # Padrino
|
@@ -1,98 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
##
|
3
|
-
# This class is an extended version of Rack::URLMap
|
4
|
-
#
|
5
|
-
# Padrino::Router like Rack::URLMap dispatches in such a way that the
|
6
|
-
# longest paths are tried first, since they are most specific.
|
7
|
-
#
|
8
|
-
# Features:
|
9
|
-
#
|
10
|
-
# * Map a path to the specified App
|
11
|
-
# * Ignore server names (this solve issues with vhost and domain aliases)
|
12
|
-
# * Use hosts instead of server name for mappings (this help us with our vhost and doman aliases)
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
#
|
16
|
-
# routes = Padrino::Router.new do
|
17
|
-
# map(:path => "/", :to => PadrinoWeb, :host => "padrino.local")
|
18
|
-
# map(:path => "/", :to => Admin, :host => "admin.padrino.local")
|
19
|
-
# end
|
20
|
-
# run routes
|
21
|
-
#
|
22
|
-
# routes = Padrino::Router.new do
|
23
|
-
# map(:path => "/", :to => PadrinoWeb, :host => /*.padrino.local/)
|
24
|
-
# end
|
25
|
-
# run routes
|
26
|
-
#
|
27
|
-
# @api semipublic
|
28
|
-
class Router
|
29
|
-
|
30
|
-
# Constructs a new route mapper instance
|
31
|
-
def initialize(*mapping, &block)
|
32
|
-
@mapping = []
|
33
|
-
mapping.each { |m| map(m) }
|
34
|
-
instance_eval(&block) if block
|
35
|
-
end
|
36
|
-
|
37
|
-
##
|
38
|
-
# Map a route path and host to a specified application.
|
39
|
-
#
|
40
|
-
# @param [Hash] options
|
41
|
-
# The options to map.
|
42
|
-
# @option options [Sinatra::Application] :to
|
43
|
-
# The class of the application to mount.
|
44
|
-
# @option options [String] :path ("/")
|
45
|
-
# The path to map the specified application.
|
46
|
-
# @option options [String] :host
|
47
|
-
# The host to map the specified application.
|
48
|
-
#
|
49
|
-
# @example
|
50
|
-
# map(:path => "/", :to => PadrinoWeb, :host => "padrino.local")
|
51
|
-
#
|
52
|
-
# @return [Array] The sorted route mappings.
|
53
|
-
# @api semipublic
|
54
|
-
def map(options={})
|
55
|
-
path = options[:path] || "/"
|
56
|
-
host = options[:host]
|
57
|
-
app = options[:to]
|
58
|
-
|
59
|
-
raise ArgumentError, "paths need to start with /" if path[0] != ?/
|
60
|
-
raise ArgumentError, "app is required" if app.nil?
|
61
|
-
|
62
|
-
path = path.chomp('/')
|
63
|
-
match = Regexp.new("^#{Regexp.quote(path).gsub('/', '/+')}(.*)", nil, 'n')
|
64
|
-
host = Regexp.new("^#{Regexp.quote(host)}$", true, 'n') unless host.nil? || host.is_a?(Regexp)
|
65
|
-
|
66
|
-
@mapping << [host, path, match, app]
|
67
|
-
sort!
|
68
|
-
end
|
69
|
-
|
70
|
-
# The call handler setup to route a request given the mappings specified.
|
71
|
-
# @api private
|
72
|
-
def call(env)
|
73
|
-
rPath = env["PATH_INFO"].to_s
|
74
|
-
script_name = env['SCRIPT_NAME']
|
75
|
-
hHost, sName, sPort = env.values_at('HTTP_HOST','SERVER_NAME','SERVER_PORT')
|
76
|
-
@mapping.each do |host, path, match, app|
|
77
|
-
next unless host.nil? || hHost =~ host
|
78
|
-
next unless rPath =~ match && rest = $1
|
79
|
-
next unless rest.empty? || rest[0] == ?/
|
80
|
-
|
81
|
-
rest = "/" if rest.empty?
|
82
|
-
|
83
|
-
return app.call(
|
84
|
-
env.merge(
|
85
|
-
'SCRIPT_NAME' => (script_name + path),
|
86
|
-
'PATH_INFO' => rest))
|
87
|
-
end
|
88
|
-
[404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{rPath}"]]
|
89
|
-
end
|
90
|
-
|
91
|
-
private
|
92
|
-
|
93
|
-
# Sorts the mapped routes in consistent order
|
94
|
-
def sort!
|
95
|
-
@mapping = @mapping.sort_by { |h, p, m, a| -p.size }
|
96
|
-
end
|
97
|
-
end # Router
|
98
|
-
end # Padrino
|
@@ -1,79 +0,0 @@
|
|
1
|
-
module Padrino
|
2
|
-
##
|
3
|
-
# Runs the Padrino apps as a self-hosted server using:
|
4
|
-
# thin, mongrel, or webrick in that order.
|
5
|
-
#
|
6
|
-
# @example
|
7
|
-
# Padrino.run! # with these defaults => host: "localhost", port: "3000", adapter: the first found
|
8
|
-
# Padrino.run!("localhost", "4000", "mongrel") # use => host: "0.0.0.0", port: "3000", adapter: "mongrel"
|
9
|
-
#
|
10
|
-
def self.run!(options={})
|
11
|
-
Padrino.load!
|
12
|
-
Server.start(Padrino.application, options)
|
13
|
-
end
|
14
|
-
|
15
|
-
##
|
16
|
-
# This module builds a Padrino server to run the project based on available handlers.
|
17
|
-
#
|
18
|
-
class Server < Rack::Server
|
19
|
-
# Server Handlers
|
20
|
-
Handlers = [:thin, :mongrel, :trinidad, :webrick]
|
21
|
-
|
22
|
-
# Starts the application on the available server with specified options.
|
23
|
-
def self.start(app, opts={})
|
24
|
-
options = {}.merge(opts) # We use a standard hash instead of Thor::CoreExt::HashWithIndifferentAccess
|
25
|
-
options.symbolize_keys!
|
26
|
-
options[:Host] = options.delete(:host) || '0.0.0.0'
|
27
|
-
options[:Port] = options.delete(:port) || 3000
|
28
|
-
options[:AccessLog] = []
|
29
|
-
if options[:daemonize]
|
30
|
-
options[:pid] = options[:pid].blank? ? File.expand_path('tmp/pids/server.pid') : opts[:pid]
|
31
|
-
FileUtils.mkdir_p(File.dirname(options[:pid]))
|
32
|
-
end
|
33
|
-
options[:server] = detect_rack_handler if options[:server].blank?
|
34
|
-
new(options, app).start
|
35
|
-
end
|
36
|
-
|
37
|
-
def initialize(options, app)
|
38
|
-
@options, @app = options, app
|
39
|
-
end
|
40
|
-
|
41
|
-
# Starts the application on the available server with specified options.
|
42
|
-
def start
|
43
|
-
puts "=> Padrino/#{Padrino.version} has taken the stage #{Padrino.env} at http://#{options[:Host]}:#{options[:Port]}"
|
44
|
-
[:INT, :TERM].each { |sig| trap(sig) { exit } }
|
45
|
-
super
|
46
|
-
ensure
|
47
|
-
puts "<= Padrino leaves the gun, takes the cannoli" unless options[:daemonize]
|
48
|
-
end
|
49
|
-
|
50
|
-
# The application the server will run.
|
51
|
-
def app
|
52
|
-
@app
|
53
|
-
end
|
54
|
-
alias :wrapped_app :app
|
55
|
-
|
56
|
-
# The options specified to the server.
|
57
|
-
def options
|
58
|
-
@options
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
# Detects the supported handler to use.
|
64
|
-
#
|
65
|
-
# @example
|
66
|
-
# detect_rack_handler => <ThinHandler>
|
67
|
-
#
|
68
|
-
def self.detect_rack_handler
|
69
|
-
Handlers.each do |handler|
|
70
|
-
begin
|
71
|
-
return handler if Rack::Handler.get(handler.to_s.downcase)
|
72
|
-
rescue LoadError
|
73
|
-
rescue NameError
|
74
|
-
end
|
75
|
-
end
|
76
|
-
fail "Server handler (#{Handlers.join(', ')}) not found."
|
77
|
-
end
|
78
|
-
end # Server
|
79
|
-
end # Padrino
|