opal 将ruby代码转化成javascript
https://github.com/opal
Opal
![]()
![]()
Opal is a ruby to javascript source-to-source compiler. It also has an implementation of the ruby corelib.
Opal is hosted on github, and there is a Freenode IRC channel at #opal, ask questions onstackoverflow (tag #opalrb).
![]()
![]()
Usage
See the website, http://opalrb.org.
Compiling ruby code
Opal.compile
is a simple interface to just compile a string of ruby into a string of javascript code.Opal.compile("puts 'wow'") # => "(function() { ... self.$puts("wow"); ... })()"Running this by itself is not enough, you need the opal runtime/corelib.
Building the corelib
Opal::Builder
can be used to build the runtime/corelib into a string.Opal::Builder.build('opal') #=> "(function() { ... })()"Running compiled code
You can write the above two strings to file, and run as:
<!DOCTYPE html>
<html>
<head>
<script src="opal.js"></script>
<script src="app.js"></script>
</head>
</html>Just open a browser to this page and view the console.
Running tests
First, install dependencies:
$ bundle install
RubySpec related repos must be cloned as a gitsubmodules:
$ git submodule update --init
The test suite can be run using (requires phantomjs):
$ rake
This will command will run all RSpec and MSpec examples in sequence.
Automated runs
A
Guardfile
with decent mappings between specs and lib/corelib/stdlib files is in place. Runbundle exec guard -i
to have it started.MSpec
MSpec tests can be run with:
$ rake mspec
Alternatively, you can just load up a rack instance using
rackup
, and visithttp://localhost:9292/
in any web browser.Rspec
RSpec tests can be run with
$ rake rspec
Code Overview
What code is supposed to run where?
lib/
code runs inside your ruby env. It compiles ruby to javascript.opal/
is the runtime/corelib for our implementation (runs in browser)stdlib/
is our implementation of ruby stdlib. It is optional (for browser).lib
The
lib
directory holds the opal parser/compiler used to compile ruby into javascript. It is also built ready for the browser intoopal-parser.js
to allow compilation in any javascript environment.corelib
This directory holds the opal runtime and corelib implemented in ruby and javascript.
stdlib
Holds the stdlib that opal currently supports. This includes
Observable
,StringScanner
,Date
, etc.Browser support
- Internet Explorer 6+
- Firefox (Current - 1) or Current
- Chrome (Current - 1) or Current
- Safari 5.1+
- Opera 12.1x or (Current - 1) or Current
Any problems encountered using the browsers listed above should be reported as a bug.
(Current - 1) or Current denotes that we support the current stable version of the browser and the version that preceded it. For example, if the current version of a browser is 24.x, we support the 24.x and 23.x versions.
12.1x or (Current - 1) or Current denotes that we support Opera 12.1x as well as the last 2 versions of Opera. For example, if the current Opera version is 20.x, then we support Opera 12.1x, 19.x and 20.x but not Opera 15.x through 18.x.
Cross-browser testing is sponsored by BrowserStack.
License
(The MIT License)
Copyright (C) 2013 by Adam Beynon
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
opal 将ruby代码转化成javascript的更多相关文章
- [转]DSL-让你的 Ruby 代码更优秀
https://ruby-china.org/topics/38428 以下摘录 DSL和Gpl DSL : domain-specific language.比如HTML是用于组织网页的‘语言’, ...
- 50行ruby代码开发一个区块链
区块链是什么?作为一个Ruby开发者,理解区块链的最好办法,就是亲自动手实现一个.只需要50行Ruby代码你就能彻底理解区块链的核心原理! 区块链 = 区块组成的链表? blockchain.ruby ...
- MyEclipse格式化JSP代码,其中Javascript无法格式化的原因
MyEclipse格式化JSP代码,其中Javascript无法格式化的原因: 可能是JSP页面代码有错误的地方,而且可能是一个很微小的错误,比如多写了一个标点符号,这个需要仔细检查,包括HTML.C ...
- Windows环境Vim编辑器如何执行Ruby代码
1.下载 Ruby 1.8.5(2006-8-25) for Windows: 在网页http://www.rubychina.net/downloads/ 上找到 --〉Ruby on Windo ...
- 在Notepad++下运行ruby代码
轻量级,轻量级,所以用notepad++来运行ruby的代码最合适不过了,虽说有更好用的轻量级工具,但是用notepad++习惯了,也懒得去再装其他工具了.好了,进入主题,先安装插件NppExec,打 ...
- 两行代码搞定 JavaScript 的日期验证
我们通常在 JavaScript 中验证日期,基本的思路大概是,先判断年月日是否有效,再判断当月是否有当日,比如一些月份没有 31 日,平年二月没有 29.30 日,闰年二月没有 30 日等等. 偶然 ...
- 高质量的javascript代码 -- 深入理解Javascript
一. 编写高质量的javascript代码基本要点a) 可维护的代码(Writing Maintainable Code)i. 可读(注释)ii. 一致(看上去是同一个人写的)iii. 已记录b) 最 ...
- 读《编写高质量代码:改善JavaScript程序的188个建议》1
建议3:减少全局变量污染 定义全局变量有3种方式: ❑在任何函数外面直接执行var语句. var f='value'; ❑直接添加一个属性到全局对象上.全局对象是所有全局变量的容器.在Web浏览器中, ...
- [置顶] Ruby,Scala和JavaScript中的函数式编程(一)
函数式编程(英语:Functional programming)或者函数程序设计,又称泛函编程,是一种编程范型,它将电脑运算视为数学上的函数计算,并且避免使用程序状态以及易变对象.函数编程语言最重要的 ...
随机推荐
- MIFARE系列8《D8M1.exe》
软件名:D8M1.exe 更新时间:2014.06.28 操作系统:windowAll 外部设备:D8读卡器 D8M1可以对MIFARE块读写操作,支持1K,4K.检验KEY后返回SAK,QTAQ,U ...
- windows32位下安装mongodb
下载mongodb:http://downloads.mongodb.org/win32/mongodb-win32-i386-2.4.5.zip 给mongodb指定一个数据存放路径:这里我们放在m ...
- 【6.24-AppCan移动开发大会倒计时】科大讯飞来了!
6.24 AppCan移动开发者大会进入倒计时,报名通道即将关闭! 50多家移动圈服务商将出席此次大会,讯飞开放平台也将作为参展商,为参会者带去前沿的语音技术.参会者可现场体验最新连续语音识别技术,识 ...
- WIN服务器出现 php-cgi.exe - FastCGI 进程意外退出
既然是不能解析PHP,那就直接运行一下PHP,看会报什么错,再对症下药,于是,在命令提示符窗口进入php安装的根目录,然后运行php -v的命令,这时窗口弹出计算机丢失msvcr110.dll的错误, ...
- php连接mysql报错No such file or directory
php测试文件如下: 1 2 3 4 5 6 7 8 9 10 11 <?php $con = mysql_connect("localhost","root&qu ...
- 修改linux端口范围 ip_local_port_range
tags: ip_local_port_range 端口范围 sysctl Linux中有限定端口的使用范围,如果我要为我的程序预留某些端口,那么我需要控制这个端口范围, 本文主要描述如何去修改端口范 ...
- JS跨域方法及原理
JS跨域分析判断 JS跨域:在不同域之间,JS进行数据传输或通信.比如ajax向不同的域请求数据.JS获取iframe中的页面中的值(iframe内外不同域) 只要协议.端口.域名有一个不同则 ...
- C#泛型集合之Dictionary<k, v>使用技巧
1.要使用Dictionary集合,需要导入C#泛型命名空间 System.Collections.Generic(程序集:mscorlib) 2.描述 1).从一组键(Key)到一组值(Value) ...
- 快速生成R语言报告(markdown+Rstudio)
先预览一下用Markdown写的报告[http://rpubs.com/loness/167347],这是HTML格式,你也可以导出Word.pdf,但是导出pdf时文中不能有中文,但是可以使用“pd ...
- 玩耍Hibernate系列(二)--基础知识
Hibernate思维导图 Hibernate映射 关于hibernate的映射要说明的一点就是关于ID的访问权限,peroperty以及field的区别: 表的主键在内存中对应一个OID对象描述 ...