I seen some RoR code that went like this: <% if ...blah, blah... -%> .. blah, blah <% end -%> What are the minus signs for in the if statement? Cannot seem to find anything about this, and searching on "-" in this context is hard to get anything meaningfull back. Thanks, - Mark -- Posted via ruby-forum.com.
I asked this question a while back, so might as well take this one. It''s undocumented, you can get it if you look at the erb code. It means ''evaluate this code, but don''t insert a newline afterwards'' Saves you from having a bunch of whitespace in your output. On 1/4/06, Mark Haliday <markhaliday@yahoo.com> wrote:> > I seen some RoR code that went like this: > > <% if ...blah, blah... -%> > > .. blah, blah > > <% end -%> > > What are the minus signs for in the if statement? Cannot seem to find > anything about this, and searching on "-" in this context is hard to get > anything meaningfull back. > > > Thanks, > > - Mark > > -- > Posted via ruby-forum.com. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: wrath.rubyonrails.org/pipermail/rails/attachments/20060104/eec6ba84/attachment.html
The minus sign means that the code will take no space on the page if the IF does not fire. I think they call it "supressing the newline that follows the %> delimiter. bruce On 4-Jan-06, at 8:55 AM, Mark Haliday wrote:> I seen some RoR code that went like this: > > <% if ...blah, blah... -%> > > .. blah, blah > > <% end -%> > > What are the minus signs for in the if statement? Cannot seem to find > anything about this, and searching on "-" in this context is hard > to get > anything meaningfull back. > > > Thanks, > > - Mark > > -- > Posted via ruby-forum.com. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > lists.rubyonrails.org/mailman/listinfo/rails
Lee Pope wrote:> I asked this question a while back, so might as well take this one. > > It''s undocumented, you can get it if you look at the erb code. > > It means ''evaluate this code, but don''t insert a newline afterwards'' > > Saves you from having a bunch of whitespace in your output.Ok, this makes sense. Thanks guys. -- Posted via ruby-forum.com.
The "-%>" causes ERb to suppress the newline on any output. If you have output, it will not have an ending newline, if you have no output, you will not get meaningless blank lines. It only seems to be documented in the ERb.rb source code: raa.ruby-lang.org/gonzui/markup/ruby/lib/erb.rb ( Do a find on :ExplicitTrimRegexp ) The ERb documentation says you can suppress newlines with the trim_mode setting, but does not say what the default trim_mode character is. -Sean Mark Haliday wrote:> I seen some RoR code that went like this: > > <% if ...blah, blah... -%> > > .. blah, blah > > <% end -%> > > What are the minus signs for in the if statement? Cannot seem to find > anything about this, and searching on "-" in this context is hard to get > anything meaningfull back. > > > Thanks, > > - Mark-- Posted via ruby-forum.com.
sean lynch wrote:>The "-%>" causes ERb to suppress the newline on any output. If you have >output, it will not have an ending newline, if you have no output, you >will not get meaningless blank lines. > >It only seems to be documented in the ERb.rb source code: >raa.ruby-lang.org/gonzui/markup/ruby/lib/erb.rb > >( Do a find on :ExplicitTrimRegexp ) > >The ERb documentation says you can suppress newlines with the trim_mode >setting, but does not say what the default trim_mode character is. > >-Sean > >Mark Haliday wrote: > > >>I seen some RoR code that went like this: >> >><% if ...blah, blah... -%> >> >>.. blah, blah >> >><% end -%> >> >>What are the minus signs for in the if statement? Cannot seem to find >>anything about this, and searching on "-" in this context is hard to get >>anything meaningfull back. >> >> >>Thanks, >> >>- Mark >> >>See also railsexpress.de/blog/articles/2005/12/06/trim-your-output -- For rails performance tuning, see: railsexpress.de/blog Subscription: railsexpress.de/blog/xml/rss20/feed.xml
This notation is typically used on embedded Ruby (ERb) lines that produce no output (if, end, etc.) so that no extraneous blank lines are produced in the HTML. On Jan 4, 2006, at 9:55 AM, Mark Haliday wrote:> I seen some RoR code that went like this: > > <% if ...blah, blah... -%> > > .. blah, blah > > <% end -%> > > What are the minus signs for in the if statement? Cannot seem to find > anything about this, and searching on "-" in this context is hard > to get > anything meaningfull back. > > > Thanks, > > - Mark > > -- > Posted via ruby-forum.com. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > lists.rubyonrails.org/mailman/listinfo/rails