views:

295

answers:

2

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, :expanded, :compressed
+3  A: 

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
Voldy
+1  A: 

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
Daemin