0

私はrails-backboneを使用しているため、 EJS gem (rails-backbone にバンドルされています)を介して JST テンプレートを使用しています。これは大きな問題ではありませんが、JST テンプレートの空白は JS コンプレッサーによって削除されません。明らかな疑問は、jst.ejs テンプレートをアセット パイプラインで圧縮できるようにするにはどうすればよいかということです。

助けてくれてありがとう。

4

1 に答える 1

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
于 2012-05-08T10:37:09.100 に答える