EzDevInfo.com

opal

Ruby to JavaScript compiler Opal: Ruby to Javascript Compiler

Cannot use Ruby Math library with Opal

Is there a way to use the ruby Math library in Opal ?

I got the following error message Uncaught NameError: uninitialized constant Object::Math when using Math::PI in my ruby method.

The ruby code :

class Numeric
  def degrees
    self * Math::PI / 180 
  end
end

The generated javascript by Opal :

/* Generated by Opal 0.6.3 */
(function($opal) {
  var self = $opal.top, $scope = $opal, nil = $opal.nil, $breaker = $opal.breaker, $slice = $opal.slice, $klass = $opal.klass;

  $opal.add_stubs(['$/', '$*']);
  return (function($base, $super) {
    function $Numeric(){};
    var self = $Numeric = $klass($base, $super, 'Numeric', $Numeric);

    var def = self._proto, $scope = self._scope;

    return (def.$degrees = function() {
      var $a, $b, self = this;

      return self['$*']((($a = ((($b = $scope.Math) == null ? $opal.cm('Math') : $b))._scope).PI == null ? $a.cm('PI') : $a.PI))['$/'](180);
    }, nil) && 'degrees'
  })(self, null)
})(Opal);

//# sourceMappingURL=/__opal_source_maps__/game_engine/numeric.js.map
;

Thanks ;)


Source: (StackOverflow)

How to decode a H323 packet?

I am looking for a third party library capable of decoding H323 packets. I think I should be able to use OpenH323. But since it's a large library, I don't know which class and function I should use to decode a packet. Any advice would be appreciated!


Source: (StackOverflow)

Advertisements

Opal: Ruby to Javascript

I learned about Opal for Ruby recently and would like to convert a Ruby file to Javascript. I've used Coffeescript before, and I can compile a Coffeescript file to Javascript with a certain command on Node.js. How do I do the same with Ruby and Opal to Javascript ?


Source: (StackOverflow)

Porting wxPython to SWT/JFace

I use some nice controls/widgets in a simple wxPython app I developed taking inspiration from the sample demo. Call it my prototype.

I am now ready to migrate my prototype to Java/SWT.

Some controls are just not there.. or.. at least.. I could not find them.

Is there anything else in the FOSS world of SWT apart from the usual:

  • SWT/JFace
  • Nebula
  • Opal

For a while I did not know about Nebula nor Opal at all. Now I do. At least you know I have done some legwork before coming here. Could it be that I am still oblivious to some fundamental set of extensions to the core SWT?

What I am doing right now is building a table, on the left - controls I use from wxPython, on the right - equivalent controls I'll use in Java/SWT.

The right column still has some gaping blanks..


Source: (StackOverflow)

Opal is completely broken?

I've been totally unsuccessful in getting Opal to work.

When I try to embed it in a Sinatra server using the tutorial here or the example code here, I get undefined method 'source_maps' for #<Opal::Server:0x8b11540>. When I use the updated code linked at the bottom of this post, I get uninitialized constant Opal::Sprockets::SourceMapHeaderPatch.

So, I abandon Sinatra and try using Opal in a Rack app instead, using their own example here. And I get a totally blank webpage.

Finally, I follow the tutorial here to the letter, and again all I get is a blank page in my browser.

So, what am I doing wrong? Or is Opal really as broken as it appears?

(oh, and that's not even mentioning the two serious out-of-bounds bugs in the rescue block in parse() in opal/parser.rb that completely kill any chance of debugging an error)


Source: (StackOverflow)

Event Complete Callbacks with Opal-jQuery

I am working on a project that handles multiple jQuery events in succession using the opal-jquery wrapper. jQuery has very effective callback functionality and I am wondering if it is possible to do this in pure ruby with Opal.


Source: (StackOverflow)

Opal rails not able to compile source at runtime

I am trying to compile ruby source at run time in a browser. Earlier I used opal version 0.6.3 in which I get compile method and used to compile my source at run time in a javascript. But there are some problem with opal 0.6.3 so I want to upgrade it to 0.7.0 or higher. For this I use opal-rails gem but now I am no longer able to compile my ruby source at run time via javascript as compile method is no longer available.


Source: (StackOverflow)

Requests for a form that submits through ajax multiply with each subsequent submit

I have a form that makes an ajax request, the problem is that every time I click on it, the amount of times it makes that request multiplies.

Now I'm sure it's because of the way I've set up submit-intercept but I don't know how else to do it whilst still encapsulating it as a single component.

I'm using react as my view layer and I've attached a function that contains code to intercept the request and this function is called in both the afterMount callback and the after_update callback; if I don't do this then either the form submit is never intercepted or it only intercepts it once and then just does a normal submit.

Now obviously it's multiplying because those events fire and add an extra submit-handler.

I'm using opal and react.rb so the code might look a little odd.

Here's my function that intercepts the submit action on the form

def set_up_login_form
    puts 'setting up form'
    login_form = Element["#login_form"]
    login_form.on :submit do |event|
        unless login_state == :processing
            event.prevent_default
            username = login_form.find('#username').value
            password = login_form.find('#password').value
            login!
            self.username = username
            self.handle_login_submit({username: username , password: password})
        end 
    end
end

Here are my call backs:

after_mount do
    fix_button #untill materialize.js gets fixed
    set_up_login_form
end

after_update do
    set_up_login_form
end

I was able to reduce the amount of requests made by checking if the component state was already in the middle of a request, whilst this doesn't reduce the amount of submit handlers being added it does stop a good amount from doing anything, but it doesn't stop the actual multiplying of handlers being added.


Source: (StackOverflow)

Can't create variable on base object in 'self.included' hook in Opal

It's as the question title says, I have an included hook in a module:

def self.included(base)
    puts 'included'
    base.extend API
end

My API requires certain variables on the object to exists but none of them are being created.

I've tried:

  1. base.variable_name = []
  2. %x|#{base}.variable_name = []|
  3. base.instance_variable_set(:@variable_name,[])
  4. base.instance_exec{@variable_name = []}
  5. 1-2 inside of base.instance_exec but using self instead of base

Yet none of them work, the console just complains that variable_name= doesn't exist.

What.the.hell?

How do I get the variable to exist on the base object inside of the included hook?


Source: (StackOverflow)