1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Merge branch 'stable'

Conflicts:
	CHANGELOG.md
	lib/haml/helpers.rb
	lib/haml/version.rb
This commit is contained in:
Norman Clarke 2013-12-04 15:13:01 -03:00
commit 40d3e7aa2f
4 changed files with 57 additions and 24 deletions

View file

@ -12,6 +12,15 @@
* General performance and memory usage improvements. (Akira Matsuda) * General performance and memory usage improvements. (Akira Matsuda)
* Don't treat the 'data' attribute specially when merging attribute hashes. (Matt Wildig and Norman Clarke) * Don't treat the 'data' attribute specially when merging attribute hashes. (Matt Wildig and Norman Clarke)
## 4.0.5
Not released yet.
* Fix for bug whereby when HAML :ugly option is "true",
ActionView::Helpers::CaptureHelper::capture returns the whole view buffer
when passed a block that returns nothing (thanks [Mircea
Moise](https://github.com/mmircea16)).
## 4.0.4 ## 4.0.4
Released on November 5, 2013 ([diff](https://github.com/haml/haml/compare/4.0.3...4.0.4)). Released on November 5, 2013 ([diff](https://github.com/haml/haml/compare/4.0.3...4.0.4)).
@ -1349,3 +1358,4 @@ has been moved to [YARD](http://yard.soen.ca).
YARD is an excellent documentation system, YARD is an excellent documentation system,
and allows us to write our documentation in [Maruku](http://maruku.rubyforge.org), and allows us to write our documentation in [Maruku](http://maruku.rubyforge.org),
which is also excellent. which is also excellent.
>>>>>>> External Changes

View file

@ -372,25 +372,16 @@ MESSAGE
position = haml_buffer.buffer.length position = haml_buffer.buffer.length
haml_buffer.capture_position = position haml_buffer.capture_position = position
block.call(*args) value = block.call(*args)
captured = haml_buffer.buffer.slice!(position..-1) captured = haml_buffer.buffer.slice!(position..-1)
return captured if haml_buffer.options[:ugly]
# Note that the "reject" is needed for rbx 1.2.4, which includes empty
# strings in the returned array when splitting by /^/.
captured = captured.split(/^/)
captured.delete('')
min_tabs = nil if captured == '' and value != haml_buffer.buffer
captured.each do |line| captured = (value.is_a?(String) ? value : nil)
tabs = line.index(/[^ ]/) || line.length
min_tabs ||= tabs
min_tabs = min_tabs > tabs ? tabs : min_tabs
end end
captured.map do |line| return nil if captured.nil?
line.slice(min_tabs, line.length) return (haml_buffer.options[:ugly] ? captured : prettify(captured))
end.join
end end
ensure ensure
haml_buffer.capture_position = nil haml_buffer.capture_position = nil
@ -669,6 +660,22 @@ MESSAGE
_erbout = _erbout = _hamlout.buffer _erbout = _erbout = _hamlout.buffer
proc { |*args| proc.call(*args) } proc { |*args| proc.call(*args) }
end end
def prettify(text)
text = text.split(/^/)
text.delete('')
min_tabs = nil
text.each do |line|
tabs = line.index(/[^ ]/) || line.length
min_tabs ||= tabs
min_tabs = min_tabs > tabs ? tabs : min_tabs
end
text.map do |line|
line.slice(min_tabs, line.length)
end.join
end
end end
end end

View file

@ -41,16 +41,9 @@ module ActionView
if Haml::Helpers.block_is_haml?(block) if Haml::Helpers.block_is_haml?(block)
#double assignment is to avoid warnings #double assignment is to avoid warnings
_hamlout = _hamlout = eval('_hamlout', block.binding) # Necessary since capture_haml checks _hamlout _hamlout = _hamlout = eval('_hamlout', block.binding) # Necessary since capture_haml checks _hamlout
value = nil
buffer = capture_haml(*args) { value = yield(*args) } str = capture_haml(*args, &block)
str =
if !buffer.empty?
buffer
elsif value.is_a?(String)
value
else
nil
end
# NonCattingString is present in Rails less than 3.1.0. When support # NonCattingString is present in Rails less than 3.1.0. When support
# for 3.0 is dropped, this can be removed. # for 3.0 is dropped, this can be removed.
return ActionView::NonConcattingString.new(str) if str && defined?(ActionView::NonConcattingString) return ActionView::NonConcattingString.new(str) if str && defined?(ActionView::NonConcattingString)

View file

@ -111,6 +111,29 @@ class TemplateTest < MiniTest::Unit::TestCase
end end
end end
def test_render_method_returning_null_with_ugly
@base.instance_eval do
def empty
nil
end
def render_something(&block)
capture(self, &block)
end
end
content_to_render = "%h1 This is part of the broken view.\n= render_something do |thing|\n = thing.empty do\n = 'test'"
result = render(content_to_render, :ugly => true)
expected_result = "<h1>This is part of the broken view.</h1>\n"
assert_equal(expected_result, result)
end
def test_simple_rendering_with_ugly
content_to_render = "%p test\n= capture { 'foo' }"
result = render(content_to_render, :ugly => true)
expected_result = "<p>test</p>\nfoo\n"
assert_equal(expected_result, result)
end
def test_templates_should_render_correctly_with_render_proc def test_templates_should_render_correctly_with_render_proc
assert_renders_correctly("standard") do |name| assert_renders_correctly("standard") do |name|
engine = Haml::Engine.new(File.read(File.dirname(__FILE__) + "/templates/#{name}.haml"), :format => :xhtml) engine = Haml::Engine.new(File.read(File.dirname(__FILE__) + "/templates/#{name}.haml"), :format => :xhtml)