Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using libsass with Rails asset pipeline

I'm trying to get libsass to work with the Rails 4 asset pipeline. So far I've cloned the ruby-libsass Gem from Github into the Vendor folder of my application. I added the followig to my gemfile:

gem 'sassc', path: 'vendor/ruby-libsass/'

I then followed the docs and added the submodules for libsass. Within the libsass folder I had to clone in the sass2scss library for it to compile. I compiled it with make install-shared which created /usr/local/lib/libsass.so. After this, running rake assets:precompile give the following error:

rake aborted!
LoadError: Could not open library 'sass': dlopen(sass, 5): image not found.
Could not open library 'libsass.dylib': dlopen(libsass.dylib, 5): image not found

So I symlinked libsass.dylib this to /usr/local/lib/libsass.dylib. After that, I received the following error:

NameError: uninitialized constant SassC::Lib::Context::SassOptions

I tried commenting out the line in /ruby-libsass/lib/sassc/lib/context.rb that calls SassOptions, and that seemed to have made it work and compiling the assets. The commented out code on line 20, context.rb:

layout :source_string, :pointer,
  :output_string, :string,
  # :options, SassOptions,
  :error_status, :int,
  :error_message, :string,
  :c_functions, :pointer,
  :included_files, :pointer,
  :num_included_files, :int`

Now, the problem I'm having is that I see no speed difference. It stays at around 7 seconds to compile my assets, with or without adding libsass to my Gemfile. Since the initial compile gave an error relating tot libsass.dylib file not being found, I assumed that it's actually using sassc instead of sass, but it looks like it isn't.

Any ideas what I could be missing? I have no experience with C, so I'm not even sure if I compiled everything correctly, etc.

like image 747
Constant Meiring Avatar asked Nov 01 '14 11:11

Constant Meiring


1 Answers

Right, I finally got it working thanks to this gem! The project is still a WIP, and can do with a few supporters. :)

Only issue I ran into is that you need to completely remove sass-rails from your project, which can be a problem if you use gems like ActiveAdmin. There are workarounds though. Then, plain css files that get included in your scss files with @import need to have .css at the end of the filename in the import.

like image 192
Constant Meiring Avatar answered Nov 14 '22 01:11

Constant Meiring