Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Gem vendor files in asset pipeline path

I have created a gem with a vendor directory containing stylesheets and javascripts from bootstrap-sass and bootstrap itself.

The directory structure is bootstrap-sass-gem/vendor/assets/javascripts

and

bootstrap-sass-gem/vendor/assets/stylesheets

I've required the gem in a test project but whenever I try to require something from that gem I receive a Sprockets::FileNotFound error.

For instance, in application.css I added *= require bootstrap. bootstrap is located at bootstrap-sass-gem/vendor/assets/stylesheets/bootstrap.scss and so by my reckoning should be included in the asset pipeline.

I'm running RVM Ruby 1.9.2 and Rails 3.1.

Here's my config file:

 $:.push File.expand_path("../lib", __FILE__)

 # Maintain your gem's version:
 require "bootstrap-sass-gem/version"

 # Describe your gem and declare its dependencies:
 Gem::Specification.new do |s|
    s.name        = "bootstrap-sass-gem"
    s.version     = BootstrapSassGem::VERSION
    s.authors     = ["James Smith"]
    s.email       = ["[email protected]"]
    s.homepage    = "http://www.smithware.co.uk"
    s.summary     = "The Bootstrap-sass project Gemified"
    s.description = "Description of BootstrapSassGem."

    s.files = Dir["{lib,vendor,rdoc}/**/*"] + Dir["*"]
    #s.test_files = Dir["test/**/*"]

    s.require_paths = ["lib/**/*"]

    # We are dependent on the asset pipeline in 3.1.0
    s.add_dependency "rails", "~> 3.1.0"

    # s.add_development_dependency ""
 end
like image 367
James Smith Avatar asked Sep 23 '11 15:09

James Smith


2 Answers

The problem was with my require_paths variable. The correct setting should have been:

s.require_paths = ["lib"]
like image 96
James Smith Avatar answered Oct 19 '22 00:10

James Smith


I had the same problem, I solved it adding a dummy engine. This way in rails 3.1 the assets path was added automatically to Rails.application.config.assets.paths.

Since Rails 3.0, if you want a gem to automatically behave as an engine, you have to specify an Engine for it somewhere inside your plugin’s lib folder.

like image 41
arocha Avatar answered Oct 19 '22 01:10

arocha