mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
We have 100% passing.
Simplified (in a way I didn't initially want) the flattening procedure. However, it helps the tests pass and that's a Good Thing. Now for speed tests and playing with globalize. git-svn-id: svn://hamptoncatlin.com/haml/trunk@17 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
6cbc2bf9b3
commit
331f0247ae
5 changed files with 43 additions and 34 deletions
|
@ -10,19 +10,14 @@ module HAML
|
|||
|
||||
def initialize(base)
|
||||
@base = base
|
||||
@tab_index = ["", " "]
|
||||
@happy_land = HappyLand.new(@base, @base.assigns)
|
||||
#pre-build the tab index up to 9
|
||||
20.times do |num|
|
||||
@tab_index << @tab_index.last + " "
|
||||
end
|
||||
end
|
||||
|
||||
def render(template = "", locals = {})
|
||||
@result = ""
|
||||
@to_close_queue = []
|
||||
|
||||
@result, @to_close_queue = "", []
|
||||
|
||||
#this helps get the right values for helpers.
|
||||
#though, it is definitely in the "hack" category
|
||||
@base.assigns.each do |key,value|
|
||||
@base.instance_eval("@#{key} = value")
|
||||
end
|
||||
|
@ -35,7 +30,7 @@ module HAML
|
|||
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
|
||||
count, line = count_levels(line)
|
||||
count, line = count_soft_tabs(line)
|
||||
#puts count.to_s + "::" + line
|
||||
if count <= @to_close_queue.size && @to_close_queue.size > 0
|
||||
(@to_close_queue.size - count).times { close_tag }
|
||||
|
@ -67,7 +62,7 @@ module HAML
|
|||
end
|
||||
|
||||
def add_single(line = "")
|
||||
@result << @tab_index[@to_close_queue.size]
|
||||
@result << tabs(@to_close_queue.size)
|
||||
@result << line.chomp + "\n"
|
||||
end
|
||||
|
||||
|
@ -149,18 +144,12 @@ module HAML
|
|||
end
|
||||
attributes
|
||||
end
|
||||
|
||||
def count_levels(line)
|
||||
[line.index(/[^ ]/)/2, line.strip]
|
||||
end
|
||||
|
||||
|
||||
def one_liner?(value)
|
||||
((value.length < 50) && value.scan(/\n/).empty?)
|
||||
end
|
||||
|
||||
def template_eval(code)
|
||||
#@base.instance_eval(code)
|
||||
#render :inline => "<%=#{code}%>"
|
||||
@happy_land.instance_eval(code)
|
||||
end
|
||||
|
||||
|
|
|
@ -13,12 +13,19 @@ module HAMLHelpers
|
|||
end
|
||||
|
||||
def find_and_flatten(input)
|
||||
s, result = StringScanner.new(input), ""
|
||||
while s.scan_until(/<(textarea|code|pre)[^>]*>/i)
|
||||
result += s.pre_match.to_s + s.matched
|
||||
tag_name = s.matched.scan(/(textarea|code|pre)/).first
|
||||
result += flatten(s.scan_until(/<\/#{tag_name}>/i))
|
||||
sets = input.scan(/<(textarea|code|pre)[^>]*>(.*?)<\/\1>/im)
|
||||
sets.each do |thing|
|
||||
input = input.gsub(thing[1], flatten(thing[1]))
|
||||
end
|
||||
result + s.rest
|
||||
input
|
||||
end
|
||||
|
||||
def tabs(count)
|
||||
" " * count
|
||||
end
|
||||
|
||||
def count_soft_tabs(line)
|
||||
[line.index(/[^ ]/)/2, line.strip]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -20,11 +20,11 @@ class HamlTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def assert_renders_correctly(name)
|
||||
#tupleize(load_result(name).scan(/\n/), @base.render(name).scan(/\n/)).each do |pair|
|
||||
tupleize(load_result(name).scan(/\n/), @base.render(name).scan(/\n/)).each do |pair|
|
||||
#test each line to make sure it matches... (helps with error messages to do them seperately)
|
||||
# assert_equal(pair.first, pair.last)
|
||||
#end
|
||||
assert_equal(load_result(name), @base.render(name))
|
||||
assert_equal(pair.first, pair.last)
|
||||
end
|
||||
#assert_equal(load_result(name), @base.render(name))
|
||||
end
|
||||
|
||||
# Make sure our little environment builds
|
||||
|
|
|
@ -22,5 +22,12 @@ class HamlTest < Test::Unit::TestCase
|
|||
find_and_flatten("<div class='text_area_test_area'>\n <textarea>Two\n lines</textarea>\n</div>\n"))
|
||||
assert_equal( "<code>Two
lines</code><pre>a
b
c</pre>",
|
||||
find_and_flatten("<code>Two\nlines</code><pre>a\nb\nc</pre>"))
|
||||
assert_equal( "<pre>Two
lines</pre>\n<pre>a
b
c</pre>",
|
||||
find_and_flatten("<pre>Two\nlines</pre>\n<pre>a\nb\nc</pre>"))
|
||||
end
|
||||
|
||||
def tabs
|
||||
assert_equals(" ", tabs(1))
|
||||
assert_equals(" ", tabs(5))
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,19 +2,25 @@
|
|||
<div class='text_area_test_area'>
|
||||
<textarea>Oneline</textarea>
|
||||
</div>
|
||||
<div class='text_area_test_area'>
|
||||
<textarea>Two
|
||||
lines</textarea>
|
||||
</div>
|
||||
<div class='text_area_test_area'>
|
||||
<textarea>Oneline</textarea>
|
||||
</div>
|
||||
<textarea>BLAH
|
||||
</textarea>
|
||||
<div class='text_area_test_area'>
|
||||
<textarea>Two
lines</textarea>
|
||||
</div>
|
||||
<textarea>BLAH
|
||||
</textarea>
|
||||
<div class='text_area_test_area'>
|
||||
<textarea>Oneline</textarea>
|
||||
</div>
|
||||
<textarea>BLAH
</textarea>
|
||||
<div class='text_area_test_area'>
|
||||
<textarea>Two
lines</textarea>
|
||||
</div>
|
||||
<textarea>BLAH
</textarea>
|
||||
<div id='flattened'>
|
||||
<div class='text_area_test_area'>
|
||||
<textarea>Two
lines</textarea>
|
||||
</div>
|
||||
<textarea>BLAH
</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue