Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikamai/meteor-opal
Meteor support for Opal, the Ruby to Javascript Compiler
https://github.com/mikamai/meteor-opal
Last synced: 24 days ago
JSON representation
Meteor support for Opal, the Ruby to Javascript Compiler
- Host: GitHub
- URL: https://github.com/mikamai/meteor-opal
- Owner: mikamai
- License: mit
- Created: 2015-02-12T13:10:54.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-05-15T15:34:11.000Z (over 9 years ago)
- Last Synced: 2024-11-01T00:32:26.699Z (2 months ago)
- Language: JavaScript
- Homepage: http://opalrb.org
- Size: 372 KB
- Stars: 15
- Watchers: 27
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-opal - Meteor Opal - Meteor support for Opal, the Ruby to Javascript Compiler (Uncategorized / Uncategorized)
README
# meteor-opal
Meteor support for Opal, the Ruby to Javascript Compiler
# DISCLAIMER
**this is alpha quality code**, it's not tested and not ready for production.
## What's Opal?
[Opal](http://opalrb.org) is a ruby to javascript compiler, an implementation of the ruby corelib and stdlib, and associated gems.
## Installation
```
meteor add mikamai:opal
```Opal is supported on both the client and the server.
Files ending with `.rb` or `.js.rb` are automatically compiled to JavaScript.## Javascript interoperability
See the [compiled ruby section](http://opalrb.org/docs/compiled_ruby/) on Opal website.
Opal uses it's own global namespace, therefore classes and functions created using Opal, are immediatley available across every other module and/or package in the application, provided you use Opal or the Javascript equivalent `Opal.`.
For example the class `User` defined above will be accessible as `User` in Opal and as `Opal.User` in Javascript.
All functions are compiled with a `$` sign in front of the name, so method `new` of class `User` becomes `Opal.User.$new` and function `b` `Opal.Object.$b` (functions resides in the Object namespace).## Namespacing and Opal
All Opal classes/functions will be globally available to all other modules through the Opal's own private namespace.
## Usage
```ruby
class User
attr_accessor :namedef initialize(name)
@name = name
enddef admin?
@name == 'Admin'
end
enddef a
123
end$b = 321 # global variable
user = User.new('Bob')
puts user # #
puts user.admin? # false
puts "Hello from #{user.name}!" # Hello from Bob!puts a # 123
puts $b # 321```
```javascript
// somewhere else in Javascriptvar user = Opal.User.$new('Bob');
console.log(user); // { _id: ??, name: 'Bob' }
console.log(user['$admin?']()); // false
// functions names cannot end in ?
// so we access them as properties
console.log('Hello from ' + user.$name() + '!'); // Hello from Bob!// function call
console.log(Opal.Object.$a()); // 123// global variable
console.log(Opal.gvars.b); // 321
```