码迷,mamicode.com
首页 > 其他好文 > 详细

erb去掉末尾换行 -%>使用方法

时间:2016-02-27 00:52:07      阅读:304      评论:0      收藏:0      [点我收藏+]

标签:

http://stackoverflow.com/questions/998979/difference-between-and-in-rails/25617607#25617607

In Ruby 2.1 (not necessarily with Rails), the - removes one trailing newline:

  • the newline must be the first char after the >
  • no spaces are removed
  • only a single newline is removed
  • you must pass the ‘-‘ option to use it

Examples:

require ‘erb‘
ERB.new("<%= ‘a‘ %>\nb").result              == "a\nb"  or raise
begin ERB.new("<%= ‘a‘ -%>\nb").result; rescue SyntaxError ; else raise; end
ERB.new("<%= ‘a‘  %>\nb"  , nil, ‘-‘).result == "a\nb"  or raise
ERB.new("<%= ‘a‘ -%>\nb"  , nil, ‘-‘).result == ‘ab‘    or raise
ERB.new("<%= ‘a‘ -%> \nb" , nil, ‘-‘).result == "a \nb" or raise
ERB.new("<%= ‘a‘ -%>\n b" , nil, ‘-‘).result == ‘a b‘   or raise
ERB.new("<%= ‘a‘ -%>\n\nb", nil, ‘-‘).result == "a\nb"  or raise

erb去掉末尾换行 -%>使用方法

标签:

原文地址:http://www.cnblogs.com/or2-/p/5222130.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!