扫描资产文件夹并将其加载到production.rb中的任何缺点?

时间:2012-06-22 07:52:04

标签: ruby-on-rails ruby asset-pipeline

发生在我身上&我的同事忘了在预编译文件列表中添加.js.css。我想更改production.rb文件以扫描javascripts / stylesheets文件夹,并动态添加到config.assets.precompile变量。代码看起来像这样:

def get_assets(folder,select_extensions,delete_from,remove_extensions)
  files     = Dir["#{folder}/**/*"].select {|e| select_extensions.include?(File.extname(e))}
  basenames = files.map {|e| e.sub(/.*#{delete_from}\//,"") }
  basenames.each do |bn|
    remove_extensions.each do |ext|
      bn.sub!(ext,"")
    end
  end
  basenames
end

在production.rb中,我会有类似的东西:

config.assets.precompile = get_assets("#{Rails.root}/app/assets/javascripts",[".js",".coffee"],"javascripts",[".coffee"]) + get_assets("#{Rails.root}/app/assets/stylesheets",[".css",".scss"],"stylesheets",[".scss"])

你认为我的想法存在任何缺点/陷阱吗?

0 个答案:

没有答案