Best way to require Haml on Rails3 engines

前端 未结 2 1996
北恋
北恋 2020-12-18 01:02

I\'m developing a Rails3 engine application, and I want to use Haml for the views.

First, what I have done was to add this to the engine Gemfile:

gem         


        
相关标签:
2条回答
  • 2020-12-18 01:14

    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/

    0 讨论(0)
  • 2020-12-18 01:21

    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.

    0 讨论(0)
提交回复
热议问题