开发者

Is it possible to set different SASS output style for development and production with Compass in rails?

开发者 https://www.devze.com 2022-12-21 20:46 出处:网络
Let say I would like to set nested style for development and compressed for production. There is only one option in Compass configuration file:

Let say I would like to set nested style for development and compressed for production. There is only one option in Compass configuration file:

output_style = :compact # or :nested,开发者_如何学Python :expanded, :compressed


It appears that it's pretty easy:

output_style = RAILS_ENV == "production" ? :compressed : :nested

To check it I've run this rake task in different environments (I had to change sass source before running this task):

namespace :sass do
  desc 'Updates stylesheets if necessary from their Sass templates.'
  task :update => :environment do
    Sass::Plugin.update_stylesheets
  end
end

You can place this task in lib/tasks/sass.rake.

Else I have this task running in my Capistrano deploy.rb to automatically update stylesheets on production during deployment:

after 'deploy:restart', 'sass:update'

namespace :sass do
  desc 'Updates the stylesheets generated by Sass'
  task :update, :roles => :app do
    invoke_command "cd #{current_release}; rake sass:update RAILS_ENV=production"
  end
end


In addition to the answer by Voldy I solved the problem by creating an initializer called sass_config and putting this in it:

Sass::Plugin.options[:style] = case RAILS_ENV
  when 'production' then :compressed
  when 'staging' then :compact
  when 'development' then :expanded
  else
    :nested
end
0

精彩评论

暂无评论...
验证码 换一张
取 消