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