首页 > 其他 > 详细

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

时间:2016-02-27 00:48:55      阅读:195      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!