Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing Assets Helpers From Templates #150

Open
ayanko opened this issue Apr 15, 2016 · 2 comments
Open

Accessing Assets Helpers From Templates #150

ayanko opened this issue Apr 15, 2016 · 2 comments

Comments

@ayanko
Copy link

ayanko commented Apr 15, 2016

Hello.

That's about using

  • asset_path
  • image_path
  • image_tag
  • and friends

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
Copy link
Author

ayanko commented Jun 26, 2017

Any updates?

@AlexRiedler
Copy link
Collaborator

AlexRiedler commented Jun 26, 2017

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants