0

I tried to upgrade to use Opal 0.7.0.beta. I want to compile to a static app and follow the steps in http://opalrb.org/docs/static_applications/

My Rakefile looks like the one below. The questions:

  1. How do I need to rework the :build task to get rid of the deprecation message. i tried. to use Opal::Server instead of Opal::Environment but it did not work.

  2. I get `Opal already loaded. Loading twice can cause troubles, please fix your setup.``

  3. I get undefined is not a function in the generated javascript Opal.mark_as_loaded(Opal.normalize_loadable_path("corelib/runtime"));

Thanks for Opal and thanks for any advice.

# Rakefile
require 'opal'
require 'opal/sprockets/environment'
require 'opal-jquery'
require 'erb'
require 'zip'


ZUPFNOTER_JS = "../deploy_files/build.js"


desc "Build our app to #{ZUPFNOTER_JS}"
task :build do
  env = Opal::Environment.new
  env.append_path "."
  env.use_gem "vector2d"

  File.open(ZUPFNOTER_JS, "w+") do |out|
    out << env["application"].to_s
  end

  Dir.glob "../public/*.scss" do |f|
    cmd = "sass #{f} > #{File.dirname(f)}/#{File.basename(f, ".scss")}.css"
    puts sh cmd
  end
end

...

Bernhard
  • 686
  • 8
  • 20

2 Answers2

2

Something like the following should work:

require 'opal'
task :build do
  env = Sprockets::Environment.new
  Opal.append_path '.'
  Opal.use_gem 'vector2d'
  Opal.paths.each { |p| env.append_path(p) }

  File.open(ZUPFNOTER_JS, 'w+') { |out| out << env['application.js'].to_s }

  # …
end

I also suggest to use the same sprockets environment to build SCSS too as it should work out of the box (maybe a require "sass" is needed too).

Elia Schito
  • 989
  • 7
  • 18
  • Thanks, Elia for the hint, this seems to work but I have two rmaining issues: I get undefined is not a function in the generated javascript `Opal.mark_as_loaded(Opal.normalize_loadable_path("corelib/runtime")); `and YUICompressor throws a syntax error in the compiled javascript. in a line containing `self.new = self.$new;` – Bernhard Feb 09 '15 at 15:04
0

Issue #2: it is enough to require opal; there is no need to load the opal.min.js in the HTML page.

Issue #3: The loaded opal.min.js was of 0.6.1

Bernhard
  • 686
  • 8
  • 20
  • So, you mean to say that the compilation includes `opal` run time too? – Jikku Jose Feb 14 '15 at 05:21
  • Yes, and there is no need to include in the HTML page. This seems do be changed between 0.6.2 and 0.7.0. But I am not really sure, maybe in 0.6 the issue was simply not a Problem even if the runtime was loaded twice. Documentaton is a bit weak, but I don't want to complain. Opal is great and the community support as well. – Bernhard Feb 14 '15 at 10:08
  • Yup, the support is great. Really wish to use Ruby for frontend work and totally forget about JS :) – Jikku Jose Feb 14 '15 at 18:40