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
|
||||
# making a possible one-line tag one line or not.
|
||||
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
|
||||
text.gsub!(/^/m, ' ' * @tabulation)
|
||||
end
|
||||
|
||||
@buffer << "#{text}"
|
||||
@buffer << text
|
||||
@real_tabs += tab_change
|
||||
end
|
||||
|
||||
|
@ -70,20 +70,20 @@ module Haml
|
|||
result = result[0...-1]
|
||||
end
|
||||
|
||||
if close_tag && Buffer.one_liner?(result)
|
||||
@buffer << result
|
||||
@buffer << "</#{close_tag}>\n"
|
||||
if close_tag && (@options[:ugly] || Buffer.one_liner?(result))
|
||||
@buffer << "#{result}</#{close_tag}>\n"
|
||||
@real_tabs -= 1
|
||||
else
|
||||
if close_tag
|
||||
@buffer << "\n"
|
||||
end
|
||||
|
||||
(result = result.gsub(/^/m, tabs(tabulation))) unless @options[:ugly]
|
||||
result = result.gsub(/^/m, tabs(tabulation)) unless @options[:ugly]
|
||||
@buffer << "#{result}\n"
|
||||
|
||||
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
|
||||
end
|
||||
end
|
||||
|
@ -109,16 +109,12 @@ module Haml
|
|||
else
|
||||
str = ">\n"
|
||||
end
|
||||
if @options[:ugly]
|
||||
@buffer << "<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper], attributes)}#{str}"
|
||||
else
|
||||
@buffer << "#{tabs(tabulation)}<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper], attributes)}#{str}"
|
||||
end
|
||||
|
||||
@buffer << "#{@options[:ugly] ? '' : tabs(tabulation)}<#{name}#{Precompiler.build_attributes(@options[:attr_wrapper], attributes)}#{str}"
|
||||
|
||||
if content
|
||||
if Buffer.one_liner?(content)
|
||||
if @options[:ugly] || Buffer.one_liner?(content)
|
||||
@buffer << "#{content}</#{name}>\n"
|
||||
elsif @options[:ugly]
|
||||
@buffer << "\n#{content}\n</#{name}>\n"
|
||||
else
|
||||
@buffer << "\n#{tabs(@real_tabs+1)}#{content}\n#{tabs(@real_tabs)}</#{name}>\n"
|
||||
end
|
||||
|
|
|
@ -385,16 +385,13 @@ class EngineTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_ugly_true
|
||||
input = "#outer\n #inner\n %p hello world"
|
||||
actual = Haml::Engine.new(input, :ugly => true).render
|
||||
expected = "<div id='outer'>\n<div id='inner'>\n<p>hello world</p>\n</div>\n</div>\n"
|
||||
assert_equal(expected, actual)
|
||||
end
|
||||
assert_equal("<div id='outer'>\n<div id='inner'>\n<p>hello world</p>\n</div>\n</div>\n",
|
||||
render("#outer\n #inner\n %p hello world", :ugly => true))
|
||||
|
||||
def test_ugly_false
|
||||
input = "#outer\n #inner\n %p hello world"
|
||||
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(expected, actual)
|
||||
assert_equal("<p>#{'s' * 75}</p>\n",
|
||||
render("%p #{'s' * 75}", :ugly => true))
|
||||
|
||||
assert_equal("<p>#{'s' * 75}</p>\n",
|
||||
render("%p= 's' * 75", :ugly => true))
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue