Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work with Rails Engines #107

Closed
jeyb opened this issue Nov 23, 2013 · 14 comments
Closed

Doesn't work with Rails Engines #107

jeyb opened this issue Nov 23, 2013 · 14 comments

Comments

@jeyb
Copy link

jeyb commented Nov 23, 2013

There was a similar problem discussed #88 but this doesn't seem to solve my issue. The solution provided there is for sprite load path.

I have a Rails 3.2.15 app. There is no mention of compass-rails or sass-rails within this application Gemfile. Within vendor/engines I have a Rails engine that has the following in the gemspec.

s.add_dependency "compass-rails", "~> 2.0.alpha.0"
s.add_dependency "sass-rails", ">= 3"

The Rails engine is included in the Gemfile of the main application. Therefore the Gemfile.lock includes compass-rails and sass-rails as one would expect. However I believe there is an issue with load paths as @import compass/css3 fails with:

Sass::SyntaxError: File to import not found or unreadable: compass/css3
Load path: Sass::Rails::Importer(/Users/jeyb/code/app_name/app/assets/stylesheets/application.css.sass)
@paynecodes
Copy link

@jeyb Keep us posted with this one. I have no clue how to fix, but am looking to integrate compass into my first Rails App/Engine

@jeyb
Copy link
Author

jeyb commented Nov 26, 2013

@jpdesigndev The problem was that the asset paths weren't being included from the engine's gems. I've found including the required gem within the main application as well as the engine's gemspec solved it.

@paynecodes
Copy link

Awesome. Thanks for the help. I'm assuming you were able to import compass related stuff from inside the engines app/assets right?

@spohlenz
Copy link

Try adding require "compass-rails" to the top of your engine.rb file within your Rails engine.

The reason for this is that gems included in the application's Gemfile are usually required automatically. However gem dependencies need to be explicitly required.

@jeyb
Copy link
Author

jeyb commented Nov 27, 2013

@spohlenz that worked. Thanks.

@jeyb jeyb closed this as completed Nov 27, 2013
@dimerman
Copy link

dimerman commented Dec 4, 2013

Hi,
I'm trying to use compass-rails to generate sprites from my rails engine but no luck.
The error I get:
ActionView::Template::Error (No files were found in the load path matching "my-engine/icons/*.png". Your current load paths are: /home/dan/work/main-app/app/assets/images (in /home/dan/work/my-engine/app/assets/stylesheets/my-engine/sources.css.scss)):

any clue on how to set the sprite load path to also use the engine's own assets directory?

@miguelgraz
Copy link

Hi @dimerman, guys.

I was working on a structure of basically 5 folders in the same level, 2 of them are rails app and the other are internal gems used on both apps, and I was trying to use compass-rails to avoid having a duplicated "icons" folder on both apps, moving the folder inside on of the gems.

I had a bunch of problems with that and, after struggling for about a day, I've overwritten the inline_image method (it was mandatory to keep using inline-image for images inside a gem's folder, basically) and made it search through all images paths of the Rails app, here is how I patched the method.

require 'compass-rails'

module Compass::SassExtensions::Functions::InlineImage
  def inline_image(path, mime_type = nil)
    path = path.value
    images = Rails.application.assets.paths.select{|pa| pa =~ /image/}
    images << Compass.configuration.images_path
    images.each do |image|
      real_path = File.join(image, path)
      if File.exists? real_path
        return inline_image_string(data(real_path), compute_mime_type(path, mime_type))
      end
    end
  end
end

Hope that can be useful for anyone else and I'd love to know from the maintainers if this can be interesting to have inside the gem itself, I would love to work to reach something like this.

@ream88
Copy link

ream88 commented Aug 26, 2014

@miguelgraz Much cleaner variant:

module Compass::SassExtensions::Functions::InlineImage
  def inline_image(path, mime_type = nil)
    path = path.value
    pathname = Rails.application.assets.find_asset(path).pathname

    raise Compass::Error, "File not found or cannot be read: #{pathname}" unless pathname.exist?

    computed_mime_type = compute_mime_type(path, mime_type)
    inline_image_string(data(pathname), computed_mime_type)
  end
end

@miguelgraz
Copy link

Indeed, thank you for that!

@ream88
Copy link

ream88 commented Aug 26, 2014

However what about merging this into the compass-rails gem?

@ream88
Copy link

ream88 commented Aug 26, 2014

Btw, @miguelgraz I fixed it in my app using following line in my engine.rb:

initializer 'compass' do
  Compass.configuration.project_path = root
end

@ghepting
Copy link

For others that stumble on this recently, the namespace is Compass::Core::SassExtensions::Functions::InlineImage in later versions of Compass (1.0+?)

@braindeaf
Copy link

I have the same or very similar problem. I have a Rails 'gem 'rails', github: "rails/rails", branch: "3-2-stable"' app, which loads an Engine which contains most of the functionality of our app. We've configured the Engine so that it is a bootable Rails app and it loads compass fine.

compass (= 0.12.6)
compass-rails (= 1.1.7)
sass (= 3.2.19)
sass-rails (= 3.2.6)

However, when we load this engine from another parent app using the same Gemfile as the Engine we get the error. Sass::SyntaxError: File to import not found or unreadable: compass

I've tired as many solutions as I have seen on the multiple issues with similar side effects, requiring 'rails-engine' in engine.rb, Setting the project_path within the engine and in an initializer, I've upgraded the above gems as much as I can but nothing.

A few puts inside ImportNode#import show that load_paths do not include the compass directories...

  private

  def import
    paths = @options[:load_paths]
    puts @options[:filename]
    puts paths.to_yaml
    puts @options[:importer].to_yaml
    puts "----"

- /Users/rl/repos/project/vendor/gems/project/app/assets/stylesheets/frontend_root.sass

  • !ruby/object:Sass::Importers::Filesystem
    root: "/Users/rl/repos/project"
    same_name_warnings: !ruby/object:Set
    hash: {}
    --- !ruby/object:Sass::Importers::Filesystem
    root: "/Users/rl/repos/project"
    same_name_warnings: !ruby/object:Set
    hash: {}

- /Users/rl/repos/project/vendor/gems/project/app/assets/stylesheets/root_tree.sass

  • !ruby/object:Sass::Importers::Filesystem
    root: "/Users/rl/repos/project"
    same_name_warnings: !ruby/object:Set
    hash: {}
    --- !ruby/object:Sass::Importers::Filesystem
    root: "/Users/rl/repos/project"
    same_name_warnings: !ruby/object:Set
    hash: {}
    Error compiling asset frontend.css:
    Sass::SyntaxError: File to import not found or unreadable: compass.
    Load path: /Users/rl/repos/project
    (in /Users/rl/repos/project/vendor/gems/engine/app/assets/stylesheets/frontend_root.sass)

Not sure where to go from here. Any ideas?

@ami1906
Copy link

ami1906 commented Aug 17, 2015

I was trying to use compass-rails and i am running into issues with inline-images. Previously i was using compass and everything seems to work fine. But now inline-image function is not working. How to get it work with compass-rails. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants