Skip to content

Commit

Permalink
Drop support for Rails 3.
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed Jun 8, 2015
1 parent ad2503c commit 1f8821c
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 55 deletions.
7 changes: 0 additions & 7 deletions .travis.yml
Expand Up @@ -8,17 +8,10 @@ rvm:
- jruby
- rbx-2
gemfile:
- test/gemfiles/Gemfile.rails-3.2.x
- test/gemfiles/Gemfile.rails-4.0.x
- test/gemfiles/Gemfile.rails-4.1.x
- test/gemfiles/Gemfile.rails-4.2.x
matrix:
exclude:
- { rvm: jruby, gemfile: test/gemfiles/Gemfile.rails-3.2.x }
- { rvm: rbx-2, gemfile: test/gemfiles/Gemfile.rails-3.2.x }
- { rvm: 2.0.0, gemfile: test/gemfiles/Gemfile.rails-3.2.x }
- { rvm: 2.1, gemfile: test/gemfiles/Gemfile.rails-3.2.x }
- { rvm: 2.2, gemfile: test/gemfiles/Gemfile.rails-3.2.x }
allow_failures:
- rvm: jruby
- rvm: rbx-2
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Expand Up @@ -2,8 +2,8 @@

## 5.0.0 (Unreleased)

* Haml now requires Ruby 1.9.2 or above.
* Rails 3.0 and 3.1 are no longer supported, matching the official
* Haml now requires Ruby 2.0.0 or above.
* Rails 3 is no longer supported, matching the official
[Maintenance Policy for Ruby on Rails](http://weblog.rubyonrails.org/2013/2/24/maintenance-policy-for-ruby-on-rails/).
(Tee Parham)
* Fix for attribute merging. When an attribute method (or literal nested hash)
Expand Down
3 changes: 1 addition & 2 deletions README.md
Expand Up @@ -42,8 +42,7 @@ To use Haml with Rails, simply add Haml to your Gemfile and run `bundle`.
gem 'haml'
~~~

Haml 5 requires Rails version 3.2 or later. If you are using Rails 3.0 or 3.1,
you should use Haml version 4.0.x:
Haml 5 will require Rails version 4.0 or later. If you are using Rails 3.x, you should use Haml version 4.0.x:

~~~ruby
gem 'haml', '~> 4.0.5'
Expand Down
2 changes: 1 addition & 1 deletion haml.gemspec
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'tilt'

spec.add_development_dependency 'rails', '>= 3.2.0'
spec.add_development_dependency 'rails', '>= 4.0.0'
spec.add_development_dependency 'rbench'
spec.add_development_dependency 'minitest', '>= 4.0'
spec.add_development_dependency 'nokogiri', '~> 1.6.0'
Expand Down
8 changes: 3 additions & 5 deletions lib/haml/helpers/action_view_mods.rb
Expand Up @@ -82,11 +82,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

Expand Down
2 changes: 1 addition & 1 deletion lib/haml/template/plugin.rb
Expand Up @@ -6,7 +6,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
Expand Down
4 changes: 0 additions & 4 deletions test/gemfiles/Gemfile.rails-3.2.x

This file was deleted.

51 changes: 18 additions & 33 deletions test/helper_test.rb
Expand Up @@ -5,8 +5,9 @@ class FormModel
extend ActiveModel::Naming
end


class HelperTest < Haml::TestCase
TEXT_AREA_CONTENT_REGEX = /<(textarea)[^>]*>\n(.*?)<\/\1>/im

Post = Struct.new('Post', :body, :error_field, :errors)
class PostErrors
def on(name)
Expand Down Expand Up @@ -164,56 +165,40 @@ 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

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_preserve_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_preserve_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_preserve_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_preserve_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
Expand Down

0 comments on commit 1f8821c

Please sign in to comment.