Best way to require Haml on Rails3 engines

纵然是瞬间 提交于 2019-11-29 06:58:56

Two things are necessary. First, in the .gemspec:

s.add_dependency 'haml', ['>= 3.0.0']

And in your lib/gem_name.rb:

require 'haml'

And then run bundle both inside the gem and app directories.

I think you will have to put haml in the engine gemspec as a dependency in order for bundler to install haml in the target application (and show up in its Gemfile.lock). Something like this:

Gem::Specification.new do |s|
  s.add_dependency(%q<haml>, [">= 0"])
end

I just tested this out on one of my engines. Without the dependency in the .gemspec it did not install haml in the target app (did not appear in Gemfile.lock). After I added haml to the gemspec as a dependency, it does show up:

PATH
  remote: /rails_plugins/mine/my_engine
  specs:
    my_engine (0.0.0)
      formtastic
      haml
      inherited_resources
      settingslogic
      sqlite3-ruby

GEM
  remote: http://rubygems.org/
  specs:
    #................
    haml (3.0.25)
    #................

If you are using jeweler, it will add the dependencies to the gemspec automatically based on what is in your Gemfile.. it even adds a developement_dependency if you have the group defined in your Gemfile. I have only looked at enginex briefly, so I don't know if it has a similar rake task to build the gemspec.

This might help clarify some things:

http://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!