I recently started using ExtJS 4 inside of Rails 3.1. I’ve been using the pre-build theme that ExtJS 4 comes bundled with (ext-all.css), but I was debating trying to bring the sass angle in. I’m pretty new to sass in general, though I really like the idea behind it, and it would be slick to be able to just edit a couple variables to re-theme an entire site.
I was wondering if anyone out there has done it yet, and how difficult it was to incorporate it in to the stylesheet asset pipeline? Specifically since it seems like it would require some rework, due to the use of compass as a base.
I have a Rails 3 (not 3.1) application running with an Ext JS 4 frontend that generates the stylesheets directly from the default themes SASS. I’m using Jammit for the asset pipeline, but it should be almost no difference in doing it with Sprockets, since the work is done in both cases by Compass.
First make sure you have Compass installed by putting it into your
Gemfile:Compass has declared the
sassgem as dependency, so there is no need to declare it. Now you need to bundle the Gem and initialize Compass:Then I created a folder
public/resources/scss, where I put all SCSS files. Within this folder I have my main application SCSS fileapplication.scss, that includes all necessary Compass modules and further partials:Next I copied all the Ext 4 SASS theme files to
public/resources/scss/ext4/defaultand created another folderpublic/resources/scss/partialswhere I put all my custom SCSS partials and the Ext 4 initialization file_ext4.scss:This is then the right place to set some Compass variables that are used by Ext 4. Here are some examples for styling the theme, copied directly from the Ext 4 SASS files:
Now you have basically everything in place:
But there is a last piece missing: Ext 4 has some custom Compass functions that needs to be in place. This file is placed in the Ext JS 4 framework under
resources/themes/lib/utils.rb. Because the original file did not work out of the box with my way of organizing the files, I simply modified it for my need and placed it directly in the Compass initialization fileconfig/compass.rb:Now you can set Ext 4 variables in your partial and all the CSS for your custom settings is generated on the fly and just all nice Compass features like Sprites.