fbonetti / elm-rails

View helpers for incorporating Elm modules into Rails views
MIT License
75 stars 20 forks source link

Use Sprockets for asset compilation #4

Closed botandrose closed 7 years ago

botandrose commented 8 years ago

Some changes here:

  1. Replaced the compilation strategy with sprockets. Now we no longer need to disable the sprockets asset cache on development.
  2. Exposed Elm::Rails.elm_make_path as a configuration setting. Note that this relies on fbonetti/ruby-elm-compiler#2
  3. Moved helper to Elm::Rails::Helper and inlined the javascript template, due to Rails not seeing the template under certain unfortunate conditions.

What do you think about something like this for an 0.2.0 release?

botandrose commented 8 years ago

@fbonetti Okay, this is still WIP, but I've got this branch passing on Travis on my fork. Can you enable Travis on this repo so subsequent pushes will build on it?

fbonetti commented 8 years ago

You should be able to build on Travis now

On May 20, 2016, at 4:55 PM, Micah Geisel notifications@github.com wrote:

@fbonetti Okay, this is still WIP, but I've got this branch passing on Travis on my fork. Can you enable Travis on this repo so subsequent pushes will build on it?

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub

botandrose commented 8 years ago

@mariochavez I put a test in place, and was trying to merge your changes in to support both Rails 4 and 5, but I'm running into issues with Rails 5 (Rails 4 test currently passes). I don't really understand how the new Sprockets system works. Can you offer any insight here?

botandrose commented 8 years ago

Also, I wonder why the single rspec test takes 6 minutes on Travis. Runs in 10 seconds locally after rm -rf elm-stuff.

mariochavez commented 8 years ago

Micah,

I was playing with it today, and it worked for me on Rails 4.2.6 and Rails 5 rc1. What is the issue that you are having?

I'll upload my sample project for Rails 4.

Elm 0.16 and 0.17 are incompatible so I had to me a change to have Elm 0.17 to work properly, which might be ok since 0.16 should not be used for new projects and migration is pretty straight forward.

Mario Alberto Chávez @mario_chavez

Aprendiendo Ruby on Rails 4 |>http://railsenespanol.co Design, develop, and launch awesome products |>https://michelada.io

On May 21, 2016, 7:10 PM -0500, Micah Geiselnotifications@github.com, wrote:

Also, I wonder why the single rspec test takes 6 minutes. Runs in 10 seconds locally afterrm -rf elm-stuff.

