Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sass import from rails engine not working

I've created a Rails Engine for assets. I don't use sprockets for css. Instead, I rely on sass's @import. This works perfectly fine in the test/dummy app, but in the Rails app that is requiring the engine, it keeps throwing

Sass::SyntaxError: File to import not found or unreadable: gumby.

I've been at this for a while, and originally the path wasn't in the load path for sass. But then I added

config.sass.load_paths << "#{Gem.loaded_specs['gumby_on_rails'].full_gem_path}/app/assets/stylesheets"

to my config/application.rb and now it definitely shows the correct path to the file I'm trying to import. It is the second to the last path listed in the following trace:

Sass::SyntaxError: File to import not found or unreadable: gumby.
Load paths:
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  CompassRails::SpriteImporter
  /Users/brandon/code/personal/blog_update/app/assets/images
  /Users/brandon/code/personal/blog_update/app/assets/javascripts
  /Users/brandon/code/personal/blog_update/app/assets/stylesheets
  /Users/brandon/code/personal/blog_update/vendor/assets/javascripts
  /Users/brandon/code/personal/blog_update/vendor/assets/stylesheets
  /Users/brandon/.rvm/gems/jruby-1.7.11@blog/gems/angularjs-rails-1.0.7/vendor/assets/javascripts
  /Users/brandon/.rvm/gems/jruby-1.7.11@blog/gems/turbolinks-2.2.2/lib/assets/javascripts
  /Users/brandon/.rvm/gems/jruby-1.7.11@blog/gems/jquery-rails-3.1.0/vendor/assets/javascripts
  /Users/brandon/.rvm/gems/jruby-1.7.11@blog/gems/coffee-rails-4.0.1/lib/assets/javascripts
  /Users/brandon/code/personal/gumby/app/assets/stylesheets
  /Users/brandon/code/personal/blog_update/app/assets/stylesheets

The rails engine's tree looks like this

app/
  assets/
    stylesheets/
      gumby/
        ...
      gumby.css.scss

(I know that technically you should namespace all your assets in an engine, but I didn't want to have gumby/gumby, and I feel the chances of a name clash are slim.)

So in the test/dummy app I can import this file via @import 'gumby';, but this fails in the Rails app. With the above exception. How do I get this working?

And by the way, this is a Rails 4.1 app, and the answers to several other "similar" questions are all due to using groups in the Gemfile. Rails 4 got rid of groups so this is not the problem/solution.

like image 344
Brandon Avatar asked Apr 28 '14 06:04

Brandon


2 Answers

So the solution for me was to suck it up and namespace it gumby/gumby. Then I also had to change the config/application.rb to:

config.assets.paths << "#{Gem.loaded_specs['gumby_on_rails'].full_gem_path}/app/assets/stylesheets"

And for some reason modular-scale wasn't being required properly, even though the engine already required it. So I had to change application.css.scss to application.css.scss.erb and put <% require 'modular-scale' %> at the top.

like image 135
Brandon Avatar answered Nov 10 '22 20:11

Brandon


then you should write it like this :

config.sass.load_paths << "#{Gem.loaded_specs['gumby_on_rails'].full_gem_path}/app/assets/stylesheets/gumby"

or try this (untested)

@import_tree 'gumby';
like image 2
blackbiron Avatar answered Nov 10 '22 20:11

blackbiron