mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Tweak the :ugly code a little.
This commit is contained in:
parent
f7f11e202b
commit
40da61392f
2 changed files with 18 additions and 25 deletions
|
@ -46,12 +46,12 @@ module Haml
|
||||||
# Renders +text+ with the proper tabulation. This also deals with
|
# Renders +text+ with the proper tabulation. This also deals with
|
||||||
# making a possible one-line tag one line or not.
|
# making a possible one-line tag one line or not.
|
||||||
def push_text(text, tab_change = 0)
|
def push_text(text, tab_change = 0)
|
||||||
if(@tabulation > 0 && !@options[:ugly])
|
if @tabulation > 0 && !@options[:ugly]
|
||||||
# Have to push every line in by the extra user set tabulation
|
# Have to push every line in by the extra user set tabulation
|
||||||
text.gsub!(/^/m, ' ' * @tabulation)
|
text.gsub!(/^/m, ' ' * @tabulation)
|
||||||
end
|
end
|
||||||
|
|
||||||
@buffer << "#{text}"
|
@buffer << text
|
||||||
@real_tabs += tab_change
|
@real_tabs += tab_change
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -70,20 +70,20 @@ module Haml
|
||||||
result = result[0...-1]
|
result = result[0...-1]
|
||||||
end
|
end
|
||||||
|
|
||||||
if close_tag && Buffer.one_liner?(result)
|
if close_tag && (@options[:ugly] || Buffer.one_liner?(result))
|
||||||
@buffer << result
|
@buffer << "#{result}</#{close_tag}>\n"
|
||||||
@buffer << "</#{close_tag}>\n"
|
|
||||||
@real_tabs -= 1
|
@real_tabs -= 1
|
||||||
else
|
else
|
||||||
if close_tag
|
if close_tag
|
||||||
@buffer << "\n"
|
@buffer << "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
(result = result.gsub(/^/m, tabs(tabulation))) unless @options[:ugly]
|
result = result.gsub(/^/m, tabs(tabulation)) unless @options[:ugly]
|
||||||
@buffer << "#{result}\n"
|
@buffer << "#{result}\n"
|
||||||
|
|
||||||
if close_tag
|
if close_tag
|
||||||
@buffer << (@options[:ugly] ? "</#{close_tag}>\n" : "#{tabs(tabulation-1)}</#{close_tag}>\n")
|
# We never get here if @options[:ugly] is true
|
||||||
|
@buffer << "#{tabs(tabulation-1)}</#{close_tag}>\n"
|
||||||
@real_tabs -= 1
|
@real_tabs -= 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -109,16 +109,12 @@ module Haml
|
||||||
else
|
else
|
||||||
str = ">\n"
|
str = ">\n"
|
||||||
end
|
end
|
||||||
if @options[:ugly]
|
|
||||||
@buffer << "<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper], attributes)}#{str}"
|
@buffer << "#{@options[:ugly] ? '' : tabs(tabulation)}<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper], attributes)}#{str}"
|
||||||
else
|
|
||||||
@buffer << "#{tabs(tabulation)}<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper], attributes)}#{str}"
|
|
||||||
end
|
|
||||||
if content
|
if content
|
||||||
if Buffer.one_liner?(content)
|
if @options[:ugly] || Buffer.one_liner?(content)
|
||||||
@buffer << "#{content}</#{name}>\n"
|
@buffer << "#{content}</#{name}>\n"
|
||||||
elsif @options[:ugly]
|
|
||||||
@buffer << "\n#{content}\n</#{name}>\n"
|
|
||||||
else
|
else
|
||||||
@buffer << "\n#{tabs(@real_tabs+1)}#{content}\n#{tabs(@real_tabs)}</#{name}>\n"
|
@buffer << "\n#{tabs(@real_tabs+1)}#{content}\n#{tabs(@real_tabs)}</#{name}>\n"
|
||||||
end
|
end
|
||||||
|
|
|
@ -385,16 +385,13 @@ class EngineTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ugly_true
|
def test_ugly_true
|
||||||
input = "#outer\n #inner\n %p hello world"
|
assert_equal("<div id='outer'>\n<div id='inner'>\n<p>hello world</p>\n</div>\n</div>\n",
|
||||||
actual = Haml::Engine.new(input, :ugly => true).render
|
render("#outer\n #inner\n %p hello world", :ugly => true))
|
||||||
expected = "<div id='outer'>\n<div id='inner'>\n<p>hello world</p>\n</div>\n</div>\n"
|
|
||||||
assert_equal(expected, actual)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_ugly_false
|
assert_equal("<p>#{'s' * 75}</p>\n",
|
||||||
input = "#outer\n #inner\n %p hello world"
|
render("%p #{'s' * 75}", :ugly => true))
|
||||||
actual = Haml::Engine.new(input, :ugly => false).render
|
|
||||||
expected = "<div id='outer'>\n <div id='inner'>\n <p>hello world</p>\n </div>\n</div>\n"
|
assert_equal("<p>#{'s' * 75}</p>\n",
|
||||||
assert_equal(expected, actual)
|
render("%p= 's' * 75", :ugly => true))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue