title: Escaping Line-Returns/End-of-Line in ERB templates
body: <p>I need to be able to format unprinted logic lines in ERB without affecting the eventual text output of the template. At this point, I don't think that ERB supports such escaping.</p>
  
  <p>This is my first major Ruby project. I am writing a code generator. My templates will include a considerable number of conditionals and enumerations. To make the template readable and maintainable, I need to be able to format the logical code and comments without distorting the eventual output. </p>
  
  <p>E.g. Suppose I want this output:</p>
  
  <pre><code>Starting erbOutput
  1
  2
  3
  4
  Ending erbOutput
  </code></pre>
  
  <p>I naively wrote the template something like so:</p>
  
  <pre><code>require 'erb'
  h=&lt;&lt;H
  Starting erbOutput
  &lt;%# comment %&gt;
  &lt;%5.times do |e|%&gt;
  &lt;%=e.to_s  %&gt;
  &lt;%end %&gt;
  &lt;%# comment %&gt;
  Ending erbOutput
  H
  s=ERB.new(h).result
  puts s
  </code></pre>
  
  <p>... but this produces </p>
  
  <pre><code>Starting erbOutput
  
  
  0
  
  1
  
  2
  
  3
  
  4
  
  
  Ending erbOutput
  </code></pre>
  
  <p>A straight print:</p>
  
  <pre><code>"Starting erbOutput\n\n\n0\n\n1\n\n2\n\n3\n\n4\n\n\nEnding erbOutput\n"
  </code></pre>
  
  <p>...makes it clear that the line-returns of the logic and comment lines are being included in the ERB output. </p>
  
  <p>I can produce the desired output by cramming the template into this awkward form:</p>
  
  <pre><code>h=&lt;&lt;H
  Starting erbOutput&lt;%# comment %&gt;
  &lt;%5.times do |e|%&gt;&lt;%=e.to_s  %&gt;
  &lt;%end %&gt;&lt;%# comment %&gt;Ending erbOutput
  H
  </code></pre>
  
  <p>... but I don't think I can debug and maintain templates without more readable formatting. Some of my conditionals and enumerations are as much as three levels deep and I comment heavily. Cramming all that on one or two lines makes the template utterly unreadable.</p>
  
  <p>Is there a way to escape or otherwise suppress the line returns of logic an comment lines in ERB? Does one of the other commonly available Ruby template modules handle this better?</p>
  
  <p>In case it matters, I am working in MacRuby 0.10 (implements Ruby 1.9.2) on MacOS 10.6.7.</p>