Skip to content

Instantly share code, notes, and snippets.

@laod
Last active December 14, 2015 14:18
Show Gist options
  • Save laod/5099827 to your computer and use it in GitHub Desktop.
Save laod/5099827 to your computer and use it in GitHub Desktop.
Opal fun - Opal::Server version: config.ru that made the current version of opal work for me. Put your files (whatever.js.opal or whatever.js.rb) in the assets directory. Change s.main to the name of the appropriate js.opal file. rackup. Enjoy. Some parts may be redundant. Investigating. Non-server version: convert.rb
require 'opal'
run Opal::Server.new { |s|
s.main = 'doi'
e = s.sprockets
e.append_path 'assets'
}
#!/usr/bin/ruby
require 'opal'
require 'opal-jquery'
require 'sprockets'
e = Sprockets::Environment.new
e.append_path 'src'
e.register_engine '.opal', Opal::Processor
e.register_engine '.rb', Opal::Processor
Opal.paths.each{|p| e.append_path p}
# parse and emit src/doi.js.rb
puts e['doi.js'].to_s
//= require jquery.min.js
require 'opal'
require 'opal-jquery'
Document.ready? {
Element["body"].append [1,2,3,4,5].map{|i| i*2}.reduce(0){|m,v| m+v}
}
@laod
Copy link
Author

laod commented Mar 6, 2013

assets is probably a poor choice of name for the directory, since it has so much rails baggage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment