-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
102 lines (62 loc) · 6.17 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Ruby.js</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='http://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>
<link href="css/main.css" rel="stylesheet" type="text/css">
</head>
<body>
<h1 class="hero">Ruby.js</h1>
<article>
<a href="https://github.com/my-codeworks/ruby-in-the-browser">
<img style="position: absolute; top: -6px; right: -6px; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub">
</a>
<h1>Ruby in the browser</h1>
<p>This is a collection of demos of what you can currently do in the area of using ruby as the scripting language of the browser. As a replacement, kinda, of javascript if you will.</p>
<p>This is an area where a lot of people have done a lot of work over the years and one where we will probably end up having binary modules for our browsers to run whatever scripting language we want in the end.</p>
<p>Sadly that's still a long ways off and here is what you can do for now:</p>
<h2>What you really want<span>(but can only use for embedded applications)</span></h2>
<p>What we really want is to use Ruby just like we use Javascript today and you can. Head over to <a href="http://trydecaf.org/">trydecaf.org/</a> and enjoy the bliss! Or check out <a href="https://github.com/timahoney/decaf">the Github project</a>.</p>
<p>But since this requires you to download another browser it's only really viable when you deliver your product as a desktop app ...</p>
<p>There are also some work on building a native code extension for Chrome of the Ruby runtime. I have not seen it available in any other form <a href="https://github.com/ruby/ruby/commit/76bc2d1ed7f13fb329c33f48756ea3c24c59a6ea">than code</a>, so I haven't tried it. It's a bit better than Decaf if it get's into the app store, it means you can use it for backend type apps without much problem.</p>
<h2>What we got so far<span>(and it's pretty awesome!)</span></h2>
<p>So no full replacement of Javascript any time soon then? Well, nearly. There are two other approaches to this problem:</p>
<h3>Ruby VM in Javascript</h3>
<p>The traditional approach here is to use LLVM/Clang to compile the Ruby source to LLVM bytecode and convert that to Javascript.</p>
<p>Currently we have the full (almost) port of Ruby 1.8.7 that Replit did (<a href="https://github.com/replit/emscripted-ruby">replit/emscripted-ruby</a>). But that is 5 years old at the time of writing (early 2017) and never mind 1.9.x we have 2.4 now and 2.5 coming so it is seriously dated.</p>
<p>Enter the work that Matz(tm) is doing with mRuby and the similar convertion of that through LLVM/Clang called Webruby (<a href="https://github.com/xxuejie/webruby">xxuejie/webruby</a>).</p>
<p>That project is, relatively, updated and compatible with a large part of the Ruby ISO standard. So it is your best bet unless you want to set up Emscripetn/LLVM on your own.</p>
<p>You can look at that code under the <code>webruby</code> directory.</p>
<h3>Ruby runtime implemented in Javascript</h3>
<p>This is where Opal (<a href="http://opalrb.org">opalrb.org</a>) comes in. This is a two part project that consists of a Ruby parser/converter and a Javascript runtime for that.</p>
<p>Basically it takes Ruby source code and transforms it to Javascript, making a few assumptions along the way.</p>
<p>These assumptions are then delivered by the Opal Ruby runtime that is basically reimplementing Ruby core and stdlib in Javascript.</p>
<p>You'll the Opal test code in the <code>opal</code> directory.</p>
<h2>Face off</h2>
<p>Well, it depends...</p>
<p>Webruby is larger (but not by a huge factor) and slower (it's a full VM on top of another VM) but supports ISO Ruby better.</p>
<p>Opal is a bit smaller and a lot faster. It also integrates better with Javascript (see the opal-jquery plugin) but it isn't really Ruby, it's close but not quite.</p>
<p>What do I mean? Well it uses Javascripts data types to it's using <code>Boolean</code> instead of <code>TrueClass</code>/<code>FalseClass</code> and throws around a bit of <code>null</code> and <code>undefined</code> at times.</p>
<p>That said it's close enough and probably easier to live with in a mixed Ruby/Javascript project, like most are bound to be.</p>
<aside class="edit">
<p>Opal has matured a lot since I originally wrote this exploration. If I was going to do a ruby in the browser project today I would definatly use Opal over the LLVM/Emscripten ports of real ruby.</p>
<p>The community is vibrant and there are a lot of libraries and frameworks to use Opal in a professional manner. Go have a look at it if you are at all interested, which I assume you are since you read this far :)</p>
</aside>
<h2>The proof is in the eating</h2>
<p>To see what we can do I have make a couple of pages where you can see the same Ruby code being excercised by the different engines. I try to keep the examples as close to each other as possible but library diffrences makes that impossible in some cases.</p>
<p>To look at and see Webruby in action have a look under the <a href="webruby/">/webruby</a> path.</p>
<p>And to look at and see Opal in action have a look under the <a href="opal/">/opal</a> path.</p>
<h2>After ever after</h2>
<p>I'll add more tests and play around a bit more with real website programming and we'll see what wins out in the end...</p>
<h1>Help</h1>
<p>Do you know of any other way of running Ruby in the browser without any binary dependencies? Fork and add code for it as well or just open an issue and I'll add it as soon as possible.</p>
<p>Many thanks for your time and I hope you enjoy the simple demos I have put together to show what you can do with Ruby in the browser!</p>
</article>
</body>
</html>