Search code examples
odooodoo-9

SASS instead of LESS in Odoo 9


How to use Sass instead of Less in Odoo v9?

I have very basic setup following guidelines of official documentation. It works as excpected with Less, but I can not make it to work with Sass. Following in views/assets.xml works as excpected:

<link href="/theme_name/static/less/style.less" rel="stylesheet" type="text/less"/>

but when I change it to scss:

<link href="/theme_name/static/scss/style.scss" rel="stylesheet" type="text/scss"/>

my styles are no longer loaded. No error is given also.

It might be worth to mention that I did get an error when I tried link type text/sass

Could not execute command 'sass'


Solution

  • Finally got time to look into this and figure out the magic behind compiling stylesheets.

    First off, the SCSS syntax is not supported. Correct link or style tag type is text/sass or text/less. Second way Odoo determines the syntax is by file extension .sass or .less. You can set either or both, result is same. See the code responsible for the magic.

    Secondly, the error message indicates that underlying operating system do not have command sass in its current execution PATH. The command itself must be pre-installed by you.

    Odoo looks for an executable sass in active system PATH and calls it with specific options listed here.

    There is diffrent versions of sass compilers, but Odoo expects it to be the ruby version.
    See installing section in sass homepage for more information.

    Addition to sass, you also need compass and bootstrap-sass ruby gems.

    How exactly you decide to install all those depends of your operating system, environment setup and taste, but you need ruby version >2.0.

    Bonus: This is how I did it in Ubutnu 14.04.

    Ubuntu by default has ruby 1.9. Check what you got with dpkg -s ruby.
    Fortunately there is a repository hosting it. So let's add that and install ruby 2.3.

    sudo apt-add-repository ppa:brightbox/ruby-ng
    sudo apt-get update
    sudo apt-get install ruby2.3 ruby2.3-dev
    

    You'll need the -dev package too. Check the version of you ruby now with ruby -v.

    Next you must install the required gems:

    gem install sass compass bootstrap-sass --user-install
    

    I used the option --user-install in my dev machine to install gems to my home dir, instead globally. That depends again of your prefeerence and system setup. But in general, the user running odoo, must also have execution permission on those gems, where ever they are.