| CODENOTIFIER | HelpYou are not signed inSign in |
Project: HAML
Revision:
Author:
Date: 22 Sep 2006 06:18:43
Changes: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.
| ... | ...@@ -11,6 +11,15 @@ | |
| 11 | 11 | The question is if this would translate! Ahah! |
| 12 | 12 | = 1 + 9 + 8 + 2 #numbers should work and this should be ignored |
| 13 | 13 | #body= " Quotes should be loved! Just like people!" |
| 14 | %p | |
| 15 | = "Holy cow " + | | |
| 16 | "multiline " + | | |
| 17 | "tags! " + | | |
| 18 | "A pipe (|) even!" | | |
| 19 | Wow. | |
| 20 | = [1, 2, 3].collect { |n| | | |
| 21 | n.to_s | | |
| 22 | }.join("|") | | |
| 14 | 23 | #combo.of_divs_with_underscore= @should_eval = "with this text" |
| 15 | 24 | .footer |
| 16 | 25 | %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" |
| ... | ...@@ -8,6 +8,7 @@ | |
| 8 | 8 | # Lines <= the maximum will be rendered on one line, |
| 9 | 9 | # i.e. <tt><p>Hello world</p></tt> |
| 10 | 10 | ONE_LINER_LENGTH = 50 |
| 11 | MULTILINE_CHAR_VALUE = '|'[0] | |
| 11 | 12 | |
| 12 | 13 | def initialize(view) |
| 13 | 14 | @view = view |
| ... | ...@@ -38,29 +39,11 @@ | |
| 38 | 39 | # Process each line of the template returning the resulting string |
| 39 | 40 | template.each_with_index do |line, index| |
| 40 | 41 | count, line = count_soft_tabs(line) |
| 41 | ||
| 42 | if count && line | |
| 43 | if line.strip[0, 3] == '!!!' | |
| 44 | @result << %|<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n| | |
| 45 | else | |
| 46 | if count <= @to_close_queue.size && @to_close_queue.size > 0 | |
| 47 | (@to_close_queue.size - count).times { close_tag } | |
| 48 | end | |
| 49 | case line.first | |
| 50 | when '.', '#' | |
| 51 | render_div(line) | |
| 52 | when '%' | |
| 53 | render_tag(line) | |
| 54 | when '/' | |
| 55 | render_comment(line) | |
| 56 | when '=' | |
| 57 | add template_eval(line[1, line.length]).to_s | |
| 58 | when '~' | |
| 59 | add find_and_flatten(template_eval(line[1, line.length])).to_s | |
| 60 | else | |
| 61 | add line.strip | |
| 62 | end | |
| 63 | end | |
| 42 | ||
| 43 | surpress_render, line, count = handle_multiline(count, line) | |
| 44 | ||
| 45 | if !surpress_render && count && line | |
| 46 | count, line = process_line(count, line) | |
| 64 | 47 | end |
| 65 | 48 | end |
| 66 | 49 | |
| ... | ...@@ -71,6 +54,52 @@ | |
| 71 | 54 | @result |
| 72 | 55 | end |
| 73 | 56 | |
| 57 | def process_line(count, line) | |
| 58 | if line.strip[0, 3] == '!!!' | |
| 59 | @result << %|<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n| | |
| 60 | else | |
| 61 | if count <= @to_close_queue.size && @to_close_queue.size > 0 | |
| 62 | (@to_close_queue.size - count).times { close_tag } | |
| 63 | end | |
| 64 | ||
| 65 | case line.first | |
| 66 | when '.', '#' | |
| 67 | render_div(line) | |
| 68 | when '%' | |
| 69 | render_tag(line) | |
| 70 | when '/' | |
| 71 | render_comment(line) | |
| 72 | when '=' | |
| 73 | add template_eval(line[1, line.length]).to_s | |
| 74 | when '~' | |
| 75 | add find_and_flatten(template_eval(line[1, line.length])).to_s | |
| 76 | else | |
| 77 | add line.strip | |
| 78 | end | |
| 79 | end | |
| 80 | return count, line | |
| 81 | end | |
| 82 | ||
| 83 | def handle_multiline(count, line) | |
| 84 | # The code to handle how a multi-line object should work. | |
| 85 | if @multiline_buffer && line[-1] == MULTILINE_CHAR_VALUE # '|' is 124 | |
| 86 | # A multiline string is active, and is being continued | |
| 87 | @multiline_buffer += line[0...-1] | |
| 88 | supress_render = true | |
| 89 | elsif line[-1] == MULTILINE_CHAR_VALUE | |
| 90 | # A multiline string has just been activated, start adding the lines | |
| 91 | @multiline_buffer = line[0...-1] | |
| 92 | @multiline_count = count | |
| 93 | supress_render = true | |
| 94 | elsif @multiline_buffer | |
| 95 | # A multiline string has just ended, make line into the result | |
| 96 | process_line(@multiline_count, @multiline_buffer) | |
| 97 | @multiline_buffer = nil | |
| 98 | supress_render = false | |
| 99 | end | |
| 100 | return supress_render, line, count | |
| 101 | end | |
| 102 | ||
| 74 | 103 | def add(line) |
| 75 | 104 | return if line.nil? |
| 76 | 105 | line.to_s.each_line do |me| |
| ... | ...@@ -132,7 +161,7 @@ | |
| 132 | 161 | class_name = object_ref.class.to_s.underscore |
| 133 | 162 | attributes.merge!(:id => "#{class_name}_#{object_ref.id}", :class => class_name) |
| 134 | 163 | end |
| 135 | ||
| 164 | ||
| 136 | 165 | if action == '/' |
| 137 | 166 | atomic_tag(tag_name, attributes) |
| 138 | 167 | elsif action == '=' || action == '~' |
| ... | ...@@ -12,7 +12,7 @@ | |
| 12 | 12 | |
| 13 | 13 | def setup |
| 14 | 14 | ActionView::Base.register_template_handler("haml", Haml::Engine) |
| 15 | @base = ActionView::Base.new(File.dirname(__FILE__) + "/../test/templates/") | |
| 15 | @base = ActionView::Base.new(File.dirname(__FILE__) + "/templates/") | |
| 16 | 16 | @engine = Haml::Engine.new(@base) |
| 17 | 17 | @base.instance_variable_set("@article", Article.new) |
| 18 | 18 | end |
| ... | ...@@ -13,6 +13,11 @@ | |
| 13 | 13 | 20 |
| 14 | 14 | </div> |
| 15 | 15 | <div id='body'> Quotes should be loved! Just like people!</div> |
| 16 | <p> | |
| 17 | Holy cow multiline tags! A pipe (|) even! | |
| 18 | Wow. | |
| 19 | 1|2|3 | |
| 20 | </p> | |
| 16 | 21 | <div class='of_divs_with_underscore' id='combo'>with this text</div> |
| 17 | 22 | <div class='footer'> |
| 18 | 23 | <strong class='shout'> |