diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aa09762..de7befb1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,13 +3,24 @@ master * Asciidoc information now available with the `asciidoc` local, which is a normal hash. * Remove `page` template local. Use `current_resource` instead. -* Dropped support for `page` & `proxy` blocks. +* Dropped support for providing a block to `page` & `proxy`. * Dropped support for instance variables inside templates. * Moved all rendering into `TemplateRenderer` and `FileRenderer` * Placed all template evaluation inside the `TemplateContext` class * Remove deprecated `request` instance * Remove old module-style extension support * Placed all `config.rb` evaluation inside the `ConfigContext` class +* Update Padrino to 0.12.0. Introduces BREAKING CHANGE for Haml. Helpers which take blocks used to require `-` instead of `=` to work correctly. Now, all helpers which output content should use `=`. See: http://www.padrinorb.com/blog/upgrading-padrino-from-0-11-x-to-0-12-0-guide +* Depend on Erubis and remove support for specifying another ERb engine. +* Removed the ability to set the `sass_cache_path`. + +3.2.2 +=== + +* Specify the full path to the NEWLINE constant +* Refactor some internals which were dependent on certain order of operations +* Updated i18n dep +* Updated Uglifier dep 3.2.1 === diff --git a/Gemfile b/Gemfile index a5046c8b..83cd68cc 100644 --- a/Gemfile +++ b/Gemfile @@ -22,7 +22,7 @@ gem 'asciidoctor', :require => false platforms :ruby do gem 'therubyracer' - gem 'redcarpet', '~> 3.0' + gem 'redcarpet', '~> 3.1' gem 'pry', :require => false, :group => :development gem 'pry-debugger', :require => false, :group => :development end diff --git a/middleman-cli/lib/middleman-cli/build.rb b/middleman-cli/lib/middleman-cli/build.rb index 635d750d..403b6aaa 100644 --- a/middleman-cli/lib/middleman-cli/build.rb +++ b/middleman-cli/lib/middleman-cli/build.rb @@ -64,6 +64,8 @@ module Middleman::Cli opts[:glob] = options['glob'] if options.has_key?('glob') opts[:clean] = options['clean'] + self.class.shared_instance.run_hook :before_build, self + action BuildAction.new(self, opts) self.class.shared_instance.run_hook :after_build, self diff --git a/middleman-cli/lib/middleman-cli/console.rb b/middleman-cli/lib/middleman-cli/console.rb index e19e7dc2..a165b835 100644 --- a/middleman-cli/lib/middleman-cli/console.rb +++ b/middleman-cli/lib/middleman-cli/console.rb @@ -34,7 +34,7 @@ module Middleman::Cli config[:environment] = opts[:environment].to_sym end - logger(opts[:debug] ? 0 : 1, opts[:instrumenting] || false) + ::Middleman::Logger.singleton(opts[:debug] ? 0 : 1, opts[:instrumenting] || false) end # TODO: get file watcher / reload! working in console diff --git a/middleman-cli/lib/middleman-cli/init.rb b/middleman-cli/lib/middleman-cli/init.rb index 2e588cc7..88af7797 100644 --- a/middleman-cli/lib/middleman-cli/init.rb +++ b/middleman-cli/lib/middleman-cli/init.rb @@ -43,7 +43,7 @@ module Middleman::Cli :desc => 'Skip Git ignores and keeps' # The init task # @param [String] name - def init(name) + def init(name = '.') key = options[:template].to_sym unless ::Middleman::Templates.registered.has_key?(key) raise Thor::Error.new "Unknown project template '#{key}'" diff --git a/middleman-cli/lib/middleman-cli/templates/shared/config.tt b/middleman-cli/lib/middleman-cli/templates/shared/config.tt index 288f0813..f96e0a26 100755 --- a/middleman-cli/lib/middleman-cli/templates/shared/config.tt +++ b/middleman-cli/lib/middleman-cli/templates/shared/config.tt @@ -24,7 +24,7 @@ # page "/admin/*" # end -# Proxy pages (http://middlemanapp.com/dynamic-pages/) +# Proxy pages (http://middlemanapp.com/basics/dynamic-pages/) # proxy "/this-page-has-no-template.html", "/template-file.html", :locals => { # :which_fake_page => "Rendering a fake page with a local variable" } diff --git a/middleman-core/features/cli_init.feature b/middleman-core/features/cli_init.feature index fc84cc08..d6d5b4b4 100644 --- a/middleman-core/features/cli_init.feature +++ b/middleman-core/features/cli_init.feature @@ -15,19 +15,29 @@ Feature: Middleman CLI | source/javascripts/all.js | | source/stylesheets/all.css | | source/stylesheets/normalize.css | - + + Scenario: Create a new project in the current directory + Given a directory named "MY_PROJECT" + When I cd to "MY_PROJECT" + And I run `middleman init` + Then the exit status should be 0 + And the following files should exist: + | Gemfile | + | config.rb | + | source/index.html.erb | + Scenario: Create a new project (alias i) When I run `middleman i MY_PROJECT` Then a directory named "MY_PROJECT" should exist - + Scenario: Create a new project (alias new) When I run `middleman new MY_PROJECT` Then a directory named "MY_PROJECT" should exist - + Scenario: Create a new project (alias n) When I run `middleman n MY_PROJECT` Then a directory named "MY_PROJECT" should exist - + Scenario: Create a new project with Rack When I run `middleman init MY_PROJECT --rack` Then a directory named "MY_PROJECT" should exist @@ -36,7 +46,7 @@ Feature: Middleman CLI | config.rb | | config.ru | | Gemfile | - + Scenario: Create a new HTML5 project When I run `middleman init MY_PROJECT --template=html5` Then a directory named "MY_PROJECT" should exist @@ -54,7 +64,7 @@ Feature: Middleman CLI | layouts/layout.erb | | humans.txt | | js/main.js | - + Scenario: Create a new HTML5 project with Rack When I run `middleman init MY_PROJECT --rack --template=html5` Then a directory named "MY_PROJECT" should exist @@ -63,7 +73,7 @@ Feature: Middleman CLI | config.rb | | config.ru | | Gemfile | - + Scenario: Create a new Mobile HTML5 project When I run `middleman init MY_PROJECT --template=mobile` Then a directory named "MY_PROJECT" should exist @@ -79,7 +89,7 @@ Feature: Middleman CLI | index.html | | humans.txt | | js/libs/respond.min.js | - + Scenario: Create a new Mobile HTML5 project with Rack When I run `middleman init MY_PROJECT --rack --template=mobile` Then a directory named "MY_PROJECT" should exist diff --git a/middleman-core/features/layouts_dir.feature b/middleman-core/features/layouts_dir.feature index 5d31d4f5..3a5b6b00 100644 --- a/middleman-core/features/layouts_dir.feature +++ b/middleman-core/features/layouts_dir.feature @@ -28,3 +28,11 @@ Feature: Layouts dir When I go to "/index.html" Then I should see "contents of the layout" + Scenario: Prefer a layout in the layouts_dir to one with the same name in the root + Given a fixture app "layouts-dir-app" + And a file named "config.rb" with: + """ + """ + And the Server is running + When I go to "/ambiguous.html" + Then I should see "contents of the layout in layouts_dir" diff --git a/middleman-core/features/markdown_redcarpet.feature b/middleman-core/features/markdown_redcarpet.feature index 39acc839..7eec709b 100644 --- a/middleman-core/features/markdown_redcarpet.feature +++ b/middleman-core/features/markdown_redcarpet.feature @@ -86,8 +86,8 @@ Feature: Markdown (Redcarpet) support Then I should see "![dust mite](http://dust.mite/image.png)" And I should not see " <%= yield %> - diff --git a/middleman-core/fixtures/capture-html-app/source/capture_html_haml.html.haml b/middleman-core/fixtures/capture-html-app/source/capture_html_haml.html.haml index bbff7ff5..20eaef40 100644 --- a/middleman-core/fixtures/capture-html-app/source/capture_html_haml.html.haml +++ b/middleman-core/fixtures/capture-html-app/source/capture_html_haml.html.haml @@ -1,4 +1,4 @@ -- capture_html :from_template do += capture_html :from_template do %h1= "I am the yielded content haml" %p I am in the template \ No newline at end of file diff --git a/middleman-core/fixtures/content-for-app/source/content_for_haml.html.haml b/middleman-core/fixtures/content-for-app/source/content_for_haml.html.haml index 13645ee7..76b29096 100644 --- a/middleman-core/fixtures/content-for-app/source/content_for_haml.html.haml +++ b/middleman-core/fixtures/content-for-app/source/content_for_haml.html.haml @@ -1,4 +1,4 @@ -- content_for :from_template do += content_for :from_template do = "I am the yielded content haml with html tags" %p I am in the template \ No newline at end of file diff --git a/middleman-core/fixtures/frontmatter-settings-app/source/layouts/override.erb b/middleman-core/fixtures/frontmatter-settings-app/source/layouts/override.erb index fcf39dc0..56bf1342 100644 --- a/middleman-core/fixtures/frontmatter-settings-app/source/layouts/override.erb +++ b/middleman-core/fixtures/frontmatter-settings-app/source/layouts/override.erb @@ -1,2 +1 @@ -<%= yield %> - Override. \ No newline at end of file +<%= yield %> Override. \ No newline at end of file diff --git a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb index fcf39dc0..56bf1342 100644 --- a/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb +++ b/middleman-core/fixtures/frontmatter-settings-neighbor-app/source/layouts/override.erb @@ -1,2 +1 @@ -<%= yield %> - Override. \ No newline at end of file +<%= yield %> Override. \ No newline at end of file diff --git a/middleman-core/fixtures/layouts-dir-app/source/ambiguous.html.erb b/middleman-core/fixtures/layouts-dir-app/source/ambiguous.html.erb new file mode 100644 index 00000000..77a651ff --- /dev/null +++ b/middleman-core/fixtures/layouts-dir-app/source/ambiguous.html.erb @@ -0,0 +1,5 @@ +--- +layout: other +--- + +Hello diff --git a/middleman-core/fixtures/layouts-dir-app/source/layouts/other.erb b/middleman-core/fixtures/layouts-dir-app/source/layouts/other.erb new file mode 100644 index 00000000..f8471491 --- /dev/null +++ b/middleman-core/fixtures/layouts-dir-app/source/layouts/other.erb @@ -0,0 +1,3 @@ +contents of the layout in layouts_dir + +<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/layouts-dir-app/source/other.erb b/middleman-core/fixtures/layouts-dir-app/source/other.erb new file mode 100644 index 00000000..6a74c4a8 --- /dev/null +++ b/middleman-core/fixtures/layouts-dir-app/source/other.erb @@ -0,0 +1,3 @@ +contents of the layout in the root + +<%= yield %> \ No newline at end of file diff --git a/middleman-core/fixtures/link-to-app/source/link_to_haml.html.haml b/middleman-core/fixtures/link-to-app/source/link_to_haml.html.haml index 7258f001..7c0ee402 100644 --- a/middleman-core/fixtures/link-to-app/source/link_to_haml.html.haml +++ b/middleman-core/fixtures/link-to-app/source/link_to_haml.html.haml @@ -1,2 +1,2 @@ -- link_to "/" do += link_to "/" do %s haml with html tags \ No newline at end of file diff --git a/middleman-core/fixtures/link-to-app/source/link_to_slim.html.slim b/middleman-core/fixtures/link-to-app/source/link_to_slim.html.slim index 847b9732..2758a64c 100644 --- a/middleman-core/fixtures/link-to-app/source/link_to_slim.html.slim +++ b/middleman-core/fixtures/link-to-app/source/link_to_slim.html.slim @@ -1,2 +1,2 @@ -- link_to "/" do += link_to "/" do s slim with html tags \ No newline at end of file diff --git a/middleman-core/fixtures/nested-layout-app/source/layouts/inner_haml.haml b/middleman-core/fixtures/nested-layout-app/source/layouts/inner_haml.haml index e3976d7c..a8c1938d 100644 --- a/middleman-core/fixtures/nested-layout-app/source/layouts/inner_haml.haml +++ b/middleman-core/fixtures/nested-layout-app/source/layouts/inner_haml.haml @@ -1,3 +1,3 @@ -- wrap_layout :outer_haml do += wrap_layout :outer_haml do Inner = yield \ No newline at end of file diff --git a/middleman-core/fixtures/nested-layout-app/source/layouts/inner_slim.slim b/middleman-core/fixtures/nested-layout-app/source/layouts/inner_slim.slim index d639b7e8..49f1ab6f 100644 --- a/middleman-core/fixtures/nested-layout-app/source/layouts/inner_slim.slim +++ b/middleman-core/fixtures/nested-layout-app/source/layouts/inner_slim.slim @@ -1,3 +1,3 @@ -- wrap_layout :outer_slim do += wrap_layout :outer_slim do h3 Inner == yield \ No newline at end of file diff --git a/middleman-core/fixtures/nested-layout-app/source/layouts/outer_haml.haml b/middleman-core/fixtures/nested-layout-app/source/layouts/outer_haml.haml index 641e42c5..eaf1671f 100644 --- a/middleman-core/fixtures/nested-layout-app/source/layouts/outer_haml.haml +++ b/middleman-core/fixtures/nested-layout-app/source/layouts/outer_haml.haml @@ -1,3 +1,3 @@ -- wrap_layout :master_haml do += wrap_layout :master_haml do Outer = yield diff --git a/middleman-core/fixtures/nested-layout-app/source/layouts/outer_slim.slim b/middleman-core/fixtures/nested-layout-app/source/layouts/outer_slim.slim index 738e5bb7..0c17185b 100644 --- a/middleman-core/fixtures/nested-layout-app/source/layouts/outer_slim.slim +++ b/middleman-core/fixtures/nested-layout-app/source/layouts/outer_slim.slim @@ -1,3 +1,3 @@ -- wrap_layout :master_slim do += wrap_layout :master_slim do h2 Outer == yield diff --git a/middleman-core/fixtures/sass-cache-path-custom-app/config.rb b/middleman-core/fixtures/sass-cache-path-custom-app/config.rb deleted file mode 100644 index c8e4e776..00000000 --- a/middleman-core/fixtures/sass-cache-path-custom-app/config.rb +++ /dev/null @@ -1,3 +0,0 @@ - - -set :sass_cache_path, File.join('/tmp', "#{File.basename(Dir.pwd)}-custom-sass_cache_path") diff --git a/middleman-core/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass b/middleman-core/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass deleted file mode 100644 index 79115283..00000000 --- a/middleman-core/fixtures/sass-cache-path-custom-app/source/stylesheets/plain.css.sass +++ /dev/null @@ -1,4 +0,0 @@ -@import "compass/reset" - -red - color: blue \ No newline at end of file diff --git a/middleman-core/fixtures/sass-cache-path-default-app/config.rb b/middleman-core/fixtures/sass-cache-path-default-app/config.rb deleted file mode 100644 index 77b161b6..00000000 --- a/middleman-core/fixtures/sass-cache-path-default-app/config.rb +++ /dev/null @@ -1,3 +0,0 @@ - -# Using default setting -# set :sass_cache_path, File.join(Dir.pwd, '.sass-cache') diff --git a/middleman-core/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass b/middleman-core/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass deleted file mode 100644 index 79115283..00000000 --- a/middleman-core/fixtures/sass-cache-path-default-app/source/stylesheets/plain.css.sass +++ /dev/null @@ -1,4 +0,0 @@ -@import "compass/reset" - -red - color: blue \ No newline at end of file diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index 0b30e314..9ee0dc42 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -3,7 +3,7 @@ require 'i18n' # Don't fail on invalid locale, that's not what our current # users expect. -::I18n.config.enforce_available_locales = false +::I18n.enforce_available_locales = false # Use ActiveSupport JSON require 'active_support/json' @@ -41,6 +41,9 @@ module Middleman # Ready (all loading and parsing of extensions complete) hook define_hook :ready + # Runs before the build is started + define_hook :before_build + # Runs after the build is finished define_hook :after_build diff --git a/middleman-core/lib/middleman-core/extension.rb b/middleman-core/lib/middleman-core/extension.rb index 78179afe..1ac42d1e 100644 --- a/middleman-core/lib/middleman-core/extension.rb +++ b/middleman-core/lib/middleman-core/extension.rb @@ -75,6 +75,7 @@ module Middleman # Bind app hooks to local methods bind_before_configuration bind_after_configuration + bind_before_build bind_after_build end @@ -136,6 +137,19 @@ module Middleman end end + def bind_before_build + ext = self + if ext.respond_to?(:before_build) + @klass.before_build do |builder| + if ext.method(:before_build).arity === 1 + ext.before_build(builder) + else + ext.before_build + end + end + end + end + def bind_after_build ext = self if ext.respond_to?(:after_build) diff --git a/middleman-core/lib/middleman-core/extensions.rb b/middleman-core/lib/middleman-core/extensions.rb index 150a5c53..7cfbec45 100644 --- a/middleman-core/lib/middleman-core/extensions.rb +++ b/middleman-core/lib/middleman-core/extensions.rb @@ -76,4 +76,4 @@ module Middleman end end -require 'middleman-core/extension' \ No newline at end of file +require 'middleman-core/extension' diff --git a/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb b/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb index b283ce77..3c753c3c 100644 --- a/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb +++ b/middleman-core/lib/middleman-core/meta_pages/sitemap_resource.rb @@ -1,6 +1,6 @@ if !defined?(::Padrino::Helpers) - require 'vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/support_lite' - require 'vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers' + require 'vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/support_lite' + require 'vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers' end module Middleman diff --git a/middleman-core/lib/middleman-core/renderers/erb.rb b/middleman-core/lib/middleman-core/renderers/erb.rb index 9ebebd82..87f91c82 100644 --- a/middleman-core/lib/middleman-core/renderers/erb.rb +++ b/middleman-core/lib/middleman-core/renderers/erb.rb @@ -7,30 +7,28 @@ module Middleman # once registered def registered(app) - # Setup a default ERb engine - app.config.define_setting :erb_engine, :erb, 'The engine to use for rendering ERb templates' - app.config.define_setting :erb_engine_prefix, ::Tilt, 'The parent module for ERb template engines' - app.before_configuration do template_extensions :erb => :html end # After config app.after_configuration do - # Find the user's prefered engine - # Convert symbols to classes - if config[:erb_engine].is_a? Symbol - engine = engine.to_s - engine = engine == 'erb' ? 'ERB' : engine.camelize - config[:erb_engine] = config[:erb_engine_prefix].const_get("#{engine}Template") - end - - # Tell Tilt to use the preferred engine - ::Tilt.prefer(config[:erb_engine]) + ::Tilt.prefer(Template, :erb) end end alias :included :registered end + + class Template < ::Tilt::ErubisTemplate + ## + # In preamble we need a flag `__in_erb_template` and SafeBuffer for padrino apps. + # + def precompiled_preamble(locals) + original = super + "__in_erb_template = true\n" << original + #.rpartition("\n").first << "#{@outvar} = _buf = ActiveSupport::SafeBuffer.new\n" + end + end end end end diff --git a/middleman-core/lib/middleman-core/renderers/haml.rb b/middleman-core/lib/middleman-core/renderers/haml.rb index e26ba812..e561de13 100644 --- a/middleman-core/lib/middleman-core/renderers/haml.rb +++ b/middleman-core/lib/middleman-core/renderers/haml.rb @@ -1,6 +1,16 @@ # Require gem require 'haml' +module SafeTemplate + def render(*) + super.html_safe + end +end + +class Tilt::HamlTemplate + include SafeTemplate +end + module Middleman module Renderers diff --git a/middleman-core/lib/middleman-core/renderers/sass.rb b/middleman-core/lib/middleman-core/renderers/sass.rb index f3022696..bd38722a 100644 --- a/middleman-core/lib/middleman-core/renderers/sass.rb +++ b/middleman-core/lib/middleman-core/renderers/sass.rb @@ -14,10 +14,6 @@ module Middleman # Default sass options app.config.define_setting :sass, {}, 'Sass engine options' - # Location of SASS .sass-cache directory. - # @return [String] - app.config.define_setting :sass_cache_path, File.join(app.root_path, '.sass-cache'), 'Location of sass cache' # runtime compile of path - app.before_configuration do template_extensions :scss => :css, :sass => :css diff --git a/middleman-core/lib/middleman-core/renderers/slim.rb b/middleman-core/lib/middleman-core/renderers/slim.rb index bd22d357..f9f6a28f 100644 --- a/middleman-core/lib/middleman-core/renderers/slim.rb +++ b/middleman-core/lib/middleman-core/renderers/slim.rb @@ -1,6 +1,20 @@ # Load gem require 'slim' +module SafeTemplate + def render(*) + super.html_safe + end +end + +class Slim::Template + include SafeTemplate + + def precompiled_preamble(locals) + "__in_slim_template = true\n" << super + end +end + module Middleman module Renderers diff --git a/middleman-core/lib/middleman-more/core_extensions/compass.rb b/middleman-core/lib/middleman-more/core_extensions/compass.rb index 1947edef..602bfe42 100644 --- a/middleman-core/lib/middleman-more/core_extensions/compass.rb +++ b/middleman-core/lib/middleman-more/core_extensions/compass.rb @@ -21,7 +21,7 @@ class Middleman::CoreExtensions::Compass < ::Middleman::Extension ::Compass.configuration do |compass_config| compass_config.project_path = app.source_dir compass_config.environment = :development - compass_config.cache_path = app.config[:sass_cache_path] + compass_config.cache = false compass_config.sass_dir = app.config[:css_dir] compass_config.css_dir = app.config[:css_dir] compass_config.javascripts_dir = app.config[:js_dir] diff --git a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb index edd762c8..6bbceb66 100644 --- a/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-core/lib/middleman-more/core_extensions/default_helpers.rb @@ -1,16 +1,20 @@ if !defined?(::Padrino::Helpers) - require 'vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/support_lite' - require 'vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers' + require 'vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/support_lite' + require 'vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers' + + # Don't fail on invalid locale, that's not what our current + # users expect. + ::I18n.enforce_available_locales = false end class Padrino::Helpers::OutputHelpers::ErbHandler # Force Erb capture not to use safebuffer def capture_from_template(*args, &block) self.output_buffer, _buf_was = '', self.output_buffer - captured_block = block.call(*args) - ret = eval('@_out_buf', block.binding) + raw = block.call(*args) + captured = template.instance_variable_get(:@_out_buf) self.output_buffer = _buf_was - [ ret, captured_block ] + engine_matches?(block) ? captured : raw end end @@ -49,6 +53,7 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension attributes = tag_attributes(options) output = ActiveSupport::SafeBuffer.new output.safe_concat "<#{name}#{attributes}>" + if content.respond_to?(:each) && !content.is_a?(String) content.each { |c| output.safe_concat c; output.safe_concat ::Padrino::Helpers::TagHelpers::NEWLINE } else @@ -249,4 +254,4 @@ class Middleman::CoreExtensions::DefaultHelpers < ::Middleman::Extension end end -Middleman::CoreExtensions::DefaultHelpers.register \ No newline at end of file +Middleman::CoreExtensions::DefaultHelpers.register diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/slim.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/slim.rb deleted file mode 100644 index e89043a8..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/slim.rb +++ /dev/null @@ -1,14 +0,0 @@ -begin - require 'slim' - - if defined? Padrino::Rendering - Padrino::Rendering.engine_configurations[:slim] = - {:generator => Temple::Generators::RailsOutputBuffer, - :buffer => "@_out_buf", :use_html_safe => true} - - class Slim::Template - include Padrino::Rendering::SafeTemplate - end - end -rescue LoadError -end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/reloader.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/reloader.rb deleted file mode 100644 index b785ca59..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/reloader.rb +++ /dev/null @@ -1,341 +0,0 @@ -require 'pathname' - -module Padrino - ## - # High performance source code reloader middleware - # - module Reloader - ## - # This reloader is suited for use in a many environments because each file - # will only be checked once and only one system call to stat(2) is made. - # - # Please note that this will not reload files in the background, and does so - # only when explicitly invoked. - # - - # The modification times for every file in a project. - MTIMES = {} - # The list of files loaded as part of a project. - LOADED_FILES = {} - # The list of object constants and classes loaded as part of the project. - LOADED_CLASSES = {} - - class << self - ## - # Specified folders can be excluded from the code reload detection process. - # Default excluded directories at Padrino.root are: test, spec, features, tmp, config, db and public - # - def exclude - @_exclude ||= %w(test spec tmp features config public db).map { |path| Padrino.root(path) } - end - - ## - # Specified constants can be excluded from the code unloading process. - # - def exclude_constants - @_exclude_constants ||= Set.new - end - - ## - # Specified constants can be configured to be reloaded on every request. - # Default included constants are: [none] - # - def include_constants - @_include_constants ||= Set.new - end - - ## - # Reload all files with changes detected. - # - def reload! - # Detect changed files - rotation do |file, mtime| - # Retrive the last modified time - new_file = MTIMES[file].nil? - previous_mtime = MTIMES[file] ||= mtime - logger.devel "Detected a new file #{file}" if new_file - # We skip to next file if it is not new and not modified - next unless new_file || mtime > previous_mtime - # Now we can reload our file - apps = mounted_apps_of(file) - if apps.present? - apps.each { |app| app.app_obj.reload! } - else - safe_load(file, :force => new_file) - # Reload also apps - Padrino.mounted_apps.each do |app| - app.app_obj.reload! if app.app_obj.dependencies.include?(file) - end - end - end - end - - ## - # Remove files and classes loaded with stat - # - def clear! - clear_modification_times - clear_loaded_classes - clear_loaded_files_and_features - end - - ## - # Returns true if any file changes are detected and populates the MTIMES cache - # - def changed? - changed = false - rotation do |file, mtime| - new_file = MTIMES[file].nil? - previous_mtime = MTIMES[file] - changed = true if new_file || mtime > previous_mtime - end - changed - end - alias :run! :changed? - - ## - # We lock dependencies sets to prevent reloading of protected constants - # - def lock! - klasses = ObjectSpace.classes do |klass| - klass._orig_klass_name.split('::')[0] - end - - klasses = klasses | Padrino.mounted_apps.map { |app| app.app_class } - Padrino::Reloader.exclude_constants.merge(klasses) - end - - ## - # A safe Kernel::require which issues the necessary hooks depending on results - # - def safe_load(file, options={}) - began_at = Time.now - force = options[:force] - file = figure_path(file) - reload = should_reload?(file) - m_time = modification_time(file) - - return if !force && m_time && !reload - - remove_loaded_file_classes(file) - remove_loaded_file_features(file) - - # Duplicate objects and loaded features before load file - klasses = ObjectSpace.classes - files = Set.new($LOADED_FEATURES.dup) - - reload_deps_of_file(file) - - # And finally load the specified file - begin - logger.devel :loading, began_at, file if !reload - logger.debug :reload, began_at, file if reload - - $LOADED_FEATURES.delete(file) if files.include?(file) - Padrino::Utils.silence_output - loaded = false - require(file) - loaded = true - update_modification_time(file) - rescue SyntaxError => e - logger.error "Cannot require #{file} due to a syntax error: #{e.message}" - ensure - Padrino::Utils.unsilence_output - new_constants = ObjectSpace.new_classes(klasses) - if loaded - process_loaded_file(:file => file, - :constants => new_constants, - :files => files) - else - logger.devel "Failed to load #{file}; removing partially defined constants" - unload_constants(new_constants) - end - end - end - - ## - # Returns true if the file is defined in our padrino root. - # - def figure_path(file) - return file if Pathname.new(file).absolute? - $:.each do |path| - found = File.join(path, file) - return File.expand_path(found) if File.exist?(found) - end - file - end - - ## - # Removes the specified class and constant. - # - def remove_constant(const) - return if exclude_constants.any? { |c| const._orig_klass_name.index(c) == 0 } && - !include_constants.any? { |c| const._orig_klass_name.index(c) == 0 } - begin - parts = const.to_s.sub(/^::(Object)?/, 'Object::').split('::') - object = parts.pop - base = parts.empty? ? Object : Inflector.constantize(parts * '::') - base.send :remove_const, object - logger.devel "Removed constant: #{const} from #{base}" - rescue NameError; end - end - - private - - ### - # Clear instance variables that keep track of # loaded features/files/mtimes. - # - def clear_modification_times - MTIMES.clear - end - - def clear_loaded_classes - LOADED_CLASSES.each do |file, klasses| - klasses.each { |klass| remove_constant(klass) } - LOADED_CLASSES.delete(file) - end - end - - def clear_loaded_files_and_features - LOADED_FILES.each do |file, dependencies| - dependencies.each { |dependency| $LOADED_FEATURES.delete(dependency) } - $LOADED_FEATURES.delete(file) - end - end - - ### - # Macro for mtime query. - # - def modification_time(file) - MTIMES[file] - end - - ### - # Macro for mtime update. - # - def update_modification_time(file) - MTIMES[file] = File.mtime(file) - end - - ### - # Tracks loaded file features/classes/constants: - # - def process_loaded_file(*args) - options = args.extract_options! - new_constants = options[:constants] - files = options[:files] - file = options[:file] - - # Store the file details - LOADED_CLASSES[file] = new_constants - LOADED_FILES[file] = Set.new($LOADED_FEATURES) - files - [file] - - # Track only features in our Padrino.root - LOADED_FILES[file].delete_if { |feature| !in_root?(feature) } - end - - ### - # Unloads all constants in new_constants. - # - def unload_constants(new_constants) - new_constants.each { |klass| remove_constant(klass) } - end - - ### - # Safe load dependencies of a file. - # - def reload_deps_of_file(file) - if features = LOADED_FILES.delete(file) - features.each { |feature| safe_load(feature, :force => true) } - end - end - - ## - # Check if file was changed or if force a reload. - # - def should_reload?(file) - MTIMES[file] && File.mtime(file) > MTIMES[file] - end - - ## - # Removes all classes declared in the specified file. - # - def remove_loaded_file_classes(file) - if klasses = LOADED_CLASSES.delete(file) - klasses.each { |klass| remove_constant(klass) } - end - end - - ## - # Remove all loaded fatures with our file. - # - def remove_loaded_file_features(file) - if features = LOADED_FILES[file] - features.each { |feature| $LOADED_FEATURES.delete(feature) } - end - end - - ## - # Return the mounted_apps providing the app location. - # Can be an array because in one app.rb we can define multiple Padrino::Application. - # - def mounted_apps_of(file) - file = figure_path(file) - Padrino.mounted_apps.find_all { |app| File.identical?(file, app.app_file) } - end - - ## - # Returns true if file is in our Padrino.root. - # - def in_root?(file) - # This is better but slow: - # Pathname.new(Padrino.root).find { |f| File.identical?(Padrino.root(f), figure_path(file)) } - figure_path(file).index(Padrino.root) == 0 - end - - ## - # Searches Ruby files in your +Padrino.load_paths+ , Padrino::Application.load_paths - # and monitors them for any changes. - # - def rotation - files_for_rotation.uniq.map do |file| - file = File.expand_path(file) - next if Padrino::Reloader.exclude.any? { |base| file.index(base) == 0 } || !File.exist?(file) - yield file, File.mtime(file) - end.compact - end - - ## - # Creates an array of paths for use in #rotation. - # - def files_for_rotation - files = Padrino.load_paths.map { |path| Dir["#{path}/**/*.rb"] }.flatten - files = files | Padrino.mounted_apps.map { |app| app.app_file } - files = files | Padrino.mounted_apps.map { |app| app.app_obj.dependencies }.flatten - end - end # self - - ## - # This class acts as a Rack middleware to be added to the application stack. - # This middleware performs a check and reload for source files at the start - # of each request, but also respects a specified cool down time - # during which no further action will be taken. - # - class Rack - def initialize(app, cooldown=1) - @app = app - @cooldown = cooldown - @last = (Time.now - cooldown) - end - - # Invoked in order to perform the reload as part of the request stack. - def call(env) - if @cooldown && Time.now > @last + @cooldown - Thread.list.size > 1 ? Thread.exclusive { Padrino.reload! } : Padrino.reload! - @last = Time.now - end - @app.call(env) - end - end - end -end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_csrf_protection.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_csrf_protection.rb deleted file mode 100644 index fd6c7bd7..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_csrf_protection.rb +++ /dev/null @@ -1,80 +0,0 @@ -require File.expand_path(File.dirname(__FILE__) + '/helper') - -describe "Application" do - before { Padrino.clear! } - after { remove_views } - - context 'CSRF protection' do - context "with CSRF protection on" do - before do - mock_app do - enable :sessions - enable :protect_from_csrf - post('/'){ 'HI' } - end - end - - should "not allow requests without tokens" do - post "/" - assert_equal 403, status - end - - should "allow requests with correct tokens" do - post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"} - assert_equal 200, status - end - - should "not allow requests with incorrect tokens" do - post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"} - assert_equal 403, status - end - end - - context "without CSRF protection on" do - before do - mock_app do - enable :sessions - disable :protect_from_csrf - post('/'){ 'HI' } - end - end - - should "allows requests without tokens" do - post "/" - assert_equal 200, status - end - - should "allow requests with correct tokens" do - post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"} - assert_equal 200, status - end - - should "allow requests with incorrect tokens" do - post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"} - assert_equal 200, status - end - end - - context "with optional CSRF protection" do - before do - mock_app do - enable :sessions - enable :protect_from_csrf - set :allow_disabled_csrf, true - post('/on') { 'HI' } - post('/off', :csrf_protection => false) { 'HI' } - end - end - - should "allow access to routes with csrf_protection off" do - post "/off" - assert_equal 200, status - end - - should "not allow access to routes with csrf_protection on" do - post "/on" - assert_equal 403, status - end - end - end -end \ No newline at end of file diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/.document b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/.document similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/.document rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/.document diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/.gitignore b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/.gitignore similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/.gitignore rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/.gitignore diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/.yardopts b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/.yardopts similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/.yardopts rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/.yardopts diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/LICENSE.txt b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/LICENSE.txt similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/LICENSE.txt rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/LICENSE.txt diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/README.rdoc b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/README.rdoc similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/README.rdoc rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/README.rdoc diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/Rakefile b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/Rakefile similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/Rakefile rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/Rakefile diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/bin/padrino b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/bin/padrino similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/bin/padrino rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/bin/padrino diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core.rb similarity index 78% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core.rb index e2ebdd24..7fc58233 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core.rb @@ -14,14 +14,19 @@ require 'padrino-core/server' require 'padrino-core/tasks' require 'padrino-core/module' - -PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= "development" unless defined?(PADRINO_ENV) +if ENV["PADRINO_ENV"] + warn 'Environment variable PADRINO_ENV is deprecated. Please, use RACK_ENV.' + ENV["RACK_ENV"] ||= ENV["PADRINO_ENV"] +end +RACK_ENV = ENV["RACK_ENV"] ||= "development" unless defined?(RACK_ENV) PADRINO_ROOT = ENV["PADRINO_ROOT"] ||= File.dirname(Padrino.first_caller) unless defined?(PADRINO_ROOT) module Padrino class ApplicationLoadError < RuntimeError # @private end + extend Loader + class << self ## # Helper method for file references. @@ -42,13 +47,13 @@ module Padrino end ## - # Helper method that return {PADRINO_ENV}. + # Helper method that return {RACK_ENV}. # # @return [Symbol] # The Padrino Environment. # def env - @_env ||= PADRINO_ENV.to_s.downcase.to_sym + @_env ||= RACK_ENV.to_s.downcase.to_sym end ## @@ -61,18 +66,10 @@ module Padrino # No applications were mounted. # def application - raise ApplicationLoadError, "At least one app must be mounted!" unless Padrino.mounted_apps && Padrino.mounted_apps.any? + raise ApplicationLoadError, "At least one app must be mounted!" unless Padrino.mounted_apps.present? router = Padrino::Router.new Padrino.mounted_apps.each { |app| app.map_onto(router) } - - if middleware.present? - builder = Rack::Builder.new - middleware.each { |c,a,b| builder.use(c, *a, &b) } - builder.run(router) - builder.to_app - else - router - end + middleware.present? ? add_middleware(router) : router end ## @@ -90,21 +87,14 @@ module Padrino # def configure_apps(&block) return unless block_given? - @@_global_configurations ||= [] - @@_global_configurations << block - @_global_configuration = lambda do |app| - @@_global_configurations.each do |configuration| - app.class_eval(&configuration) - end - end + global_configurations << block end ## - # Returns project-wide configuration settings defined in - # {configure_apps} block. + # Stores global configuration blocks. # - def apps_configuration - @_global_configuration + def global_configurations + @_global_configurations ||= [] end ## @@ -119,15 +109,21 @@ module Padrino # @return [NilClass] # def set_encoding - if RUBY_VERSION < '1.9' - $KCODE='u' - else - Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::UTF_8 - end + Encoding.default_external = Encoding::UTF_8 + Encoding.default_internal = Encoding::UTF_8 nil end + ## + # Creates Rack stack with the router added to the middleware chain. + # + def add_middleware(router) + builder = Rack::Builder.new + middleware.each{ |mw,args,block| builder.use(mw, *args, &block) } + builder.run(router) + builder.to_app + end + ## # A Rack::Builder object that allows to add middlewares in front of all # Padrino applications. @@ -161,8 +157,8 @@ module Padrino # @yield [] # The given block will be passed to the initialized middleware. # - def use(m, *args, &block) - middleware << [m, args, block] + def use(mw, *args, &block) + middleware << [mw, args, block] end ## diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application.rb similarity index 61% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application.rb index 67c5c4ab..fed2d1c5 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application.rb @@ -1,12 +1,10 @@ require 'padrino-core/application/flash' require 'padrino-core/application/rendering' require 'padrino-core/application/routing' -require 'padrino-core/application/showexceptions' +require 'padrino-core/application/show_exceptions' +require 'padrino-core/application/authenticity_token' module Padrino - class ApplicationSetupError < RuntimeError - end - ## # Subclasses of this become independent Padrino applications # (stemming from Sinatra::Application). @@ -26,20 +24,24 @@ module Padrino Padrino.logger end + # TODO: Remove this hack after getting rid of thread-unsafe http_router: + alias_method :original_call, :call + def call(*args) + settings.init_mutex.synchronize do + instance_eval{ undef :call } + class_eval{ alias_method :call, :original_call } + instance_eval{ undef :original_call } + super(*args) + end + end + class << self def inherited(base) begun_at = Time.now CALLERS_TO_IGNORE.concat(PADRINO_IGNORE_CALLERS) base.default_configuration! - base.prerequisites.concat([ - File.join(base.root, '/models.rb'), - File.join(base.root, '/models/**/*.rb'), - File.join(base.root, '/lib.rb'), - File.join(base.root, '/lib/**/*.rb') - ]).uniq! - Padrino.require_dependencies(base.prerequisites) logger.devel :setup, begun_at, base - super(base) # Loading the subclass inherited method + super(base) end ## @@ -54,10 +56,10 @@ module Padrino # MyApp.reload! # def reload! - logger.devel "Reloading #{settings}" + logger.devel "Reloading application #{settings}" reset! reset_router! - Padrino.require_dependencies(settings.app_file, :force => true) # Reload the app file + Padrino.require_dependencies(settings.app_file, :force => true) require_dependencies default_filters! default_routes! @@ -90,6 +92,26 @@ module Padrino router.routes end + ## + # Returns an absolute path of view in application views folder. + # + # @example + # Admin.view_path 'users/index' #=> "/home/user/test/admin/views/users/index" + # + def view_path(view) + File.expand_path(view, views) + end + + ## + # Returns an absolute path of application layout. + # + # @example + # Admin.layout_path :application #=> "/home/user/test/admin/views/layouts/application" + # + def layout_path(layout) + view_path("layouts/#{layout}") + end + ## # Setup the application by registering initializers, load paths and logger. # Invoked automatically when an application is first instantiated. @@ -103,11 +125,11 @@ module Padrino settings.default_routes! settings.default_errors! if defined?(I18n) + Reloader.special_files += settings.locale_path I18n.load_path << settings.locale_path I18n.reload! end @_configured = true - @_configured end ## @@ -127,7 +149,13 @@ module Padrino # directory that need to be added to +$LOAD_PATHS+ from this application # def load_paths - @_load_paths ||= %w[models lib mailers controllers helpers].map { |path| File.join(settings.root, path) } + @_load_paths ||= [ + 'models', + 'lib', + 'mailers', + 'controllers', + 'helpers', + ].map { |path| File.join(settings.root, path) } end ## @@ -143,8 +171,14 @@ module Padrino # def dependencies [ - 'urls.rb', 'config/urls.rb', 'mailers/*.rb', 'mailers.rb', - 'controllers/**/*.rb', 'controllers.rb', 'helpers/**/*.rb', 'helpers.rb' + 'urls.rb', + 'config/urls.rb', + 'mailers/*.rb', + 'mailers.rb', + 'controllers/**/*.rb', + 'controllers.rb', + 'helpers/**/*.rb', + 'helpers.rb', ].map { |file| Dir[File.join(settings.root, file)] }.flatten end @@ -167,38 +201,67 @@ module Padrino @_prerequisites ||= [] end + def default(option, *args, &block) + set(option, *args, &block) unless respond_to?(option) + end + protected + ## # Defines default settings for Padrino application. # def default_configuration! - # Overwriting Sinatra defaults - set :app_file, File.expand_path(caller_files.first || $0) # Assume app file is first caller + set :app_file, File.expand_path(caller_files.first || $0) + set :app_name, settings.to_s.underscore.to_sym + set :environment, Padrino.env set :reload, Proc.new { development? } set :logging, Proc.new { development? } + set :method_override, true - set :sessions, false - set :public_folder, Proc.new { Padrino.root('public', uri_root) } - set :views, Proc.new { File.join(root, 'views') } - set :images_path, Proc.new { File.join(public_folder, 'images') } - set :protection, true - - set :haml, { :ugly => (Padrino.env == :production) } if defined?(Haml) - - # Padrino specific - set :uri_root, '/' - set :app_name, settings.to_s.underscore.to_sym set :default_builder, 'StandardFormBuilder' + + # TODO: Remove this hack after getting rid of thread-unsafe http_router: + set :init_mutex, Mutex.new + + # TODO: Remove this line after sinatra version up. + set :add_charset, %w[javascript xml xhtml+xml].map {|t| "application/#{t}" } + + default_paths! + default_security! + global_configuration! + setup_prerequisites! + end + + def setup_prerequisites! + prerequisites.concat(default_prerequisites).uniq! + Padrino.require_dependencies(prerequisites) + end + + def default_paths! + set :locale_path, Proc.new { Dir.glob File.join(root, 'locale/**/*.{rb,yml}') } + set :views, Proc.new { File.join(root, 'views') } + + set :uri_root, '/' + set :public_folder, Proc.new { Padrino.root('public', uri_root) } + set :images_path, Proc.new { File.join(public_folder, 'images') } + end + + def default_security! + set :protection, :except => :path_traversal set :authentication, false - - set :locale_path, Proc.new { Dir[File.join(settings.root, '/locale/**/*.{rb,yml}')] } - - # Authenticity token + set :sessions, false set :protect_from_csrf, false set :allow_disabled_csrf, false - # Load the Global Configurations - class_eval(&Padrino.apps_configuration) if Padrino.apps_configuration + end + + ## + # Applies global padrino configuration blocks to current application. + # + def global_configuration! + Padrino.global_configurations.each do |configuration| + class_eval(&configuration) + end end ## @@ -220,9 +283,7 @@ module Padrino # def default_filters! before do - unless @_content_type - response['Content-Type'] = 'text/html;charset=utf-8' - end + response['Content-Type'] = 'text/html;charset=utf-8' unless @_content_type end end @@ -249,7 +310,20 @@ module Padrino Padrino.require_dependencies(dependencies, :force => true) end + ## + # Returns globs of default paths of application prerequisites. + # + def default_prerequisites + [ + '/models.rb', + '/models/**/*.rb', + '/lib.rb', + '/lib/**/*.rb', + ].map{ |glob| File.join(settings.root, glob) } + end + private + # Overrides the default middleware for Sinatra based on Padrino conventions. # Also initializes the application after setting up the middleware. def setup_default_middleware(builder) @@ -267,9 +341,33 @@ module Padrino # sets up csrf protection for the app: def setup_csrf_protection(builder) - if protect_from_csrf? && !sessions? - raise(<<-ERROR) -`protect_from_csrf` is activated, but `sessions` are not. To enable csrf + check_csrf_protection_dependency + + if protect_from_csrf? + options = options_for_csrf_protection_setup + options.merge!(protect_from_csrf) if protect_from_csrf.kind_of?(Hash) + builder.use(options[:except] ? Padrino::AuthenticityToken : Rack::Protection::AuthenticityToken, options) + end + end + + # returns the options used in the builder for csrf protection setup + def options_for_csrf_protection_setup + options = { :logger => logger } + + if allow_disabled_csrf? + options.merge!({ + :reaction => :report, + :report_key => 'protection.csrf.failed' + }) + end + options + end + + # throw an exception if the protect_from_csrf is active but sessions not. + def check_csrf_protection_dependency + if (protect_from_csrf? && !sessions?) && !defined?(Padrino::IGNORE_CSRF_SETUP_WARNING) + warn(<<-ERROR) +`protect_from_csrf` is activated, but `sessions` seem to be off. To enable csrf protection, use: enable :sessions @@ -277,19 +375,12 @@ protection, use: or deactivate protect_from_csrf: disable :protect_from_csrf -ERROR - end - if protect_from_csrf? - if allow_disabled_csrf? - builder.use Rack::Protection::AuthenticityToken, - :reaction => :report, - :report_key => 'protection.csrf.failed', - :logger => logger - else - builder.use Rack::Protection::AuthenticityToken, - :logger => logger - end +If you use a different session store, ignore this warning using: + + # in boot.rb: + Padrino::IGNORE_CSRF_SETUP_WARNING = true + ERROR end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/authenticity_token.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/authenticity_token.rb new file mode 100644 index 00000000..2515c864 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/authenticity_token.rb @@ -0,0 +1,25 @@ +module Padrino + class AuthenticityToken < Rack::Protection::AuthenticityToken + def initialize(app, options = {}) + @app = app + @except = options[:except] + @except = Array(@except) unless @except.is_a?(Proc) + super + end + + def call(env) + if except?(env) + @app.call(env) + else + super + end + end + + def except?(env) + return false unless @except + path_info = env['PATH_INFO'] + @except.is_a?(Proc) ? @except.call(env) : @except.any?{|path| + path.is_a?(Regexp) ? path.match(path_info) : path == path_info } + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/flash.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/flash.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/flash.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/flash.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering.rb similarity index 92% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering.rb index 4b71d840..cda7a205 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering.rb @@ -195,14 +195,16 @@ module Padrino options[:layout] = @layout if options[:layout].nil? || options[:layout] == true # Resolve layouts similar to in Rails if options[:layout].nil? && !settings.templates.has_key?(:layout) - layout_path, layout_engine = *resolved_layout + layout_path = settings.fetch_layout_path(options[:layout]) + is_included_extension = %w[.slim .erb .haml].include?(File.extname(layout_path.to_s)) + layout_path, layout_engine = *(is_included_extension ? resolve_template(layout_path) : resolved_layout) # We need to force layout false so sinatra don't try to render it options[:layout] = layout_path || false - options[:layout] = false unless layout_engine == engine # TODO allow different layout engine + options[:layout] = false unless is_included_extension ? layout_engine : layout_engine == engine options[:layout_engine] = layout_engine || engine if options[:layout] elsif options[:layout].present? - options[:layout] = settings.fetch_layout_path(options[:layout] || @layout) + options[:layout], options[:layout_engine] = *resolve_template(settings.fetch_layout_path(options[:layout]), options) end # Default to original layout value if none found. options[:layout] ||= layout_was @@ -272,15 +274,21 @@ module Padrino end # Resolve view path and options. - options.reverse_merge!(DEFAULT_RENDERING_OPTIONS) + options = DEFAULT_RENDERING_OPTIONS.merge(options) view_path = options.delete(:views) || settings.views || "./views" target_extension = File.extname(template_path)[1..-1] || "none" # explicit template extension template_path = template_path.chomp(".#{target_extension}") + template_glob = + if respond_to?(:request) && request.controller.present? + File.join("{,#{request.controller}}", template_path) + else + template_path + end # Generate potential template candidates - templates = Dir[File.join(view_path, template_path) + ".*"].map do |file| + templates = Dir[File.join(view_path, template_glob) + ".*"].map do |file| template_engine = File.extname(file)[1..-1].to_sym # Retrieves engine extension - template_file = file.sub(view_path, '').chomp(".#{template_engine}").to_sym # retrieves template filename + template_file = file.squeeze('/').sub(view_path, '').chomp(".#{template_engine}").to_sym # retrieves template filename [template_file, template_engine] unless IGNORE_FILE_PATTERN.any? { |pattern| template_engine.to_s =~ pattern } end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/erubis.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/erubis.rb similarity index 68% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/erubis.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/erubis.rb index b53433c0..c225c71c 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/erubis.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/erubis.rb @@ -40,15 +40,18 @@ begin def render(*args) app = args.first app_class = app.class - @padrino_app = app.kind_of?(Padrino::Application) || - (app_class.respond_to?(:erb) && app_class.erb[:engine_class] == Padrino::Erubis::SafeBufferTemplate) + @is_padrino_app = app.kind_of?(Padrino::Application) || + (app_class.respond_to?(:erb) && app_class.erb[:engine_class] == Padrino::Erubis::SafeBufferTemplate) super end + ## + # In preamble we need a flag `__in_erb_template` and SafeBuffer for padrino apps. + # def precompiled_preamble(locals) - buf = @padrino_app ? "ActiveSupport::SafeBuffer.new" : "''" - old_postamble = super.split("\n")[0..-2] - [old_postamble, "#{@outvar} = _buf = (#{@outvar} || #{buf})"].join("\n") + original = super + return original unless @is_padrino_app + "__in_erb_template = true\n" << original.rpartition("\n").first << "#{@outvar} = _buf = ActiveSupport::SafeBuffer.new\n" end end end @@ -57,8 +60,9 @@ begin Tilt.prefer(Padrino::Erubis::Template, :erb) if defined? Padrino::Rendering - Padrino::Rendering.engine_configurations[:erb] = - {:engine_class => Padrino::Erubis::SafeBufferTemplate} + Padrino::Rendering.engine_configurations[:erb] = { + :engine_class => Padrino::Erubis::SafeBufferTemplate, + } end rescue LoadError end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/haml.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/haml.rb similarity index 82% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/haml.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/haml.rb index 064ea41a..c1e67903 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/rendering/extensions/haml.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/haml.rb @@ -17,8 +17,9 @@ begin end if defined? Padrino::Rendering - Padrino::Rendering.engine_configurations[:haml] = - {:escape_html => true} + Padrino::Rendering.engine_configurations[:haml] = { + :escape_html => true, + } class Tilt::HamlTemplate include Padrino::Rendering::SafeTemplate diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/slim.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/slim.rb new file mode 100644 index 00000000..afd9ad56 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/rendering/extensions/slim.rb @@ -0,0 +1,21 @@ +begin + require 'slim' + + if defined? Padrino::Rendering + Padrino::Rendering.engine_configurations[:slim] = { + :generator => Temple::Generators::RailsOutputBuffer, + :buffer => "@_out_buf", + :use_html_safe => true, + :disable_capture => true, + } + + class Slim::Template + include Padrino::Rendering::SafeTemplate + + def precompiled_preamble(locals) + "__in_slim_template = true\n" << super + end + end + end +rescue LoadError +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/routing.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/routing.rb similarity index 92% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/routing.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/routing.rb index 526bbdba..8a3c7944 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/routing.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/routing.rb @@ -15,6 +15,19 @@ class Sinatra::Request end end +## +# This patches Sinatra to accept UTF-8 urls on JRuby 1.7.6 +# +if RUBY_ENGINE == 'jruby' && defined?(JRUBY_VERSION) && JRUBY_VERSION > '1.7.4' + class Sinatra::Base + class << self + alias_method :old_generate_method, :generate_method + def generate_method(method_name, &block) + old_generate_method(method_name.to_sym, &block) + end + end + end +end class HttpRouter def rewrite_partial_path_info(env, request); end @@ -61,7 +74,7 @@ class HttpRouter class Route VALID_HTTP_VERBS.replace %w[GET POST PUT PATCH DELETE HEAD OPTIONS LINK UNLINK] - attr_accessor :use_layout, :controller, :action, :cache, :cache_key, :cache_expires_in, :parent + attr_accessor :use_layout, :controller, :action, :cache, :cache_key, :cache_expires, :parent def before_filters(&block) @_before_filters ||= [] @@ -172,6 +185,7 @@ class HttpRouter env['router.request'] = request env['router.params'] ||= {} #{"env['router.params'].merge!(Hash[#{param_names.inspect}.zip(request.params)])" if dynamic?} + env['router.params'] = env['router.params'].with_indifferent_access @router.rewrite#{"_partial" if route.match_partially}_path_info(env, request) response = @router.process_destination_path(#{path_ivar}, env) return response unless router.pass_on_response(response) @@ -193,7 +207,7 @@ module Padrino def apply?(request) detect = @args.any? do |arg| case arg - when Symbol then request.route_obj && (request.route_obj.name == arg or request.route_obj.name == [@scoped_controller, arg].flatten.join("_").to_sym) + when Symbol then request.route_obj && (request.route_obj.name == arg or request.route_obj.name == [@scoped_controller, arg].flatten.join(" ").to_sym) else arg === request.path_info end end || @options.any? do |name, val| @@ -500,7 +514,13 @@ module Padrino def compiled_router if @deferred_routes - deferred_routes.each { |routes| routes.each { |(route, dest)| route.to(dest) } } + deferred_routes.each do |routes| + routes.each do |(route, dest)| + route.to(dest) + route.before_filters.flatten! + route.after_filters.flatten! + end + end @deferred_routes = nil router.sort! end @@ -557,10 +577,10 @@ module Padrino def url(*args) params = args.extract_options! # parameters is hash at end names, params_array = args.partition{|a| a.is_a?(Symbol)} - name = names.join("_").to_sym # route name is concatenated with underscores + name = names[0, 2].join(" ").to_sym # route name is concatenated with underscores if params.is_a?(Hash) params[:format] = params[:format].to_s unless params[:format].nil? - params = value_to_param(params) + params = value_to_param(params.symbolize_keys) end url = if params_array.empty? @@ -568,10 +588,7 @@ module Padrino else compiled_router.path(name, *(params_array << params)) end - url[0,0] = conform_uri(uri_root) if defined?(uri_root) - url[0,0] = conform_uri(ENV['RACK_BASE_URI']) if ENV['RACK_BASE_URI'] - url = "/" if url.blank? - url + rebase_url(url) rescue HttpRouter::InvalidRouteException route_error = "route mapping for url(#{name.inspect}) could not be found!" raise Padrino::Routing::UnrecognizedException.new(route_error) @@ -586,6 +603,17 @@ module Padrino route('HEAD', path, *args, &block) end + def rebase_url(url) + if url.start_with?('/') + new_url = '' + new_url << conform_uri(uri_root) if defined?(uri_root) + new_url << conform_uri(ENV['RACK_BASE_URI']) if ENV['RACK_BASE_URI'] + new_url << url + else + url.blank? ? '/' : url + end + end + private # Parse params from the url method def value_to_param(value) @@ -702,8 +730,8 @@ module Padrino invoke_hook(:padrino_route_added, route, verb, path, args, options, block) # Add Application defaults. - route.before_filters.concat(@filters[:before]) - route.after_filters.concat(@filters[:after]) + route.before_filters << @filters[:before] + route.after_filters << @filters[:after] if @_controller route.use_layout = @layout route.controller = Array(@_controller)[0].to_s @@ -786,7 +814,7 @@ module Padrino name = options.delete(:name) if name.nil? && options.key?(:name) if name controller_name = controller.join("_") - name = "#{controller_name}_#{name}".to_sym unless controller_name.blank? + name = "#{controller_name} #{name}".to_sym unless controller_name.blank? end # Merge in option defaults. @@ -856,9 +884,10 @@ module Padrino def provides(*types) @_use_format = true condition do - mime_types = types.map { |t| mime_type(t) }.compact - url_format = params[:format].to_sym if params[:format] - accepts = request.accept.map(&:to_str) + mime_types = types.map { |t| mime_type(t) }.compact + url_format = params[:format].to_sym if params[:format] + accepts = request.accept.map(&:to_str) + accepts.clear if accepts == ["*/*"] # Per rfc2616-sec14: # Assume */* if no ACCEPT header is given. @@ -890,7 +919,12 @@ module Padrino if matched_format @_content_type = url_format || accept_format || :html - content_type(@_content_type, :charset => 'utf-8') + + if @_content_type != :json + content_type(@_content_type, :charset => 'utf-8') + else + content_type(@_content_type) + end end matched_format @@ -924,17 +958,24 @@ module Padrino # url(:show, :id => 1) # url(:show, :name => :test) # url(:show, 1) - # url("/foo") + # url("/foo", false, false) # # @see Padrino::Routing::ClassMethods#url # def url(*args) - # Delegate to Sinatra 1.2 for simple url("/foo") - # http://www.sinatrarb.com/intro#Generating%20URLs - return super if args.first.is_a?(String) && !args[1].is_a?(Hash) - - # Delegate to Padrino named route URL generation. - settings.url(*args) + if args.first.is_a?(String) + url_path = settings.rebase_url(args.shift) + if args.empty? + url_path + else + # Delegate sinatra-style urls to Sinatra. Ex: url("/foo", false, false) + # http://www.sinatrarb.com/intro#Generating%20URLs + super url_path, *args + end + else + # Delegate to Padrino named route URL generation. + settings.url(*args) + end end alias :url_for :url @@ -944,9 +985,15 @@ module Padrino # @example # absolute_url(:show, :id => 1) # => http://example.com/show?id=1 # absolute_url(:show, 24) # => https://example.com/admin/show/24 + # absolute_url('/foo/bar') # => https://example.com/admin/foo/bar + # absolute_url('baz') # => https://example.com/admin/foo/baz # - def absolute_url( *args ) - uri url(*args), true, false + def absolute_url(*args) + url_path = args.shift + if url_path.is_a?(String) && !url_path.start_with?('/') + url_path = request.env['PATH_INFO'].rpartition('/').first << '/' << url_path + end + uri url(url_path, *args), true, false end def recognize_path(path) @@ -958,10 +1005,12 @@ module Padrino # def current_path(*path_params) if path_params.last.is_a?(Hash) - path_params[-1] = params.merge(path_params[-1]) + path_params[-1] = params.merge(path_params[-1].with_indifferent_access) else path_params << params end + + path_params[-1] = path_params[-1].symbolize_keys @route.path(*path_params) end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/showexceptions.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/show_exceptions.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/application/showexceptions.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/application/show_exceptions.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/caller.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/caller.rb similarity index 96% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/caller.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/caller.rb index 6b7837b0..f3129eb3 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/caller.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/caller.rb @@ -5,7 +5,7 @@ module Padrino %r{lib/padrino-.*$}, %r{/padrino-.*/(lib|bin)}, %r{/bin/padrino$}, - %r{/sinatra(/(base|main|showexceptions))?\.rb$}, + %r{/sinatra(/(base|main|show_?exceptions))?\.rb$}, %r{lib/tilt.*\.rb$}, %r{lib/rack.*\.rb$}, %r{lib/mongrel.*\.rb$}, diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/adapter.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/adapter.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/adapter.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/adapter.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/base.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/base.rb similarity index 79% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/base.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/base.rb index 81b36de0..2a87cde6 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/base.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/base.rb @@ -18,11 +18,19 @@ module Padrino method_option :daemonize, :type => :boolean, :aliases => "-d", :desc => "Run daemonized in the background." method_option :pid, :type => :string, :aliases => "-i", :desc => "File to store pid." method_option :debug, :type => :boolean, :desc => "Set debugging flags." + method_option :options, :type => :array, :aliases => "-O", :desc => "--options NAME=VALUE NAME2=VALUE2'. pass VALUE to the server as option NAME. If no VALUE, sets it to true. Run '#{$0} --server_options" + method_option :server_options, :type => :boolean, :desc => "Tells the current server handler's options that can be used with --options" + def start prepare :start require File.expand_path("../adapter", __FILE__) require File.expand_path('config/boot.rb') - Padrino::Cli::Adapter.start(options) + + if options[:server_options] + puts server_options(options) + else + Padrino::Cli::Adapter.start(options) + end end desc "stop", "Stops the Padrino application (alternatively use 'st')." @@ -116,7 +124,7 @@ module Padrino help(task.to_s) raise SystemExit end - ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||= options.environment.to_s + ENV["RACK_ENV"] ||= options.environment.to_s chdir(options.chdir) unless File.exist?('config/boot.rb') puts "=> Could not find boot file in: #{options.chdir}/config/boot.rb !!!" @@ -124,6 +132,29 @@ module Padrino end end + # https://github.com/rack/rack/blob/master/lib/rack/server.rb\#L100 + def server_options(options) + begin + info = [] + server = Rack::Handler.get(options[:server]) || Rack::Handler.default(options) + if server && server.respond_to?(:valid_options) + info << "" + info << "Server-specific options for #{server.name}:" + + has_options = false + server.valid_options.each do |name, description| + next if name.to_s.match(/^(Host|Port)[^a-zA-Z]/) # ignore handler's host and port options, we do our own. + info << " -O %-21s %s" % [name, description] + has_options = true + end + return "" if !has_options + end + info.join("\n") + rescue NameError + return "Warning: Could not find handler specified (#{options[:server] || 'default'}) to determine handler-specific options" + end + end + protected def self.banner(task=nil, *args) diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/console.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/console.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/console.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/console.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/rake.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/rake.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/rake.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/rake.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/rake_tasks.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/rake_tasks.rb similarity index 85% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/rake_tasks.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/rake_tasks.rb index bed51675..9d3e1e4d 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/cli/rake_tasks.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/cli/rake_tasks.rb @@ -16,6 +16,16 @@ task :environment do end end +# Loads skeleton Padrino environment, no models, no application settings. +task :skeleton do + module Padrino::Reloader + def self.safe_load(file, options) + super unless file.include?('/models/') + end + end + require File.expand_path('config/boot.rb', Rake.application.original_dir) +end + desc "Generate a secret key" task :secret do shell.say SecureRandom.hex(32) diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/command.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/command.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/command.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/command.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/images/404.png b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/images/404.png similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/images/404.png rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/images/404.png diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/images/500.png b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/images/500.png similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/images/500.png rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/images/500.png diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/loader.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/loader.rb similarity index 64% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/loader.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/loader.rb index 894a0ca2..8b75276c 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/loader.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/loader.rb @@ -1,5 +1,5 @@ module Padrino - class << self + module Loader ## # Hooks to be called before a load/reload. # @@ -40,17 +40,6 @@ module Padrino @_after_load end - ## - # The used +$LOAD_PATHS+ from Padrino. - # - # @return [Array] - # The load paths used by Padrino. - # - def load_paths - @_load_paths_was = %w(lib models shared).map { |path| Padrino.root(path) } - @_load_paths ||= @_load_paths_was - end - ## # Requires necessary dependencies as well as application files from root # lib and models. @@ -60,21 +49,18 @@ module Padrino # def load! return false if loaded? - t = Time.now - + began_at = Time.now @_called_from = first_caller - Padrino.set_encoding - Padrino.set_load_paths(*load_paths) - Padrino::Logger.setup! # Initialize our logger - Padrino.require_dependencies("#{root}/config/database.rb", :nodeps => true) # Be sure to don't remove constants from dbs. - Padrino::Reloader.lock! # Now we can remove constant from here to down - Padrino.before_load.each(&:call) # Run before hooks - Padrino.dependency_paths.each { |path| Padrino.require_dependencies(path) } - Padrino.after_load.each(&:call) # Run after hooks - Padrino::Reloader.run! + set_encoding + set_load_paths(*load_paths) + Logger.setup! + require_dependencies("#{root}/config/database.rb") + Reloader.lock! + before_load.each(&:call) + require_dependencies(*dependency_paths) + after_load.each(&:call) + logger.devel "Loaded Padrino in #{Time.now - began_at} seconds" Thread.current[:padrino_loaded] = true - - Padrino.logger.devel "Loaded Padrino in #{Time.now - t} seconds" end ## @@ -83,14 +69,14 @@ module Padrino # @return [NilClass] # def clear! - Padrino.clear_middleware! - Padrino.mounted_apps.clear + clear_middleware! + mounted_apps.clear @_load_paths = nil @_dependency_paths = nil @_global_configuration = nil - Padrino.before_load.clear - Padrino.after_load.clear - Padrino::Reloader.clear! + before_load.clear + after_load.clear + Reloader.clear! Thread.current[:padrino_loaded] = nil end @@ -98,10 +84,10 @@ module Padrino # Method for reloading required applications and their files. # def reload! - return unless Padrino::Reloader.changed? - Padrino.before_load.each(&:call) # Run before hooks - Padrino::Reloader.reload! # detects the modified files - Padrino.after_load.each(&:call) # Run after hooks + return unless Reloader.changed? + before_load.each(&:call) + Reloader.reload! + after_load.each(&:call) end ## @@ -147,38 +133,55 @@ module Padrino # require_dependencies("#{Padrino.root}/lib/**/*.rb") # def require_dependencies(*paths) - options = paths.extract_options! - - # Extract all files to load - files = paths.flatten.map { |path| Dir[path] }.flatten.uniq.sort + options = paths.extract_options!.merge( :cyclic => true ) + files = paths.flatten.map{|path| Dir[path].sort_by{|v| v.count('/') }}.flatten.uniq while files.present? - errors, failed = [], [] + error, fatal, loaded = nil, nil, nil - size_at_start = files.size - - # Now we try to require our dependencies, we dup files - # so we don't perform delete on the original array during - # iteration, this prevent problems with Rubinus files.dup.each do |file| begin - Padrino::Reloader.safe_load(file, options.dup) + Reloader.safe_load(file, options) files.delete(file) + loaded = true rescue NameError, LoadError => e - Padrino.logger.devel "Problem while loading #{file}: #{e}" - errors << e - failed << file + logger.devel "Cyclic dependency reload for #{e.class}: #{e.message}" + error = e rescue Exception => e - raise e + fatal = e + break end end - # Stop processing if nothing loads or if everything has loaded - raise errors.last if files.size == size_at_start && files.present? - break if files.empty? + if fatal || !loaded + e = fatal || error + logger.error "#{e.class}: #{e.message}; #{e.backtrace.first}" + raise e + end end end + ## + # Concat to +$LOAD_PATH+ the given paths. + # + # @param [Array] paths + # The paths to concat. + # + def set_load_paths(*paths) + load_paths.concat(paths).uniq! + $LOAD_PATH.concat(paths).uniq! + end + + ## + # The used +$LOAD_PATHS+ from Padrino. + # + # @return [Array] + # The load paths used by Padrino. + # + def load_paths + @_load_paths ||= load_paths_was.dup + end + ## # Returns default list of path globs to load as dependencies. # Appends custom dependency patterns to the be loaded for Padrino. @@ -190,35 +193,32 @@ module Padrino # Padrino.dependency_paths << "#{Padrino.root}/uploaders/*.rb" # def dependency_paths - @_dependency_paths ||= (dependency_paths_was + Array(module_paths)) - end - - ## - # Concat to +$LOAD_PATH+ the given paths. - # - # @param [Array] paths - # The paths to concat. - # - def set_load_paths(*paths) - $:.concat(paths); load_paths.concat(paths) - $:.uniq!; load_paths.uniq! + @_dependency_paths ||= dependency_paths_was + module_paths end private def module_paths - Padrino.modules.map(&:dependency_paths).flatten! + modules.map(&:dependency_paths).flatten + end + + def load_paths_was + @_load_paths_was ||= [ + "#{root}/lib", + "#{root}/models", + "#{root}/shared", + ].freeze end def dependency_paths_was - [ + @_dependency_paths_was ||= [ "#{root}/config/database.rb", "#{root}/lib/**/*.rb", - "#{root}/shared/lib/**/*.rb", "#{root}/models/**/*.rb", + "#{root}/shared/lib/**/*.rb", "#{root}/shared/models/**/*.rb", "#{root}/config/apps.rb" - ] + ].freeze end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/cs.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/cs.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/cs.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/cs.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/da.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/da.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/da.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/da.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/de.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/de.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/de.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/de.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/en.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/en.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/en.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/en.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/es.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/es.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/es.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/es.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/fr.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/fr.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/fr.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/fr.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/hu.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/hu.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/hu.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/hu.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/it.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/it.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/it.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/it.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ja.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/ja.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ja.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/ja.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/lv.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/lv.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/lv.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/lv.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/nl.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/nl.yml similarity index 93% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/nl.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/nl.yml index 868087be..905d40b3 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/nl.yml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/nl.yml @@ -11,7 +11,7 @@ nl: day_names: [zondag, maandag, dinsdag, woensdag, donderdag, vrijdag, zaterdag] abbr_day_names: [zo, ma, di, wo, do, vr, za] - month_names: [~, januari, februari, maart, april, mei, juni, juli, augustus, september, oktober, november] + month_names: [~, januari, februari, maart, april, mei, juni, juli, augustus, september, oktober, november, december] abbr_month_names: [~, jan, feb, maa, apr, mei, jun, jul, aug, sep, okt, nov, dec] order: - day diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/no.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/no.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/no.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/no.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/pl.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/pl.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/pl.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/pl.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/pt_br.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/pt_br.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/pt_br.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/pt_br.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ro.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/ro.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ro.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/ro.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ru.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/ru.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/ru.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/ru.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/sv.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/sv.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/sv.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/sv.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/tr.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/tr.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/tr.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/tr.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/uk.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/uk.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/uk.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/uk.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/zh_cn.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/zh_cn.yml similarity index 75% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/zh_cn.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/zh_cn.yml index 1cde0a12..d5aed381 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/zh_cn.yml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/zh_cn.yml @@ -4,9 +4,9 @@ zh_cn: # Use the strftime parameters for formats. # When no format has been given, it uses default. # You can provide other formats here if you like! - default: "%Y 年 %m 月 %d 日" - short: "%b 月 %d 日" - long: "公元 %Y 年 %B 月 %d 日" + default: "%Y年%m月%d日" + short: "%b月%d日" + long: "%Y年%B月%d日" only_day: "%e" day_names: [星期日, 星期一, 星期二, 星期三, 星期四, 星期五, 星期六] @@ -20,9 +20,9 @@ zh_cn: time: formats: - default: "%Y 年 %b 月 %d 日 %H:%M:%S %z" - short: "%d 月 %b 日 %H:%M" - long: "%Y 年 %B 月 %d 日 %H 时 %M 分" + default: "%Y年%b月%d日 %H:%M:%S %z" + short: "%b月%d日 %H:%M" + long: "%Y年%B%d日 %H时%M分" am: "上午" pm: "下午" diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/zh_tw.yml b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/zh_tw.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/locale/zh_tw.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/locale/zh_tw.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/logger.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/logger.rb similarity index 98% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/logger.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/logger.rb index bd863f8b..ad4f6645 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/logger.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/logger.rb @@ -52,10 +52,10 @@ module Padrino # :devel:: Development-related information that is unnecessary in debug mode # Levels = { - :fatal => 7, - :error => 6, - :warn => 4, - :info => 3, + :fatal => 4, + :error => 3, + :warn => 2, + :info => 1, :debug => 0, :devel => -1, } unless defined?(Levels) @@ -194,13 +194,13 @@ module Padrino # def colorize(string, *colors) colors.each do |c| - string = string.send(c) + string = string.colorize(c) end string end def stylized_level(level) - style = ColoredLevels[level].map { |c| "\e[%dm" % String.colors[c] } * '' + style = ColoredLevels[level].map { |c| "\e[%dm" % String::Colorizer.colors[c] } * '' [style, super, "\e[0m"] * '' end end @@ -280,7 +280,7 @@ module Padrino stream = case config[:stream] when :to_file - FileUtils.mkdir_p(Padrino.root('log')) unless File.exists?(Padrino.root('log')) + FileUtils.mkdir_p(Padrino.root('log')) unless File.exist?(Padrino.root('log')) File.new(Padrino.root('log', "#{Padrino.env}.log"), 'a+') when :null then StringIO.new when :stdout then $stdout diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/module.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/module.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/module.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/module.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/mounter.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/mounter.rb similarity index 91% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/mounter.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/mounter.rb index 76901dab..1bb9086e 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/mounter.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/mounter.rb @@ -8,10 +8,11 @@ module Padrino # Mounter.new("blog_app", :app_file => "/path/to/blog/app.rb").to("/blog") # class Mounter + DEFAULT_CASCADE = [404, 405] class MounterException < RuntimeError end - attr_accessor :name, :uri_root, :app_file, :app_class, :app_root, :app_obj, :app_host + attr_accessor :name, :uri_root, :app_file, :app_class, :app_root, :app_obj, :app_host, :cascade ## # @param [String, Padrino::Application] name @@ -31,8 +32,9 @@ module Padrino @app_file = options[:app_file] || locate_app_file @app_obj = options[:app_obj] || app_constant || locate_app_object ensure_app_file! || ensure_app_object! - @app_root = options[:app_root] || File.dirname(@app_file) + @app_root = options[:app_root] || (@app_obj.respond_to?(:root) && @app_obj.root || File.dirname(@app_file)) @uri_root = "/" + @cascade = options[:cascade] ? true == options[:cascade] ? DEFAULT_CASCADE.dup : Array(options[:cascade]) : [] Padrino::Reloader.exclude_constants << @app_class end @@ -82,11 +84,12 @@ module Padrino def map_onto(router) app_data, app_obj = self, @app_obj app_obj.set :uri_root, app_data.uri_root - app_obj.set :app_name, app_data.name + app_obj.set :app_name, app_data.app_obj.app_name.to_s app_obj.set :app_file, app_data.app_file unless ::File.exist?(app_obj.app_file) app_obj.set :root, app_data.app_root unless app_data.app_root.blank? - app_obj.set :public_folder, Padrino.root('public', app_data.uri_root) unless File.exists?(app_obj.public_folder) + app_obj.set :public_folder, Padrino.root('public', app_data.uri_root) unless File.exist?(app_obj.public_folder) app_obj.set :static, File.exist?(app_obj.public_folder) if app_obj.nil? + app_obj.set :cascade, app_data.cascade app_obj.setup_application! # Initializes the app here with above settings. router.map(:to => app_obj, :path => app_data.uri_root, :host => app_data.app_host) end @@ -106,7 +109,9 @@ module Padrino # def named_routes app_obj.routes.map { |route| - name_array = "(#{route.name.to_s.split("_").map { |piece| %Q[:#{piece}] }.join(", ")})" + route_name = route.name.to_s + route_name.sub!(/^#{route.controller} /, "") if route.controller + name_array = "(#{route.controller ? %Q[:#{route.controller}] + ", " : ""}:#{route_name})" request_method = route.request_methods.first next if route.name.blank? || request_method == 'HEAD' original_path = route.original_path.is_a?(Regexp) ? route.original_path.inspect : route.original_path diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader.rb new file mode 100644 index 00000000..0a56e42e --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader.rb @@ -0,0 +1,250 @@ +require 'pathname' +require 'padrino-core/reloader/rack' +require 'padrino-core/reloader/storage' + +module Padrino + ## + # High performance source code reloader middleware + # + module Reloader + ## + # This reloader is suited for use in a many environments because each file + # will only be checked once and only one system call to stat(2) is made. + # + # Please note that this will not reload files in the background, and does so + # only when explicitly invoked. + # + extend self + + # The modification times for every file in a project. + MTIMES = {} + + ## + # Specified folders can be excluded from the code reload detection process. + # Default excluded directories at Padrino.root are: test, spec, features, tmp, config, db and public + # + def exclude + @_exclude ||= Set.new %w(test spec tmp features config public db).map{ |path| Padrino.root(path) } + end + + ## + # Specified constants can be excluded from the code unloading process. + # + def exclude_constants + @_exclude_constants ||= Set.new + end + + ## + # Specified constants can be configured to be reloaded on every request. + # Default included constants are: [none] + # + def include_constants + @_include_constants ||= Set.new + end + + ## + # Reload apps and files with changes detected. + # + def reload! + rotation do |file| + next unless file_changed?(file) + reload_special(file) || reload_regular(file) + end + end + + ## + # Remove files and classes loaded with stat + # + def clear! + MTIMES.clear + Storage.clear! + end + + ## + # Returns true if any file changes are detected. + # + def changed? + rotation do |file| + break true if file_changed?(file) + end + end + + ## + # We lock dependencies sets to prevent reloading of protected constants + # + def lock! + klasses = ObjectSpace.classes do |klass| + klass._orig_klass_name.split('::').first + end + klasses |= Padrino.mounted_apps.map(&:app_class) + exclude_constants.merge(klasses) + end + + ## + # A safe Kernel::require which issues the necessary hooks depending on results + # + def safe_load(file, options={}) + began_at = Time.now + file = figure_path(file) + return unless options[:force] || file_changed?(file) + + Storage.prepare(file) # might call #safe_load recursively + logger.devel(file_new?(file) ? :loading : :reload, began_at, file) + begin + with_silence{ require(file) } + Storage.commit(file) + update_modification_time(file) + rescue Exception => e + unless options[:cyclic] + logger.error "#{e.class}: #{e.message}; #{e.backtrace.first}" + logger.error "Failed to load #{file}; removing partially defined constants" + end + Storage.rollback(file) + raise e + end + end + + ## + # Removes the specified class and constant. + # + def remove_constant(const) + return if constant_excluded?(const) + base, _, object = const.to_s.rpartition('::') + base = base.empty? ? Object : base.constantize + base.send :remove_const, object + logger.devel "Removed constant #{const} from #{base}" + rescue NameError + end + + ## + # Returns the list of special tracked files for Reloader. + # + def special_files + @special_files ||= Set.new + end + + ## + # Sets the list of special tracked files for Reloader. + # + def special_files=(files) + @special_files = Set.new(files) + end + + private + + ## + # Returns absolute path of the file. + # + def figure_path(file) + return file if Pathname.new(file).absolute? + $LOAD_PATH.each do |path| + found = File.join(path, file) + return File.expand_path(found) if File.file?(found) + end + file + end + + ## + # Reloads the file if it's special. For now it's only I18n locale files. + # + def reload_special(file) + return unless special_files.any?{ |f| File.identical?(f, file) } + if defined?(I18n) + began_at = Time.now + I18n.reload! + update_modification_time(file) + logger.devel :reload, began_at, file + end + true + end + + ## + # Reloads ruby file and applications dependent on it. + # + def reload_regular(file) + apps = mounted_apps_of(file) + if apps.present? + apps.each { |app| app.app_obj.reload! } + update_modification_time(file) + else + safe_load(file) + reloadable_apps.each do |app| + app.app_obj.reload! if app.app_obj.dependencies.include?(file) + end + end + end + + ### + # Macro for mtime update. + # + def update_modification_time(file) + MTIMES[file] = File.mtime(file) + end + + ### + # Returns true if the file is new or it's modification time changed. + # + def file_changed?(file) + file_new?(file) || File.mtime(file) > MTIMES[file] + end + + ### + # Returns true if the file is new. + # + def file_new?(file) + MTIMES[file].nil? + end + + ## + # Return the mounted_apps providing the app location. + # Can be an array because in one app.rb we can define multiple Padrino::Application. + # + def mounted_apps_of(file) + Padrino.mounted_apps.select { |app| File.identical?(file, app.app_file) } + end + + ## + # Searches Ruby files in your +Padrino.load_paths+ , Padrino::Application.load_paths + # and monitors them for any changes. + # + def rotation + files_for_rotation.each do |file| + file = File.expand_path(file) + next if Reloader.exclude.any? { |base| file.start_with?(base) } || !File.file?(file) + yield file + end + nil + end + + ## + # Creates an array of paths for use in #rotation. + # + def files_for_rotation + files = Set.new + Padrino.load_paths.each{ |path| files += Dir.glob("#{path}/**/*.rb") } + reloadable_apps.each do |app| + files << app.app_file + files += app.app_obj.dependencies + end + files + special_files + end + + def constant_excluded?(const) + (exclude_constants - include_constants).any?{ |c| const._orig_klass_name.start_with?(c) } + end + + def reloadable_apps + Padrino.mounted_apps.select{ |app| app.app_obj.respond_to?(:reload) && app.app_obj.reload? } + end + + ## + # Disables output, yields block, switches output back. + # + def with_silence + verbosity_level, $-v = $-v, nil + yield + ensure + $-v = verbosity_level + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader/rack.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader/rack.rb new file mode 100644 index 00000000..a1b0d059 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader/rack.rb @@ -0,0 +1,26 @@ +module Padrino + module Reloader + ## + # This class acts as a Rack middleware to be added to the application stack. + # This middleware performs a check and reload for source files at the start + # of each request, but also respects a specified cool down time + # during which no further action will be taken. + # + class Rack + def initialize(app, cooldown=1) + @app = app + @cooldown = cooldown + @last = (Time.now - cooldown) + end + + # Invoked in order to perform the reload as part of the request stack. + def call(env) + if @cooldown && Time.now > @last + @cooldown + Thread.list.size > 1 ? Thread.exclusive { Padrino.reload! } : Padrino.reload! + @last = Time.now + end + @app.call(env) + end + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader/storage.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader/storage.rb new file mode 100644 index 00000000..34630e27 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/reloader/storage.rb @@ -0,0 +1,55 @@ +module Padrino + module Reloader + module Storage + extend self + + def clear! + files.each_key do |file| + remove(file) + $LOADED_FEATURES.delete(file) + end + @files = {} + end + + def remove(name) + file = files[name] || return + file[:constants].each{ |constant| Reloader.remove_constant(constant) } + file[:features].each{ |feature| $LOADED_FEATURES.delete(feature) } + files.delete(name) + end + + def prepare(name) + file = remove(name) + @old_entries ||= {} + @old_entries[name] = { + :constants => ObjectSpace.classes, + :features => old_features = Set.new($LOADED_FEATURES.dup) + } + features = file && file[:features] || [] + features.each{ |feature| Reloader.safe_load(feature, :force => true) } + $LOADED_FEATURES.delete(name) if old_features.include?(name) + end + + def commit(name) + entry = { + :constants => ObjectSpace.new_classes(@old_entries[name][:constants]), + :features => Set.new($LOADED_FEATURES) - @old_entries[name][:features] - [name] + } + files[name] = entry + @old_entries.delete(name) + end + + def rollback(name) + new_constants = ObjectSpace.new_classes(@old_entries[name][:constants]) + new_constants.each{ |klass| Reloader.remove_constant(klass) } + @old_entries.delete(name) + end + + private + + def files + @files ||= {} + end + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/router.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/router.rb similarity index 79% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/router.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/router.rb index 1d0a9af9..4ffd78aa 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/router.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/router.rb @@ -62,14 +62,15 @@ module Padrino host = Regexp.new("^#{Regexp.quote(host)}$", true, 'n') unless host.nil? || host.is_a?(Regexp) @mapping << [host, path, match, app] - sort! end # The call handler setup to route a request given the mappings specified. def call(env) + began_at = Time.now path_info = env["PATH_INFO"].to_s script_name = env['SCRIPT_NAME'] http_host = env['HTTP_HOST'] + last_result = nil @mapping.each do |host, path, match, app| next unless host.nil? || http_host =~ host @@ -78,18 +79,16 @@ module Padrino rest = "/" if rest.empty? - return app.call( - env.merge( - 'SCRIPT_NAME' => (script_name + path), - 'PATH_INFO' => rest)) + last_result = app.call(env.merge('SCRIPT_NAME' => script_name + path, 'PATH_INFO' => rest)) + + cascade_setting = app.respond_to?(:cascade) ? app.cascade : true + cascade_statuses = cascade_setting.respond_to?(:include?) ? cascade_setting : Mounter::DEFAULT_CASCADE + break unless cascade_setting && cascade_statuses.include?(last_result[0]) + end + last_result || begin + Padrino::Logger::Rack.new(nil,'/').send(:log, env, 404, {}, began_at) if logger.debug? + [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path_info}"]] end - [404, {"Content-Type" => "text/plain", "X-Cascade" => "pass"}, ["Not Found: #{path_info}"]] - end - - private - - def sort! - @mapping = @mapping.sort_by { |h, p, m, a| -p.size } end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/server.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/server.rb similarity index 90% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/server.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/server.rb index 27395fe4..60d8829d 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/server.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/server.rb @@ -31,6 +31,11 @@ module Padrino FileUtils.mkdir_p(File.dirname(options[:pid])) end options[:server] = detect_rack_handler if options[:server].blank? + if options[:options].is_a?(Array) + parsed_server_options = options.delete(:options).map { |opt| opt.split('=', 2) }.flatten + server_options = Hash[*parsed_server_options].symbolize_keys! + options.merge!(server_options) + end new(options, app).start end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/support_lite.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/support_lite.rb similarity index 89% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/support_lite.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/support_lite.rb index 97cbe518..a511d396 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/support_lite.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/support_lite.rb @@ -2,8 +2,9 @@ # This file loads certain extensions required by Padrino from ActiveSupport. # require 'active_support/core_ext/module/aliasing' # alias_method_chain -require 'active_support/core_ext/hash/keys' # symbolize_keys require 'active_support/core_ext/hash/reverse_merge' # reverse_merge +require 'active_support/core_ext/hash/keys' # symbolize_keys +require 'active_support/core_ext/hash/indifferent_access' # params[:foo] require 'active_support/core_ext/hash/slice' # slice require 'active_support/core_ext/object/blank' # present? require 'active_support/core_ext/array/extract_options' # extract_options @@ -199,27 +200,41 @@ end # puts help.red.bold # class String - def self.colors - @_colors ||= { - :clear => 0, - :bold => 1, - :black => 30, - :red => 31, - :green => 32, - :yellow => 33, - :blue => 34, - :magenta => 35, - :cyan => 36, - :white => 37 - } + # colorize(:red) + def colorize(color) + Colorizer.send(color, self) end - colors.each do |color, value| - define_method(color) do - ["\e[", value.to_s, "m", self, "\e[", self.class.colors[:clear], "m"] * '' + # Used to colorize strings for the shell + class Colorizer + # Returns colors integer mapping + def self.colors + @_colors ||= { + :clear => 0, + :bold => 1, + :black => 30, + :red => 31, + :green => 32, + :yellow => 33, + :blue => 34, + :magenta => 35, + :cyan => 36, + :white => 37 + } + end + + # Defines class level color methods + # i.e Colorizer.red("hello") + class << self + Colorizer.colors.each do |color, value| + define_method(color) do |target| + "\e[#{value}m" << target << "\e[0m" + end + end end end + # Strip unnecessary indentation of the front of a string def undent gsub(/^.{#{slice(/^ +/).size}}/, '') end @@ -242,19 +257,3 @@ I18n.load_path += Dir["#{File.dirname(__FILE__)}/locale/*.yml"] if defined?(I18n # Used to determine if this file has already been required # module SupportLite; end - -module Padrino - class Utils - ### - # Silences output verbosity level so load - # errors are not visible when safe_load(file) - # - def self.silence_output - @verbosity_level, $-v = $-v, nil - end - - def self.unsilence_output - $-v = @verbosity_level - end - end -end \ No newline at end of file diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/tasks.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/tasks.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/tasks.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/tasks.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/version.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/version.rb similarity index 87% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/version.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/version.rb index d61bd265..023e2eb6 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/lib/padrino-core/version.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/lib/padrino-core/version.rb @@ -6,7 +6,7 @@ # module Padrino # The version constant for the current version of Padrino. - VERSION = '0.11.4' unless defined?(Padrino::VERSION) + VERSION = '0.12.0' unless defined?(Padrino::VERSION) # # The current Padrino version. diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/padrino-core.gemspec b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/padrino-core.gemspec old mode 100755 new mode 100644 similarity index 96% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/padrino-core.gemspec rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/padrino-core.gemspec index 114296fe..56488b67 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/padrino-core.gemspec +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/padrino-core.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = ">= 1.3.6" s.version = Padrino.version s.date = Time.now.strftime("%Y-%m-%d") + s.license = "MIT" s.extra_rdoc_files = Dir["*.rdoc"] s.files = `git ls-files`.split("\n") @@ -38,6 +39,6 @@ Gem::Specification.new do |s| end s.add_dependency("http_router", "~> 0.11.0") s.add_dependency("thor", "~> 0.17.0") - s.add_dependency("activesupport", ">= 3.1", "< 4.0") + s.add_dependency("activesupport", ">= 3.1") s.add_dependency("rack-protection", ">= 1.5.0") end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/Gemfile b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/Gemfile similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/Gemfile rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/Gemfile diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/app/app.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/app/app.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/app/app.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/app/app.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/app_gem.gemspec b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/app_gem.gemspec similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/app_gem.gemspec rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/app_gem.gemspec diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/lib/app_gem.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/lib/app_gem.rb similarity index 95% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/lib/app_gem.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/lib/app_gem.rb index e4a4b239..39a09987 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/lib/app_gem.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/lib/app_gem.rb @@ -4,4 +4,4 @@ module AppGem extend Padrino::Module gem! 'app_gem' -end \ No newline at end of file +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/lib/app_gem/version.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/lib/app_gem/version.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/app_gem/lib/app_gem/version.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/app_gem/lib/app_gem/version.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/.components b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/.components similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/.components rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/.components diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/.gitignore b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/.gitignore similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/.gitignore rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/.gitignore diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/complex.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/complex.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/complex.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/complex.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/helpers/system_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/helpers/system_helpers.rb new file mode 100644 index 00000000..105ff085 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/helpers/system_helpers.rb @@ -0,0 +1,8 @@ +require 'resolv' + +SystemDemo.helpers do + def resolv + Resolv.name + end +end + diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/kiq.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/kiq.rb new file mode 100644 index 00000000..5e60b547 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/kiq.rb @@ -0,0 +1,3 @@ +class Kiq < ::Sinatra::Base + set :root, '/weird' +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/lib/myklass.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/lib/myklass.rb new file mode 100644 index 00000000..ad5a865d --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/lib/myklass.rb @@ -0,0 +1,2 @@ +class MyKlass < OpenStruct +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/lib/myklass/mysubklass.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/lib/myklass/mysubklass.rb new file mode 100644 index 00000000..e2fde456 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/lib/myklass/mysubklass.rb @@ -0,0 +1,4 @@ +class MyKlass + class MySubKlass + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/models/child.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/models/child.rb new file mode 100644 index 00000000..2876c100 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/models/child.rb @@ -0,0 +1,2 @@ +class Child < Parent +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/models/parent.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/models/parent.rb new file mode 100644 index 00000000..f0aedee6 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/models/parent.rb @@ -0,0 +1,5 @@ +class Parent + def family + 'Danes' + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/render.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/render.rb new file mode 100644 index 00000000..db6d68f8 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/render.rb @@ -0,0 +1,13 @@ +PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT + +class RenderDemo < Padrino::Application + set :reload, true +end + +RenderDemo.controllers :blog do + get '/' do + render 'post' + end +end + +Padrino.load! diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/simple.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/simple.rb similarity index 90% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/simple.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/simple.rb index fd9d3bc8..8263ef1d 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/apps/simple.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/simple.rb @@ -1,5 +1,5 @@ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT -# Remove this comment if you want do some like this: ruby PADRINO_ENV=test app.rb +# Remove this comment if you want do some like this: ruby RACK_ENV=test app.rb # # require 'rubygems' # require 'padrino-core' diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/static.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/static.rb new file mode 100644 index 00000000..ca8828c8 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/static.rb @@ -0,0 +1,10 @@ +PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT + +class StaticDemo < Padrino::Application + disable :reload + def self.reload! + fail 'reload! called' + end +end + +Padrino.load! diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/system.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/system.rb new file mode 100644 index 00000000..5cc4e8ae --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/system.rb @@ -0,0 +1,13 @@ +PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT + +class SystemDemo < Padrino::Application + set :reload, true +end + +SystemDemo.controllers do + get '/' do + resolv + end +end + +Padrino.load! diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/views/blog/post.erb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/views/blog/post.erb new file mode 100644 index 00000000..9f8d6f24 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/apps/views/blog/post.erb @@ -0,0 +1 @@ +okay \ No newline at end of file diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/a.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/a.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/a.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/a.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/b.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/b.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/b.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/b.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/c.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/c.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/c.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/c.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/e.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/circular/e.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/e.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/circular/e.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/f.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/circular/f.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/f.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/circular/f.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/g.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/circular/g.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/circular/g.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/circular/g.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/d.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/d.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/fixtures/dependencies/d.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/dependencies/d.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/layouts/layout.erb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/layouts/layout.erb new file mode 100644 index 00000000..c1de6be7 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/fixtures/layouts/layout.erb @@ -0,0 +1 @@ +<%= yield %> absolute layout \ No newline at end of file diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/helper.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/helper.rb similarity index 95% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/helper.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/helper.rb index ba921acf..972be7e4 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/helper.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/helper.rb @@ -1,4 +1,4 @@ -ENV['PADRINO_ENV'] = 'test' +ENV['RACK_ENV'] = 'test' PADRINO_ROOT = File.dirname(__FILE__) unless defined?(PADRINO_ROOT) require File.expand_path('../../../load_paths', __FILE__) @@ -56,7 +56,7 @@ class MiniTest::Spec path = "/views/#{name}" path += ".#{options.delete(:locale)}" if options[:locale].present? path += ".#{options[:format]}" if options[:format].present? - path += ".erb" unless options[:format].to_s =~ /haml|rss|atom/ + path += ".erb" unless options[:format].to_s =~ /erb|slim|haml|rss|atom/ path += ".builder" if options[:format].to_s =~ /rss|atom/ file = File.dirname(__FILE__) + path File.open(file, 'w') { |io| io.write content } diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/mini_shoulda.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/mini_shoulda.rb similarity index 78% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/mini_shoulda.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/mini_shoulda.rb index b61816a3..ed61ab5b 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/mini_shoulda.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/mini_shoulda.rb @@ -29,10 +29,10 @@ class ColoredIO def print(o) case o - when "." then @io.send(:print, o.green) - when "E" then @io.send(:print, o.red) - when "F" then @io.send(:print, o.yellow) - when "S" then @io.send(:print, o.magenta) + when "." then @io.send(:print, o.colorize(:green)) + when "E" then @io.send(:print, o.colorize(:red)) + when "F" then @io.send(:print, o.colorize(:yellow)) + when "S" then @io.send(:print, o.colorize(:magenta)) else @io.send(:print, o) end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_application.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_application.rb similarity index 89% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_application.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_application.rb index 5c8b5632..6dac258a 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_application.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_application.rb @@ -25,19 +25,6 @@ describe "Application" do assert !Padrino.configure_apps end - should 'check haml options on production' do - assert defined?(Haml), 'Haml not defined' - assert_equal :test, PadrinoPristine.environment - assert !PadrinoPristine.haml[:ugly] - Padrino.stub :env, :production do - PadrinoPristine.send :default_configuration! - assert_equal :production, Padrino.env - assert_equal :production, PadrinoPristine.environment - assert PadrinoPristine.haml[:ugly] - PadrinoPristine.environment = :test - end - end - should 'check padrino specific options' do assert !PadrinoPristine.instance_variable_get(:@_configured) PadrinoPristine.send(:setup_application!) @@ -97,6 +84,11 @@ describe "Application" do assert_equal "Foo in nil", body end + should "resolve views and layouts paths" do + assert_equal Padrino.root('views')+'/users/index', PadrinoPristine.view_path('users/index') + assert_equal Padrino.root('views')+'/layouts/app', PadrinoPristine.layout_path(:app) + end + context "errors" do should "haven't mapped errors on development" do mock_app { get('/'){ 'HI' } } diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_core.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_core.rb similarity index 81% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_core.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_core.rb index 546b1686..5ee1a255 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_core.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_core.rb @@ -27,12 +27,8 @@ describe "Core" do should 'set correct utf-8 encoding' do Padrino.set_encoding - if RUBY_VERSION <'1.9' - assert_equal 'UTF8', $KCODE - else - assert_equal Encoding.default_external, Encoding::UTF_8 - assert_equal Encoding.default_internal, Encoding::UTF_8 - end + assert_equal Encoding.default_external, Encoding::UTF_8 + assert_equal Encoding.default_internal, Encoding::UTF_8 end should 'have load paths' do @@ -73,5 +69,18 @@ describe "Core" do res = Rack::MockRequest.new(Padrino.application).get("/") assert_equal "yes", res["Middleware-Called"] end + + should "properly set default options" do + mock_app do + default :foo, :bar + default :zoo, :baz + set :foo, :bam + set :moo, :bam + default :moo, :ban + end + assert_equal @app.settings.foo, :bam + assert_equal @app.settings.zoo, :baz + assert_equal @app.settings.moo, :bam + end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_csrf_protection.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_csrf_protection.rb new file mode 100644 index 00000000..3e2977d5 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_csrf_protection.rb @@ -0,0 +1,161 @@ +require File.expand_path(File.dirname(__FILE__) + '/helper') + +describe "Application" do + before { Padrino.clear! } + after { remove_views } + + context 'CSRF protection' do + context "with CSRF protection on" do + before do + mock_app do + enable :sessions + enable :protect_from_csrf + post('/'){ 'HI' } + end + end + + should "not allow requests without tokens" do + post "/" + assert_equal 403, status + end + + should "allow requests with correct tokens" do + post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"} + assert_equal 200, status + end + + should "not allow requests with incorrect tokens" do + post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"} + assert_equal 403, status + end + end + + context "without CSRF protection on" do + before do + mock_app do + enable :sessions + disable :protect_from_csrf + post('/'){ 'HI' } + end + end + + should "allows requests without tokens" do + post "/" + assert_equal 200, status + end + + should "allow requests with correct tokens" do + post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "a"} + assert_equal 200, status + end + + should "allow requests with incorrect tokens" do + post "/", {"authenticity_token" => "a"}, 'rack.session' => {:csrf => "b"} + assert_equal 200, status + end + end + + context "with optional CSRF protection" do + before do + mock_app do + enable :sessions + enable :protect_from_csrf + set :allow_disabled_csrf, true + post('/on') { 'HI' } + post('/off', :csrf_protection => false) { 'HI' } + end + end + + should "allow access to routes with csrf_protection off" do + post "/off" + assert_equal 200, status + end + + should "not allow access to routes with csrf_protection on" do + post "/on" + assert_equal 403, status + end + end + + context "with :except option that is using Proc" do + before do + mock_app do + enable :sessions + set :protect_from_csrf, :except => proc{|env| ["/", "/foo"].any?{|path| path == env['PATH_INFO'] }} + post("/") { "Hello" } + post("/foo") { "Hello, foo" } + post("/bar") { "Hello, bar" } + end + end + + should "allow ignoring CSRF protection on specific routes" do + post "/" + assert_equal 200, status + post "/foo" + assert_equal 200, status + post "/bar" + assert_equal 403, status + end + end + + context "with :except option that is using String and Regexp" do + before do + mock_app do + enable :sessions + set :protect_from_csrf, :except => ["/a", %r{^/a.c$}] + post("/a") { "a" } + post("/abc") { "abc" } + post("/foo") { "foo" } + end + end + + should "allow ignoring CSRF protection on specific routes" do + post "/a" + assert_equal 200, status + post "/abc" + assert_equal 200, status + post "/foo" + assert_equal 403, status + end + end + + context "with custom protection options" do + before do + mock_app do + enable :sessions + set :protect_from_csrf, :authenticity_param => 'foobar' + post("/a") { "a" } + end + end + + should "allow configuring protection options" do + post "/a", {"foobar" => "a"}, 'rack.session' => {:csrf => "a"} + assert_equal 200, status + end + end + + context "with middleware" do + before do + class Middleware < Sinatra::Base + post("/middleware") { "Hello, middleware" } + post("/dummy") { "Hello, dummy" } + end + mock_app do + enable :sessions + set :protect_from_csrf, :except => proc{|env| ["/", "/middleware"].any?{|path| path == env['PATH_INFO'] }} + use Middleware + post("/") { "Hello" } + end + end + + should "allow ignoring CSRF protection on specific routes of middleware" do + post "/" + assert_equal 200, status + post "/middleware" + assert_equal 200, status + post "/dummy" + assert_equal 403, status + end + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_dependencies.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_dependencies.rb similarity index 75% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_dependencies.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_dependencies.rb index 4e2cfdd0..85fccf90 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_dependencies.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_dependencies.rb @@ -2,6 +2,17 @@ require File.expand_path(File.dirname(__FILE__) + '/helper') describe "Dependencies" do context 'when we require a dependency that have another dependency' do + setup do + @log_level = Padrino::Logger::Config[:test] + @io = StringIO.new + Padrino::Logger::Config[:test] = { :log_level => :error, :stream => @io } + Padrino::Logger.setup! + end + + teardown do + Padrino::Logger::Config[:test] = @log_level + Padrino::Logger.setup! + end should 'raise an error without reloading it twice' do capture_io do @@ -15,6 +26,7 @@ describe "Dependencies" do end end assert_equal 1, D + assert_match /RuntimeError: SomeThing/, @io.string end should 'resolve dependency problems' do @@ -27,6 +39,7 @@ describe "Dependencies" do end assert_equal ["B", "C"], A_result assert_equal "C", B_result + assert_equal "", @io.string end should 'remove partially loaded constants' do @@ -37,8 +50,8 @@ describe "Dependencies" do Padrino.root("fixtures/dependencies/circular/g.rb") ) end - assert_equal ["name"], F.fields + assert_equal "", @io.string end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_filters.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_filters.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_filters.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_filters.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_flash.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_flash.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_flash.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_flash.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_locale.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_locale.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_locale.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_locale.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_logger.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_logger.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_logger.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_logger.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_mounter.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_mounter.rb similarity index 78% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_mounter.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_mounter.rb index 097be4b7..c05a73a1 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_mounter.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_mounter.rb @@ -24,7 +24,14 @@ describe "Mounter" do assert_equal "TestApp", mounter.app_class assert_equal "/path/to/test.rb", mounter.app_file assert_equal "/test_app", mounter.uri_root - assert_equal File.dirname(mounter.app_file), mounter.app_root + assert_equal Padrino.root, mounter.app_root + end + + should 'use app.root if available' do + require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/kiq') + mounter = Padrino::Mounter.new("kiq", :app_class => "Kiq") + mounter.to("/test_app") + assert_equal '/weird', mounter.app_root end should 'check locate_app_file with __FILE__' do @@ -53,6 +60,17 @@ describe "Mounter" do assert_equal ["some_namespace/an_app"], Padrino.mounted_apps.map(&:name) end + should 'correctly set a name of a namespaced app' do + module ::SomeNamespace2 + class AnApp < Padrino::Application + get(:index) { settings.app_name } + end + end + Padrino.mount("SomeNamespace2::AnApp").to("/") + res = Rack::MockRequest.new(Padrino.application).get("/") + assert_equal "some_namespace2/an_app", res.body + end + should 'mount a primary app to root uri' do mounter = Padrino.mount("test_app", :app_file => __FILE__).to("/") assert_equal "test_app", mounter.name @@ -130,30 +148,56 @@ describe "Mounter" do put(:update) { "users update" } delete(:destroy) { "users delete" } end + controllers :foo_bar do + get(:index) { "foo bar index" } + get(:new) { "foo bar new" } + post(:create) { "foo bar create" } + put(:update) { "foo bar update" } + delete(:destroy) { "foo bar delete" } + end end Padrino.mount("one_app").to("/") Padrino.mount("two_app").to("/two_app") assert_equal 15, Padrino.mounted_apps[0].routes.size - assert_equal 7, Padrino.mounted_apps[1].routes.size + assert_equal 14, Padrino.mounted_apps[1].routes.size assert_equal 6, Padrino.mounted_apps[0].named_routes.size - assert_equal 5, Padrino.mounted_apps[1].named_routes.size + assert_equal 10, Padrino.mounted_apps[1].named_routes.size first_route = Padrino.mounted_apps[0].named_routes[3] - assert_equal "posts_show", first_route.identifier.to_s + assert_equal "posts show", first_route.identifier.to_s assert_equal "(:posts, :show)", first_route.name assert_equal "GET", first_route.verb assert_equal "/posts/show/:id(.:format)", first_route.path another_route = Padrino.mounted_apps[1].named_routes[2] - assert_equal "users_create", another_route.identifier.to_s + assert_equal "users create", another_route.identifier.to_s assert_equal "(:users, :create)", another_route.name assert_equal "POST", another_route.verb assert_equal "/two_app/users/create", another_route.path regexp_route = Padrino.mounted_apps[0].named_routes[5] - assert_equal "posts_regexp", regexp_route.identifier.to_s + assert_equal "posts regexp", regexp_route.identifier.to_s assert_equal "(:posts, :regexp)", regexp_route.name assert_equal "/\\/foo|\\/baz/", regexp_route.path + foo_bar_route = Padrino.mounted_apps[1].named_routes[5] + assert_equal "(:foo_bar, :index)", foo_bar_route.name + end + + should "configure cascade apps" do + class ::App1 < Padrino::Application + get(:index) { halt 404, 'index1' } + end + class ::App2 < Padrino::Application + get(:index) { halt 404, 'index2' } + end + class ::App3 < Padrino::Application + get(:index) { halt 404, 'index3' } + end + Padrino.mount('app1', :cascade => true).to('/foo') + Padrino.mount('app2').to('/foo') + Padrino.mount('app3').to('/foo') + res = Rack::MockRequest.new(Padrino.application).get("/foo") + assert_equal 'index2', res.body end should 'correctly instantiate a new padrino application' do diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_complex.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_complex.rb similarity index 95% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_complex.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_complex.rb index d64af1a2..b2006cb1 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_complex.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_complex.rb @@ -47,7 +47,7 @@ describe "ComplexReloader" do new_buffer.gsub!(/get\(:destroy\)/, 'get(:destroy, :with => :id)') begin File.open(Complex1Demo.app_file, "w") { |f| f.write(new_buffer) } - sleep 1.2 # We need at least a cooldown of 1 sec. + sleep 1.1 # We need at least a cooldown of 1 sec. get "/complex_2_demo" assert_equal new_phrase, body @@ -65,7 +65,7 @@ describe "ComplexReloader" do assert_equal 200, status get "/complex_2_demo/var/destroy/variable" - assert_equal '{:id=>"variable"}', body + assert_equal '{"id"=>"variable"}', body ensure # Now we need to prevent to commit a new changed file so we revert it File.open(Complex1Demo.app_file, "w") { |f| f.write(buffer) } diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_simple.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_simple.rb similarity index 98% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_simple.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_simple.rb index ffcc37f4..4d4ecf10 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_reloader_simple.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_simple.rb @@ -61,7 +61,7 @@ describe "SimpleReloader" do buffer = File.read(SimpleDemo.app_file) new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase) File.open(SimpleDemo.app_file, "w") { |f| f.write(new_buffer) } - sleep 2 # We need at least a cooldown of 1 sec. + sleep 1.1 # We need at least a cooldown of 1 sec. get "/" assert_equal new_phrase, body diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_system.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_system.rb new file mode 100644 index 00000000..1105d792 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_reloader_system.rb @@ -0,0 +1,64 @@ +require File.expand_path(File.dirname(__FILE__) + '/helper') +require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/kiq') +require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system') +require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/static') + +describe "SystemReloader" do + context 'for wierd and difficult reload events' do + should 'reload system features if they were required only in helper' do + @app = SystemDemo + @app.reload! + get '/' + assert_equal 'Resolv', body + end + + should 'reload children on parent change' do + @app = SystemDemo + assert_equal Child.new.family, 'Danes' + parent_file = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/models/parent.rb') + new_class = <<-DOC + class Parent + def family + 'Dancy' + end + def shmamily + 'Shmancy' + end + end + DOC + begin + backup = File.read(parent_file) + Padrino::Reloader.reload! + assert_equal 'Danes', Parent.new.family + assert_equal 'Danes', Child.new.family + File.open(parent_file, "w") { |f| f.write(new_class) } + Padrino::Reloader.reload! + assert_equal 'Dancy', Parent.new.family + assert_equal 'Shmancy', Parent.new.shmamily + assert_equal 'Dancy', Child.new.family + assert_equal 'Shmancy', Child.new.shmamily + ensure + File.open(parent_file, "w") { |f| f.write(backup) } + end + end + + should 'tamper with LOAD_PATH' do + SystemDemo.load_paths.each do |lib_dir| + assert_includes $LOAD_PATH, lib_dir + end + Padrino.send(:load_paths_was).each do |lib_dir| + assert_includes $LOAD_PATH, lib_dir + end + end + + should 'not fail horribly on reload event with non-padrino apps' do + Padrino.mount("kiq").to("/") + Padrino.reload! + end + + should 'not reload apps with disabled reload' do + Padrino.mount(StaticDemo).to("/") + Padrino.reload! + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_rendering.rb similarity index 88% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_rendering.rb index 8cceffaf..2c915294 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_rendering.rb @@ -209,6 +209,43 @@ describe "Rendering" do assert_equal "haml", body.chomp end + should 'allow to render template with layout option that using other template engine.' do + create_layout :"layouts/foo", "application layout for <%= yield %>", :format => :erb + create_view :slim, "| slim", :format => :slim + create_view :haml, "haml", :format => :haml + create_view :erb, "erb", :format => :erb + mock_app do + get("/slim") { render("slim.slim", :layout => "foo.erb") } + get("/haml") { render("haml.haml", :layout => "foo.erb") } + get("/erb") { render("erb.erb", :layout => "foo.erb") } + end + get "/slim" + assert_equal "application layout for slim", body.chomp + get "/haml" + assert_equal "application layout for haml", body.chomp + get "/erb" + assert_equal "application layout for erb", body.chomp + end + + should 'allow to use extension with layout method.' do + create_layout :"layouts/bar", "application layout for <%= yield %>", :format => :erb + create_view :slim, "| slim", :format => :slim + create_view :haml, "haml", :format => :haml + create_view :erb, "erb", :format => :erb + mock_app do + layout "bar.erb" + get("/slim") { render("slim.slim") } + get("/haml") { render("haml.haml") } + get("/erb") { render("erb.erb") } + end + get "/slim" + assert_equal "application layout for slim", body.chomp + get "/haml" + assert_equal "application layout for haml", body.chomp + get "/erb" + assert_equal "application layout for erb", body.chomp + end + context 'for application render functionality' do should "work properly with logging and missing layout" do @@ -385,11 +422,15 @@ describe "Rendering" do mock_app do get("/foo", :provides => [:html, :js]) { render :foo } end + + I18n.enforce_available_locales = false I18n.locale = :none get "/foo.js" assert_equal "Im Js", body get "/foo" assert_equal "Im Erb", body + I18n.enforce_available_locales = true + I18n.locale = :en get "/foo" assert_equal "Im English Erb", body @@ -407,6 +448,14 @@ describe "Rendering" do assert_equal 404, status end + should 'resolve templates and layouts located in absolute paths' do + mock_app do + get("/foo") { render 'apps/views/blog/post', :layout => 'layout', :views => File.dirname(__FILE__)+'/fixtures' } + end + get '/foo' + assert_match /okay absolute layout/, body + end + should 'resolve template content_type and locale with layout' do create_layout :foo, "Hello <%= yield %> in a Js layout", :format => :js create_layout :foo, "Hello <%= yield %> in a Js-En layout", :format => :js, :locale => :en @@ -425,11 +474,15 @@ describe "Rendering" do layout :foo get("/bar", :provides => [:html, :js, :json]) { render :bar } end + + I18n.enforce_available_locales = false I18n.locale = :none get "/bar.js" assert_equal "Hello Im Js in a Js layout", body get "/bar" assert_equal "Hello Im Erb in a Erb layout", body + I18n.enforce_available_locales = true + I18n.locale = :en get "/bar" assert_equal "Hello Im English Erb in a Erb-En layout", body @@ -447,6 +500,14 @@ describe "Rendering" do assert_equal "Im a json", body get "/bar.pk" assert_equal 404, status + + end + + should 'resolve template location relative to controller name' do + require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/render') + @app = RenderDemo + get '/blog' + assert_equal 'okay', body end should 'renders erb with blocks' do diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering_extensions.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_rendering_extensions.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_rendering_extensions.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_rendering_extensions.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_restful_routing.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_restful_routing.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_restful_routing.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_restful_routing.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_router.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_router.rb similarity index 60% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_router.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_router.rb index 0bb7767d..61e0af73 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_router.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_router.rb @@ -17,8 +17,8 @@ describe "Router" do } map = Padrino::Router.new( { :path => '/bar', :to => app }, - { :path => '/foo', :to => app }, - { :path => '/foo/bar', :to => app } + { :path => '/foo/bar', :to => app }, + { :path => '/foo', :to => app } ) res = Rack::MockRequest.new(map).get("/") @@ -69,6 +69,125 @@ describe "Router" do assert_equal "/", res["X-PathInfo"] end + should "dispatch requests to cascade mounted apps" do + app = lambda { |env| + scary = !!env['PATH_INFO'].match(/scary/) + [scary ? 404 : 200, { + 'X-ScriptName' => env['SCRIPT_NAME'], + 'X-PathInfo' => env['PATH_INFO'], + 'Content-Type' => 'text/plain' + }, [""]] + } + api = lambda { |env| + spooky = !!env['QUERY_STRING'].match(/spooky/) + [spooky ? 200 : 404, { + 'X-API' => spooky, + 'X-ScriptName' => env['SCRIPT_NAME'], + 'X-PathInfo' => env['PATH_INFO'], + 'Content-Type' => 'application/json' + }, [""]] + } + map = Padrino::Router.new( + { :path => '/bar', :to => api }, + { :path => '/bar', :to => app } + ) + + res = Rack::MockRequest.new(map).get("/werewolf") + assert_equal 404, res.status + assert_equal nil, res["X-API"] + assert_equal nil, res["X-ScriptName"] + assert_equal nil, res["X-PathInfo"] + + res = Rack::MockRequest.new(map).get("/bar/mitzvah") + assert res.ok? + assert_equal nil, res["X-API"] + assert_equal 'text/plain', res["Content-Type"] + assert_equal "/bar", res["X-ScriptName"] + assert_equal "/mitzvah", res["X-PathInfo"] + + res = Rack::MockRequest.new(map).get("/bar?spooky") + assert res.ok? + assert_equal true, res["X-API"] + assert_equal 'application/json', res["Content-Type"] + assert_equal "/bar", res["X-ScriptName"] + assert_equal "/", res["X-PathInfo"] + + res = Rack::MockRequest.new(map).get("/bar/scary") + assert_equal 404, res.status + assert_equal nil, res["X-API"] + assert_equal 'text/plain', res["Content-Type"] + assert_equal "/bar", res["X-ScriptName"] + assert_equal "/scary", res["X-PathInfo"] + end + + should "dispatch requests to cascade mounted apps and not cascade ok statuses" do + + api = mock_app do + get 'scary' do + "1" + end + set :cascade, true + end + + app = mock_app do + get 'scary' do + "2" + end + set :cascade, false + end + + app2 = mock_app do + get 'terrifying' do + "" + end + end + + map = Padrino::Router.new( + { :path => '/bar', :to => api }, + { :path => '/bar', :to => app }, + { :path => '/bar', :to => app2 } + ) + + res = Rack::MockRequest.new(map).get("/bar/scary") + assert res.ok? + #asserting that on ok we're good to go + assert_equal "1", res.body + + res = Rack::MockRequest.new(map).get("/bar/terrifying") + assert !res.ok? + + end + + should "dispatch requests to cascade mounted apps until it sees a cascade == false or []g" do + app = mock_app do + get 'scary' do + "" + end + set :cascade, [] + end + + app2 = mock_app do + get 'terrifying' do + "" + end + end + + map = Padrino::Router.new( + { :path => '/bar', :to => app }, + { :path => '/bar', :to => app2 } + ) + + request_case = lambda { + Rack::MockRequest.new(map).get("/bar/terrifying") + } + + app.cascade = false + assert !request_case.call.ok? + + app.cascade = true + assert request_case.call.ok? + end + should "dispatches hosts correctly" do map = Padrino::Router.new( { :host => "foo.org", :to => lambda { |env| diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_routing.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_routing.rb similarity index 92% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_routing.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_routing.rb index dfad8e48..29c61e5f 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_routing.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_routing.rb @@ -1,4 +1,4 @@ -#encoding: utf-8 +#encoding: utf-8 require File.expand_path(File.dirname(__FILE__) + '/helper') class FooError < RuntimeError; end @@ -56,6 +56,32 @@ describe "Routing" do } end + should 'fail with unrecognized route exception when namespace is invalid' do + mock_app do + controller :foo_bar do + get(:index){ "okey" } + get(:test_baz){ "okey" } + end + end + assert_equal "/foo_bar", @app.url_for(:foo_bar, :index) + assert_raises(Padrino::Routing::UnrecognizedException) { + get @app.url_for(:foo, :bar, :index) + } + assert_raises(Padrino::Routing::UnrecognizedException) { + get @app.url_for(:foo, :bar_index) + } + assert_equal "/foo_bar/test_baz", @app.url_for(:foo_bar, :test_baz) + assert_raises(Padrino::Routing::UnrecognizedException) { + get @app.url_for(:foo_bar, :test, :baz) + } + assert_raises(Padrino::Routing::UnrecognizedException) { + get @app.url_for(:foo, :bar_test, :baz) + } + assert_raises(Padrino::Routing::UnrecognizedException) { + get @app.url_for(:foo, :bar_test_baz) + } + end + should 'accept regexp routes' do mock_app do get(%r./fob|/baz.) { "regexp" } @@ -102,11 +128,11 @@ describe "Routing" do end should 'parse routes that are encoded' do - mock_app do + mock_app do get('/щч') { 'success!' } end get(URI.escape('/щч')) - assert_equal 'success!', body + assert_equal 'success!', body end should 'parse routes that include encoded slash' do @@ -120,9 +146,7 @@ describe "Routing" do end should 'encode params using UTF-8' do - skip unless ''.respond_to?(:encoding) # for 1.8.7 - - mock_app do + mock_app do get('/:foo') { params[:foo].encoding.name } end get '/bar' @@ -260,6 +284,14 @@ describe "Routing" do assert_equal "https://example.org/hash/1", body end + should 'generate absolute urls from stringified keys' do + mock_app do + get(:hash, with: :id) { absolute_url(:hash, "id" => 1) } + end + get "/hash/2" + assert_equal "http://example.org/hash/1", body + end + should 'generate proper absolute urls for mounted apps' do class Test < Padrino::Application get :foo do @@ -272,6 +304,24 @@ describe "Routing" do assert_equal 'http://example.org/test/foo?id=1', body end + should 'rebase simple string urls to app uri_root' do + mock_app do + set :uri_root, '/app' + get(:a){ url('/foo') } + get(:b){ url('bar') } + get(:c){ absolute_url('/foo') } + get(:d, :map => '/d/e/f'){ absolute_url('bar') } + end + get "/a" + assert_equal "/app/foo", body + get "/b" + assert_equal "bar", body + get "/c" + assert_equal "http://example.org/app/foo", body + get "/d/e/f" + assert_equal "http://example.org/app/d/e/bar", body + end + should 'allow regex url with format' do mock_app do get(/.*/, :provides => :any) { "regexp" } @@ -354,7 +404,7 @@ describe "Routing" do get("/foo"){ content_type(:json); content_type.to_s } end get "/foo" - assert_equal 'application/json;charset=utf-8', content_type + assert_equal 'application/json', content_type assert_equal 'json', body end @@ -367,7 +417,7 @@ describe "Routing" do end should "allow .'s in param values" do - skip + skip # TODO fix this? mock_app do get('/id/:email', :provides => [:json]) { |email, format| [email, format] * '/' } end @@ -474,7 +524,7 @@ describe "Routing" do end end get "/posts" - assert_equal "posts_index", body + assert_equal "posts index", body end should "preserve the format if you set it manually" do @@ -640,7 +690,7 @@ describe "Routing" do assert_equal 'application/javascript;charset=utf-8', response["Content-Type"] get "/a.json" assert_equal "json", body - assert_equal 'application/json;charset=utf-8', response["Content-Type"] + assert_equal 'application/json', response["Content-Type"] get "/a.foo" assert_equal "foo", body assert_equal 'application/foo;charset=utf-8', response["Content-Type"] @@ -676,8 +726,8 @@ describe "Routing" do assert_equal "1", body get "/admin/show/1" assert_equal "show 1", body - assert_equal "/admin/1", @app.url(:admin_index, :id => 1) - assert_equal "/admin/show/1", @app.url(:admin_show, :id => 1) + assert_equal "/admin/1", @app.url(:admin, :index, :id => 1) + assert_equal "/admin/show/1", @app.url(:admin, :show, :id => 1) get "/foo/bar" assert_equal "foo_bar_index", body end @@ -1446,6 +1496,51 @@ describe "Routing" do assert_equal '{"test"=>"what"}', body end + should "work only for the given controller and route when using before-filter with route's name" do + mock_app do + controller :foo do + before(:index) { @a = "only to :index" } + get(:index) { @a } + get(:main) { @a } + end + end + get '/foo/' + assert_equal 'only to :index', body + get '/foo/main' + assert_equal '', body + end + + should "work only for the given controller and route when using after-filter with route's name" do + mock_app do + controller :after_controller do + global = "global variable" + get(:index) { global } + get(:main) { global } + after(:index) { global = nil } + end + end + get '/after_controller' + assert_equal 'global variable', body + get '/after_controller' + assert_equal '', body + end + + should "execute the before/after filters when they are inserted after the target route" do + mock_app do + controller :after_test do + global = "global variable" + get(:index) { global } + get(:foo) { global } + before(:index) { global.delete!(" ") } + after(:index) { global = "after" } + end + end + get '/after_test' + assert_equal 'globalvariable', body + get '/after_test/foo' + assert_equal 'after', body + end + should 'work with controller and arbitrary params' do mock_app do get(:testing) { params[:foo] } @@ -1790,6 +1885,33 @@ describe "Routing" do assert ok? end + should 'return params as a HashWithIndifferentAccess object via GET' do + mock_app do + get('/foo/:bar') { "#{params["bar"]} #{params[:bar]}" } + get(:foo, :map => '/prefix/:var') { "#{params["var"]} #{params[:var]}" } + end + + get('/foo/some_text') + assert_equal "some_text some_text", body + + get('/prefix/var') + assert_equal "var var", body + end + + should 'return params as a HashWithIndifferentAccess object via POST' do + mock_app do + post('/user') do + "#{params["user"]["full_name"]} #{params[:user][:full_name]}" + end + end + + post '/user', {:user => {:full_name => 'example user'}} + assert_equal "example user example user", body + + post '/user', {"user" => {"full_name" => 'example user'}} + assert_equal "example user example user", body + end + should 'have MethodOverride middleware with more options' do mock_app do put('/hi', :provides => [:json]) { 'hi' } @@ -1840,7 +1962,7 @@ describe "Routing" do end should 'render a custom error page using error method' do - skip + skip # TODO sinatra bug? mock_app do error(404) { "custom 404 error" } end @@ -1867,8 +1989,8 @@ describe "Routing" do get(:simple, :map => "/simple/:id") { } get(:with_format, :with => :id, :provides => :js) { } end - assert_equal [:foo_bar, { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic)) - assert_equal [:foo_bar, { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18)) + assert_equal [:"foo bar", { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic)) + assert_equal [:"foo bar", { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18)) assert_equal [:simple, { :id => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar")) assert_equal [:simple, { :id => "true" }], @app.recognize_path(@app.url(:simple, :id => true)) assert_equal [:simple, { :id => "9" }], @app.recognize_path(@app.url(:simple, :id => 9)) diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_support_lite.rb b/middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_support_lite.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-core-0.11.4/test/test_support_lite.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-core-0.12.0/test/test_support_lite.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/abstract_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/abstract_handler.rb deleted file mode 100644 index 0ba38600..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/abstract_handler.rb +++ /dev/null @@ -1,96 +0,0 @@ -module Padrino - module Helpers - module OutputHelpers - ## - # Returns the list of all available template handlers. - # - # @example - # OutputHelpers.handlers => [, ] - # - def self.handlers - @_template_handlers ||= [] - end - - ## - # Registers a new handler as available to the output helpers. - # - # @example - # OutputHelpers.register(OutputHelpers::HamlHandler) - # - def self.register(handler) - handlers << handler - end - - # @abstract Extend this to create a template handler. - class AbstractHandler - attr_reader :template - - def initialize(template) - @template = template - end - - ## - # Returns extension of the template. - # - # @example - # @handler.template_extension => "erb" - # - def template_extension - caller.find { |c| c =~ /\/views\// }[/\.([\w]*?)\:/, 1] rescue nil - # "/some/path/app/views/posts/foo.html.erb:3:in `evaluate_source'" - # => "erb" - end - - ## - # Returns an array of engines used for the template. - # - # @example - # @handler.engines => [:erb, :erubis] - # - def engines - # Implemented in subclass. - end - - ## - # Returns true if the current template type is same as this handlers; false otherwise. - # - # @example - # @handler.is_type? => true - # - def is_type? - # Implemented in subclass. - end - - ## - # Returns true if the block given is of the handler's template type; false otherwise. - # - # @example - # @handler.block_is_type?(block) => true - # - def block_is_type?(block) - # Implemented in subclass. - end - - ## - # Captures the html from a block of template code for this handler. - # - # @example - # @handler.capture_from_template(&block) => "...html..." - # - def capture_from_template(*args, &block) - # Implemented in subclass. - end - - ## - # Outputs the given text to the templates buffer directly. - # - # @example - # @handler.concat_to_template("This will be output to the template buffer") - # - def concat_to_template(text="") - # Implemented in subclass. - end - end - end - end -end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/erb_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/erb_handler.rb deleted file mode 100644 index 3d073177..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/erb_handler.rb +++ /dev/null @@ -1,78 +0,0 @@ -module Padrino - module Helpers - module OutputHelpers - ## - # Handler for reading and writing from an erb template. - # - class ErbHandler < AbstractHandler - attr_reader :output_buffer - - def initialize(template) - super - @output_buffer = template.instance_variable_get(:@_out_buf) - end - - ## - # Returns true if the current template type is same as this handlers; false otherwise. - # - # @example - # @handler.is_type? => true - # - def is_type? - !self.output_buffer.nil? - end - - ## - # Captures the html from a block of template code for this handler. - # - # @example - # @handler.capture_from_template(&block) => "...html..." - # - def capture_from_template(*args, &block) - self.output_buffer, _buf_was = ActiveSupport::SafeBuffer.new, self.output_buffer - captured_block = block.call(*args) - ret = eval("@_out_buf", block.binding) - self.output_buffer = _buf_was - [ ret, captured_block ] - end - - ## - # Outputs the given text to the templates buffer directly. - # - # @example - # @handler.concat_to_template("This will be output to the template buffer") - # - def concat_to_template(text="") - self.output_buffer << text if is_type? && text - nil - end - - ## - # Returns true if the block given is of the handler's template type; false otherwise. - # - # @example - # @handler.block_is_type?(block) => true - # - def block_is_type?(block) - is_type? || (block && eval('defined?(__in_erb_template)', block.binding)) - end - - ## - # Returns an array of engines used for the template. - # - # @example - # @handler.engines => [:erb, :erubis] - # - def engines - @_engines ||= [:erb, :erubis] - end - - protected - def output_buffer=(val) - template.instance_variable_set(:@_out_buf, val) - end - end - OutputHelpers.register(ErbHandler) - end - end -end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/haml_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/haml_handler.rb deleted file mode 100644 index dd57fd97..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/haml_handler.rb +++ /dev/null @@ -1,63 +0,0 @@ -module Padrino - module Helpers - module OutputHelpers - ## - # Handler for reading and writing from a haml template. - # - class HamlHandler < AbstractHandler - ## - # Returns true if the current template type is same as this handlers; false otherwise. - # - # @example - # @handler.is_type? => true - # - def is_type? - template.respond_to?(:is_haml?) && template.is_haml? - end - - ## - # Returns true if the block given is of the handler's template type; false otherwise. - # - # @example - # @handler.block_is_type?(block) => true - # - def block_is_type?(block) - template.block_is_haml?(block) - end - - ## - # Captures the html from a block of template code for this handler. - # - # @example - # @handler.capture_from_template(&block) => "...html..." - # - def capture_from_template(*args, &block) - eval("_hamlout ||= @haml_buffer", block.binding) - template.capture_haml(*args, &block) - end - - ## - # Outputs the given text to the templates buffer directly. - # - # @example - # @handler.concat_to_template("This will be output to the template buffer") - # - def concat_to_template(text="") - template.haml_concat(text) - nil - end - - ## - # Returns an array of engines used for the template. - # - # @example - # @handler.engines => [:haml] - # - def engines - @_engines ||= [:haml] - end - end - OutputHelpers.register(HamlHandler) - end - end -end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/slim_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/slim_handler.rb deleted file mode 100644 index 3b8ab5be..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers/slim_handler.rb +++ /dev/null @@ -1,78 +0,0 @@ -module Padrino - module Helpers - module OutputHelpers - ## - # Handler for reading and writing from a slim template. - # - class SlimHandler < AbstractHandler - attr_reader :output_buffer - - def initialize(template) - super - @output_buffer = template.instance_variable_get(:@_out_buf) - end - - ## - # Returns true if the current template type is same as this handlers; false otherwise. - # - # @example - # @handler.is_type? => true - # - def is_type? - !self.output_buffer.nil? - end - - ## - # Captures the html from a block of template code for this handler. - # - # @example - # @handler.capture_from_template(&block) => "...html..." - # - def capture_from_template(*args, &block) - self.output_buffer, _buf_was = ActiveSupport::SafeBuffer.new, self.output_buffer - captured_block = block.call(*args) - ret = eval("@_out_buf", block.binding) - self.output_buffer = _buf_was - [ ret, captured_block ] - end - - ## - # Outputs the given text to the templates buffer directly. - # - # @example - # @handler.concat_to_template("This will be output to the template buffer") - # - def concat_to_template(text="") - self.output_buffer << text if is_type? && text - nil - end - - ## - # Returns true if the block given is of the handler's template type; false otherwise. - # - # @example - # @handler.block_is_type?(block) => true - # - def block_is_type?(block) - is_type? || (block && eval('defined? __in_erb_template', block.binding)) - end - - ## - # Returns an array of engines used for the template. - # - # @example - # @handler.engines => [:erb, :erubis] - # - def engines - @_engines ||= [:slim] - end - - protected - def output_buffer=(val) - template.instance_variable_set(:@_out_buf, val) - end - end - OutputHelpers.register(SlimHandler) - end - end -end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.slim deleted file mode 100644 index ca16c418..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.slim +++ /dev/null @@ -1 +0,0 @@ -p.slim= partial 'partials/slim', :engine => "slim" \ No newline at end of file diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_erb.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_erb.erb deleted file mode 100644 index c7f7e123..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_erb.erb +++ /dev/null @@ -1,3 +0,0 @@ -<% form_for( :object, '/' ) do |f| %> - <%= $number_of_captures += 1 %> -<% end %> \ No newline at end of file diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_haml.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_haml.haml deleted file mode 100644 index 26102762..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_haml.haml +++ /dev/null @@ -1,2 +0,0 @@ -- form_for :object, '/' do |f| - = $number_of_captures += 1 diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_slim.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_slim.slim deleted file mode 100644 index 26102762..00000000 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/double_capture_slim.slim +++ /dev/null @@ -1,2 +0,0 @@ -- form_for :object, '/' do |f| - = $number_of_captures += 1 diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.document b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/.document similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.document rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/.document diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.gitignore b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/.gitignore similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.gitignore rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/.gitignore diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.yardopts b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/.yardopts similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/.yardopts rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/.yardopts diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/LICENSE.txt b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/LICENSE.txt similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/LICENSE.txt rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/LICENSE.txt diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/README.rdoc b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/README.rdoc similarity index 97% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/README.rdoc rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/README.rdoc index ec68bac6..0e2049d0 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/README.rdoc +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/README.rdoc @@ -102,9 +102,9 @@ For more information on using asset helpers, check out the guide for Form helpers are the 'standard' form tag helpers you would come to expect when building forms. A simple example of constructing a non-object form would be: - - form_tag '/destroy', :class => 'destroy-form', :method => 'delete' do + = form_tag '/destroy', :class => 'destroy-form', :method => 'delete' do = flash_tag(:notice) - - field_set_tag do + = field_set_tag do %p = label_tag :username, :class => 'first' = text_field_tag :username, :value => params[:username] @@ -116,7 +116,7 @@ example of constructing a non-object form would be: = select_tag :strategy, :options => ['delete', 'destroy'], :selected => 'delete' %p = check_box_tag :confirm_delete - - field_set_tag(:class => 'buttons') do + = field_set_tag(:class => 'buttons') do = submit_tag "Remove" For more information on using form helpers, check out the guide for @@ -129,7 +129,7 @@ using a simple, intuitive syntax. A form_for using these basic fields might look like: - - form_for @user, '/register', :id => 'register' do |f| + = form_for @user, '/register', :id => 'register' do |f| = f.error_messages %p = f.label :username, :caption => "Nickname" @@ -147,7 +147,7 @@ A form_for using these basic fields might look like: = f.label :color, :caption => "Favorite Color?" = f.select :color, :options => ['red', 'black'] %p - - fields_for @user.location do |location| + = fields_for @user.location do |location| = location.text_field :street = location.text_field :city %p @@ -159,7 +159,7 @@ There is also an additional StandardFormBuilder which builds on the abstract fie A form_for using these standard fields might be: - - form_for @user, '/register', :id => 'register' do |f| + = form_for @user, '/register', :id => 'register' do |f| = f.error_messages = f.text_field_block :name, :caption => "Full name" = f.text_field_block :email diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/Rakefile b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/Rakefile similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/Rakefile rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/Rakefile diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers.rb similarity index 98% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers.rb index 2d51c6fd..0aac0e1e 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers.rb @@ -9,6 +9,7 @@ require 'active_support/inflector' # humanize FileSet.glob_require('padrino-helpers/**/*.rb', __FILE__) I18n.load_path += Dir["#{File.dirname(__FILE__)}/padrino-helpers/locale/*.yml"] +I18n.enforce_available_locales = true module Padrino ## diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/asset_tag_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/asset_tag_helpers.rb similarity index 92% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/asset_tag_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/asset_tag_helpers.rb index d7c25265..53131196 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/asset_tag_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/asset_tag_helpers.rb @@ -4,9 +4,12 @@ module Padrino # Helpers related to producing assets (images, stylesheets, js, etc) within templates. # module AssetTagHelpers - FRAGMENT_HASH = "#".html_safe.freeze APPEND_ASSET_EXTENSIONS = ["js", "css"] ABSOLUTE_URL_PATTERN = %r{^(https?://)} + ASSET_FOLDERS = { + :js => 'javascripts', + :css => 'stylesheets', + } ## # Creates a div to display the flash of given type if it exists. @@ -79,34 +82,16 @@ module Padrino options = args.extract_options! fragment = options.delete(:anchor).to_s if options[:anchor] fragment = options.delete(:fragment).to_s if options[:fragment] - - url = ActiveSupport::SafeBuffer.new - if block_given? - if args[0] - url.concat(args[0]) - url.concat(FRAGMENT_HASH).concat(fragment) if fragment - else - url.concat(FRAGMENT_HASH) - url.concat(fragment) if fragment - end - options.reverse_merge!(:href => url) - link_content = capture_html(&block) - return '' unless parse_conditions(url, options) - result_link = content_tag(:a, link_content, options) - block_is_template?(block) ? concat_content(result_link) : result_link + name = block_given? ? '' : args.shift + if url = args.first + url << '#' << fragment if fragment else - if args[1] - url.concat(args[1]) - url.safe_concat(FRAGMENT_HASH).concat(fragment) if fragment - else - url = FRAGMENT_HASH - url.concat(fragment) if fragment - end - name = args[0] - return name unless parse_conditions(url, options) - options.reverse_merge!(:href => url) - content_tag(:a, name, options) + url = '#' + url << fragment if fragment end + options.reverse_merge!(:href => url) + return name unless parse_conditions(url, options) + block_given? ? content_tag(:a, options, &block) : content_tag(:a, name, options) end ## @@ -312,9 +297,13 @@ module Padrino # # Generates: /images/example.jpg?1269008689 # asset_path :images, 'example.jpg' # - def asset_path(kind, source) + # # Generates: /uploads/file.ext?1269008689 + # asset_path 'uploads/file.ext' + # + def asset_path(kind, source = nil) + kind, source = source, kind if source.nil? source = asset_normalize_extension(kind, URI.escape(source.to_s)) - return source if source =~ ABSOLUTE_URL_PATTERN || source =~ /^\// # absolute source + return source if source =~ ABSOLUTE_URL_PATTERN || source =~ /^\// source = File.join(asset_folder_name(kind), source) timestamp = asset_timestamp(source) result_path = uri_root_path(source) @@ -322,6 +311,7 @@ module Padrino end private + ## # Returns the URI root of the application with optional paths appended. # @@ -353,16 +343,19 @@ module Padrino ### # Returns the asset folder given a kind. # + # Configureable by setting kind_asset_folder. + # # @example # asset_folder_name(:css) => 'stylesheets' # asset_folder_name(:js) => 'javascripts' # asset_folder_name(:images) => 'images' + # asset_folder_name(:abrakadabrah) => 'abrakadabrah' # def asset_folder_name(kind) - case kind - when :css then 'stylesheets' - when :js then 'javascripts' - else kind.to_s + if self.class.respond_to? "#{kind}_asset_folder" + self.class.send "#{kind}_asset_folder" + else + (ASSET_FOLDERS[kind] || kind).to_s end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/breadcrumb_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/breadcrumb_helpers.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/breadcrumb_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/breadcrumb_helpers.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_builder/abstract_form_builder.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_builder/abstract_form_builder.rb similarity index 90% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_builder/abstract_form_builder.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_builder/abstract_form_builder.rb index efbf1c30..a2a2486d 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_builder/abstract_form_builder.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_builder/abstract_form_builder.rb @@ -32,51 +32,43 @@ module Padrino end def text_field(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.text_field_tag field_name(field), options end def number_field(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.number_field_tag field_name(field), options end def telephone_field(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.telephone_field_tag field_name(field), options end alias_method :phone_field, :telephone_field def email_field(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.email_field_tag field_name(field), options end def search_field(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.search_field_tag field_name(field), options end def url_field(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.url_field_tag field_name(field), options end def text_area(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.text_area_tag field_name(field), options end def password_field(field, options={}) - options.reverse_merge!(:value => field_value(field), :id => field_id(field)) - options.merge!(:class => field_error(field, options)) + merge_default_options!(field, options) @template.password_field_tag field_name(field), options end @@ -143,13 +135,23 @@ module Padrino # f.fields_for :addresses # f.fields_for :addresses, address # f.fields_for :addresses, @addresses - def fields_for(child_association, instance_or_collection=nil, &block) + # f.fields_for :addresses, address, index: i + def fields_for(child_association, instance_or_collection=nil, options={}, &block) default_collection = self.object.send(child_association) + include_index = default_collection.respond_to?(:each) + custom_index = options.has_key?(:index) + nested_options = { :parent => self, :association => child_association } nested_objects = instance_or_collection ? Array(instance_or_collection) : Array(default_collection) nested_objects.each_with_index.map do |child_instance, index| - nested_options[:index] = include_index ? index : nil + if custom_index + nested_options[:index] = options[:index] + elsif include_index + nested_options[:index] = index + else + nested_options[:index] = nil + end @template.fields_for(child_instance, { :nested => nested_options }, &block) end.join("\n").html_safe end @@ -246,6 +248,7 @@ module Padrino # Returns the object's models name. # def object_model_name(explicit_object=object) + return @options[:as] if root_form? && @options[:as].is_a?(Symbol) explicit_object.is_a?(Symbol) ? explicit_object : explicit_object.class.to_s.underscore.gsub(/\//, '_') end @@ -280,7 +283,8 @@ module Padrino end variants.inject(''.html_safe) do |html, variant| variant[2] = "#{field_id(field)}_#{variant[1]}" - html << @template.label_tag("#{field_name(field)}[]", :for => variant[2], :caption => "#{yield(variant)} #{variant[0]}") + caption = yield(variant) << ' ' << variant[0] + html << @template.label_tag("#{field_name(field)}[]", :for => variant[2], :caption => caption) end end @@ -311,6 +315,11 @@ module Padrino :attributes_name => "#{@options[:nested][:association]}_attributes" } end + + def merge_default_options!(field, options) + options.reverse_merge!(:value => field_value(field), :id => field_id(field)) + options.merge!(:class => field_error(field, options)) + end end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_builder/standard_form_builder.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_builder/standard_form_builder.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_builder/standard_form_builder.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_builder/standard_form_builder.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_helpers.rb similarity index 82% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_helpers.rb index 2f39ed27..b714d22e 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/form_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/form_helpers.rb @@ -19,6 +19,8 @@ module Padrino # Also accepts HTML options. # @option settings [String] :builder ("StandardFormBuilder") # The FormBuilder class to use such as StandardFormBuilder. + # @option settings [Symbol] :as + # Sets custom form object name. # @param [Proc] block # The fields and content inside this form. # @@ -29,12 +31,14 @@ module Padrino # @example # form_for :user, '/register' do |f| ... end # form_for @user, '/register', :id => 'register' do |f| ... end + # form_for @user, '/register', :as => :customer do |f| ... end # def form_for(object, url, settings={}, &block) instance = builder_instance(object, settings) html = capture_html(instance, &block) settings[:multipart] = instance.multipart unless settings.include?(:multipart) settings.delete(:namespace) + settings.delete(:as) form_tag(url, settings) { html } end @@ -78,6 +82,7 @@ module Padrino # form_tag '/register', :class => "registration_form" do ... end # def form_tag(url, options={}, &block) + options = options.dup desired_method = options[:method].to_s options.delete(:method) unless desired_method =~ /get|post/i options.reverse_merge!(:method => 'post', @@ -90,9 +95,7 @@ module Padrino inner_form_html << csrf_token_field end inner_form_html << mark_safe(capture_html(&block)) - not_concat = options.delete(:not_concat) - form_html = content_tag(:form, inner_form_html, options) - not_concat ? form_html : concat_content(form_html) + concat_content content_tag(:form, inner_form_html, options) end ## @@ -172,50 +175,45 @@ module Padrino # def error_messages_for(*objects) options = objects.extract_options!.symbolize_keys - objects = objects.map { |object_name| - object_name.is_a?(Symbol) ? instance_variable_get("@#{object_name}") : object_name - }.compact - count = objects.inject(0) { |sum, object| sum + object.errors.count } + objects = objects.map{ |obj| resolve_object(obj) }.compact + count = objects.inject(0){ |sum, object| sum + object.errors.count } + return ''.html_safe if count.zero? - unless count.zero? - html = {} - [:id, :class, :style].each do |key| - if options.include?(key) - value = options[key] - html[key] = value unless value.blank? - else - html[key] = 'field-errors' unless key == :style - end + html_options = {} + [:id, :class, :style].each do |key| + if options.include?(key) + value = options[key] + html_options[key] = value unless value.blank? + else + html_options[key] = 'field-errors' unless key == :style + end + end + + I18n.with_options :locale => options[:locale], :scope => [:models, :errors, :template] do |locale| + object_name = options[:object_name] || objects.first.class.to_s.underscore.gsub(/\//, ' ') + + header_message = if options.include?(:header_message) + options[:header_message] + else + model_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1) + locale.t :header, :count => count, :model => model_name end - options[:object_name] ||= objects.first.class.to_s.underscore.gsub(/\//, ' ') + body_message = options[:message] || locale.t(:body) - I18n.with_options :locale => options[:locale], :scope => [:models, :errors, :template] do |locale| - header_message = if options.include?(:header_message) - options[:header_message] - else - object_name = options[:object_name] - object_name = I18n.t(:name, :default => object_name.humanize, :scope => [:models, object_name], :count => 1) - locale.t :header, :count => count, :model => object_name + error_messages = objects.inject(''.html_safe) do |text, object| + object.errors.each do |field, message| + field_name = I18n.t(field, :default => field.to_s.humanize, :scope => [:models, object_name, :attributes]) + text << content_tag(:li, "#{field_name} #{message}") end - message = options.include?(:message) ? options[:message] : locale.t(:body) - error_messages = objects.map { |object| - object_name = options[:object_name] - object.errors.map { |f, msg| - field = I18n.t(f, :default => f.to_s.humanize, :scope => [:models, object_name, :attributes]) - content_tag(:li, "%s %s" % [field, msg]) - } - }.join - - contents = ActiveSupport::SafeBuffer.new - contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank? - contents << content_tag(:p, message) unless message.blank? - contents << safe_content_tag(:ul, error_messages) - - content_tag(:div, contents, html) + text end - else - '' + + contents = ActiveSupport::SafeBuffer.new + contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank? + contents << content_tag(:p, body_message) unless body_message.blank? + contents << content_tag(:ul, error_messages) + content_tag(:div, contents, html_options) end end @@ -251,24 +249,12 @@ module Padrino # # @api public def error_message_on(object, field, options={}) - object = object.is_a?(Symbol) ? instance_variable_get("@#{object}") : object - error = object.errors[field] rescue nil - error = if defined?(Ohm::Model) && object.is_a?(Ohm::Model) - I18n.t("ohm.errors.messages.#{error[0]}", :default => error[0].to_s) - else - # Array(error).first is necessary because some ORMs - # give us an array others directly a value. - Array(error)[0] - end - - if error = Array(error)[0] - options.reverse_merge!(:tag => :span, :class => :error) - tag = options.delete(:tag) - error = [options.delete(:prepend), error, options.delete(:append)].compact.join(" ") - content_tag(tag, error, options) - else - '' - end + error = Array(resolve_object(object).errors[field]).first + return ''.html_safe unless error + options = options.reverse_merge(:tag => :span, :class => :error) + tag = options.delete(:tag) + error = [options.delete(:prepend), error, options.delete(:append)].compact.join(" ") + content_tag(tag, error, options) end ## @@ -290,14 +276,15 @@ module Padrino # label_tag :username, :class => 'long-label' do ... end # def label_tag(name, options={}, &block) - options.reverse_merge!(:caption => "#{name.to_s.humanize}: ", :for => name) - caption_text = options.delete(:caption).html_safe + options = options.reverse_merge(:caption => "#{name.to_s.humanize}: ", :for => name) + caption_text = ''.html_safe + caption_text.concat options.delete(:caption) caption_text.safe_concat "* " if options.delete(:required) - if block_given? # label with inner content + if block_given? label_content = caption_text.concat capture_html(&block) concat_content(content_tag(:label, label_content, options)) - else # regular label + else content_tag(:label, caption_text, options) end end @@ -360,7 +347,7 @@ module Padrino # # => # def text_field_tag(name, options={}) - input_tag(:text, options.reverse_merge!(:name => name)) + input_tag(:text, options.reverse_merge(:name => name)) end ## @@ -510,8 +497,7 @@ module Padrino # hidden_field_tag :session_key, :value => "__secret__" # def hidden_field_tag(name, options={}) - options.reverse_merge!(:name => name) - input_tag(:hidden, options) + input_tag(:hidden, options.reverse_merge(:name => name)) end ## @@ -521,7 +507,7 @@ module Padrino # text_area_tag :username, :class => 'long', :value => "Demo?" # def text_area_tag(name, options={}) - options.reverse_merge!(:name => name, :rows => "", :cols => "") + options = options.reverse_merge(:name => name, :rows => "", :cols => "") content_tag(:textarea, options.delete(:value).to_s, options) end @@ -533,8 +519,7 @@ module Padrino # # @api public def password_field_tag(name, options={}) - options.reverse_merge!(:name => name) - input_tag(:password, options) + input_tag(:password, options.reverse_merge(:name => name)) end ## @@ -544,8 +529,7 @@ module Padrino # check_box_tag :remember_me, :value => 'Yes' # def check_box_tag(name, options={}) - options.reverse_merge!(:name => name, :value => '1') - input_tag(:checkbox, options) + input_tag(:checkbox, options.reverse_merge(:name => name, :value => '1')) end ## @@ -555,8 +539,7 @@ module Padrino # radio_button_tag :remember_me, :value => 'true' # def radio_button_tag(name, options={}) - options.reverse_merge!(:name => name) - input_tag(:radio, options) + input_tag(:radio, options.reverse_merge(:name => name)) end ## @@ -568,8 +551,7 @@ module Padrino # @api public def file_field_tag(name, options={}) name = "#{name}[]" if options[:multiple] - options.reverse_merge!(:name => name) - input_tag(:file, options) + input_tag(:file, options.reverse_merge(:name => name)) end ## @@ -613,18 +595,12 @@ module Padrino # @return [String] The HTML input field based on the +options+ specified. # def select_tag(name, options={}) - options.reverse_merge!(:name => name) + options = options.reverse_merge(:name => name) + options[:name] = "#{options[:name]}[]" if options[:multiple] collection, fields = options.delete(:collection), options.delete(:fields) options[:options] = options_from_collection(collection, fields) if collection - prompt = options.delete(:include_blank) - select_options_html = if options[:options] - options_for_select(options.delete(:options), options.delete(:selected)) - elsif options[:grouped_options] - grouped_options_for_select(options.delete(:grouped_options), options.delete(:selected), prompt) - end - select_options_html = select_options_html.unshift(blank_option(prompt)) if select_options_html.is_a?(Array) - options.merge!(:name => "#{options[:name]}[]") if options[:multiple] - safe_content_tag(:select, select_options_html, options) + options_tags = extract_option_tags!(options) + content_tag(:select, options_tags, options) end ## @@ -641,8 +617,7 @@ module Padrino # button_tag "Cancel", :class => 'clear' # def button_tag(caption, options = {}) - options.reverse_merge!(:value => caption) - input_tag(:button, options) + input_tag(:button, options.reverse_merge(:value => caption)) end ## @@ -660,10 +635,9 @@ module Padrino # submit_tag :class => 'btn' # def submit_tag(*args) - options = args[-1].is_a?(Hash) ? args.pop : {} - caption = args.length >= 1 ? args.shift : "Submit" - options.reverse_merge!(:value => caption) - input_tag(:submit, options) + options = args.extract_options! + caption = args.length >= 1 ? args.first : "Submit" + input_tag(:submit, options.reverse_merge(:value => caption)) end ## @@ -677,11 +651,10 @@ module Padrino # @return [String] The html image button based on the +options+ specified. # # @example - # submit_tag "Create", :class => 'success' + # image_submit_tag 'form/submit.png' # def image_submit_tag(source, options={}) - options.reverse_merge!(:src => image_path(source)) - input_tag(:image, options) + input_tag(:image, options.reverse_merge(:src => image_path(source))) end ## @@ -747,14 +720,14 @@ module Padrino # # # def button_to(*args, &block) + options = args.extract_options!.dup name, url = args[0], args[1] - options = args.extract_options! options['data-remote'] = 'true' if options.delete(:remote) submit_options = options.delete(:submit_options) || {} if block_given? - form_tag(url, options, &block) + form_tag(url || name, options, &block) else - form_tag(url, options.merge!(:not_concat => true)) do + form_tag(url, options) do submit_tag(name, submit_options) end end @@ -780,7 +753,7 @@ module Padrino # @return [String] The html range field # def range_field_tag(name, options = {}) - options.reverse_merge!(:name => name) + options = options.reverse_merge(:name => name) if range = options.delete(:range) options[:min], options[:max] = range.min, range.max end @@ -802,39 +775,27 @@ module Padrino ## # Returns the options tags for a select based on the given option items. # - def options_for_select(option_items, selected_value=nil) + def options_for_select(option_items, state = {}) return [] if option_items.blank? - option_items.map do |caption, value, disabled| - value ||= caption - disabled ||= false - content_tag(:option, caption, :value => value, :selected => option_is_selected?(value, caption, selected_value), :disabled => disabled) + option_items.map do |caption, value, attributes| + html_attributes = { :value => value || caption }.merge(attributes||{}) + html_attributes[:selected] ||= option_is_selected?(value, caption, state[:selected]) + html_attributes[:disabled] ||= option_is_selected?(value, caption, state[:disabled]) + content_tag(:option, caption, html_attributes) end end ## # Returns the optgroups with options tags for a select based on the given :grouped_options items. # - def grouped_options_for_select(collection, selected=nil, prompt=false) - if collection.is_a?(Hash) - collection.map do |key, value| - # Hash format: - # {:first => [1,2,3], :second => [4,5,6]} - # or: - # {:first => [[1,2,3], {:disabled => true}], :second => [4,5,6]} - attributes_hash = value.last.is_a?(Hash) ? value.pop : nil - disabled ||= attributes_hash && attributes_hash.include?(:disabled) ? attributes_hash[:disabled] : false - content_tag :optgroup, options_for_select(value, selected), :label => key, :disabled => disabled - end - elsif collection.is_a?(Array) - # Array format: - # ["Option Label", [:option1, :option2, ...]] - # or: - # ["Option Label", [:option1, :option2, ...], true] - # the last item tells if it is disabled or not. This is keeps it backwards compatible. - collection.map do |optgroup| - disabled ||= optgroup.count > 2 ? optgroup.pop : false - content_tag :optgroup, options_for_select(optgroup.last, selected), :label => optgroup.first, :disabled => disabled - end + def grouped_options_for_select(collection, state = {}) + collection.map do |item| + caption = item.shift + attributes = item.last.kind_of?(Hash) ? item.pop : {} + value = item.flatten(1) + attributes = value.pop if value.last.kind_of?(Hash) + html_attributes = { :label => caption }.merge(attributes||{}) + content_tag(:optgroup, options_for_select(value, state), html_attributes) end end @@ -842,11 +803,15 @@ module Padrino # Returns the blank option serving as a prompt if passed. # def blank_option(prompt) - return unless prompt case prompt - when String then content_tag(:option, prompt, :value => '') - when Array then content_tag(:option, prompt.first, :value => prompt.last) - else content_tag(:option, '', :value => '') + when nil, false + nil + when String + content_tag(:option, prompt, :value => '') + when Array + content_tag(:option, prompt.first, :value => prompt.last) + else + content_tag(:option, '', :value => '') end end @@ -877,6 +842,7 @@ module Padrino end private + ## # Returns the FormBuilder class to use based on all available setting sources # If explicitly defined, returns that, otherwise returns defaults. @@ -914,6 +880,32 @@ module Padrino [value.to_s, caption.to_s].include?(selected.to_s) end end + + def extract_option_state!(options) + { + :selected => Array(options.delete(:selected))|Array(options.delete(:selected_options)), + :disabled => Array(options.delete(:disabled_options)) + } + end + + def extract_option_tags!(options) + state = extract_option_state!(options) + option_tags = case + when options[:options] + options_for_select(options.delete(:options), state) + when options[:grouped_options] + grouped_options_for_select(options.delete(:grouped_options), state) + else + [] + end + prompt = options.delete(:include_blank) + option_tags.unshift(blank_option(prompt)) if prompt + option_tags + end + + def resolve_object(object) + object.is_a?(Symbol) ? instance_variable_get("@#{object}") : object + end end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/format_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/format_helpers.rb similarity index 99% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/format_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/format_helpers.rb index 534b9117..a1d3d186 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/format_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/format_helpers.rb @@ -78,7 +78,7 @@ module Padrino def simple_format(text, options={}) t = options.delete(:tag) || :p start_tag = tag(t, options, true) - text = escape_html(text.to_s.dup) + text = escape_html(text.to_s.dup) unless text.html_safe? text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n text.gsub!(/\n\n+/, "\n\n#{start_tag}") # 2+ newline -> paragraph text.gsub!(/([^\n]\n)(?=[^\n])/, '\1
') # 1 newline -> br diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/cs.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/cs.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/cs.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/cs.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/da.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/da.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/da.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/da.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/de.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/de.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/de.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/de.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/en.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/en.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/en.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/en.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/es.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/es.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/es.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/es.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/fr.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/fr.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/fr.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/fr.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/hu.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/hu.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/hu.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/hu.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/it.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/it.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/it.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/it.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ja.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/ja.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ja.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/ja.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/lv.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/lv.yml similarity index 99% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/lv.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/lv.yml index 199af0ef..9773b32d 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/lv.yml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/lv.yml @@ -15,7 +15,7 @@ lv: format: # Where is the currency sign? %u is the currency unit, %n the number (default: $5.00). format: "%u %n" - unit: "LVL" + unit: '€' # These three are to override number.format and are optional. separator: "," delimiter: "." diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/nl.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/nl.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/nl.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/nl.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/no.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/no.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/no.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/no.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/pl.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/pl.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/pl.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/pl.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/pt_br.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/pt_br.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/pt_br.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/pt_br.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ro.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/ro.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ro.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/ro.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ru.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/ru.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/ru.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/ru.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/sv.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/sv.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/sv.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/sv.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/tr.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/tr.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/tr.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/tr.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/uk.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/uk.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/uk.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/uk.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/zh_cn.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/zh_cn.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/zh_cn.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/zh_cn.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/zh_tw.yml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/zh_tw.yml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/locale/zh_tw.yml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/locale/zh_tw.yml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/number_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/number_helpers.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/number_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/number_helpers.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers.rb similarity index 87% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers.rb index 69e8e945..91f7af5e 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/output_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers.rb @@ -8,6 +8,20 @@ module Padrino base.send(:include, SinatraCurrentEngine) unless base.method_defined?(:current_engine) end + ## + # Returns the list of all available template handlers. + # + def self.handlers + @_template_handlers ||= {} + end + + ## + # Registers a new handler as available to the output helpers. + # + def self.register(engine, handler) + handlers[engine] = handler + end + ## # Module used to detect the current engine in vanilla Sinatra apps. # @@ -45,14 +59,11 @@ module Padrino # # => "" # def capture_html(*args, &block) - handler = find_proper_handler - captured_block, captured_html = nil, "" - if handler && handler.is_type? && handler.block_is_type?(block) - captured_html, captured_block = handler.capture_from_template(*args, &block) + if handler = find_proper_handler + handler.capture_from_template(*args, &block) + else + block.call(*args) end - # invoking the block directly if there was no template - captured_html = block_given? && ( captured_block || block.call(*args) ) if captured_html.blank? - captured_html end alias :capture :capture_html @@ -68,10 +79,9 @@ module Padrino # concat_content("This will be output to the template buffer") # def concat_content(text="") - handler = find_proper_handler - if handler && handler.is_type? + if handler = find_proper_handler handler.concat_to_template(text) - else # theres no template to concat, return the text directly + else text end end @@ -105,7 +115,7 @@ module Padrino # def block_is_template?(block) handler = find_proper_handler - block && handler && handler.block_is_type?(block) + block && handler && handler.engine_matches?(block) end ## @@ -124,7 +134,9 @@ module Padrino # content_for(:name) { |name| ...content... } # content_for(:name, "I'm Jeff") # - def content_for(key, content = nil, &block) + def content_for(key, content = nil, options = {}, &block) + options = content if content.is_a?(Hash) + content_blocks[key.to_sym].clear if options[:flush] content_blocks[key.to_sym] << (block_given? ? block : Proc.new { content }) end @@ -185,7 +197,8 @@ module Padrino # find_proper_handler => # def find_proper_handler - OutputHelpers.handlers.map { |h| h.new(self) }.find { |h| h.engines.include?(current_engine) && h.is_type? } + handler_class = OutputHelpers.handlers[current_engine] + handler_class && handler_class.new(self) end ## diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/abstract_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/abstract_handler.rb new file mode 100644 index 00000000..e54c226d --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/abstract_handler.rb @@ -0,0 +1,61 @@ +module Padrino + module Helpers + module OutputHelpers + class AbstractHandler + attr_reader :template, :output_buffer + + def initialize(template) + @template = template + @output_buffer = template.instance_variable_get(:@_out_buf) + end + + ## + # Returns true if the block given is of the handler's template type; false otherwise. + # + # @example + # @handler.engine_matches?(block) => true + # + def engine_matches?(block) + end + + ## + # Captures the html from a block of template code for this handler. + # + # This method is called to capture content of a block-loving helpers in templates. + # Haml has a special method to do this, for Erb and Slim we save original buffer, + # call the block and then restore the buffer. + # + # @example + # @handler.capture_from_template(&block) => "...html..." + # + def capture_from_template(*args, &block) + self.output_buffer, _buf_was = ActiveSupport::SafeBuffer.new, self.output_buffer + raw = block.call(*args) + captured = template.instance_variable_get(:@_out_buf) + self.output_buffer = _buf_was + engine_matches?(block) ? captured : raw + end + + ## + # Outputs the given text to the template. + # + # This method is called when template uses block-aware helpers. For Slim and Haml such + # helpers just return output to use with `=`. For Erb this method is implemented in + # ErbHandler by concatenating given text to output buffer. + # + # @example + # @handler.concat_to_template("This will be output to the template buffer") + # + def concat_to_template(text="") + text + end + + protected + + def output_buffer=(val) + template.instance_variable_set(:@_out_buf, val) + end + end + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/erb_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/erb_handler.rb new file mode 100644 index 00000000..f394783c --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/erb_handler.rb @@ -0,0 +1,27 @@ +module Padrino + module Helpers + module OutputHelpers + ## + # Handler for Erb template. + # + class ErbHandler < AbstractHandler + ## + # Outputs the given text to the templates buffer directly. + # + def concat_to_template(text="") + output_buffer << text + nil + end + + ## + # Returns true if the block is Erb. + # + def engine_matches?(block) + block.binding.eval('defined? __in_erb_template') + end + end + OutputHelpers.register(:erb, ErbHandler) + OutputHelpers.register(:erubis, ErbHandler) + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/haml_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/haml_handler.rb new file mode 100644 index 00000000..0b37c29d --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/haml_handler.rb @@ -0,0 +1,25 @@ +module Padrino + module Helpers + module OutputHelpers + ## + # Handler for Haml templates. + # + class HamlHandler < AbstractHandler + ## + # Returns true if the block is for Haml + # + def engine_matches?(block) + template.block_is_haml?(block) + end + + ## + # Captures the html from a block of template code for this handler. + # + def capture_from_template(*args, &block) + engine_matches?(block) ? template.capture_haml(*args, &block) : block.call(*args) + end + end + OutputHelpers.register(:haml, HamlHandler) + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/slim_handler.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/slim_handler.rb new file mode 100644 index 00000000..65735cc0 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/output_helpers/slim_handler.rb @@ -0,0 +1,18 @@ +module Padrino + module Helpers + module OutputHelpers + ## + # Handler for Slim templates. + # + class SlimHandler < AbstractHandler + ## + # Returns true if the block is for Slim. + # + def engine_matches?(block) + block.binding.eval('defined? __in_slim_template') + end + end + OutputHelpers.register(:slim, SlimHandler) + end + end +end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/render_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/render_helpers.rb similarity index 57% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/render_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/render_helpers.rb index 79ec87c4..a7ac1705 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/render_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/render_helpers.rb @@ -30,27 +30,30 @@ module Padrino # # @note If using this from Sinatra, pass explicit +:engine+ option # - def partial(template, options={}) - options.reverse_merge!(:locals => {}, :layout => false) - path = template.to_s.split(File::SEPARATOR) - object_name = path[-1].to_sym - path[-1] = "_#{path[-1]}" + def partial(template, options={}, &block) + options = options.reverse_merge(:locals => {}, :layout => false) explicit_engine = options.delete(:engine) - template_path = File.join(path).to_sym - raise 'Partial collection specified but is nil' if options.has_key?(:collection) && options[:collection].nil? - if collection = options.delete(:collection) - options.delete(:object) - counter = 0 - collection.map { |member| - counter += 1 - options[:locals].merge!(object_name => member, "#{object_name}_counter".to_sym => counter) - render(explicit_engine, template_path, options.dup) - }.join("\n").html_safe + + path,_,name = template.to_s.rpartition(File::SEPARATOR) + template_path = File.join(path,"_#{name}").to_sym + object_name = name.to_sym + + objects, counter = if options[:collection].respond_to?(:inject) + [options.delete(:collection), 0] else - if member = options.delete(:object) - options[:locals].merge!(object_name => member) + [[options.delete(:object)], nil] + end + + locals = options[:locals] + objects.inject(''.html_safe) do |html,object| + locals[object_name] = object if object + locals["#{object_name}_counter".to_sym] = counter += 1 if counter + if block_given? + output = render(explicit_engine, template_path, options){ capture_html(&block) }.html_safe + html << (block_is_template?(block) ? concat_content(output) : output) + else + html << render(explicit_engine, template_path, options).html_safe end - render(explicit_engine, template_path, options.dup).html_safe end end alias :render_partial :partial diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/tag_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/tag_helpers.rb similarity index 99% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/tag_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/tag_helpers.rb index a39e1a5f..f097e87b 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/tag_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/tag_helpers.rb @@ -129,7 +129,7 @@ module Padrino if content.respond_to?(:each) && !content.is_a?(String) content.each { |c| output.concat c; output.safe_concat NEWLINE } else - output.concat content + output.concat content.to_s end output.safe_concat "" diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/translation_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/translation_helpers.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/lib/padrino-helpers/translation_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/lib/padrino-helpers/translation_helpers.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/padrino-helpers.gemspec b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/padrino-helpers.gemspec similarity index 93% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/padrino-helpers.gemspec rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/padrino-helpers.gemspec index 01d1d61c..8cd0e5ad 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/padrino-helpers.gemspec +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/padrino-helpers.gemspec @@ -14,6 +14,7 @@ Gem::Specification.new do |s| s.required_rubygems_version = ">= 1.3.6" s.version = Padrino.version s.date = Time.now.strftime("%Y-%m-%d") + s.license = "MIT" s.extra_rdoc_files = Dir["*.rdoc"] s.files = `git ls-files`.split("\n") @@ -23,5 +24,5 @@ Gem::Specification.new do |s| s.rdoc_options = ["--charset=UTF-8"] s.add_dependency("padrino-core", Padrino.version) - s.add_dependency("i18n", "~> 0.6") + s.add_dependency("i18n", "~> 0.6", ">= 0.6.7") end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/app.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/app.rb similarity index 80% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/app.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/app.rb index 88c18aed..c0b1d078 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/app.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/app.rb @@ -1,22 +1,14 @@ -require 'sinatra/base' -require 'haml' -require 'erubis' -require 'slim' -require 'padrino-core/application/rendering/extensions/erubis' -require 'padrino-core/application/rendering/extensions/haml' -require 'padrino-core/application/rendering/extensions/slim' +require 'padrino-core' class MarkupDemo < Sinatra::Base register Padrino::Helpers + register Padrino::Rendering configure do set :logging, false set :padrino_logging, false set :environment, :test set :root, File.dirname(__FILE__) - set :erb, :engine_class => Padrino::Erubis::SafeBufferTemplate - set :haml, :escape_html => true - set :slim, :generator => Temple::Generators::RailsOutputBuffer, :buffer => "out_buf" set :sessions, true set :protect_from_csrf, true end @@ -50,6 +42,18 @@ class MarkupDemo < Sinatra::Base content_tag(:span, "This not a template block") end end + + def content_tag_with_block + one = content_tag(:p) do + "one" + end + two = content_tag(:p) do + "two" + end + one << two + rescue + "

