我通过EJS gem (由rails-backbone捆绑)使用rails-backbone和JST模板。这不是一个大问题,但是JS压缩器不会删除JST模板中的空格。因此,显而易见的问题是:如何通过资产管道对jst.ejs模板进行压缩?
谢谢你的帮助。
发布于 2012-05-08 18:37:09
我的解决方案是:
# initializers/clean_ejs_template.rb
require 'ejs'
module EJS
class << self
def compile(source, options = {})
source = source.dup
escape_quotes!(source)
#replace_interpolation_tags!(source, options)
#replace_evaluation_tags!(source, options)
escape_whitespace!(source)
# remove extra whitespace and newlines
source.gsub!(/\s{2,}|\\n/,'')
# use _.template instead
"_.template('#{source}')"
#"function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments);};" +
# "with(obj||{}){__p.push('#{source}');}return __p.join('');}"
end
end
endhttps://stackoverflow.com/questions/10309766
复制相似问题