rails / coffee-rails

CoffeeScript adapter for the Rails asset pipeline. Also adds support for .coffee views.
MIT License
230 stars 64 forks source link

.js.coffee.erb doesn't work in app/views #36

Closed yasirs closed 10 years ago

yasirs commented 11 years ago

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.

frodsan commented 11 years ago

IMO, this is not a issue. Use .js.coffee. It's the intended behaviour.

silasdavis commented 11 years ago

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.

silasdavis commented 11 years ago

It also creates issues with IDEs like rubymine which don't provide indentation and syntax checking for coffee/erb without the erb file extension.

YodaTravis commented 11 years ago

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?

TylerRick commented 11 years ago

Perhaps there is a good explanation. I too am curious what it is...

codyrobbins commented 11 years ago

Yeah, this is definitely inconsistent, nonintuitive, and confusing—it should be fixed.

See similar discussions and head-scratching:

pavolzbell commented 10 years ago

any updates on this? current confusing state is definitely not good in my opinion

chrisdpeters commented 10 years ago

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.

robin850 commented 10 years ago

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.

chrisdpeters commented 10 years ago

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

andersennl commented 10 years ago

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.

andersennl commented 10 years ago

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.

fzondlo commented 10 years ago

Agree with @silasdavis

This is not intuitive at all.

dhruvg commented 10 years ago

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

andersennl commented 10 years ago

@dhruvg Well, I had exactly the same problem like you so I ended up writing everything in jQuery ;-)

rept commented 10 years ago

Confusing indeed!

mikbe commented 10 years ago

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.

cervinka commented 10 years ago

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

matthaliski commented 10 years ago

@cervinka - that works awesome.

muloka commented 10 years ago

:+1:

josh commented 10 years ago

Sorry, but I don't think this is a feature this specific plugin should support.