Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into jruby-1.7
Conflicts: README.markdown
- Loading branch information
Showing
3,369 changed files
with
249,552 additions
and
60,184 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "spec/ext/commonjs"] | ||
path = spec/ext/commonjs | ||
url = https://github.com/kriskowal/commonjs.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
rvm: | ||
- 1.9.3 | ||
- 1.9.2 | ||
- 1.8.7 | ||
- jruby-18mode | ||
- jruby-19mode | ||
notifications: | ||
recipients: | ||
- cowboyd@thefrontside.net | ||
before_install: git submodule update --init |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
source 'http://rubygems.org' | ||
|
||
# Specify your gem's dependencies in commonjs.gemspec | ||
gemspec | ||
|
||
gem "therubyracer", :platforms => :ruby | ||
gem "therubyrhino", "~> 1.73.3", :platforms => :jruby |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
# CommonJS [![Build Status](https://secure.travis-ci.org/cowboyd/commonjs.rb.png)](http://travis-ci.org/cowboyd/commonjs.rb) | ||
|
||
Host CommonJS JavaScript environments in Ruby | ||
|
||
## Why? | ||
|
||
The internet is now awash with non-browser JavaScript code. Much of this code conforms to some | ||
simple conventions that let you use it anywhere you have a JavaScript interpreter available. These | ||
conventions are collectively called "commonjs" | ||
|
||
We have several JavaScript interpreters available to us from Ruby. Therefore, why shouldn't we be | ||
able to use commonjs applications and libraries? | ||
|
||
## Using common JS from Ruby. | ||
|
||
`CommonJS` now passes all of the Modules 1.0 unit tests | ||
|
||
env = CommonJS::Environment.new(:path => '/path/to/lib/dir') | ||
env.require('foo.js') | ||
|
||
|
||
|
||
## Future directions | ||
|
||
By default, all you get with a bare commonjs environment is the Modules API | ||
|
||
The plan however, is to allow you to extend your commonjs environment to have whatever native | ||
interfaces you want in it. So for example, if you want to allow filesystem access, as well as | ||
access to the process information, you would say: | ||
|
||
env.modules :filesystem, :process | ||
|
||
## Supported runtimes | ||
|
||
### Current | ||
|
||
* The Ruby Racer (V8) - [https://github.com/cowboyd/therubyracer] | ||
* The Ruby Rhino (JRuby) - [https://github.com/cowboyd/therubyrhino] | ||
|
||
### Desired | ||
|
||
* Johnson (TraceMonkey) - [https://github.com/jbarnette/johnson] | ||
* Lyndon (MacRuby) - [https://github.com/defunkt/lyndon] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env rake | ||
require "bundler/gem_tasks" | ||
|
||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new('spec') do |spec| | ||
spec.rspec_opts = ['--color', "--format documentation"] | ||
end | ||
|
||
task :default => :spec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# -*- encoding: utf-8 -*- | ||
require File.expand_path('../lib/commonjs/version', __FILE__) | ||
|
||
Gem::Specification.new do |gem| | ||
gem.authors = ["Charles Lowell"] | ||
gem.email = ["cowboyd@thefrontside.net"] | ||
gem.description = "Host CommonJS JavaScript environments in Ruby" | ||
gem.summary = "Provide access to your Ruby and Operating System runtime via the commonjs API" | ||
gem.homepage = "http://github.com/cowboyd/commonjs.rb" | ||
|
||
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } | ||
gem.files = `git ls-files`.split("\n") | ||
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") | ||
gem.name = "commonjs" | ||
gem.require_paths = ["lib"] | ||
gem.version = CommonJS::VERSION | ||
|
||
gem.add_development_dependency "rake" | ||
gem.add_development_dependency "rspec" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require "commonjs/version" | ||
|
||
module CommonJS | ||
autoload :Environment, 'commonjs/environment' | ||
autoload :Module, 'commonjs/module' | ||
end |
39 changes: 39 additions & 0 deletions
39
lib/ruby/common/commonjs-0.2.6/lib/commonjs/environment.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
require 'pathname' | ||
module CommonJS | ||
class Environment | ||
|
||
attr_reader :runtime | ||
|
||
def initialize(runtime, options = {}) | ||
@runtime = runtime | ||
@paths = [options[:path]].flatten.map {|path| Pathname(path)} | ||
@modules = {} | ||
end | ||
|
||
def require(module_id) | ||
unless mod = @modules[module_id] | ||
filepath = find(module_id) or fail LoadError, "no such module '#{module_id}'" | ||
load = @runtime.eval("(function(module, require, exports) {#{File.read(filepath)}})", filepath.expand_path.to_s) | ||
@modules[module_id] = mod = Module.new(module_id, self) | ||
load.call(mod, mod.require_function, mod.exports) | ||
end | ||
return mod.exports | ||
end | ||
|
||
def native(module_id, impl) | ||
@modules[module_id] = Module::Native.new(impl) | ||
end | ||
|
||
def new_object | ||
@runtime['Object'].new | ||
end | ||
|
||
private | ||
|
||
def find(module_id) | ||
if loadpath = @paths.find { |path| path.join("#{module_id}.js").exist? } | ||
loadpath.join("#{module_id}.js") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module CommonJS | ||
class Module | ||
|
||
attr_reader :id | ||
attr_accessor :exports | ||
|
||
def initialize(id, env) | ||
@id = id | ||
@env = env | ||
@exports = env.new_object | ||
@segments = id.split('/') | ||
end | ||
|
||
def require_function | ||
@require_function ||= lambda do |*args| | ||
this, module_id = *args | ||
module_id ||= this #backwards compatibility with TRR < 0.10 | ||
@env.require(expand(module_id)) | ||
end | ||
end | ||
|
||
private | ||
|
||
def expand(module_id) | ||
return module_id unless module_id =~ /(\.|\..)/ | ||
module_id.split('/').inject(@segments[0..-2]) do |path, element| | ||
path.tap do | ||
if element == '.' | ||
#do nothing | ||
elsif element == '..' | ||
path.pop | ||
else | ||
path.push element | ||
end | ||
end | ||
end.join('/') | ||
end | ||
|
||
|
||
class Native | ||
|
||
attr_reader :exports | ||
|
||
def initialize(impl) | ||
@exports = impl | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.