decaf

Ruby in the browser.

  • 所有者: timimahoney/decaf
  • 平台:
  • 许可证:
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

Decaf

Decaf is a modification of WebKit that runs Ruby in the browser. Use Ruby to access the DOM, work with the web standards, and even print to the inspector. Now, you can build an entire web application in Ruby instead of JavaScript.

To use Ruby in the browser, either download a binary or build it yourself.

<script type='text/ruby'>
    window.onload do
        introduction = document.create_element('p')
        introduction.inner_text = 'Hello, world!'
        document.body.append_child(introduction)
    end
</script>

Using Ruby in the Browser

The same web platform APIs used by JavaScript are available in Ruby. If you're not familiar with JavaScript and the DOM, then check out these resources:

Differences from JavaScript

There are a few major differences between the APIs in JavaScript and Ruby.

  • In Ruby, methods and attributes are specified in underscore_case instead of camelCase.
  • The window variable is accessible from only the top-most scope. Elsewhere you can use the global $window.
  • Ruby accepts Procs and blocks as callbacks and listeners. For example:
# Ruby with implicit blocks
$window.set_timeout(1000) { console.log('Hello!') }
$window.onload do, event, console.log('The window loaded.')
end

# Ruby with explicit Procs
$window.set_timeout(Proc.new { console.log('Hello!') }, 1000)
$window.onload = Proc.new do, event, console.log('The window loaded.')
end

Final Notes

If you find any problems, then please report them in the issues section.

主要指标

概览
名称与所有者timimahoney/decaf
主编程语言C++
编程语言Emacs Lisp (语言数: 27)
平台
许可证
所有者活动
创建于2013-04-03 02:46:50
推送于2013-05-27 19:59:53
最后一次提交
发布数3
最新版本名称0.2 (发布于 )
第一版名称0.1 (发布于 )
用户参与
星数468
关注者数20
派生数8
提交数132.2k
已启用问题?
问题数18
打开的问题数8
拉请求数0
打开的拉请求数0
关闭的拉请求数0
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?