28

I'm trying to decide if I should include Compass when starting a new Rails 3.1 project. I haven't used Compass before.

Rails 3.1 now supports SCSS directly. The Rails 3.1 asset pipeline (via sprockets) now compiles stylesheets automatically. And I can use a SCSS version of a CSS framework such as Blueprint directly.

What benefits will I get from using Compass with Rails 3.1?

OldTroll
  • 773
  • 6
  • 22
Daniel Kehoe
  • 10,952
  • 6
  • 63
  • 82
  • 4
    On the Compass mailing list, Wynn Netherland answered the question: "Compass is to Rails what Sass is to Ruby. Compass packages patterns and best practices for Sass for things like CSS3, asset url helpers, and more, not just grid frameworks." – Daniel Kehoe Jun 12 '11 at 14:44
  • 8
    I think he meant Compass is to Sass what Rails is to Ruby (at least if my memory of the SAT is correct) – Chris Nicola Sep 03 '11 at 16:48

4 Answers4

20

Compass provides a lot of good mixins, a pretty powerful sprite-generator, and a tight integration with Blueprint in a way that means you don't have to use non-semantic col classes all over your HTML.

There's not really much benefit to using Compass if you're not using the mixins, but then again there isn't much benefit to using SCSS if you're not using them (nesting and variables are nice, but mixins help keep browser-specific implementation of properties in a single location).

However, I found Blueprint to be more of a hassle than it is worth. I would still use Compass for the mixins, but right now compatibility between Rails 3.1 and Compass is terrible (you have to jump through some hoops and you still sacrifice some functionality).

In a somewhat related note, the way Rails 3.1 compiles assets is rather "broken". It doesn't consider how the community has been using Sass for the last year or two — keeping variables, mixins, and page partials all separate to be included by a master file in order. The "automatic" way Sprockets loads and compiles Sass disassociates files from each other, so even if you define the load order manually in your application.css, variables you set in a file are not available to subsequently loaded files.

coreyward
  • 77,547
  • 20
  • 137
  • 166
  • 1
    Thanks for the cautionary note on current Rails 3.1 issues. It seems the Compass sprite generator and the mixins have continuing value. Are there alternatives to Blueprint that provide a CSS reset and semantically named classes? – Daniel Kehoe Jun 10 '11 at 21:18
  • 1
    Re: Semantic CSS Frameworks, I don't think so. The difference is in applying styles to classes named "span-3 prepend-2" you wrap your menu in a ` – coreyward Jun 11 '11 at 00:43
  • 1
    I tend to use a version of Eric Myers' (sp?) CSS reset, and then build on top of that. Up until recently I've used all my own mixins, but I've started using the Compass mixins. I still do all my layout-related CSS myself. It's too quick and easy to do without a css grid framework as is, unless you're doing a very grid-based design (or something that has to be super flexible, like a Wordpress theme [shudders]). – coreyward Jun 11 '11 at 00:45
  • 1
    Readers should note that this answer relates to a pre-release version of Rails 3.1 The latest release candidate of Rails 3.1 has fixed the Sprockets issues with including partials. I think it safe to assume that it will be working nicely once 3.1 actually ships. – nocache Aug 31 '11 at 14:38
14

Bourbon (by Thoughtbot) is a light alternative to compass that integrates well with rails 3.1.

It has the main css3 mixins you get with compass (background-images, box shadow, border radius, gradients...). It also has helpers to style buttons, "gridify" your layout and a few more goodies.

You might miss some of the power features compass has, but that can be easily overcome with the power of sass : just copy/create you're own mixin!

Compass often gave me headaches when upgrading my rails app. I appreciate the simplicty of Bourbon (although it might give you headaches as well... in the morning :-) )

charlysisto
  • 3,700
  • 17
  • 30
  • 3
    Bourbon and Rails 3.1 feels right to me. Better separation of concerns than trying to do everything with Compass. – Daniel Kehoe Aug 23 '11 at 23:37
1

Compass is a design-agnostic framework - e.g. you don't have to worry about which browsers the users have.

e.g. Compass has add-ons, like for example the CSS3 cross-browser features: http://compass-style.org/reference/compass/css3/ this way you can specify things in your .scss files browser-independent

Side-Note:

The way Rails 3.1 processes .scss files, is one at a time -- e.g. if you define variables in one file, they don't get carried over to the other .scss files. IMHO not really optimal solution.

Tilo
  • 33,354
  • 5
  • 79
  • 106
  • 1
    Blueprint is a design-agnostic CSS framework and I don't need Compass to install it directly as SCSS files with Rails 3.1. – Daniel Kehoe Jun 10 '11 at 20:57
1

The html5boilerplate compass plugin is a great time-saver too, so for these reasons I would use compass

stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189