failed

".html_safe + end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/button_to.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/button_to.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/button_to.haml similarity index 59% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/button_to.haml index fa189844..570db5a0 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/button_to.haml @@ -1,5 +1,5 @@ -- button_to 'Foo button', '/foo', :class => 'foo-form' do - - field_set_tag do += button_to 'Foo button', '/foo', :class => 'foo-form' do + = field_set_tag do = label_tag :username = content_tag(:p, 'button_to test', :id => 'test-point') = button_to 'Bar button', '/bar' diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/button_to.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/button_to.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/button_to.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.haml similarity index 56% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.haml index 527c0115..37e0f3dd 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.haml @@ -3,10 +3,10 @@ %span Captured Line 2 = @content -- concat_in_p('Concat Line 3') += concat_in_p('Concat Line 3') -- concat_if_block_is_template('haml') do += concat_if_block_is_template('haml') do %span This is haml %span This is haml -- concat_ruby_not_template_block += concat_ruby_not_template_block diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.slim similarity index 55% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.slim index 04186e7b..4a72b2ac 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/capture_concat.slim +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/capture_concat.slim @@ -3,10 +3,10 @@ span Captured Line 2 = @content -- concat_in_p('Concat Line 3') += concat_in_p('Concat Line 3') -- concat_if_block_is_template('slim') do += concat_if_block_is_template('slim') do span This is slim span This is slim -- concat_ruby_not_template_block \ No newline at end of file += concat_ruby_not_template_block diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.erb similarity index 59% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.erb index bede704d..acd3da7a 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.erb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.erb @@ -11,4 +11,13 @@
<%= yield_content :demo2, "Johnny", "Smith" %>
<%= content_for?(:demo).to_s %> -
<%= content_for?(:fake).to_s %> \ No newline at end of file +
<%= content_for?(:fake).to_s %> + +<% content_for :demo3 do %> +

