Closes ticket #6 and means that multiline-pipe based comments are added.
I also broke up the render method a bit to keep it from becoming a *wee* bit too big. Love, Hampton. git-svn-id: svn://hamptoncatlin.com/haml/trunk@47 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
e330b4ffc5
commit
8e245a6de7
|
@ -8,6 +8,7 @@ module Haml #:nodoc:
|
|||
# Lines <= the maximum will be rendered on one line,
|
||||
# i.e. <tt><p>Hello world</p></tt>
|
||||
ONE_LINER_LENGTH = 50
|
||||
MULTILINE_CHAR_VALUE = '|'[0]
|
||||
|
||||
def initialize(view)
|
||||
@view = view
|
||||
|
@ -39,13 +40,28 @@ module Haml #:nodoc:
|
|||
template.each_with_index do |line, index|
|
||||
count, line = count_soft_tabs(line)
|
||||
|
||||
if count && line
|
||||
surpress_render, line, count = handle_multiline(count, line)
|
||||
|
||||
if !surpress_render && count && line
|
||||
count, line = process_line(count, line)
|
||||
end
|
||||
end
|
||||
|
||||
# Close all the open tags
|
||||
@to_close_queue.length.times { close_tag }
|
||||
|
||||
# Return the result string
|
||||
@result
|
||||
end
|
||||
|
||||
def process_line(count, line)
|
||||
if line.strip[0, 3] == '!!!'
|
||||
@result << %|<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n|
|
||||
else
|
||||
if count <= @to_close_queue.size && @to_close_queue.size > 0
|
||||
(@to_close_queue.size - count).times { close_tag }
|
||||
end
|
||||
|
||||
case line.first
|
||||
when '.', '#'
|
||||
render_div(line)
|
||||
|
@ -61,14 +77,27 @@ module Haml #:nodoc:
|
|||
add line.strip
|
||||
end
|
||||
end
|
||||
end
|
||||
return count, line
|
||||
end
|
||||
|
||||
# Close all the open tags
|
||||
@to_close_queue.length.times { close_tag }
|
||||
|
||||
# Return the result string
|
||||
@result
|
||||
def handle_multiline(count, line)
|
||||
# The code to handle how a multi-line object should work.
|
||||
if @multiline_buffer && line[-1] == MULTILINE_CHAR_VALUE # '|' is 124
|
||||
# A multiline string is active, and is being continued
|
||||
@multiline_buffer += line[0...-1]
|
||||
supress_render = true
|
||||
elsif line[-1] == MULTILINE_CHAR_VALUE
|
||||
# A multiline string has just been activated, start adding the lines
|
||||
@multiline_buffer = line[0...-1]
|
||||
@multiline_count = count
|
||||
supress_render = true
|
||||
elsif @multiline_buffer
|
||||
# A multiline string has just ended, make line into the result
|
||||
process_line(@multiline_count, @multiline_buffer)
|
||||
@multiline_buffer = nil
|
||||
supress_render = false
|
||||
end
|
||||
return supress_render, line, count
|
||||
end
|
||||
|
||||
def add(line)
|
||||
|
|
|
@ -12,7 +12,7 @@ class HamlTest < Test::Unit::TestCase
|
|||
|
||||
def setup
|
||||
ActionView::Base.register_template_handler("haml", Haml::Engine)
|
||||
@base = ActionView::Base.new(File.dirname(__FILE__) + "/../test/templates/")
|
||||
@base = ActionView::Base.new(File.dirname(__FILE__) + "/templates/")
|
||||
@engine = Haml::Engine.new(@base)
|
||||
@base.instance_variable_set("@article", Article.new)
|
||||
end
|
||||
|
|
|
@ -13,6 +13,11 @@
|
|||
20
|
||||
</div>
|
||||
<div id='body'> Quotes should be loved! Just like people!</div>
|
||||
<p>
|
||||
Holy cow multiline tags! A pipe (|) even!
|
||||
Wow.
|
||||
1|2|3
|
||||
</p>
|
||||
<div class='of_divs_with_underscore' id='combo'>with this text</div>
|
||||
<div class='footer'>
|
||||
<strong class='shout'>
|
||||
|
|
|
@ -11,6 +11,15 @@
|
|||
The question is if this would translate! Ahah!
|
||||
= 1 + 9 + 8 + 2 #numbers should work and this should be ignored
|
||||
#body= " Quotes should be loved! Just like people!"
|
||||
%p
|
||||
= "Holy cow " + |
|
||||
"multiline " + |
|
||||
"tags! " + |
|
||||
"A pipe (|) even!" |
|
||||
Wow.
|
||||
= [1, 2, 3].collect { |n| |
|
||||
n.to_s |
|
||||
}.join("|") |
|
||||
#combo.of_divs_with_underscore= @should_eval = "with this text"
|
||||
.footer
|
||||
%strong.shout= "This is a really long ruby quote. It should be loved and wrapped because its more than 50 characters. This value may change in the future and this test may look stupid. \nSo, I'm just making it *really* long. God, I hope this works"
|
||||
|
|
Loading…
Reference in New Issue