2012-04-25 49 views
0

我使用rails-backbone,因此通過EJS gem(由rails-backbone綁定)使用JST模板。這不是一個大問題,但JST模板中的空白不會被JS壓縮器刪除。所以,顯而易見的問題是:我怎樣才能讓jst.ejs模板被資產管道壓縮?使用Rails 3.2和Asset Pipeline壓縮JST模板

謝謝你的幫助。

+0

你的'.jst.ejs'擴展添加到您的模板?當我的模板都是'.jst'而不是'.jst.ejs'時,我遇到了這個問題。 – MGA 2013-01-28 16:11:23

回答

1

我的解決辦法:

# 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 
相關問題