One

+<% end %> +<% content_for :demo3, :flush => true do %> +

Two

+<% end %> + +
<%= yield_content :demo3 %>
diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.haml similarity index 54% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.haml index 80055aa8..d3dd07c4 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.haml @@ -1,12 +1,19 @@ -- content_for :demo do += content_for :demo do %h1 This is content yielded from a content_for .demo= yield_content :demo -- content_for :demo2 do |fname, lname| += content_for :demo2 do |fname, lname| %h1 This is content yielded with name #{fname + " " + lname} .demo2= yield_content :demo2, "Johnny", "Smith" .demo_has_content= content_for?(:demo) .fake_has_content= content_for?(:fake) + += content_for :demo3 do + %p{:class => "duplication"} One += content_for :demo3, :flush => true do + %p{:class => "duplication"} Two + +.demo3= yield_content :demo3 diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.slim similarity index 62% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.slim index be66c854..d7f87691 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_for.slim +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_for.slim @@ -9,4 +9,11 @@ .demo2= yield_content :demo2, "Johnny", "Smith" .demo_has_content= content_for?(:demo) -.fake_has_content= content_for?(:fake) \ No newline at end of file +.fake_has_content= content_for?(:fake) + +- content_for :demo3 do + p.duplication One +- content_for :demo3, :flush => true do + p.duplication Two + +.demo3= yield_content :demo3 diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.erb similarity index 88% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.erb index 2771f33a..d1f1f010 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.erb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.erb @@ -9,3 +9,5 @@ <% content_tag(:p) do %> Test 4 <% end %> + +<%= content_tag_with_block %> diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.haml similarity index 54% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.haml index 780a2332..55812685 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.haml @@ -2,8 +2,10 @@ = content_tag :p, "Test 2" -- content_tag(:p, :class => 'test', :id => 'test3') do += content_tag(:p, :class => 'test', :id => 'test3') do %span Test 3 -- content_tag(:p) do += content_tag(:p) do %span Test 4 + += content_tag_with_block diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.slim similarity index 81% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.slim index 5ba06188..237e99c4 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/content_tag.slim +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/content_tag.slim @@ -6,4 +6,6 @@ span Test 3 =content_tag(:p) do - span Test 4 \ No newline at end of file + span Test 4 + += content_tag_with_block diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/current_engine.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/current_engine.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/current_engine.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/current_engine.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/current_engine.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/current_engine.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/current_engine.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/fields_for.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/fields_for.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/fields_for.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/fields_for.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/fields_for.slim similarity index 66% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/fields_for.slim index 6a67d79b..9046b11c 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/fields_for.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/fields_for.slim @@ -1,13 +1,13 @@ - @user = MarkupUser.new -- form_for @user , '/demo1', :id => 'demo-fields-for' do |f| += form_for @user , '/demo1', :id => 'demo-fields-for' do |f| = f.text_field :gender - - fields_for @user.permission do |permission| + = fields_for @user.permission do |permission| = permission.check_box :can_edit = permission.check_box :can_delete - - f.fields_for :telephone do |child_form| + = f.fields_for :telephone do |child_form| = child_form.label :number = child_form.text_field :number - - f.fields_for :addresses do |child_form| + = f.fields_for :addresses do |child_form| = child_form.label :name = child_form.text_field :name - unless child_form.object.new_record? diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_for.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_for.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_for.haml similarity index 92% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_for.haml index dfc71a00..59e9573c 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_for.haml @@ -1,4 +1,4 @@ -- form_for MarkupUser.new, '/demo', :id => 'demo' do |f| += form_for MarkupUser.new, '/demo', :id => 'demo' do |f| = f.error_messages(:header_message => "custom MarkupUser cannot be saved!") = f.hidden_field :session_id %p @@ -43,7 +43,7 @@ %p = f.image_submit "buttons/post.png", :class => 'success', :id => 'image-button' -- form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f| += form_for MarkupUser.new, '/another_demo', :id => 'demo2', :method => 'get' do |f| = f.error_messages :header_message => "custom MarkupUser cannot be saved!" = f.hidden_field :session_id = f.text_field_block :username, { :class => 'input' }, { :caption => 'Nickname: ', :class => 'label' } @@ -55,5 +55,5 @@ = f.submit_block "Create", { :class => 'button' } = f.image_submit_block "buttons/ok.png", { :class => 'image' } -- form_for :markup_user, '/third_demo', :id => 'demo3', :method => 'get' do |f| += form_for :markup_user, '/third_demo', :id => 'demo3', :method => 'get' do |f| = f.text_field_block :username diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_for.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_for.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_for.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_tag.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_tag.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_tag.haml similarity index 90% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_tag.haml index 4cf41167..b39a3131 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_tag.haml @@ -1,6 +1,6 @@ -- form_tag '/simple', :class => 'simple-form' do += form_tag '/simple', :class => 'simple-form' do = error_messages_for nil - - field_set_tag do + = field_set_tag do = hidden_field_tag :session_id, :value => "__secret__" = label_tag :username = text_field_tag :username @@ -26,10 +26,10 @@ = check_box_tag :remember_me = submit_tag -- form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do += form_tag '/advanced', :id => 'advanced', :class => 'advanced-form', :method => 'get' do = error_messages_for MarkupUser.new, :header_message => "There are problems with saving user!" = hidden_field_tag :session_id, :value => "__secret__" - - field_set_tag "Advanced", :class => 'advanced-field-set' do + = field_set_tag "Advanced", :class => 'advanced-field-set' do %p = label_tag :username, :class => 'first', :caption => "Nickname" = text_field_tag :username, :value => params[:username], :id => 'the_username' @@ -69,10 +69,10 @@ %p = range_field_tag('ranger_with_min_max', :min => 1, :max => 50) = range_field_tag('ranger_with_range', :range => 1..5) - - field_set_tag(:class => 'buttons') do + = field_set_tag(:class => 'buttons') do = submit_tag "Login" = button_tag "Cancel" = image_submit_tag "buttons/submit.png" -- form_tag '/dontprotect', :class => 'no-protection', :protect_from_csrf => false do += form_tag '/dontprotect', :class => 'no-protection', :protect_from_csrf => false do = submit_tag "Login" diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_tag.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/form_tag.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/form_tag.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/link_to.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/link_to.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/link_to.haml similarity index 63% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/link_to.haml index b53277d4..ee317470 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.haml +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/link_to.haml @@ -1,4 +1,4 @@ = link_to "Test 1 No Block", '/test1', :class => 'test', :id => 'test1' -- link_to("/test2", :class => 'test', :id => 'test2') do += link_to("/test2", :class => 'test', :id => 'test2') do %span Test 2 With Block diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/link_to.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/link_to.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/link_to.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/mail_to.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/mail_to.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/mail_to.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/mail_to.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/mail_to.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/mail_to.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/mail_to.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/meta_tag.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/meta_tag.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/meta_tag.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/meta_tag.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/meta_tag.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/meta_tag.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/meta_tag.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_erb.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/partials/_erb.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_erb.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/partials/_erb.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_haml.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/partials/_haml.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_haml.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/partials/_haml.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_slim.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/partials/_slim.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/partials/_slim.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/partials/_slim.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/simple_partial.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/simple_partial.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/simple_partial.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/markup_app/views/simple_partial.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/simple_partial.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/simple_partial.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/simple_partial.slim new file mode 100644 index 00000000..698d9a0e --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/markup_app/views/simple_partial.slim @@ -0,0 +1 @@ +p.slim= partial 'partials/slim', :engine => "slim" diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/app.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/app.rb similarity index 78% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/app.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/app.rb index bf4bc057..7dfadb45 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/app.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/app.rb @@ -1,8 +1,7 @@ PADRINO_ROOT = File.dirname(__FILE__) unless defined? PADRINO_ROOT -PADRINO_ENV = 'test' unless defined? PADRINO_ENV +RACK_ENV = 'test' unless defined? RACK_ENV require 'padrino-core' -require 'slim' class RenderUser attr_accessor :name @@ -17,9 +16,6 @@ class RenderDemo < Padrino::Application set :logging, false set :padrino_logging, false set :environment, :test - set :erb, :engine_class => Padrino::Erubis::SafeBufferTemplate - set :haml, :escape_html => true - set :slim, :generator => Temple::Generators::RailsOutputBuffer end # get current engines from partials @@ -36,6 +32,10 @@ class RenderDemo < Padrino::Application render "double_capture_#{params[:ext]}" end + get '/wrong_capture_:ext' do + render "wrong_capture_#{params[:ext]}" + end + # partial with object get '/partial/object' do partial 'template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" } @@ -55,4 +55,16 @@ class RenderDemo < Padrino::Application get '/partial/foward_slash' do partial '/template/user', :object => RenderUser.new('John'), :locals => { :extra => "bar" } end + + get '/render_block_:ext' do + render "render_block_#{params[:ext]}" do + content_tag :div, 'go block!' + end + end + + get '/partial_block_:ext' do + partial "partial_block_#{params[:ext]}" do + content_tag :div, 'go block!' + end + end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.erb new file mode 100644 index 00000000..d33d1c34 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.erb @@ -0,0 +1,3 @@ +
+<%= yield %> +
diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.haml new file mode 100644 index 00000000..24303b3d --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.haml @@ -0,0 +1,2 @@ +.deep + = yield diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.slim new file mode 100644 index 00000000..24303b3d --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_deep.slim @@ -0,0 +1,2 @@ +.deep + = yield diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_erb.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_erb.erb new file mode 100644 index 00000000..b155dfd4 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_erb.erb @@ -0,0 +1,10 @@ +

