Skip to content

Commit

Permalink
Merge branch 'stable'
Browse files Browse the repository at this point in the history
Conflicts:
	CHANGELOG.md
  • Loading branch information
norman committed Mar 21, 2013
2 parents 8241fb2 + dcd601a commit baacf23
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ matrix:
# Rails 4 doesn't run on Ruby 1.8
- { rvm: 1.8.7, gemfile: test/gemfiles/Gemfile.rails-4.0.x }

allow_failures:
- { rvm: jruby, gemfile: test/gemfiles/Gemfile.rails-4.0.x }

branches:
only:
- master
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
* Make escape_once respect hexadecimal references. (Matt Wildig)
* General performance and memory usage improvements. (Akira Matsuda)

## 4.0.1 (Unreleased)
## 4.0.1

Released March 21, 2013 ([diff](https://github.com/haml/haml/compare/4.0.0...4.0.1)).

* Remove Rails 3.2.3+ textarea hack in favor of a more general solution.
* Fix some performance regressions.
Expand All @@ -19,6 +21,10 @@
(thanks [Alisdair McDiarmid](https://github.com/alisdair))
* Fix support for sass-rails 4.0 beta.
(thanks [Ryunosuke SATO](https://github.com/tricknotes))
* Load "haml/template" in Railtie in order to prevent user options set in a
Rails initializer from being overwritten
* Don't depend on Rails in haml/template to allow using Haml with ActionView
but without Rails itself. (thanks [Hunter Haydel](https://github.com/wedgex))

## 4.0.0

Expand Down
13 changes: 7 additions & 6 deletions lib/haml/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def adjust_tabs(tab_change)
<% end %>
<% if ugly %>
fix_textareas!(result, nil) if toplevel? && result.include?('<textarea')
fix_textareas!(result) if toplevel? && result.include?('<textarea')
return result
<% else %>
<% if !(in_tag && preserve_tag && !nuke_inner_whitespace) %>
Expand Down Expand Up @@ -184,7 +184,7 @@ def adjust_tabs(tab_change)
<% if in_tag && !nuke_inner_whitespace %> result = tabs(tabulation) + result <% end %>
end
fix_textareas!(result, tabs(tabulation)) if toplevel? && result.include?('<textarea')
fix_textareas!(result) if toplevel? && result.include?('<textarea')
<% if in_tag && !nuke_inner_whitespace %>
result = "\\n\#{result}\\n\#{tabs(tabulation-1)}"
Expand Down Expand Up @@ -271,14 +271,15 @@ def self.merge_attrs(to, from)
# @param options [Hash] The options hash provided by the Haml::Buffer
# @since Haml 4.0.1
# @private
def fix_textareas!(input, tabs)
def fix_textareas!(input)
pattern = /([ ]*)<(textarea)([^>]*)>(\n|&#x000A;)(.*?)(<\/\2>)/im
input.gsub!(pattern) do |s|
match = pattern.match(s)
content = match[5]
unless tabs.nil?
content.sub!(match[1].to_s, '')
content.sub!(tabs, '')
if match[4] == '&#x000A;'
content.sub!(/\A /, '&#x0020;')
else
content.sub!(/\A[ ]*/, '')
end
"#{match[1]}<#{match[2]}#{match[3]}>\n#{content}</#{match[2]}>"
end
Expand Down
1 change: 1 addition & 0 deletions lib/haml/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
module Haml
class Railtie < ::Rails::Railtie
initializer :haml do |app|
require "haml/template"
if defined?(::Sass::Rails::SassTemplate) && app.config.assets.enabled
require "haml/sass_rails_filter"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/haml/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def rails_xss_safe?; true; end
end


Haml::Template.options[:ugly] = !Rails.env.development?
Haml::Template.options[:ugly] = defined?(Rails) ? !Rails.env.development? : true
Haml::Template.options[:escape_html] = true

require 'haml/template/plugin'
51 changes: 43 additions & 8 deletions test/helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def [](name)
def setup
@base = ActionView::Base.new
@base.controller = ActionController::Base.new
@base.view_paths << File.expand_path("../templates", __FILE__)

if defined?(ActionController::Response)
# This is needed for >=3.0.0
Expand Down Expand Up @@ -137,24 +138,58 @@ def test_pre
render('= content_tag "pre", "Foo bar\n baz"', :action_view))
end

def test_text_area
regex = /<(textarea)[^>]*>(.*?)<\/\1>/im

# Rails >= 3.2.3 adds a newline after opening textarea tags.
# 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
if major == 4 || ((major == 3) && (minor >= 2) && (tiny >= 3))
regex = /<(textarea)[^>]*>\n(.*?)<\/\1>/im
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(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(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)
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
end

def test_capture_haml
assert_equal(<<HTML, render(<<HAML))
"<p>13</p>\\n"
Expand Down
4 changes: 4 additions & 0 deletions test/templates/_text_area_helper.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- defined?(text_area_helper) and nil # silence a warning
.foo
.bar
= text_area :post, :body

0 comments on commit baacf23

Please sign in to comment.