leshill / handlebars_assets

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

wrong compilerInfo generated for external templates. #63

Closed nicolai86 closed 11 years ago

nicolai86 commented 11 years ago

hey there

just some days ago I upgraded to handlebars_assets 0.12.1 and now I've got a problem with wrong compilerInfo being generated.

I've got a private gem (really just a rails engine file and some templates) and all templates from within the gem are generated with the old compilerInfo, [2, 1.0.0.rc3], causing handlebars to raise an exception.

Here's a accurate summary:

gem 'rails', '3.2.12' 
# ...
# Gemfile, outside of asset group
gem 'handlebars_assets', '0.12.1'

I'm using an initializer to change HandlebarsTemplates to JST:

# config/handlebars_assets.rb
HandlebarsAssets::Config.template_namespace = 'JST'

inside my application.coffee I'm requiring the main file from inside my own gem:

# application.coffee
#= require fail_bowl

the main file in my gem actually requires all necessary templates:

# fail_bowl.coffee
#= require_tree ./templates

Now to the interesting parts: The app & the gem contain templates -

all templates inside the main application get the following, correct compilerInfo:

this.compilerInfo = [3,'>= 1.0.0-rc.4'];

all templates from the gem get the wrong compiler info:

this.compilerInfo = [2,'>= 1.0.0-rc.3'];

when I change the template the file is regenerated, but the wrong compilerInfo sticks around!

I'm thankful for all suggestions :)

cheers, Raphael

leshill commented 11 years ago

Hi @nicolai86,

This was not clear to me from your description: did you regenerate the assets in the private gem? All the templates your app uses need to be regenerated.

nicolai86 commented 11 years ago

@leshill I've updated the ticket with a more accurate problem description. My first take on it was actually wrong.

leshill commented 11 years ago

Hi @nicolai86,

I am not familiar with that setup, but from looking at the compiler info we can see that the gem templates are not using the latest gem. Some possibilities:

nicolai86 commented 11 years ago

Hey @leshill ,

since public/assets is empty and the gem is also declaring handlebars_assets 0.12.1 inside the gemspec I guess it's due to out of date templates. I'm the maintainer of that gem - so how do I force the templates to be regenerated without touching each and every one of them?

leshill commented 11 years ago

Hi @nicolai86,

Since the situation is opaque to me: where exactly are the out-of-date precompiled templates? Inside the gem? Inside the app somewhere? Somewhere else (cloudfront etc)?

nicolai86 commented 11 years ago

Hey @leshill

well that's kind of confusing to me, too. The raw templates are inside the gem, but they should be precompiled inside the app since it's requiring the templates using the asset pipeline. So the app is serving the out-of-date precompiled templates.

nicolai86 commented 11 years ago

what's confusing me is that changing the templates inside the gem solves my problem, while clearing the asset cache does not. how can that be? :(

leshill commented 11 years ago

If you are in development mode, the files are cached in tmp/cache/assets, clear that directory out.

leshill commented 11 years ago

That is a good question. You need to identify where the assets are coming from :(

nicolai86 commented 11 years ago

I guess I'll settle with changing all templates, since that solves my problem for now.

One interesting observation though:

First, I'm removing the tmp/cache directory: rm -fr /tmp/cache/

Now, I'm using cURL to request a template from my gem, but the asset cache directory has not been recreated.

looks like javascript files from external resources are handled differently. The log only reads

Started GET "/assets/templates/fail_bowl_template.js?body=1" for 127.0.0.1 at 2013-05-25 00:15:39 +0200
Served asset /templates/fail_bowl_template.js - 200 OK (0ms)

This puzzles me - since if they are not cached, why would I get stale compilerInfos ?

There's some magic going on I can't understand right now. :(

nicolai86 commented 11 years ago

oh, and thanks for your fast help! you are awesome, @leshill

leshill commented 11 years ago

Hi @nicolai86,

If you ever resolve exactly what was happening, please add it to this issue :)