首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Rails 3.2和Asset Pipeline压缩JST模板

使用Rails 3.2和Asset Pipeline压缩JST模板
EN

Stack Overflow用户
提问于 2012-04-25 13:21:26
回答 1查看 686关注 0票数 0

我通过EJS gem (由rails-backbone捆绑)使用rails-backbone和JST模板。这不是一个大问题,但是JS压缩器不会删除JST模板中的空格。因此,显而易见的问题是:如何通过资产管道对jst.ejs模板进行压缩?

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-05-08 18:37:09

我的解决方案是:

代码语言:javascript
复制
# 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10309766

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档