Closed yasirs closed 10 years ago
IMO, this is not a issue. Use .js.coffee
. It's the intended behaviour.
In that case it is inconsistent with what goes on in the asset pipeline, where you need js.coffee.erb
extension in order to have erb pre-processing (as you should). For this reason alone I think the behaviour should be the same. Also why not just assume erb pre-preprocessing for *.html
files instead of naming them *.html.erb
? It's entirely inconsistent and surprising.
It also creates issues with IDEs like rubymine which don't provide indentation and syntax checking for coffee/erb without the erb
file extension.
Can someone explain how or why this is the expected behavior?
I would agree with @silasdavis that it would seem to be more consistent to have the file as .js.coffee.erb
What am I missing?
Perhaps there is a good explanation. I too am curious what it is...
Yeah, this is definitely inconsistent, nonintuitive, and confusing—it should be fixed.
See similar discussions and head-scratching:
any updates on this? current confusing state is definitely not good in my opinion
I just tried creating a view template called create.js.coffee.erb
and ran across this thread in a Google search. I would argue that this would be more consistent/intuitive than simply create.js.coffee
.
Hello there,
could someone tells us which version of sprockets{-rails}/coffee-rails you are using please ? It looks like the problem is gone with the following dependencies:
At least, I'm unable to reproduce the problem.
sprockets 2.10.1 sprockets-rails 2.0.1 coffee-rails 4.0.1
On Thursday, January 16, 2014, Robin Dupret notifications@github.com wrote:
Hello there,
could someone tells us which version of sprockets{-rails}/coffee-rails you are using please ? It looks like the problem is gone with the following dependencies:
- sprockets 2.10.0
- sprockets-rails 2.0.1
- coffee-rails 4.0.0
At least, I'm unable to reproduce the problem.
— Reply to this email directly or view it on GitHubhttps://github.com/rails/coffee-rails/issues/36#issuecomment-32494101 .
Chris Peters Founder, Minimal Orange, LLC chris@minimalorange.com minimalorange.comhttp://www.minimalorange.com/?utm_source=business+email&utm_medium=email&utm_campaign=Email+Signatures +1 (614) 372-6670
I came across this issue as well and I definitely agree with @silasdavis. Has there been an update in the meantime? My RubyMine is completely overwhelmed.
Thanks a lot for the tip!
Am 11.02.2014 um 04:07 schrieb Dmitry Ishkov notifications@github.com:
I also stumbled on this issue in RubyMine. To fix RubyMine highlighting you can go to Settings > File Types > RHTML files and register a new pattern "*.js.coffee"
— Reply to this email directly or view it on GitHub.
Agree with @silasdavis
This is not intuitive at all.
@andersennl were you able to retain the coffee / js syntax higlighting after making the RubyMine change? Because after I do it, the erb highlighting is fixed, but in the process, my coffee higlighting disappears.
@dhruvg Well, I had exactly the same problem like you so I ended up writing everything in jQuery ;-)
Confusing indeed!
This is absolutely NOT the expected behavior. For instance what if I'm using Slim, not erb? Is my coffee script now run through erb even though I'm using slim?
Either way it's not working as I get an error saying my partial can't be found.
if you want to handle .js.coffee.erb extension, you can use this:
# config/initializers/coffee_erb_handler.rb
ActionView::Template.register_template_handler 'coffee.erb', Coffee::Rails::TemplateHandler # without this there will be template not found error
class ActionView::PathResolver < ActionView::Resolver
EXTRACT_METHODS = %w{extract_handler_and_format_and_variant extract_handler_and_format} # name for rails 4.1 resp. 4.0
method_name = EXTRACT_METHODS.detect{|m| method_defined?(m) || private_method_defined?(m)}
raise 'unknown extract method name' if method_name.nil?
old_method_name = "old_#{method_name}"
alias_method old_method_name, method_name
define_method(method_name) do |path, default_formats|
self.send(old_method_name, path.gsub(/\.js\.coffee\.erb$/, '.js.coffee'), default_formats)
end
end
Little dirty, but I really love RubyMine syntax highlighting with .js.coffee.erb extension!
Tested in Rails 4.0.3 and 4.1.1
@cervinka - that works awesome.
:+1:
Sorry, but I don't think this is a feature this specific plugin should support.
If js views are written in coffee-script, the expected filename is .js.coffee rather than .js.coffee.erb. See http://stackoverflow.com/questions/7616097/how-to-render-new-js-coffee-erb-in-app-views
This is counter-intuitive and may waste mythical man-months with developers scratching heads.