ndbroadbent / turbo-sprockets-rails3

Speeds up your Rails 3 assets:precompile by only recompiling changed files, and only compiling once to generate all assets
MIT License
976 stars 78 forks source link

Always precompile certain assets? #111

Open camertron opened 8 years ago

camertron commented 8 years ago

Hey guys, thanks for this awesome gem. Is there a way to tell turbo-sprockets to always precompile certain assets, regardless of if the source file has changed?

ur5us commented 8 years ago

@camertron Out of curiosity, how's that useful?

camertron commented 8 years ago

@ur5us I initially filed this because we were trying to generate assets that contained translations per locale. The contents of the assets themselves describe which parts of en.yml to include, then the assets are generated dynamically per locale. So, you might have translations.i18njs that gets compiled into two Javascript files, translations-en.js for English and translations-ja.js for Japanese. The problem is that if en.yml or ja.yml change, the assets aren't recompiled. I ended up solving the problem by working around turbo-sprockets.

Casara commented 8 years ago

@camertron I have the same problem, how did you solve? I solved by changing the version of assets, but does not want to do that whenever there is a change in some yml file.

camertron commented 8 years ago

@Casara I wrote a couple of gems to work around turbo-sprockets. The first is called generated-assets and it's capable of dynamically generating assets in code. You specify a path and the contents of the file, and the gem handles the rest.

The second gem is called i18n-js-assets. It uses generated-assets to dynamically add a series of translated javascript files to the asset pipeline.

Both these gems have (I think) a decent README, so I'd look there for more details.

Casara commented 8 years ago

@camertron Thank you! Problem solved! Only one thing, these gems work with Rails 5?

camertron commented 8 years ago

@Casara thanks to a recent pull request, i18n-js-assets now supports sprockets 4, but unfortunately the dependency constraints of generated-assets will prevent you from using i18n-js-assets with Rails 5. I just did some dependency hacking and all the tests pass under Rails 5, so it should just be a matter of relaxing the dependencies a bit. I'd happily accept a pull request :)