Skip to content

Instantly share code, notes, and snippets.

@elia
Created November 25, 2019 23:18
Show Gist options
  • Save elia/04f0dc0b63af1eb0747f522c9ce8c715 to your computer and use it in GitHub Desktop.
Save elia/04f0dc0b63af1eb0747f522c9ce8c715 to your computer and use it in GitHub Desktop.
The base for this is `rails new prova_opal`
diff --git a/Gemfile b/Gemfile
index 3e42940..e3305df 100644
--- a/Gemfile
+++ b/Gemfile
@@ -21,6 +21,7 @@ gem 'jbuilder', '~> 2.7'
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
+gem 'opal-rails', '~> 1.0'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
diff --git a/Gemfile.lock b/Gemfile.lock
index aa81747..e4673e2 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -58,6 +58,7 @@ GEM
zeitwerk (~> 2.2)
addressable (2.7.0)
public_suffix (>= 2.0.2, < 5.0)
+ ast (2.4.0)
bindex (0.8.1)
bootsnap (1.4.5)
msgpack (~> 1.0)
@@ -82,6 +83,10 @@ GEM
concurrent-ruby (~> 1.0)
jbuilder (2.9.1)
activesupport (>= 4.2.0)
+ jquery-rails (4.3.5)
+ rails-dom-testing (>= 1, < 3)
+ railties (>= 4.2.0)
+ thor (>= 0.14, < 2.0)
listen (3.1.5)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
@@ -102,6 +107,27 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.5)
mini_portile2 (~> 2.4.0)
+ opal (1.0.0)
+ ast (>= 2.3.0)
+ parser (= 2.5.3.0)
+ opal-activesupport (0.3.3)
+ opal (>= 0.5.0, < 2)
+ opal-jquery (0.4.4)
+ opal (>= 0.10.0, < 1.1)
+ opal-rails (1.1.2)
+ jquery-rails
+ opal (~> 1.0.0)
+ opal-activesupport (>= 0.0.5)
+ opal-jquery (~> 0.4.4)
+ opal-sprockets (~> 0.4.6)
+ rails (>= 5.1, < 6.1)
+ sprockets-rails (>= 2.3.3, < 4.0)
+ opal-sprockets (0.4.8.1.0.3.7)
+ opal (~> 1.0.0)
+ sprockets (~> 3.7)
+ tilt (>= 1.4)
+ parser (2.5.3.0)
+ ast (~> 2.4.0)
public_suffix (4.0.1)
puma (4.3.0)
nio4r (~> 2.0)
@@ -160,7 +186,7 @@ GEM
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
spring (>= 1.2, < 3.0)
- sprockets (4.0.0)
+ sprockets (3.7.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.2.1)
@@ -205,6 +231,7 @@ DEPENDENCIES
capybara (>= 2.15)
jbuilder (~> 2.7)
listen (>= 3.0.5, < 3.2)
+ opal-rails (~> 1.0)
puma (~> 4.1)
rails (~> 6.0.1)
sass-rails (>= 6)
diff --git a/app/assets/javascript/application.js b/app/assets/javascript/application.js
new file mode 100644
index 0000000..29be117
--- /dev/null
+++ b/app/assets/javascript/application.js
@@ -0,0 +1,2 @@
+//= require opal_app
+Opal.load('opal_app')
diff --git a/app/assets/javascript/opal_app.js.rb b/app/assets/javascript/opal_app.js.rb
new file mode 100644
index 0000000..cea77e2
--- /dev/null
+++ b/app/assets/javascript/opal_app.js.rb
@@ -0,0 +1,6 @@
+`Opal.loaded(['corelib/random/MersenneTwister'])`
+require 'opal'
+
+puts 'hello from opal app'.upcase
+srand 123
+5.times { puts rand 456 }
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 09705d1..1d7dde8 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,2 +1,4 @@
class ApplicationController < ActionController::Base
+ def index
+ end
end
diff --git a/app/views/application/index.html.erb b/app/views/application/index.html.erb
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/app/views/application/index.html.erb
@@ -0,0 +1 @@
+
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb
index 657c9ed..6ee4bf9 100644
--- a/app/views/layouts/application.html.erb
+++ b/app/views/layouts/application.html.erb
@@ -6,7 +6,7 @@
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
- <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
</head>
<body>
diff --git a/config/routes.rb b/config/routes.rb
index c06383a..8e140d1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,3 +1,3 @@
Rails.application.routes.draw do
- # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
+ root to: 'application#index'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment