inline_javascript 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +40 -0
- data/History.txt +4 -0
- data/Manifest.txt +21 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +89 -0
- data/Rakefile +30 -0
- data/ext/inline_java_script_v8_wrapper/extconf.rb +6 -0
- data/ext/inline_java_script_v8_wrapper/inline_java_script_v8_wrapper.cc +103 -0
- data/lib/inline_java_script.rb +43 -0
- data/lib/inline_java_script/v8_wrapper.rb +21 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/helpers/spec_helper.rb +1 -0
- data/spec/inline_javascript_spec.rb +18 -0
- data/spec/inline_javascript_v8_wrapper_extn_spec.rb +27 -0
- data/tasks/extconf.rake +13 -0
- data/tasks/extconf/inline_java_script_v8_wrapper.rake +43 -0
- metadata +101 -0
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use 1.9.2@ruby_inline_javascript
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
RedCloth (4.2.7)
|
5
|
+
activesupport (2.3.11)
|
6
|
+
diff-lcs (1.1.2)
|
7
|
+
hoe (2.9.1)
|
8
|
+
rake (>= 0.8.7)
|
9
|
+
i18n (0.5.0)
|
10
|
+
json (1.5.1)
|
11
|
+
newgem (1.5.3)
|
12
|
+
RedCloth (>= 4.1.1)
|
13
|
+
activesupport (~> 2.3.4)
|
14
|
+
hoe (>= 2.4.0)
|
15
|
+
rubigen (>= 1.5.3)
|
16
|
+
syntax (>= 1.0.0)
|
17
|
+
rake (0.8.7)
|
18
|
+
rdoc (3.5.3)
|
19
|
+
rspec (2.5.0)
|
20
|
+
rspec-core (~> 2.5.0)
|
21
|
+
rspec-expectations (~> 2.5.0)
|
22
|
+
rspec-mocks (~> 2.5.0)
|
23
|
+
rspec-core (2.5.1)
|
24
|
+
rspec-expectations (2.5.0)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
rspec-mocks (2.5.0)
|
27
|
+
rubigen (1.5.6)
|
28
|
+
activesupport (>= 2.3.5)
|
29
|
+
i18n
|
30
|
+
syntax (1.0.0)
|
31
|
+
|
32
|
+
PLATFORMS
|
33
|
+
ruby
|
34
|
+
|
35
|
+
DEPENDENCIES
|
36
|
+
hoe (>= 2.7.0)
|
37
|
+
json
|
38
|
+
newgem (>= 1.5.3)
|
39
|
+
rdoc (>= 3.2)
|
40
|
+
rspec (>= 2.5)
|
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
.rspec
|
2
|
+
.rvmrc
|
3
|
+
Gemfile
|
4
|
+
Gemfile.lock
|
5
|
+
History.txt
|
6
|
+
Manifest.txt
|
7
|
+
PostInstall.txt
|
8
|
+
README.rdoc
|
9
|
+
Rakefile
|
10
|
+
ext/inline_java_script_v8_wrapper/extconf.rb
|
11
|
+
ext/inline_java_script_v8_wrapper/inline_java_script_v8_wrapper.cc
|
12
|
+
lib/inline_java_script.rb
|
13
|
+
lib/inline_java_script/v8_wrapper.rb
|
14
|
+
script/console
|
15
|
+
script/destroy
|
16
|
+
script/generate
|
17
|
+
spec/helpers/spec_helper.rb
|
18
|
+
spec/inline_javascript_spec.rb
|
19
|
+
spec/inline_javascript_v8_wrapper_extn_spec.rb
|
20
|
+
tasks/extconf.rake
|
21
|
+
tasks/extconf/inline_java_script_v8_wrapper.rake
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
= inline_javascript
|
2
|
+
|
3
|
+
* http://github.com/moowahaha/ruby_inline_javascript
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Call JavaScript methods from Ruby using either InlineJavaScript or, more directly,
|
8
|
+
InlineJavaScript::V8Wrapper.
|
9
|
+
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* InlineJavaScript supports calling methods with multiple parameters of Fixnum (integer),
|
14
|
+
String, Hash, Array or any other class that supports the ".to_json" method (as provided
|
15
|
+
by the "json" gem).
|
16
|
+
|
17
|
+
* InlineJavaScript supports JavaScript return values of type String, Integer, Hash, Array or any
|
18
|
+
other type supported by JavaScript's "JSON.stringify()" method.
|
19
|
+
|
20
|
+
* InlineJavaScript::V8Wrapper only currently supports functions returning basic scalars,
|
21
|
+
that it then turns into strings.
|
22
|
+
|
23
|
+
|
24
|
+
== SYNOPSIS:
|
25
|
+
|
26
|
+
To call a JavaScript function as if it was Ruby:
|
27
|
+
|
28
|
+
require 'inline_java_script'
|
29
|
+
|
30
|
+
js = InlineJavaScript.new('function my_add (a, b) { return a+b}')
|
31
|
+
js.my_add(1, 2) #=> 3
|
32
|
+
|
33
|
+
Using more complex types:
|
34
|
+
|
35
|
+
js = InlineJavaScript.new('function my_concat (a) { return {concat_string: a[0] + " " + a[1]} }')
|
36
|
+
js.my_concat(['hello', 'world']) #=> {"concat_string" => "hello world"}
|
37
|
+
|
38
|
+
To call the V8 engine directly (no smarts):
|
39
|
+
|
40
|
+
require 'inline_java_script/v8_wrapper'
|
41
|
+
|
42
|
+
wrapper = InlineJavaScript::V8Wrapper.new
|
43
|
+
wrapper.execute('1 + 2') #=> "3"
|
44
|
+
|
45
|
+
An instance of the V8Wrapper maintains state:
|
46
|
+
|
47
|
+
wrapper = InlineJavaScript::V8Wrapper.new
|
48
|
+
wrapper.execute('var e = "monster"')
|
49
|
+
wrapper.execute('e') #=> "monster"
|
50
|
+
|
51
|
+
# ... But I cannot access another instance...
|
52
|
+
InlineJavaScript::V8Wrapper.new.execute('e') #=> SyntaxError
|
53
|
+
|
54
|
+
|
55
|
+
== REQUIREMENTS:
|
56
|
+
|
57
|
+
* Google's libv8. I installed this using Homebrew (https://github.com/mxcl/homebrew)
|
58
|
+
by running "brew install v8" on OSX. libv8 is also available for other operating
|
59
|
+
systems through various means (e.g. yum install libv8-dev).
|
60
|
+
|
61
|
+
|
62
|
+
== INSTALL:
|
63
|
+
|
64
|
+
* gem install inline_javascript
|
65
|
+
|
66
|
+
== LICENSE:
|
67
|
+
|
68
|
+
(The MIT License)
|
69
|
+
|
70
|
+
Copyright (c) 2011 Stephen Hardisty.
|
71
|
+
|
72
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
73
|
+
a copy of this software and associated documentation files (the
|
74
|
+
'Software'), to deal in the Software without restriction, including
|
75
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
76
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
77
|
+
permit persons to whom the Software is furnished to do so, subject to
|
78
|
+
the following conditions:
|
79
|
+
|
80
|
+
The above copyright notice and this permission notice shall be
|
81
|
+
included in all copies or substantial portions of the Software.
|
82
|
+
|
83
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
84
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
85
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
86
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
87
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
88
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
89
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/inline_java_script'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
|
9
|
+
$hoe = Hoe.spec 'inline_javascript' do
|
10
|
+
self.developer 'Stephen Hardisty', 'moowahaha@hotmail.com'
|
11
|
+
self.post_install_message = 'PostInstall.txt'
|
12
|
+
self.rubyforge_name = self.name
|
13
|
+
self.extra_deps = [['json','>= 0']]
|
14
|
+
|
15
|
+
self.clean_globs = [
|
16
|
+
'ext/inline_java_script_v8_wrapper/Makefile',
|
17
|
+
'ext/inline_java_script_v8_wrapper/*.{o,so,bundle,a,log,dll}',
|
18
|
+
'ext/inline_java_script_v8_wrapper/conftest.dSYM'
|
19
|
+
]
|
20
|
+
|
21
|
+
self.spec_extras = { :extensions => ["ext/inline_java_script_v8_wrapper/extconf.rb"] }
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default do
|
25
|
+
sh 'rake clean && rake extconf:compile && rake spec'
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'newgem/tasks'
|
29
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
30
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include <v8.h>
|
3
|
+
|
4
|
+
using namespace v8;
|
5
|
+
|
6
|
+
class V8Context {
|
7
|
+
|
8
|
+
public:
|
9
|
+
|
10
|
+
V8Context() {
|
11
|
+
this->context = Context::New();
|
12
|
+
}
|
13
|
+
|
14
|
+
~V8Context() {
|
15
|
+
this->dispose();
|
16
|
+
}
|
17
|
+
|
18
|
+
void dispose() {
|
19
|
+
this->context.Dispose();
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE execute(VALUE javascript_string) {
|
23
|
+
Context::Scope context_scope(this->context);
|
24
|
+
|
25
|
+
HandleScope handle_scope;
|
26
|
+
|
27
|
+
Handle<String> source = String::New(StringValueCStr(javascript_string));
|
28
|
+
|
29
|
+
TryCatch try_catch;
|
30
|
+
|
31
|
+
Handle<Script> javascript_functions = Script::Compile(source);
|
32
|
+
|
33
|
+
if (javascript_functions.IsEmpty()) {
|
34
|
+
throw_javascript_exception(&try_catch);
|
35
|
+
}
|
36
|
+
|
37
|
+
Handle<Value> result = javascript_functions->Run();
|
38
|
+
|
39
|
+
return this->rb_result(result, &try_catch);
|
40
|
+
}
|
41
|
+
|
42
|
+
private:
|
43
|
+
|
44
|
+
Persistent<Context> context;
|
45
|
+
|
46
|
+
VALUE rb_result(Handle<Value> result, TryCatch *try_catch) {
|
47
|
+
if (result.IsEmpty()) {
|
48
|
+
throw_javascript_exception(try_catch);
|
49
|
+
}
|
50
|
+
|
51
|
+
if (result->IsUndefined()) {
|
52
|
+
return Qnil;
|
53
|
+
}
|
54
|
+
|
55
|
+
String::Utf8Value str(result);
|
56
|
+
|
57
|
+
return rb_str_new2(*str);
|
58
|
+
}
|
59
|
+
|
60
|
+
void throw_javascript_exception(TryCatch *try_catch) {
|
61
|
+
Handle<Value> exception = try_catch->Exception();
|
62
|
+
String::AsciiValue exception_str(exception);
|
63
|
+
|
64
|
+
Handle<Message> message = try_catch->Message();
|
65
|
+
if (message.IsEmpty()) {
|
66
|
+
rb_raise(rb_eSyntaxError, "JavaScript error: %s", *exception_str);
|
67
|
+
}
|
68
|
+
|
69
|
+
int line = message->GetLineNumber();
|
70
|
+
String::Utf8Value sourceline(message->GetSourceLine());
|
71
|
+
|
72
|
+
rb_raise(rb_eSyntaxError, "JavaScript error: %s on line %d:\n%s", *exception_str, line, *sourceline);
|
73
|
+
}
|
74
|
+
|
75
|
+
};
|
76
|
+
|
77
|
+
VALUE rb_cInlineJavaScriptV8Wrapper = Qnil;
|
78
|
+
|
79
|
+
VALUE rb_execute_java_script(VALUE self, VALUE javascript_string) {
|
80
|
+
V8Context *this_context;
|
81
|
+
Data_Get_Struct(self, V8Context, this_context);
|
82
|
+
return this_context->execute(javascript_string);
|
83
|
+
|
84
|
+
}
|
85
|
+
|
86
|
+
void dispose_of_context(V8Context *this_context) {
|
87
|
+
this_context->dispose();
|
88
|
+
free(this_context);
|
89
|
+
}
|
90
|
+
|
91
|
+
VALUE allocate_context(VALUE klass) {
|
92
|
+
V8Context *this_context = new V8Context();
|
93
|
+
return Data_Wrap_Struct(klass, 0, dispose_of_context, this_context);
|
94
|
+
}
|
95
|
+
|
96
|
+
extern "C" void Init_inline_java_script_v8_wrapper() {
|
97
|
+
VALUE rb_cInlineJavaScript = rb_define_class("InlineJavaScript", rb_cObject);
|
98
|
+
rb_cInlineJavaScriptV8Wrapper = rb_define_class_under(rb_cInlineJavaScript, "V8Wrapper", rb_cObject);
|
99
|
+
|
100
|
+
rb_define_method(rb_cInlineJavaScriptV8Wrapper, "execute", (VALUE(*)(...))&rb_execute_java_script, 1);
|
101
|
+
rb_define_alloc_func(rb_cInlineJavaScriptV8Wrapper, allocate_context);
|
102
|
+
}
|
103
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
#== SYNOPSIS:
|
4
|
+
#
|
5
|
+
#To call a JavaScript function as if it was Ruby:
|
6
|
+
#
|
7
|
+
# require 'inline_java_script'
|
8
|
+
#
|
9
|
+
# js = InlineJavaScript.new('function my_add (a, b) { return a+b}')
|
10
|
+
# js.my_add(1, 2) #=> 3
|
11
|
+
#
|
12
|
+
#Using more complex types:
|
13
|
+
#
|
14
|
+
# js = InlineJavaScript.new('function my_concat (a) { return {concat_string: a[0] + " " + a[1]} }')
|
15
|
+
# js.my_concat(['hello', 'world']) #=> {"concat_string" => "hello world"}
|
16
|
+
|
17
|
+
|
18
|
+
class InlineJavaScript
|
19
|
+
VERSION = '0.1'
|
20
|
+
|
21
|
+
# Takes a string containing some JavaScript and executes it. The state is maintained.
|
22
|
+
# JavaScript functions defined in the string can be called directly from an instance
|
23
|
+
# of InlineJavaScript as if they were methods.
|
24
|
+
|
25
|
+
def initialize javascript_functions
|
26
|
+
require File.join(File.dirname(__FILE__), %w{.. ext inline_java_script_v8_wrapper inline_java_script_v8_wrapper})
|
27
|
+
|
28
|
+
@wrapper = InlineJavaScript::V8Wrapper.new
|
29
|
+
@wrapper.execute(javascript_functions)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Attempts to call whatever JavaScript function you defined in the constructor.
|
33
|
+
# It will accept any number of parameters of String, Fixnum, Array or Hash and can
|
34
|
+
# support returning the same from JavaScript.
|
35
|
+
|
36
|
+
def method_missing(method, *arguments, &unused_block)
|
37
|
+
json_arguments = arguments.map do |arg|
|
38
|
+
"JSON.parse(" + arg.to_json.to_json + ")"
|
39
|
+
end
|
40
|
+
|
41
|
+
JSON[@wrapper.execute("JSON.stringify({result: #{method}(#{json_arguments.join(',')})})")]['result']
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), %w{.. .. ext inline_java_script_v8_wrapper inline_java_script_v8_wrapper})
|
2
|
+
|
3
|
+
#== SYNOPSIS:
|
4
|
+
#To call the V8 engine:
|
5
|
+
#
|
6
|
+
# require 'inline_java_script/v8_wrapper'
|
7
|
+
#
|
8
|
+
# wrapper = InlineJavaScript::V8Wrapper.new
|
9
|
+
# wrapper.execute('1 + 2') #=> "3"
|
10
|
+
#
|
11
|
+
#An instance of the V8Wrapper maintains state:
|
12
|
+
#
|
13
|
+
# wrapper = InlineJavaScript::V8Wrapper.new
|
14
|
+
# wrapper.execute('var e = "monster"')
|
15
|
+
# wrapper.execute('e') #=> "monster"
|
16
|
+
#
|
17
|
+
# # ... But I cannot access another instance...
|
18
|
+
# InlineJavaScript::V8Wrapper.new.execute('e') #=> SyntaxError
|
19
|
+
|
20
|
+
class InlineJavaScript::V8Wrapper
|
21
|
+
end
|
data/script/console
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# File: script/console
|
3
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
4
|
+
|
5
|
+
libs = " -r irb/completion"
|
6
|
+
# Perhaps use a console_lib to store any extra methods I may want available in the cosole
|
7
|
+
# libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
|
8
|
+
libs << " -r #{File.dirname(__FILE__) + '/../lib/pickaxe.rb'}"
|
9
|
+
puts "Loading pickaxe gem"
|
10
|
+
exec "#{irb} #{libs} --simple-prompt"
|
data/script/destroy
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/destroy'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Destroy.new.run(ARGV)
|
data/script/generate
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'rubigen'
|
6
|
+
rescue LoadError
|
7
|
+
require 'rubygems'
|
8
|
+
require 'rubigen'
|
9
|
+
end
|
10
|
+
require 'rubigen/scripts/generate'
|
11
|
+
|
12
|
+
ARGV.shift if ['--help', '-h'].include?(ARGV[0])
|
13
|
+
RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
|
14
|
+
RubiGen::Scripts::Generate.new.run(ARGV)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'inline_java_script'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
describe InlineJavaScript do
|
2
|
+
|
3
|
+
it "should call pass arguments and return results" do
|
4
|
+
js = InlineJavaScript.new('function concat (a, b) { return(a + " " + b) }')
|
5
|
+
js.concat('bath', 'rules').should == 'bath rules'
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be able to deal with numeric values" do
|
9
|
+
js = InlineJavaScript.new('function add (a, b) { return(a + b) }')
|
10
|
+
js.add(1, 100).should == 101
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should handle more complex types" do
|
14
|
+
js = InlineJavaScript.new('function something (some_array) { return {second: some_array[1]} }')
|
15
|
+
js.something(%w{hopefully this works great}).should == {'second' => 'this'}
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/../ext/inline_java_script_v8_wrapper/inline_java_script_v8_wrapper"
|
2
|
+
|
3
|
+
describe InlineJavaScript::V8Wrapper do
|
4
|
+
|
5
|
+
it "should execute some javascript" do
|
6
|
+
wrapper = InlineJavaScript::V8Wrapper.new
|
7
|
+
wrapper.execute('function blah() { return "hello"}')
|
8
|
+
wrapper.execute('blah()').should == "hello"
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not have globally scoped JS" do
|
12
|
+
InlineJavaScript::V8Wrapper.new.execute('function i_should_have_a_short_life() {}')
|
13
|
+
|
14
|
+
wrapper = InlineJavaScript::V8Wrapper.new
|
15
|
+
wrapper.execute('function i_am_wasted_javascript () {}')
|
16
|
+
-> { wrapper.execute('i_should_have_a_short_life()') }.should raise_error(SyntaxError)
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return nil when nothing is returned" do
|
20
|
+
InlineJavaScript::V8Wrapper.new.execute('var x = 2').should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should throw exceptions with syntax errors" do
|
24
|
+
-> { InlineJavaScript::V8Wrapper.new.execute('sdfsdf') }.should raise_error(SyntaxError)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/tasks/extconf.rake
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :extconf do
|
2
|
+
desc "Compiles the Ruby extension"
|
3
|
+
task :compile
|
4
|
+
end
|
5
|
+
|
6
|
+
task :compile => "extconf:compile"
|
7
|
+
|
8
|
+
task :test => :compile
|
9
|
+
|
10
|
+
BIN = "*.{bundle,jar,so,obj,pdb,lib,def,exp,o}"
|
11
|
+
$hoe.clean_globs |= ["ext/**/#{BIN}", "lib/**/#{BIN}", 'ext/**/Makefile']
|
12
|
+
$hoe.spec.require_paths = Dir['{lib,ext/*}']
|
13
|
+
$hoe.spec.extensions = FileList["ext/**/extconf.rb"].to_a
|
@@ -0,0 +1,43 @@
|
|
1
|
+
namespace :extconf do
|
2
|
+
extension = File.basename(__FILE__, '.rake')
|
3
|
+
|
4
|
+
ext = "ext/#{extension}"
|
5
|
+
ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
|
6
|
+
ext_files = FileList[
|
7
|
+
"#{ext}/*.c",
|
8
|
+
"#{ext}/*.h",
|
9
|
+
"#{ext}/*.rl",
|
10
|
+
"#{ext}/extconf.rb",
|
11
|
+
"#{ext}/Makefile",
|
12
|
+
# "lib"
|
13
|
+
]
|
14
|
+
|
15
|
+
|
16
|
+
task :compile => extension do
|
17
|
+
if Dir.glob("**/#{extension}.{o,so,dll}").length == 0
|
18
|
+
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
19
|
+
STDERR.puts "Gem actually failed to build. Your system is"
|
20
|
+
STDERR.puts "NOT configured properly to build #{GEM_NAME}."
|
21
|
+
STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
22
|
+
exit(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Builds just the #{extension} extension"
|
27
|
+
task extension.to_sym => ["#{ext}/Makefile", ext_so ]
|
28
|
+
|
29
|
+
file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
|
30
|
+
Dir.chdir(ext) do ruby "extconf.rb" end
|
31
|
+
end
|
32
|
+
|
33
|
+
file ext_so => ext_files do
|
34
|
+
Dir.chdir(ext) do
|
35
|
+
sh(RUBY_PLATFORM =~ /win32/ ? 'nmake' : 'make') do |ok, res|
|
36
|
+
if !ok
|
37
|
+
require "fileutils"
|
38
|
+
FileUtils.rm Dir.glob('*.{so,o,dll,bundle}')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: inline_javascript
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Stephen Hardisty
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-02-27 00:00:00.000000000 +11:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
requirement: &2757730 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2757730
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: hoe
|
28
|
+
requirement: &2757460 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.9.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2757460
|
37
|
+
description: ! 'Call JavaScript methods from Ruby using either InlineJavaScript or,
|
38
|
+
more directly,
|
39
|
+
|
40
|
+
InlineJavaScript::V8Wrapper.'
|
41
|
+
email:
|
42
|
+
- moowahaha@hotmail.com
|
43
|
+
executables: []
|
44
|
+
extensions:
|
45
|
+
- ext/inline_java_script_v8_wrapper/extconf.rb
|
46
|
+
extra_rdoc_files:
|
47
|
+
- History.txt
|
48
|
+
- Manifest.txt
|
49
|
+
- PostInstall.txt
|
50
|
+
files:
|
51
|
+
- .rspec
|
52
|
+
- .rvmrc
|
53
|
+
- Gemfile
|
54
|
+
- Gemfile.lock
|
55
|
+
- History.txt
|
56
|
+
- Manifest.txt
|
57
|
+
- PostInstall.txt
|
58
|
+
- README.rdoc
|
59
|
+
- Rakefile
|
60
|
+
- ext/inline_java_script_v8_wrapper/extconf.rb
|
61
|
+
- ext/inline_java_script_v8_wrapper/inline_java_script_v8_wrapper.cc
|
62
|
+
- lib/inline_java_script.rb
|
63
|
+
- lib/inline_java_script/v8_wrapper.rb
|
64
|
+
- script/console
|
65
|
+
- script/destroy
|
66
|
+
- script/generate
|
67
|
+
- spec/helpers/spec_helper.rb
|
68
|
+
- spec/inline_javascript_spec.rb
|
69
|
+
- spec/inline_javascript_v8_wrapper_extn_spec.rb
|
70
|
+
- tasks/extconf.rake
|
71
|
+
- tasks/extconf/inline_java_script_v8_wrapper.rake
|
72
|
+
has_rdoc: true
|
73
|
+
homepage: http://github.com/moowahaha/ruby_inline_javascript
|
74
|
+
licenses: []
|
75
|
+
post_install_message: PostInstall.txt
|
76
|
+
rdoc_options:
|
77
|
+
- --main
|
78
|
+
- README.rdoc
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
- ext/inline_java_script_v8_wrapper
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project: inline_javascript
|
96
|
+
rubygems_version: 1.5.2
|
97
|
+
signing_key:
|
98
|
+
specification_version: 3
|
99
|
+
summary: Call JavaScript methods from Ruby using either InlineJavaScript or, more
|
100
|
+
directly, InlineJavaScript::V8Wrapper.
|
101
|
+
test_files: []
|