我通过EJS gem(由 rails-backbone 捆绑)使用rails-backbone和 JST 模板。这不是一个大问题,但是 JS 压缩器不会删除 JST 模板中的空格。所以,显而易见的问题是:如何让资产管道压缩 jst.ejs 模板?
感谢您的任何帮助。
我通过EJS gem(由 rails-backbone 捆绑)使用rails-backbone和 JST 模板。这不是一个大问题,但是 JS 压缩器不会删除 JST 模板中的空格。所以,显而易见的问题是:如何让资产管道压缩 jst.ejs 模板?
感谢您的任何帮助。
我的解决方案:
# 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
end