You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rubygem-haml/rubygem-haml-4.11.x-Drop-su...

131 lines
5.0 KiB

From 1f8821ce8bea3d36b1b7fa01730dff5ec0c0377c Mon Sep 17 00:00:00 2001
From: Norman Clarke <norman@njclarke.com>
Date: Mon, 8 Jun 2015 14:55:59 -0300
Subject: [PATCH] Drop support for Rails 3.
---
lib/haml/helpers/action_view_mods.rb | 8 ++---
lib/haml/template/plugin.rb | 2 -
test/helper_test.rb | 52 ++++++++++++-----------------------
3 files changed, 23 insertions(+), 39 deletions(-)
diff --git a/lib/haml/helpers/action_view_mods.rb b/lib/haml/helpers/action_view_mods.rb
index b17429d..ad0c13c 100644
--- a/lib/haml/helpers/action_view_mods.rb
+++ b/lib/haml/helpers/action_view_mods.rb
@@ -87,11 +87,9 @@ def is_haml?
end
end
- if ActionPack::VERSION::MAJOR == 4
- module Tags
- class TextArea
- include HamlSupport
- end
+ module Tags
+ class TextArea
+ include HamlSupport
end
end
diff --git a/lib/haml/template/plugin.rb b/lib/haml/template/plugin.rb
index 322e445..6d96aae 100644
--- a/lib/haml/template/plugin.rb
+++ b/lib/haml/template/plugin.rb
@@ -16,7 +16,7 @@ def handles_encoding?; true; end
def compile(template)
options = Haml::Template.options.dup
- if (ActionPack::VERSION::MAJOR >= 4) && template.respond_to?(:type)
+ if template.respond_to?(:type)
options[:mime_type] = template.type
elsif template.respond_to? :mime_type
options[:mime_type] = template.mime_type
diff --git a/test/helper_test.rb b/test/helper_test.rb
index f6293a8..b1f9701 100644
--- a/test/helper_test.rb
+++ b/test/helper_test.rb
@@ -27,6 +27,8 @@
end
class HelperTest < MiniTest::Unit::TestCase
+ TEXT_AREA_CONTENT_REGEX = /<(textarea)[^>]*>\n(.*?)<\/\1>/im
+
Post = Struct.new('Post', :body, :error_field, :errors)
class PostErrors
def on(name)
@@ -157,29 +159,15 @@ def test_pre
render('= content_tag "pre", "Foo bar\n baz"', :action_view))
end
- # Rails >= 3.2.3 adds a newline after opening textarea tags.
- def self.rails_text_area_helpers_emit_a_newline?
- major, minor, tiny = ActionPack::VERSION::MAJOR, ActionPack::VERSION::MINOR, ActionPack::VERSION::TINY
- major == 4 || ((major == 3) && (minor >= 2) && (tiny >= 3))
- end
-
- def text_area_content_regex
- @text_area_content_regex ||= if self.class.rails_text_area_helpers_emit_a_newline?
- /<(textarea)[^>]*>\n(.*?)<\/\1>/im
- else
- /<(textarea)[^>]*>(.*?)<\/\1>/im
- end
- end
-
def test_text_area_tag
output = render('= text_area_tag "body", "Foo\nBar\n Baz\n Boom"', :action_view)
- match_data = output.match(text_area_content_regex)
+ match_data = output.match(TEXT_AREA_CONTENT_REGEX)
assert_equal "Foo&#x000A;Bar&#x000A; Baz&#x000A; Boom", match_data[2]
end
def test_text_area
output = render('= text_area :post, :body', :action_view)
- match_data = output.match(text_area_content_regex)
+ match_data = output.match(TEXT_AREA_CONTENT_REGEX)
assert_equal "Foo bar&#x000A;baz", match_data[2]
end
@@ -187,26 +175,24 @@ def test_partials_should_not_cause_textareas_to_be_indented
# non-indentation of textareas rendered inside partials
@base.instance_variable_set('@post', Post.new("Foo", nil, PostErrors.new))
output = render(".foo\n .bar\n = render '/text_area_helper'", :action_view)
- match_data = output.match(text_area_content_regex)
+ match_data = output.match(TEXT_AREA_CONTENT_REGEX)
assert_equal 'Foo', match_data[2]
end
- if rails_text_area_helpers_emit_a_newline?
- def test_textareas_should_prerve_leading_whitespace
- # leading whitespace preservation
- @base.instance_variable_set('@post', Post.new(" Foo", nil, PostErrors.new))
- output = render(".foo\n = text_area :post, :body", :action_view)
- match_data = output.match(text_area_content_regex)
- assert_equal '&#x0020; Foo', match_data[2]
- end
-
- def test_textareas_should_prerve_leading_whitespace_in_partials
- # leading whitespace in textareas rendered inside partials
- @base.instance_variable_set('@post', Post.new(" Foo", nil, PostErrors.new))
- output = render(".foo\n .bar\n = render '/text_area_helper'", :action_view)
- match_data = output.match(text_area_content_regex)
- assert_equal '&#x0020; Foo', match_data[2]
- end
+ def test_textareas_should_prerve_leading_whitespace
+ # leading whitespace preservation
+ @base.instance_variable_set('@post', Post.new(" Foo", nil, PostErrors.new))
+ output = render(".foo\n = text_area :post, :body", :action_view)
+ match_data = output.match(TEXT_AREA_CONTENT_REGEX)
+ assert_equal '&#x0020; Foo', match_data[2]
+ end
+
+ def test_textareas_should_prerve_leading_whitespace_in_partials
+ # leading whitespace in textareas rendered inside partials
+ @base.instance_variable_set('@post', Post.new(" Foo", nil, PostErrors.new))
+ output = render(".foo\n .bar\n = render '/text_area_helper'", :action_view)
+ match_data = output.match(TEXT_AREA_CONTENT_REGEX)
+ assert_equal '&#x0020; Foo', match_data[2]
end
def test_capture_haml