From 3a3d5bbe3b2a4bae065e8504c360571bf5c5ff77 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Fri, 8 Feb 2013 23:00:29 -0800 Subject: [PATCH] Override form_tag to use url_for. Fixes #739 --- .../features/helpers_form_tag.feature | 26 +++++++++++++++++++ .../core_extensions/default_helpers.rb | 7 +++++ 2 files changed, 33 insertions(+) create mode 100644 middleman-more/features/helpers_form_tag.feature diff --git a/middleman-more/features/helpers_form_tag.feature b/middleman-more/features/helpers_form_tag.feature new file mode 100644 index 00000000..643ca18a --- /dev/null +++ b/middleman-more/features/helpers_form_tag.feature @@ -0,0 +1,26 @@ +Feature: form_tag helper + + Scenario: form_tag produces relative links + Given a fixture app "indexable-app" + And an empty file named "config.rb" + And a file named "source/form_tag.html.erb" with: + """ + absolute: <% form_tag "/needs_index.html#absolute", :relative => true do %> + <% end %> + relative: <% form_tag "needs_index.html#relative", :relative => true do %> + <% end %> + """ + And a file named "source/form_tag/sub.html.erb" with: + """ + absolute: <% form_tag "/needs_index.html#absolute", :relative => true do %> + <% end %> + relative: <% form_tag "../needs_index.html#relative", :relative => true do %> + <% end %> + """ + And the Server is running at "indexable-app" + When I go to "/form_tag.html" + Then I should see 'action="needs_index.html#absolute"' + Then I should see 'action="needs_index.html#relative"' + When I go to "/form_tag/sub.html" + Then I should see 'action="../needs_index.html#absolute"' + Then I should see 'action="../needs_index.html#relative"' diff --git a/middleman-more/lib/middleman-more/core_extensions/default_helpers.rb b/middleman-more/lib/middleman-more/core_extensions/default_helpers.rb index 6ecedcf0..e980b922 100644 --- a/middleman-more/lib/middleman-more/core_extensions/default_helpers.rb +++ b/middleman-more/lib/middleman-more/core_extensions/default_helpers.rb @@ -203,6 +203,13 @@ module Middleman super(*args, &block) end + + # Modified Padrino form_for that uses Middleman's url_for + # to transform the URL. + def form_tag(url, options={}, &block) + url = url_for(url, options) + super + end end end end