hogan_assets icon indicating copy to clipboard operation
hogan_assets copied to clipboard

hogan_assets stopped working in Rails when upgrading sprockets-rails to latest version (3.0)

Open dennmart opened this issue 9 years ago • 1 comments

Ever since the most recent release of sprockets-rails 3.0 in December, hogan_assets is currently not working properly in Rails. In my case, all my Javascript calls to HoganTemplates are now undefined. I did a bit of digging and it seems like the updated version of Sprockets has plenty of changes, and now the hogan_assets gem is not registering the .mustache / .slimstache extensions when it initializes.

In particular, in lib/hogan_assets/engine.rb, after defining the initializer, there's a there's a check to see if app.assets is defined. In previous versions of Sprockets, this was set up, but with the latest version, it's now nil. I don't know a much about Sprockets, but this issue seems to explain why: https://github.com/rails/sprockets-rails/issues/292

Out of curiosity, I cloned hogan_assets and modified the initializer based on what was mentioned in the issue I linked to as so:

module HoganAssets
  class Engine < ::Rails::Engine
    initializer "sprockets.hogan", :group => :all do |app|
      HoganAssets::Config.load_yml! if HoganAssets::Config.yml_exists?
      Rails.application.config.assets.configure do |env|
        HoganAssets::Config.template_extensions.each do |ext|
          env.register_engine(".#{ext}", Tilt)
        end
      end 
    end 
  end 
end

When I did this change, everything worked as expected - the Slimstache files were being properly registered and included in my app as it was before.

I was going to submit a pull request, but as I mentioned, I don't know much about Sprockets, so I don't know if this has adverse effects outside of my use case. Let me know if I can help with that somehow.

dennmart avatar Jan 24 '16 10:01 dennmart

I think these are the same changes I needed to make on handlebars_assets ; I really wish I had time to merge the projects common functionality. I will see what I can do.

AlexRiedler avatar Jan 24 '16 18:01 AlexRiedler