Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best method for storing SASS generated CSS in your application and source control?

If you are using HAML and SASS in your Rails application, then any templates you define in public/stylesheet/*.sass will be compiled into *.css stylesheets. From your code, you use stylesheet_link_tag to pull in the asset by name without having to worry about the extension.

Many people dislike storing generated code or compiled code in version control, and it also stands to reason that the public/ directory shouldn't contain elements that you don't send to the browser.

What is the best pattern to follow when laying out SASS resources in your Rails project?

like image 819
Pete Avatar asked Sep 17 '08 18:09

Pete


4 Answers

The compass framework recommends putting your sass stylesheets under app/stylesheets and your compiled css in public/stylesheets/compiled.

You can configure this by adding the following code to your environment.rb:

Sass::Plugin.options[:template_location] = {
  "#{RAILS_ROOT}/app/stylesheets" => "#{RAILS_ROOT}/public/stylesheets/compiled"
}

If you use the compass framework, it sets up this configuration for you when you install it.

like image 106
chriseppstein Avatar answered Oct 23 '22 08:10

chriseppstein


I always version all stylesheets in "public/stylesheets/sass/*.sass" and set up an exclude filter for compiled ones:

/public/stylesheets/*.css
like image 24
mislav Avatar answered Oct 23 '22 09:10

mislav


Honestly, I like having my compiled SASS stylesheets in version control. They're small, only change when your .sass files change, and having them deploy with the rest of your app means the SASS compiler doesn't ever need to fire in production.

The other advantage (albeit a small one) is that if you're not using page caching, your rails process doesn't need to have write access to your public_html directory. So there's one fewer way an exploit of your server can be evil.

like image 6
Nate Avatar answered Oct 23 '22 07:10

Nate


Somewhat related, but it's a good idea to regenerate your CSS during your capistrano deployments. This callback hook does just that:

after "deploy:update_code" do
  rails_env = fetch(:rails_env, "production")
  run "#{release_path}/script/runner -e #{rails_env} 'Sass::Plugin.update_stylesheets'"
end

Update: This should no longer be necessary with modern versions of Haml/Sass.

like image 5
Ryan McGeary Avatar answered Oct 23 '22 08:10

Ryan McGeary