在资产管道路径中获取Gem供应商文件 [英] Get Gem vendor files in asset pipeline path
问题描述
我创建了一个包含来自 bootstrap-sass 的样式表和javascript以及引导自身的供应商目录的gem。
目录结构是
bootstrap-sass-gem / vendor / assets / javascripts
和
bootstrap-sass-gem / vendor / assets / stylesheets
我在测试中需要gem项目,但每当我尝试从该宝石中获得一些东西时,我都会收到一个 Sprockets :: FileNotFound
错误。
,在application.css中我添加了 * = require bootstrap
。
bootstrap位于 bootstrap-sass-gem / vendor / assets / stylesheets / bootstrap.scss
,因此我的清算应包含在资产管道中。 / p>
我运行RVM Ruby 1.9.2和Rails 3.1。
这是我的配置文件:
$ :. push File.expand_path(../ lib,__FILE__)
#保持你的宝石版本:
需要bootstrap-sass-gem / version
#描述你的gem并声明它的依赖:
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 =BootstrapSassGem的描述。
$ b $ s.files = Dir [{lib,vendor,rdoc} / ** / *] + Dir [*]
#s.test_files = Dir [test / ** / *]
s.require_paths = [lib / ** / *]
#我们依赖于3.1.0 $ b中的资产管道$ b s.add_dependencyrails,〜> 3.1.0
#s.add_development_dependency
end
我遇到了同样的问题,我解决了它添加虚拟引擎的问题。这种方式在rails 3.1资源路径被自动添加到Rails.application.config.assets.paths。
从Rails 3.0开始,如果你想要一个gem自动表现为一个
引擎,你必须在你的
插件的lib文件夹中的某处指定一个Engine。
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
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.
这篇关于在资产管道路径中获取Gem供应商文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!