leshill / handlebars_assets

Use handlebars.js templates with the Rails asset pipeline.
MIT License
649 stars 159 forks source link

Accessing Assets Helpers From Templates #150

Open ayanko opened 8 years ago

ayanko commented 8 years ago

Hello.

That's about using

After upgrade to latest version (4.2.6) and handlebars_assets(0.23.0) sprockets don't want anymore to compile templates like:

.wrapper
  .illustration
    = image_tag('rails.png')

That's because we don't pass context anymore for new transformer.

There is easy solution:


module HandlebarsAssets
  class HandlebarsProcessor
    def call(input)
      renderer = HandlebarsRenderer.new(path: input[:filename])
      engine = renderer.choose_engine(input[:data])
      context = input[:environment].context_class.new(input)
      renderer.compile(engine.render(context))
    end
  end
end

P.S. Sorry I don't have time to create PR ..

ayanko commented 7 years ago

Any updates?

AlexRiedler commented 7 years ago

@ayanko it can be pretty error prone to use the helpers indicated in templates since one happens at precompile time and the manifest might change before going to production.

I would think this might still work currently on newer versions; although the result might not be as clean as you would hope (chicken and egg; since the rails.png might not be compiled yet).

I might have some time later this week to see if this works; although I am not sure about the chicken egg issues that could occur.