prefix

+
+<%= yield %> +
+
+<% partial 'deep.erb' do %> +Done +<% end %> +
+

postfix

diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_haml.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_haml.haml new file mode 100644 index 00000000..49e44a1c --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_haml.haml @@ -0,0 +1,7 @@ +%h1 prefix +.haml-block + = yield +.go-deep + = partial 'deep.haml' do + Done +%h3 postfix diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_slim.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_slim.slim new file mode 100644 index 00000000..34d0b50c --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/_partial_block_slim.slim @@ -0,0 +1,7 @@ +h1 prefix +.slim-block + = yield +.go-deep + = partial 'deep.slim' do + | Done +h3 postfix diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engine.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engine.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engine.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engine.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_erb.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engines/_erb.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_erb.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engines/_erb.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_haml.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engines/_haml.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_haml.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engines/_haml.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_slim.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engines/_slim.slim similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/current_engines/_slim.slim rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/current_engines/_slim.slim diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_erb.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_erb.erb new file mode 100644 index 00000000..aae2849a --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_erb.erb @@ -0,0 +1,3 @@ +<% form_for( :object, '/' ) do |f| %> + <%= $number_of_captures += 1 %> +<% end %> diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_haml.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_haml.haml new file mode 100644 index 00000000..28951e3d --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_haml.haml @@ -0,0 +1,2 @@ += form_for :object, '/' do |f| + = $number_of_captures += 1 diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_slim.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_slim.slim new file mode 100644 index 00000000..28951e3d --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/double_capture_slim.slim @@ -0,0 +1,2 @@ += form_for :object, '/' do |f| + = $number_of_captures += 1 diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/erb/test.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/erb/test.erb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/erb/test.erb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/erb/test.erb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/explicit_engine.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/explicit_engine.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/explicit_engine.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/explicit_engine.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/haml/test.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/haml/test.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/haml/test.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/haml/test.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_erb.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_erb.erb new file mode 100644 index 00000000..1417078c --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_erb.erb @@ -0,0 +1,5 @@ +

