From: Robert Klemme Date: 2011-03-07T21:31:05+09:00 Subject: Re: Blank lines generated by ERB - Can we prevent them? On Sun, Mar 6, 2011 at 1:55 AM, RichardOnRails wrote: > Hi, > > I'm running: > Ruby 1.8.6 > eRuby 1.0.5 > WinXP-Pro/SP3 > > I've got a three-line script: > <%#- Example from -%> > <%#- http://www.linuxtopia.org/online_books/programming_books/ruby_tutorial/Ruby_and_the_Web_Using_eruby.html > -%> > This text is <% a = 100; print "#{a}% Live!" %> > === end of script === > > that produces 5 lines of output in a Command Window (2 blank lines, a > line of text and 2 more blank lines): > K:\_Projects\Ruby\_Ruby_Tests\TestEruby>eruby Test_eruby_01.erb > > > This text is 100% Live! > > > K:\_Projects\Ruby\_Ruby_Tests\TestEruby> > === end of relevant portion of Cmd Window === > > I haven't been able to get rid of those blank lines.  Is there a way? Use less tags and let them span multiple lines. Remember that erb will copy everything literally that is not between <%%> so line endings are simply copied over. You can do 13:28:16 Temp$ erb19 x.erb This text is 100% Live!" 13:29:44 Temp$ cat -n x.erb 1 <%#- 2 Example from 3 http://www.linuxtopia.org/online_books/programming_books/ruby_tutorial/Ruby_and_the_Web_Using_eruby.html 4 -%>This text is <% a = 100 %><%= a %>% Live!" 13:29:45 Temp$ And, btw, note to not use print, puts and the line in erb templates. If you want to include output in the file you need to use <%= %> because print may send output to a completely different place plus even if you catch the same (i.e. stdout) order may be wrong. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/