m0gg / dart-rails

Handle dart scripts for rails so they get compiled to js for browsers without dart support.
MIT License
21 stars 2 forks source link

Sprockets 3.x Compatibility #16

Closed noahmayr closed 8 years ago

noahmayr commented 9 years ago

Your gem doesn't appear to work with sprockets 3.x which caused me a bit of a headache since it's on of those gems I don't tend to manually put in my gemfile but apparently some internals have changed that affect the dart2js compilation process in your gem.

m0gg commented 9 years ago

Could you please provide some more information, like an error message or something? I'll have a look at this as soon as i can.

noahmayr commented 9 years ago

it was something about the context instance variable of sprockes' directive processor being nonexistent and judging by their commit history it was removed during the update to 3.x. I already set my project to use 2.x so I can't provide exact error messages.

TastyCatFood commented 8 years ago

Hi, hate to bother you but the same issue here.

======================

Javascript console: undefined local variable or method `context' for #

=====================

rake assets:precompile: rake aborted! NameError: undefined local variable or methodcontext' for #Sprockets::DirectiveProcessor:0x007f489167aaa8 /home/bitnami/Tutorial/app/assets/dart/dart_app.js:2 /home/bitnami/Tutorial/vendor/bundle/ruby/2.0.0/gems/dart-rails-0.3.1/lib/dart/sprockets/directive_processor_dart2js.rb:9:inprocess_dart_directive' /home/bitnami/Tutorial/vendor/bundle/ruby/2.0.0/gems/sprockets-3.3.5/lib/sprockets/directive_processor.rb:183:inblock in process_directives' /home/bitnami/Tutorial/vendor/bundle/ruby/2.0.0/gems/sprockets-3.3.5/lib/sprockets/directive_processor.rb:178:ineach'

=================

I added "p self.class.name" to the method throwing the error , "process_dart_directive(path)", and found "Sprockets::DirectiveProcessor" is the ower of the function. And its method "process_directives(directives)" is calling "process_dart_directive(path)". In the caller method comment, it says I must subclass DirectiveProcessor for a custom directive and your doc mentions "Dart::SprocketsDirectiveDart2js".

I searched all my files for the string "SprocketsDirectiveDart2js", hoping to find the file that contains the class but only readme contains the string.

bitnami@linux:~/Tutorial$ rails -v Rails 4.2.2

bitnami@linux:~/Tutorial$ bundle show |egrep -i "sprocket|dart"

I thought I must be doing something world shakingly stupid and thought of just giving up but since there is another guy with the same issue, maybe this is something relevant. Hope I'm not just wasting your time and thanks for an interesting gem.

m0gg commented 8 years ago

I'm actually surprised that this gem is used. The initial idea was to serve both dart and js scripts. But since Google announced they won't implement native dart in Chrome i quite abandoned the further development. Anyways, i'll have a look right now. It seems that some of the sprockets internals have changed. The gem actually is an evil reeimplentation of the JS-handling, so this case is not really unexpected.

m0gg commented 8 years ago

I updated the gem to version 0.3.3 with 26931de72e0263f29f1225fcaa50e67fc4ac6861 It worked well for my application after upgrading to

Please check and report back if it is working for you too.

TastyCatFood commented 8 years ago

Thank you very much for an incredibly fast fix. It was basically fine.

But I wished your install guide could mention: 1) to run "pub get" in assets/dart to get rails_ujs package. 2) to run chmod a+rwx on user_home./pub_cache or grant the apache the rights. 3)to grant apache the execution right on the dart sdk dir(my case /usr/lib/dart); otherwise realtime compilation does not work.

I'm actually surprised that this gem is used

Dartium and chrome running side by side helps debugging. And I wanted to try dart because: 1) I'm new to the web. 2) Dart is like C++ or Java and easier than javascript for me. 3) Web pages are like desktop apps now thanks to ajax and local storage and dart let me use old designs. 4)Dart is not going to die tomorrow. Google is big enough to maintain and use it for internal things and it's probably more manageable than other options.

At last, thanks again, your gem is nice.

m0gg commented 8 years ago

But I wished your install guide could mention: 1) to run "pub get" in assets/dart to get rails_ujs package.

That is mentioned in https://github.com/m0gg/dart-rails#setup at point 4., it says you may either omit the rails_ujs or run rake pub:get

2) to run chmod a+rwx on user_home./pub_cache or grant the apache the rights.

Actually this is specifically required for your setup because you use Spache. And it's weird Apache want's to write to your home directory. This should not be required.

3)to grant apache the execution right on the dart sdk dir(my case /usr/lib/dart); otherwise realtime compilation does not work.

I used to keep the dart-sdk in my home directory for easier upgrades. If you want, you may have a look at https://github.com/m0gg/ruby-dart2js#find-sdk This shows you alternative ways to specify the path to the SDK to use.

1) I'm new to the web. 2) Dart is like C++ or Java and easier than javascript for me. 3) Web pages are like desktop apps now thanks to ajax and local storage and dart let me use old designs. 4)Dart is not going to die tomorrow. Google is big enough to maintain and use it for internal things and it's probably more manageable than other options.

Please supply your thoughts about that here too: https://github.com/m0gg/dart-rails/issues/17 I'm not thinking dart is going to die either, i'm just questioning the benefit of beeing able to deliver dart scripts.