Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'stable'

Conflicts:
	CHANGELOG.md
  • Loading branch information...
commit baacf2329b1c4fa744855834a22106d21508cdb9 2 parents 8241fb2 + dcd601a
Norman Clarke norman authored
3  .travis.yml
View
@@ -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
8 CHANGELOG.md
View
@@ -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.
@@ -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
13 lib/haml/buffer.rb
View
@@ -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) %>
@@ -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)}"
@@ -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
1  lib/haml/railtie.rb
View
@@ -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
2  lib/haml/template.rb
View
@@ -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 test/helper_test.rb
View
@@ -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
@@ -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"
4 test/templates/_text_area_helper.html.haml
View
@@ -0,0 +1,4 @@
+- defined?(text_area_helper) and nil # silence a warning
+.foo
+ .bar
+ = text_area :post, :body
Please sign in to comment.
Something went wrong with that request. Please try again.