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
Make angular-rails-templates work with Sprockets 3.0 #93
Comments
👍 Let me know if you need help with the new API. |
To get unblocked, here are some sample files until it gets merged in to angular-rails-templates: https://gist.github.com/stevenharman/8493700 http://minhajuddin.com/2013/04/28/angularjs-templates-and-rails-with-eager-loading |
Note: this doesn't watch for changes |
@rafaelfranca With the temporary solution I have to have rails c open in a tab and have to delete temp assets every time I make a slim change. Is there a better way around this than listed where I don't have to delete the temp assets? Thanks! |
So if you don't want to have to use rails c and Rails.cache.clear, you can run guard and have this in your guard file: guard 'rake', :task => 'tmp:clear' do and have this in your gem file gem 'guard' |
tmp:clear is annoying like h*ll :/ |
/CC |
+1 |
1 similar comment
+1 |
Had to downgrade to version |
+1 |
+1 (to use sprockets transformers instead) |
Thanks @davetron5000 for PR and everybody else for suggestions. Did anybody manage to get this gem working with sprockets transformers? |
any update on this? At the moment I'm stuck with: angular.module('templates', []).run(['$templateCache', function($templateCache) {
<%
environment.context_class.instance_eval { include ActionView::Helpers::JavaScriptHelper }
app_root = File.expand_path('../../', __FILE__)
templates = File.join(app_root, %w{templates ** *.html})
Dir.glob(templates).each do |f|
key = f.gsub(%r(^#{app_root}/templates/), '')
html = File.read(f).squish
%>
$templateCache.put("<%= key %>", "<%= escape_javascript(html) %>");
<% end %>
}]); but I have to run |
any updates regarding support sprockets 3? |
+1 |
Having issues to both use Sprockets 3 and downgrade I ended up getting rid of the gem completely and solved it like that (hope this will help maintainers to fix the issue if it is not done yet): 1 - Add 2 - Create require 'fileutils'
if Rails.env.development?
cache_path = Rails.root.join('tmp/cache/assets/development')
FileUtils.rm_rf(cache_path)
listener = Listen.to(Rails.root.join('app/assets/templates')) do |modified, added, removed|
# clearing cache
FileUtils.rm_rf(cache_path)
end
listener.start
end 3 - Create (function(){
'use strict';
angular.module('templates', []).run(['$templateCache', function($templateCache) {
<%
environment.context_class.instance_eval { include ActionView::Helpers::JavaScriptHelper }
app_root = File.expand_path('../../', __FILE__)
templates = File.join(app_root, %w{templates ** *.html})
Dir.glob(templates).each do |f|
key = f.gsub(%r(^#{app_root}/templates/), '')
html = File.read(f).squish
%>
$templateCache.put("<%= key %>", "<%= escape_javascript(html) %>");
<% end %>
}]);
}()); Done.. now just require your templates in //= require angular
// ...
//= require ./templates
// ...
angular.module('myApp', ['templates']); |
+1 |
6 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
👍 |
@mcasimir thanks a million for the sample setup! works great. for anyone else using his fix, it expects templates to be placed in app/assets/templates. you may need to tweak for your own setup. |
👍 |
@jonricaurte Is there a gulp workflow that will compile .html files into the angular $templateCache like this gem was doing? I'd be interested in learning about it. |
@mvarrieur yes. Here is what I use for gulp file:
using gulp-rename, slim, gulp-ng-html2js, gulp-minify-html, gulp-concat, gulp-rename |
@jonricaurte how do you integrate this with your rails workflow? a quick example would be great :). thanks |
+1 |
2 similar comments
+1 |
👍 |
A note in the README regarding this issue (until it is resolved) would help save a lot of time |
+1 |
Might as well try to fix it...running into issues implementing register_transformer. Any help would be appreciated. Thanks. How to intercept '.html' requests in Rails using Sprockets >3.0 Transformers? (ie fix 'angular-rails-templates' gem) http://stackoverflow.com/questions/33701654/how-to-intercept-html-requests-in-rails-using-sprockets-3-0-transformers-i |
+1 to get this fixed |
+1 |
1 similar comment
+1 |
The @superchris's fork has the proper fix to this issue. It can be improved to not have to rename templates to |
@superchris are you going to release your solution as a separate gem and add the support of slim and other preprocessors? I think it will be a perfect solution, because it seems that current gem is not going to bring a support of sprockets 3.+. |
Angular on Rails 4.2.3 app, setup with bower-rails + angular-rails-templates. This app uses sprockets v2.12.3, as angular-rails-templates won't support v3. As a workaround you can delete angular-rails-templates and follow these steps: pitr/angular-rails-templates#93 (comment). This app will move to this format next.
|
+1 |
Thanks everyone for encouragement, and especially thanks to work by @superchris I was able to take his branch and adapt it so that the gem works like it used to with sprocket 2, eg. no need to rename templates to .nghaml (see #126) I am releasing version 1.0.0.beta1 which supports Sprocket 3 (Rails 4.2) and in about a week 1.0.0 |
@pitr Thanks for your work on this! Much appreciated. |
Version v1.0.0 is out, supporting both Rails 4.2 and 5.0 |
Version v1.0.0 It's work! Very nice! |
The new version of sprockets will require angular-rails-templates to use transformers instead of what it is currently using according to @rafaelfranca:
rails/sprockets#22
Sprockets 3.0.0 includes support for babel transpiling using the es6 gem which is going to be very important as angular moves towards using ecmascript 6.
Thanks.
The text was updated successfully, but these errors were encountered: