Get Gem vendor files in asset pipeline path

2019-04-06 14:01发布

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       = ["James@smithware.co.uk"]
    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

3条回答
smile是对你的礼貌
2楼-- · 2019-04-06 14:35

i think the asset pipeline expects your files to be named like bootstrap.css.scss. and I'm not sure, but maybe you need to define a railtie for your gem for rails to find the vendored stylesheets

查看更多
Root(大扎)
3楼-- · 2019-04-06 14:37

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

s.require_paths = ["lib"]
查看更多
Anthone
4楼-- · 2019-04-06 14:37

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.

查看更多
登录 后发表回答