— You are receiving this because you were mentioned. Reply to this email directly orview it on GitHub(https://github.com/fbonetti/elm-rails/pull/4#issuecomment-220807117)

botandrose commented 8 years ago

Hi Mario, the issue I'm having is that the test is failing. :smile: If you take a look at the Travis run for Rails 5, you will see the error, while this same test passes on Rails 4. Would you mind taking a shot at getting the test to pass?

mariochavez commented 8 years ago

Ok I'll look at it tomorrow, in my time zone is 2am. Btw I have this sample protect for Rails 4 and Elm 0.17 https://github.com/mariochavez/rails4-and-elm-017

botandrose commented 8 years ago

BTW, pushed another commit that makes the test output much more readable. Travis time is down to 1:30 now, too, for some reason.

ujh commented 8 years ago

This fails for me with the following error (on a Rails 4 project with Ruby 2.2.5):

RuntimeError - can't modify frozen Array:
   () Users/uh/.rvm/gems/ruby-2.2.5@riskmethods/bundler/gems/elm-rails-e1128e370e97/lib/elm/rails/railtie.rb:17:in `block (2 levels) in <class:Railtie>'
  sprockets-rails (3.0.4) lib/sprockets/railtie.rb:144:in `block in build_environment'
  sprockets-rails (3.0.4) lib/sprockets/railtie.rb:143:in `build_environment'
  railties (4.2.6) lib/rails/railtie.rb:194:in `method_missing'
  js_assets (0.1.2) lib/js_assets/list.rb:10:in `fetch'
  js_assets (0.1.2) app/assets/javascripts/app_assets.js.erb:1:in `_evaluate_template'
  sprockets (3.6.0) lib/sprockets/erb_processor.rb:26:in `call'
  sprockets (3.6.0) lib/sprockets/erb_processor.rb:13:in `call'
  sprockets (3.6.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
  sprockets (3.6.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
  sprockets (3.6.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
  sprockets (3.6.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
  sprockets (3.6.0) lib/sprockets/loader.rb:60:in `block in load'
  sprockets (3.6.0) lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
  sprockets (3.6.0) lib/sprockets/loader.rb:44:in `load'
  sprockets (3.6.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
  sprockets (3.6.0) lib/sprockets/cached_environment.rb:47:in `load'
  sprockets (3.6.0) lib/sprockets/bundle.rb:23:in `block in call'
  sprockets (3.6.0) lib/sprockets/utils.rb:183:in `dfs'
  sprockets (3.6.0) lib/sprockets/bundle.rb:24:in `call'
  sprockets (3.6.0) lib/sprockets/processor_utils.rb:75:in `call_processor'
  sprockets (3.6.0) lib/sprockets/processor_utils.rb:57:in `block in call_processors'
  sprockets (3.6.0) lib/sprockets/processor_utils.rb:56:in `call_processors'
  sprockets (3.6.0) lib/sprockets/loader.rb:134:in `load_from_unloaded'
  sprockets (3.6.0) lib/sprockets/loader.rb:60:in `block in load'
  sprockets (3.6.0) lib/sprockets/loader.rb:317:in `fetch_asset_from_dependency_cache'
  sprockets (3.6.0) lib/sprockets/loader.rb:44:in `load'
  sprockets (3.6.0) lib/sprockets/cached_environment.rb:20:in `block in initialize'
  sprockets (3.6.0) lib/sprockets/cached_environment.rb:47:in `load'
  sprockets (3.6.0) lib/sprockets/base.rb:66:in `find_asset'
  sprockets (3.6.0) lib/sprockets/base.rb:92:in `[]'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:341:in `find_asset'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:333:in `find_debug_asset'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:216:in `block in lookup_debug_asset'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:229:in `block in resolve_asset'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:228:in `resolve_asset'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:215:in `lookup_debug_asset'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:128:in `block in javascript_include_tag'
  sprockets-rails (3.0.4) lib/sprockets/rails/helper.rb:127:in `javascript_include_tag'
  app/views/layouts/admin.html.erb:8:in `_app_views_layouts_admin_html_erb__2642866237773396316_70242857192980'
  actionview (4.2.6) lib/action_view/template.rb:145:in `block in render'
  activesupport (4.2.6) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.6) lib/active_support/notifications.rb:164:in `instrument'
  actionview (4.2.6) lib/action_view/template.rb:333:in `instrument'
  actionview (4.2.6) lib/action_view/template.rb:143:in `render'
  actionview (4.2.6) lib/action_view/renderer/template_renderer.rb:66:in `render_with_layout'
  actionview (4.2.6) lib/action_view/renderer/template_renderer.rb:52:in `render_template'
  actionview (4.2.6) lib/action_view/renderer/template_renderer.rb:14:in `render'
  actionview (4.2.6) lib/action_view/renderer/renderer.rb:46:in `render_template'
  actionview (4.2.6) lib/action_view/renderer/renderer.rb:27:in `render'
  actionview (4.2.6) lib/action_view/rendering.rb:100:in `_render_template'
  actionpack (4.2.6) lib/action_controller/metal/streaming.rb:217:in `_render_template'
  actionview (4.2.6) lib/action_view/rendering.rb:83:in `render_to_body'
  actionpack (4.2.6) lib/action_controller/metal/rendering.rb:32:in `render_to_body'
  actionpack (4.2.6) lib/action_controller/metal/renderers.rb:37:in `render_to_body'
  actionpack (4.2.6) lib/abstract_controller/rendering.rb:25:in `render'
  actionpack (4.2.6) lib/action_controller/metal/rendering.rb:16:in `render'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in render'
  activesupport (4.2.6) lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
  /Users/uh/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/benchmark.rb:303:in `realtime'
  activesupport (4.2.6) lib/active_support/core_ext/benchmark.rb:12:in `ms'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:44:in `block in render'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
  activerecord (4.2.6) lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:43:in `render'
  actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:10:in `default_render'
  actionpack (4.2.6) lib/action_controller/metal/implicit_render.rb:5:in `send_action'
  actionpack (4.2.6) lib/abstract_controller/base.rb:198:in `process_action'
  actionpack (4.2.6) lib/action_controller/metal/rendering.rb:10:in `process_action'
  actionpack (4.2.6) lib/abstract_controller/callbacks.rb:20:in `block in process_action'
  activesupport (4.2.6) lib/active_support/callbacks.rb:117:in `call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:555:in `block (2 levels) in compile'
  activesupport (4.2.6) lib/active_support/callbacks.rb:505:in `call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:92:in `__run_callbacks__'
  activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_process_action_callbacks'
  activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.6) lib/abstract_controller/callbacks.rb:19:in `process_action'
  actionpack (4.2.6) lib/action_controller/metal/rescue.rb:29:in `process_action'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
  activesupport (4.2.6) lib/active_support/notifications.rb:164:in `block in instrument'
  activesupport (4.2.6) lib/active_support/notifications/instrumenter.rb:20:in `instrument'
  activesupport (4.2.6) lib/active_support/notifications.rb:164:in `instrument'
  actionpack (4.2.6) lib/action_controller/metal/instrumentation.rb:30:in `process_action'
  actionpack (4.2.6) lib/action_controller/metal/params_wrapper.rb:250:in `process_action'
  activerecord (4.2.6) lib/active_record/railties/controller_runtime.rb:18:in `process_action'
  actionpack (4.2.6) lib/abstract_controller/base.rb:137:in `process'
  actionview (4.2.6) lib/action_view/rendering.rb:30:in `process'
  actionpack (4.2.6) lib/action_controller/metal.rb:196:in `dispatch'
  actionpack (4.2.6) lib/action_controller/metal/rack_delegation.rb:13:in `dispatch'
  actionpack (4.2.6) lib/action_controller/metal.rb:237:in `block in action'
  actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:74:in `dispatch'
  actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:43:in `serve'
  actionpack (4.2.6) lib/action_dispatch/journey/router.rb:43:in `block in serve'
  actionpack (4.2.6) lib/action_dispatch/journey/router.rb:30:in `serve'
  actionpack (4.2.6) lib/action_dispatch/routing/route_set.rb:817:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/rack/agent_hooks.rb:30:in `traced_call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/rack/browser_monitoring.rb:32:in `traced_call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/rack/developer_mode.rb:48:in `traced_call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  http_accept_language (2.0.5) lib/http_accept_language/middleware.rb:14:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  warden (1.2.6) lib/warden/manager.rb:35:in `block in call'
  warden (1.2.6) lib/warden/manager.rb:34:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/etag.rb:24:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/conditionalget.rb:25:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/head.rb:13:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/flash.rb:260:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activerecord (4.2.6) lib/active_record/query_cache.rb:36:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activerecord (4.2.6) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.6) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.6) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.6) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.6) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:84:in `protected_app_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:79:in `better_errors_call'
  better_errors (2.1.1) lib/better_errors/middleware.rb:57:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.6) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.6) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.6) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.6) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.6) lib/rails/rack/logger.rb:20:in `call'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack-cache (1.6.1) lib/rack/cache/context.rb:140:in `forward'
  rack-cache (1.6.1) lib/rack/cache/context.rb:249:in `fetch'
  rack-cache (1.6.1) lib/rack/cache/context.rb:189:in `lookup'
  rack-cache (1.6.1) lib/rack/cache/context.rb:66:in `call!'
  rack-cache (1.6.1) lib/rack/cache/context.rb:51:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.6) lib/action_dispatch/middleware/static.rb:120:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  honeybadger (2.6.0) lib/honeybadger/rack/error_notifier.rb:33:in `block in call'
  honeybadger (2.6.0) lib/honeybadger/config.rb:198:in `with_request'
  honeybadger (2.6.0) lib/honeybadger/rack/error_notifier.rb:30:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  honeybadger (2.6.0) lib/honeybadger/rack/user_feedback.rb:28:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  honeybadger (2.6.0) lib/honeybadger/rack/user_informer.rb:18:in `call'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.6) lib/rails/engine.rb:518:in `call'
  railties (4.2.6) lib/rails/application.rb:165:in `call'
  railties (4.2.6) lib/rails/railtie.rb:194:in `method_missing'
  newrelic_rpm (3.15.2.317) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /Users/uh/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /Users/uh/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /Users/uh/.rvm/rubies/ruby-2.2.5/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
lsimoneau commented 7 years ago

These commits have been incorporated into #12 which I'll be merging shortly, so I'm closing this one. I've added tests with sample Rails 4.2 and 5.0 apps to validate that elm compilation works in those environments. @ujh if you're still experiencing issues let me know and I'll see if we can reproduce them in one of the tests.