prefix

+
+<%= yield %> +
+

postfix

diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_haml.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_haml.haml new file mode 100644 index 00000000..5e270fc2 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_haml.haml @@ -0,0 +1,4 @@ +%h1 prefix +.haml-block + = yield +%h3 postfix diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_slim.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_slim.slim new file mode 100644 index 00000000..93509351 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/render_block_slim.slim @@ -0,0 +1,4 @@ +h1 prefix +.slim-block + = yield +h3 postfix diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/_user.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/template/_user.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/_user.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/template/_user.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/haml_template.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/template/haml_template.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/haml_template.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/template/haml_template.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/some_template.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/template/some_template.haml similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/fixtures/render_app/views/template/some_template.haml rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/template/some_template.haml diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_erb.erb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_erb.erb new file mode 100644 index 00000000..edcd6db3 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_erb.erb @@ -0,0 +1,3 @@ +<%= form_for( :object, '/' ) do |f| %> + <%= content_tag(:p, 'this is wrong') %> +<% end %> diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_haml.haml b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_haml.haml new file mode 100644 index 00000000..f40514d8 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_haml.haml @@ -0,0 +1,2 @@ +- form_for :object, '/' do |f| + = content_tag(:p, 'this is wrong') diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_slim.slim b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_slim.slim new file mode 100644 index 00000000..f40514d8 --- /dev/null +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/fixtures/render_app/views/wrong_capture_slim.slim @@ -0,0 +1,2 @@ +- form_for :object, '/' do |f| + = content_tag(:p, 'this is wrong') diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/helper.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/helper.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/helper.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/helper.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_asset_tag_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_asset_tag_helpers.rb similarity index 92% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_asset_tag_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_asset_tag_helpers.rb index afa5d678..a510a708 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_asset_tag_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_asset_tag_helpers.rb @@ -98,6 +98,16 @@ describe "AssetTagHelpers" do assert_have_selector :a, :content => "Test 1 No Block", :href => '/test1', :class => 'test', :id => 'test1' assert_have_selector :a, :content => "Test 2 With Block", :href => '/test2', :class => 'test', :id => 'test2' end + + should "not double-escape" do + actual_link = link_to('test escape', '?a=1&b=2') + assert_has_tag('a', :href => '?a=1&b=2') { actual_link } + end + + should "escape scary things" do + actual_link = link_to('test escape', '?a=1&b=') + assert_no_match(' "/js/application.js?#{time.to_i}", :type => "text/javascript") { actual_html } + end + should "display javascript item for long relative path" do time = stop_time_for_test actual_html = javascript_include_tag('example/demo/application') @@ -356,4 +374,20 @@ describe "AssetTagHelpers" do assert_has_tag('link', :type => 'my-type', :rel => 'my-rel', :href => "/blog/post.rss", :title => 'my-title') { feed_tag :rss, "/blog/post.rss", :type => "my-type", :rel => "my-rel", :title => "my-title" } end end + + context 'for #asset_path method' do + should 'generate proper paths for js and css' do + assert_match /\/javascripts\/app.js\?\d+/, asset_path(:js, 'app') + assert_match /\/stylesheets\/app.css\?\d+/, asset_path(:css, 'app') + end + + should 'generate proper paths for images and other files' do + assert_match /\/images\/app.png\?\d+/, asset_path(:images, 'app.png') + assert_match /\/documents\/app.pdf\?\d+/, asset_path(:documents, 'app.pdf') + end + + should 'generate proper paths for public folder' do + assert_match /\/files\/file.ext\?\d+/, asset_path('files/file.ext') + end + end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_breadcrumb_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_breadcrumb_helpers.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_breadcrumb_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_breadcrumb_helpers.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_builder.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_form_builder.rb similarity index 97% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_builder.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_form_builder.rb index 8a64b7f3..0f86d7ee 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_builder.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_form_builder.rb @@ -70,6 +70,16 @@ describe "FormBuilder" do assert_has_tag(:input, :type => 'text', :name => 'user[role_types_attributes][0][name]', :id => 'foo_user_role_types_attributes_0_name') { actual_html } end + should "display correct form html with :as option" do + actual_html = form_for(@user, '/update', :as => :customer) do |f| + f.text_field(:first_name) << f.fields_for(:role_types) { |role| role.text_field(:name) } + end + + assert_has_no_tag(:form, :as => 'customer') { actual_html } + assert_has_tag(:input, :type => 'text', :name => 'customer[first_name]', :id => 'customer_first_name') { actual_html } + assert_has_tag(:input, :type => 'text', :name => 'customer[role_types_attributes][0][name]', :id => 'customer_role_types_attributes_0_name') { actual_html } + end + should "display correct form html with remote option and method put" do actual_html = form_for(@user, '/update', :"accept-charset" => "UTF-8", :remote => true, :method => 'put') { "Demo" } assert_has_tag('form', :"accept-charset" => "UTF-8", :method => 'post', "data-remote" => 'true') { actual_html } @@ -917,6 +927,23 @@ describe "FormBuilder" do assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_0_name', :name => 'user[addresses_attributes][1][businesses_attributes][0][name]') { actual_html } end + should "display fields for nested forms with custom indices" do + actual_html = standard_builder.fields_for :addresses do |child_form| + html = ''.html_safe + child_form.object.businesses.each_with_index do |business, i| + html += child_form.fields_for(:businesses, business, :index => ('a'..'z').to_a[i]) do |second_child_form| + second_child_form.label(:name) + + second_child_form.text_field(:name) + + second_child_form.check_box('_destroy') + end + end + html + end + + assert_has_tag('label', :for => 'user_addresses_attributes_1_businesses_attributes_a_name', :content => 'Name') { actual_html } + assert_has_tag('input', :type => 'text', :id => 'user_addresses_attributes_1_businesses_attributes_a_name', :name => 'user[addresses_attributes][1][businesses_attributes][a][name]') { actual_html } + end + should "display nested children fields in erb" do visit '/erb/fields_for' # Telephone diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_form_helpers.rb similarity index 97% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_form_helpers.rb index c9052c61..034bc945 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_form_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_form_helpers.rb @@ -646,9 +646,9 @@ describe "FormHelpers" do should "take a range as a collection for options" do actual_html = select_tag(:favorite_color, :options => (1..3)) assert_has_tag(:select) { actual_html } - assert_has_tag('select option', :value => '1') { actual_html } - assert_has_tag('select option', :value => '2') { actual_html } - assert_has_tag('select option', :value => '3') { actual_html } + assert_has_tag('select option', :content => '1', :value => '1') { actual_html } + assert_has_tag('select option', :content => '2', :value => '2') { actual_html } + assert_has_tag('select option', :content => '3', :value => '3') { actual_html } end should "include blank for grouped options" do @@ -675,7 +675,7 @@ describe "FormHelpers" do should "display select tag with grouped options for a nested array and accept disabled groups" do opts = [ ["Friends",["Yoda",["Obiwan",2]]], - ["Enemies", ["Palpatine",['Darth Vader',3]], true] + ["Enemies", ["Palpatine",['Darth Vader',3]], {:disabled => true}] ] actual_html = select_tag( 'name', :grouped_options => opts ) assert_has_tag(:select, :name => "name") { actual_html } @@ -686,8 +686,8 @@ describe "FormHelpers" do should "display select tag with grouped options for a nested array and accept disabled groups and/or with disabled options" do opts = [ - ["Friends",["Yoda",["Obiwan",2, true]]], - ["Enemies", [["Palpatine", "Palpatine", true],['Darth Vader',3]], true] + ["Friends",["Yoda",["Obiwan",2, {:disabled => true}]]], + ["Enemies", [["Palpatine", "Palpatine", {:disabled => true}],['Darth Vader',3]], {:disabled => true}] ] actual_html = select_tag( 'name', :grouped_options => opts ) assert_has_tag(:select, :name => "name") { actual_html } @@ -713,22 +713,10 @@ describe "FormHelpers" do assert_has_tag(:option, :value => "3", :content => "Darth Vader") { actual_html } end - should "display select tag with grouped options for a hash and accept disabled groups" do - opts = { - "Friends" => ["Yoda",["Obiwan",2]], - "Enemies" => ["Palpatine",['Darth Vader',3], {:disabled => true}] - } - actual_html = select_tag( 'name', :grouped_options => opts ) - assert_has_tag(:select, :name => "name") { actual_html } - assert_has_tag(:option, :disabled => 'disabled', :count => 0) { actual_html } - assert_has_tag(:optgroup, :disabled => 'disabled', :count => 1) { actual_html } - assert_has_tag(:optgroup, :label => "Enemies", :disabled => 'disabled') { actual_html } - end - should "display select tag with grouped options for a hash and accept disabled groups and/or with disabled options" do opts = { - "Friends" => ["Yoda",["Obiwan",2,true]], - "Enemies" => [["Palpatine","Palpatine",true],["Darth Vader",3], {:disabled => true}] + "Friends" => ["Yoda",["Obiwan",2,{:disabled => true}]], + "Enemies" => [["Palpatine","Palpatine",{:disabled => true}],["Darth Vader",3], {:disabled => true}] } actual_html = select_tag( 'name', :grouped_options => opts ) assert_has_tag(:select, :name => "name") { actual_html } @@ -739,6 +727,18 @@ describe "FormHelpers" do assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :disabled => 'disabled') { actual_html } end + should "display select tag with grouped options for a rails-style attribute hash" do + opts = { + "Friends" => ["Yoda",["Obiwan",2,{:magister=>'no'}],{:lame=>'yes'}], + "Enemies" => [["Palpatine","Palpatine",{:scary=>'yes',:old=>'yes'}],["Darth Vader",3,{:disabled=>true}]] + } + actual_html = select_tag( 'name', :grouped_options => opts, :disabled_options => [2], :selected => ['Yoda'] ) + assert_has_tag(:optgroup, :label => "Friends", :lame => 'yes') { actual_html } + assert_has_tag(:option, :value => "Palpatine", :content => "Palpatine", :scary => 'yes', :old => 'yes') { actual_html } + assert_has_tag(:option, :content => "Darth Vader", :disabled => 'disabled') { actual_html } + assert_has_tag(:option, :content => "Obiwan", :disabled => 'disabled') { actual_html } + assert_has_tag(:option, :content => "Yoda", :selected => 'selected') { actual_html } + end should "display select tag in ruby with multiple attribute" do actual_html = select_tag(:favorite_color, :multiple => true, :options => ['only', 'option']) @@ -756,7 +756,7 @@ describe "FormHelpers" do end should "display options with values and accept disabled options" do - options = [['Green', 'green1', true], ['Blue', 'blue1'], ['Black', "black1"]] + options = [['Green', 'green1', {:disabled => true}], ['Blue', 'blue1'], ['Black', "black1"]] actual_html = select_tag(:favorite_color, :options => options) assert_has_tag(:select, :name => 'favorite_color') { actual_html } assert_has_tag('select option', :disabled => 'disabled', :count => 1) { actual_html } diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_format_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_format_helpers.rb similarity index 96% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_format_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_format_helpers.rb index 52108099..85982c3e 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_format_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_format_helpers.rb @@ -29,6 +29,16 @@ describe "FormatHelpers" do assert_equal "

Look me! A class!

", actual_text end + should "escape html tags" do + actual_text = simple_format("Will you escape that?") + assert_equal "

Will you escape <b>that</b>?

", actual_text + end + + should "support already sanitized text" do + actual_text = simple_format("Don't try to escape me!".html_safe) + assert_equal "

Don't try to escape me!

", actual_text + end + context 'wrapped in a custom tag' do should "format simple text into html format" do actual_text = simple_format("Here is some basic text...\n...with a line break.", :tag => :div) diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_locale.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_locale.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_locale.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_locale.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_number_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_number_helpers.rb similarity index 100% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_number_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_number_helpers.rb diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_output_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_output_helpers.rb similarity index 77% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_output_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_output_helpers.rb index 2140bec2..d8bcaf4c 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_output_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_output_helpers.rb @@ -9,20 +9,26 @@ describe "OutputHelpers" do context 'for #content_for method' do should 'work for erb templates' do visit '/erb/content_for' - assert_have_selector '.demo h1', :content => "This is content yielded from a content_for" - assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith" + assert_have_selector '.demo h1', :content => "This is content yielded from a content_for", :count => 1 + assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith", :count => 1 + assert_have_no_selector '.demo3 p', :content => "One", :class => "duplication" + assert_have_selector '.demo3 p', :content => "Two", :class => "duplication" end should "work for haml templates" do visit '/haml/content_for' - assert_have_selector '.demo h1', :content => "This is content yielded from a content_for" - assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith" + assert_have_selector '.demo h1', :content => "This is content yielded from a content_for", :count => 1 + assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith", :count => 1 + assert_have_no_selector '.demo3 p', :content => "One", :class => "duplication" + assert_have_selector '.demo3 p', :content => "Two", :class => "duplication" end should "work for slim templates" do visit '/slim/content_for' - assert_have_selector '.demo h1', :content => "This is content yielded from a content_for" - assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith" + assert_have_selector '.demo h1', :content => "This is content yielded from a content_for", :count => 1 + assert_have_selector '.demo2 h1', :content => "This is content yielded with name Johnny Smith", :count => 1 + assert_have_no_selector '.demo3 p', :content => "One", :class => "duplication" + assert_have_selector '.demo3 p', :content => "Two", :class => "duplication" end end # content_for @@ -49,20 +55,20 @@ describe "OutputHelpers" do context 'for #capture_html method' do should "work for erb templates" do visit '/erb/capture_concat' - assert_have_selector 'p span', :content => "Captured Line 1" - assert_have_selector 'p span', :content => "Captured Line 2" + assert_have_selector 'p span', :content => "Captured Line 1", :count => 1 + assert_have_selector 'p span', :content => "Captured Line 2", :count => 1 end should "work for haml templates" do visit '/haml/capture_concat' - assert_have_selector 'p span', :content => "Captured Line 1" - assert_have_selector 'p span', :content => "Captured Line 2" + assert_have_selector 'p span', :content => "Captured Line 1", :count => 1 + assert_have_selector 'p span', :content => "Captured Line 2", :count => 1 end should "work for slim templates" do visit '/slim/capture_concat' - assert_have_selector 'p span', :content => "Captured Line 1" - assert_have_selector 'p span', :content => "Captured Line 2" + assert_have_selector 'p span', :content => "Captured Line 1", :count => 1 + assert_have_selector 'p span', :content => "Captured Line 2", :count => 1 end end @@ -79,30 +85,27 @@ describe "OutputHelpers" do should "work for slim templates" do visit '/slim/capture_concat' - # TODO Get Slim concat working - # assert_have_selector 'p', :content => "Concat Line 3", :count => 1 + assert_have_selector 'p', :content => "Concat Line 3", :count => 1 end end context 'for #block_is_template?' do should "work for erb templates" do visit '/erb/capture_concat' - assert_have_selector 'p', :content => "The erb block passed in is a template", :class => 'is_template' - # TODO Get ERB template detection working (fix block_is_erb? method) - # assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template' + assert_have_selector 'p', :content => "The erb block passed in is a template", :class => 'is_template', :count => 1 + assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template', :count => 1 end should "work for haml templates" do visit '/haml/capture_concat' - assert_have_selector 'p', :content => "The haml block passed in is a template", :class => 'is_template' - assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template' + assert_have_selector 'p', :content => "The haml block passed in is a template", :class => 'is_template', :count => 1 + assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template', :count => 1 end should "work for slim templates" do visit '/slim/capture_concat' - # TODO Get Slim template detection working - # assert_have_selector 'p', :content => "The slim block passed in is a template", :class => 'is_template' - assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template' + assert_have_selector 'p', :content => "The slim block passed in is a template", :class => 'is_template', :count => 1 + assert_have_no_selector 'p', :content => "The ruby block passed in is a template", :class => 'is_template', :count => 1 end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_render_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_render_helpers.rb similarity index 58% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_render_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_render_helpers.rb index c4dffb5a..b03e7d4f 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_render_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_render_helpers.rb @@ -54,6 +54,57 @@ describe "RenderHelpers" do end end + context 'render with block' do + should 'render slim with block' do + visit '/render_block_slim' + assert_have_selector 'h1', :content => 'prefix' + assert_have_selector 'h3', :content => 'postfix' + assert_have_selector '.slim-block' + assert_have_selector 'div', :content => 'go block!' + end + should 'render erb with block' do + visit '/render_block_erb' + assert_have_selector 'h1', :content => 'prefix' + assert_have_selector 'h3', :content => 'postfix' + assert_have_selector '.erb-block' + assert_have_selector 'div', :content => 'go block!' + end + should 'render haml with block' do + visit '/render_block_haml' + assert_have_selector 'h1', :content => 'prefix' + assert_have_selector 'h3', :content => 'postfix' + assert_have_selector '.haml-block' + assert_have_selector 'div', :content => 'go block!' + end + end + + context 'partial with block' do + should 'show partial slim with block' do + visit '/partial_block_slim' + assert_have_selector 'h1', :content => 'prefix' + assert_have_selector 'h3', :content => 'postfix' + assert_have_selector '.slim-block' + assert_have_selector 'div', :content => 'go block!' + assert_have_selector 'div.deep', :content => 'Done' + end + should 'show partial erb with block' do + visit '/partial_block_erb' + assert_have_selector 'h1', :content => 'prefix' + assert_have_selector 'h3', :content => 'postfix' + assert_have_selector '.erb-block' + assert_have_selector 'div', :content => 'go block!' + assert_have_selector 'div.deep', :content => 'Done' + end + should 'show partial haml with block' do + visit '/partial_block_haml' + assert_have_selector 'h1', :content => 'prefix' + assert_have_selector 'h3', :content => 'postfix' + assert_have_selector '.haml-block' + assert_have_selector 'div', :content => 'go block!' + assert_have_selector 'div.deep', :content => 'Done' + end + end + context 'for #current_engine method' do should 'detect correctly current engine for a padrino application' do visit '/current_engine' @@ -90,5 +141,21 @@ describe "RenderHelpers" do visit '/double_capture_erb' assert_equal 1,$number_of_captures end + + should "fail on wrong erb usage" do + assert_raises(SyntaxError) do + visit '/wrong_capture_erb' + end + end + + should "ignore wrong haml usage" do + visit '/wrong_capture_haml' + assert_have_no_selector 'p', :content => 'this is wrong' + end + + should "ignore wrong slim usage" do + visit '/wrong_capture_slim' + assert_have_no_selector 'p', :content => 'this is wrong' + end end end diff --git a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_tag_helpers.rb b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_tag_helpers.rb similarity index 87% rename from middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_tag_helpers.rb rename to middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_tag_helpers.rb index 1bec5fb0..6f3f8a48 100644 --- a/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.11.4/test/test_tag_helpers.rb +++ b/middleman-core/lib/vendored-middleman-deps/padrino-helpers-0.12.0/test/test_tag_helpers.rb @@ -64,12 +64,20 @@ describe "TagHelpers" do assert_has_tag('p.large#star', :content => "<>") { actual_html } end + should "convert to a string if the content is not a string" do + actual_html = content_tag(:p, 97) + assert_has_tag('p', :content => "97") { actual_html } + end + should "support tags with erb" do visit '/erb/content_tag' assert_have_selector :p, :content => "Test 1", :class => 'test', :id => 'test1' assert_have_selector :p, :content => "Test 2" assert_have_selector :p, :content => "Test 3" assert_have_selector :p, :content => "Test 4" + assert_have_selector :p, :content => "one" + assert_have_selector :p, :content => "two" + assert_have_no_selector :p, :content => "failed" end should "support tags with haml" do @@ -78,6 +86,9 @@ describe "TagHelpers" do assert_have_selector :p, :content => "Test 2" assert_have_selector :p, :content => "Test 3", :class => 'test', :id => 'test3' assert_have_selector :p, :content => "Test 4" + assert_have_selector :p, :content => "one" + assert_have_selector :p, :content => "two" + assert_have_no_selector :p, :content => "failed" end should "support tags with slim" do @@ -86,6 +97,9 @@ describe "TagHelpers" do assert_have_selector :p, :content => "Test 2" assert_have_selector :p, :content => "Test 3", :class => 'test', :id => 'test3' assert_have_selector :p, :content => "Test 4" + assert_have_selector :p, :content => "one" + assert_have_selector :p, :content => "two" + assert_have_no_selector :p, :content => "failed" end end diff --git a/middleman-core/middleman-core.gemspec b/middleman-core/middleman-core.gemspec index 527fdca4..f1fac373 100644 --- a/middleman-core/middleman-core.gemspec +++ b/middleman-core/middleman-core.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_dependency("bundler", ["~> 1.1"]) s.add_dependency("rack", [">= 1.4.5"]) s.add_dependency("tilt", ["~> 1.4.1"]) + s.add_dependency("erubis") s.add_dependency("hooks", ["~> 0.3"]) # Helpers