cappruby 0.0.0
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/Rakefile +52 -0
- data/VERSION +1 -0
- data/bin/cappruby +24 -0
- data/build/CappRuby/CappRuby.j +1 -0
- data/cappruby.gemspec +67 -0
- data/demos/simple_app/config/build.yml +0 -0
- data/demos/simple_app/lib/application.rb +29 -0
- data/demos/simple_app/lib/menu.rb +18 -0
- data/framework/array.js +46 -0
- data/framework/cappruby.js +52 -0
- data/framework/class.js +127 -0
- data/framework/enumerator.js +39 -0
- data/framework/file.js +42 -0
- data/framework/geometry.js +106 -0
- data/framework/hash.js +109 -0
- data/framework/mapings.js +86 -0
- data/framework/method.js +120 -0
- data/framework/module.js +72 -0
- data/framework/object.js +128 -0
- data/framework/objj_additions.js +84 -0
- data/framework/proc.js +31 -0
- data/framework/string.js +101 -0
- data/framework/variable.js +53 -0
- data/framework/vm.js +176 -0
- data/framework/window.js +68 -0
- data/lib/cappruby/app_builder.rb +135 -0
- data/lib/cappruby/framework_builder.rb +60 -0
- data/lib/cappruby/ruby_builder.rb +494 -0
- data/lib/cappruby.rb +73 -0
- metadata +92 -0
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "cappruby"
|
8
|
+
gem.summary = %q{cappruby}
|
9
|
+
gem.description = %q{cappruby}
|
10
|
+
gem.email = "adam@adambeynon.com"
|
11
|
+
gem.homepage = "http://github.com/adambeynon/cappruby"
|
12
|
+
gem.authors = ["Adam Beynon"]
|
13
|
+
gem.add_development_dependency "vienna", ">= 0"
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rake/rdoctask'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "cappruby #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
data/bin/cappruby
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby -wKU
|
2
|
+
|
3
|
+
require File.expand_path(
|
4
|
+
File.join(File.dirname(__FILE__), %w[.. lib cappruby]))
|
5
|
+
|
6
|
+
CappRuby.tools ARGV
|
7
|
+
|
8
|
+
|
9
|
+
# require 'fileutils'
|
10
|
+
#
|
11
|
+
# OUTPUT_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', 'build'))
|
12
|
+
# FRAMEWORK_NAME = "CappRuby"
|
13
|
+
# DOTJ_PATH = File.join(OUTPUT_DIR, FRAMEWORK_NAME, FRAMEWORK_NAME) + '.j'
|
14
|
+
# PLIST_PATH = File.join(OUTPUT_DIR, FRAMEWORK_NAME) + 'Info.plist'
|
15
|
+
#
|
16
|
+
# JS_SOURCES = File.join(File.dirname(__FILE__), '..', 'runtime', '**', '*.js')
|
17
|
+
#
|
18
|
+
# FileUtils.mkdir_p(File.join(OUTPUT_DIR, FRAMEWORK_NAME))
|
19
|
+
#
|
20
|
+
# File.open(DOTJ_PATH, 'wb') do |j|
|
21
|
+
# Dir.glob(JS_SOURCES).each do |src|
|
22
|
+
# j.write src
|
23
|
+
# end
|
24
|
+
# end
|
@@ -0,0 +1 @@
|
|
1
|
+
./../runtime/object.js./../runtime/objj_additions.js./../runtime/opal.js
|
data/cappruby.gemspec
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{cappruby}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Adam Beynon"]
|
12
|
+
s.date = %q{2010-01-30}
|
13
|
+
s.default_executable = %q{cappruby}
|
14
|
+
s.description = %q{cappruby}
|
15
|
+
s.email = %q{adam@adambeynon.com}
|
16
|
+
s.executables = ["cappruby"]
|
17
|
+
s.files = [
|
18
|
+
"Rakefile",
|
19
|
+
"VERSION",
|
20
|
+
"bin/cappruby",
|
21
|
+
"build/CappRuby/CappRuby.j",
|
22
|
+
"cappruby.gemspec",
|
23
|
+
"demos/simple_app/config/build.yml",
|
24
|
+
"demos/simple_app/lib/application.rb",
|
25
|
+
"demos/simple_app/lib/menu.rb",
|
26
|
+
"framework/array.js",
|
27
|
+
"framework/cappruby.js",
|
28
|
+
"framework/class.js",
|
29
|
+
"framework/enumerator.js",
|
30
|
+
"framework/file.js",
|
31
|
+
"framework/geometry.js",
|
32
|
+
"framework/hash.js",
|
33
|
+
"framework/mapings.js",
|
34
|
+
"framework/method.js",
|
35
|
+
"framework/module.js",
|
36
|
+
"framework/object.js",
|
37
|
+
"framework/objj_additions.js",
|
38
|
+
"framework/proc.js",
|
39
|
+
"framework/string.js",
|
40
|
+
"framework/variable.js",
|
41
|
+
"framework/vm.js",
|
42
|
+
"framework/window.js",
|
43
|
+
"lib/cappruby.rb",
|
44
|
+
"lib/cappruby/app_builder.rb",
|
45
|
+
"lib/cappruby/framework_builder.rb",
|
46
|
+
"lib/cappruby/ruby_builder.rb"
|
47
|
+
]
|
48
|
+
s.homepage = %q{http://github.com/adambeynon/cappruby}
|
49
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
50
|
+
s.require_paths = ["lib"]
|
51
|
+
s.rubygems_version = %q{1.3.5}
|
52
|
+
s.summary = %q{cappruby}
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_development_dependency(%q<vienna>, [">= 0"])
|
60
|
+
else
|
61
|
+
s.add_dependency(%q<vienna>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<vienna>, [">= 0"])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
class AppController
|
2
|
+
|
3
|
+
attr_accessor :adam
|
4
|
+
|
5
|
+
def applicationWillFinishLaunching(notification)
|
6
|
+
puts "Woohoo!"
|
7
|
+
window :title => "Main Window" do |win|
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def applicationDidFinishLaunching(notification)
|
13
|
+
puts "Erm, better actually do some stuff now."
|
14
|
+
win = CPWindow.alloc
|
15
|
+
# inline javascript/objective-j
|
16
|
+
# `console.log(10)`
|
17
|
+
[1,2,3].each do |a|
|
18
|
+
puts a
|
19
|
+
end
|
20
|
+
|
21
|
+
bob = 20
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# class AppController
|
2
|
+
#
|
3
|
+
# def application_menu
|
4
|
+
# @application_menu ||= menu do |main|
|
5
|
+
# main.submenu :file do |file|
|
6
|
+
# file.item :new, :key => "n"
|
7
|
+
# file.item :open, :key => "o"
|
8
|
+
# file.item :save, :key => "s"
|
9
|
+
# end
|
10
|
+
# main.submenu :edit do |edit|
|
11
|
+
# file.item :copy, :key => "c"
|
12
|
+
# file.item :cut, :key => "x"
|
13
|
+
# file.item :paste, :key => "v"
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# end
|
data/framework/array.js
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
/*
|
2
|
+
* array.js
|
3
|
+
* cappruby
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
rb_cArray = nil;
|
28
|
+
|
29
|
+
function rb_ary_each(ary, sel) {
|
30
|
+
var _$ = cappruby_block; cappruby_block = nil;
|
31
|
+
if (!_$) throw "no block passed to ary#each. need to return enumerator"
|
32
|
+
|
33
|
+
for (var i = 0; i < ary.length; i++) {
|
34
|
+
cr_yield(_$, [ary[i]]);
|
35
|
+
}
|
36
|
+
};
|
37
|
+
|
38
|
+
function Init_Array() {
|
39
|
+
rb_cArray = objj_getClass("CPArray");
|
40
|
+
// rb_include_module(rb_cArray, rb_mEnumerable);
|
41
|
+
|
42
|
+
// rb_define_singleton_method(rb_cArray, "[]", rb_ary_s_create, -1);
|
43
|
+
// rb_define_singleton_method(rb_cArray, "try_convert", rb_ary_s_create, 1);
|
44
|
+
|
45
|
+
rb_define_method(rb_cArray, "each", rb_ary_each, 0);
|
46
|
+
};
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
* cappruby.js
|
3
|
+
* cappruby
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
/**
|
28
|
+
Main CappRuby entry point.
|
29
|
+
|
30
|
+
main_file - the .rb file to load (and run)
|
31
|
+
args - Passed from main. We send these to CPApplicationMain
|
32
|
+
namedArgs - ditto.
|
33
|
+
*/
|
34
|
+
function cappruby_main(main_file, args, namedArgs) {
|
35
|
+
cappruby_init();
|
36
|
+
cappruby_file_hash['/lib/application.rb'](cappruby_top_self);
|
37
|
+
// cappruby_trial(cappruby_top_self);
|
38
|
+
CPApplicationMain(args, namedArgs);
|
39
|
+
// console.log("jere");
|
40
|
+
};
|
41
|
+
|
42
|
+
/**
|
43
|
+
call all cappruby inits
|
44
|
+
*/
|
45
|
+
function cappruby_init() {
|
46
|
+
Init_Object();
|
47
|
+
Init_Array();
|
48
|
+
Init_String();
|
49
|
+
Init_Proc();
|
50
|
+
Init_VM();
|
51
|
+
Init_Mappings();
|
52
|
+
};
|
data/framework/class.js
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
/*
|
2
|
+
* class.js
|
3
|
+
* cappruby
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
function rb_define_class(id, super_class) {
|
28
|
+
var klass;
|
29
|
+
|
30
|
+
if (rb_const_defined(rb_cObject, id)) {
|
31
|
+
klass = rb_const_get(rb_cObject, id);
|
32
|
+
if ((super_class !== CPObject) && (klass.super_class !== super_class)) {
|
33
|
+
throw id + " already exists: different super value given"
|
34
|
+
}
|
35
|
+
return klass;
|
36
|
+
}
|
37
|
+
|
38
|
+
if (!super_class) {
|
39
|
+
// warning?
|
40
|
+
super_class = CPObject;
|
41
|
+
}
|
42
|
+
klass = objj_allocateClassPair(super_class, id);
|
43
|
+
// ivars? hmmm, probably dont need to.
|
44
|
+
objj_registerClassPair(klass);
|
45
|
+
// heh?
|
46
|
+
objj_addClassForBundle(klass, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
|
47
|
+
// do we need a class table? maybe not..
|
48
|
+
rb_const_set(rb_cObject, id, klass);
|
49
|
+
return klass;
|
50
|
+
};
|
51
|
+
|
52
|
+
function rb_define_method(klass, id, func, arity) {
|
53
|
+
var m = new cappruby_method_t(id, func, []);
|
54
|
+
m.arity = arity;
|
55
|
+
|
56
|
+
klass.method_list.push(m);
|
57
|
+
klass.method_dtable[id] = m;
|
58
|
+
m.method_imp.displayName = klass.name + "#" + id;
|
59
|
+
return true;
|
60
|
+
};
|
61
|
+
|
62
|
+
function rb_define_singleton_method(klass, id, func, arity) {
|
63
|
+
return rb_define_method(rb_singleton_class(klass), id, func, arity);
|
64
|
+
};
|
65
|
+
|
66
|
+
/**
|
67
|
+
Returns the singleton class. Meta classes are already singleton classes,
|
68
|
+
so this method just returns the meta class itself. Classes in objj are
|
69
|
+
not singleton, so a new class will be created, and returned, and then
|
70
|
+
injected into the hierarchy. CLS_META identifies meta classes, while
|
71
|
+
CLS_CLASS identifies classes. A singleton class will have a CLS_SINGLETON
|
72
|
+
also, which is added on creation. Note, althogh a meta class is singleton,
|
73
|
+
it will not have a CLS_SINGLETON mask
|
74
|
+
*/
|
75
|
+
function rb_singleton_class(klass) {
|
76
|
+
if (klass.isa.info & CLS_CLASS) {
|
77
|
+
if (klass.isa.info & CLS_SINGLETON) {
|
78
|
+
// already a singleton
|
79
|
+
return klass.isa;
|
80
|
+
}
|
81
|
+
else {
|
82
|
+
// not a singleton, so make it one. keep same name
|
83
|
+
var s = objj_allocateClassPair(klass.isa, klass.isa.name);
|
84
|
+
_class_initialize(s);
|
85
|
+
s.info |= CLS_SINGLETON;
|
86
|
+
klass.isa = s;
|
87
|
+
return klass.isa;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
// meta class, so its already a singleton
|
92
|
+
return klass.isa;
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
function boot_defclass(id, superclass) {
|
97
|
+
var o = rb_class_boot(superclass, id);
|
98
|
+
// rb_class_tbl[id] = o;
|
99
|
+
rb_const_set((rb_cObject ? rb_cObject : o), id, o);
|
100
|
+
return o;
|
101
|
+
};
|
102
|
+
|
103
|
+
function rb_class_boot(superclass, name) {
|
104
|
+
return rb_objj_create_class(name, superclass);
|
105
|
+
};
|
106
|
+
|
107
|
+
function rb_objj_create_class(name, superclass) {
|
108
|
+
var RB_CLASS = 0;
|
109
|
+
return rb_objj_alloc_class(name, superclass, RB_CLASS, nil);
|
110
|
+
};
|
111
|
+
|
112
|
+
function rb_alloc_class(type, klass) {
|
113
|
+
var obj = new RClass();
|
114
|
+
obj.$klass = klass;
|
115
|
+
obj.$type = type;
|
116
|
+
return obj;
|
117
|
+
};
|
118
|
+
|
119
|
+
rb_anonymous_count = 0;
|
120
|
+
|
121
|
+
function rb_objj_alloc_class(name, superclass, type, klass) {
|
122
|
+
name = name || ("RubyAnonymous" + rb_anonymous_count++);
|
123
|
+
superclass = superclass || rb_cObject;
|
124
|
+
var o = objj_allocateClassPair(superclass, name);
|
125
|
+
objj_registerClassPair(o);
|
126
|
+
return o;
|
127
|
+
};
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/*
|
2
|
+
* enumerator.js
|
3
|
+
* cappruby
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
rb_cEnumerator = nil;
|
28
|
+
|
29
|
+
function rb_enumerator_alloc(cls, sel) {
|
30
|
+
return CPEnumerator;
|
31
|
+
};
|
32
|
+
|
33
|
+
function Init_Enumerator() {
|
34
|
+
// Is this silly?
|
35
|
+
rb_cEnumerator = objj_getClass("CPEnumerator");
|
36
|
+
// rb_include_module(rb_cEnumerator, rb_mEnumerable);
|
37
|
+
|
38
|
+
rb_define_singleton_method(rb_cEnumerator, "alloc", rb_enumerator_alloc, 0);
|
39
|
+
};
|
data/framework/file.js
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
/*
|
2
|
+
* file.js
|
3
|
+
* cappruby
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
/**
|
28
|
+
hash of all full filenames => contents. Ruby files will be wrapped in a func
|
29
|
+
so execute it.
|
30
|
+
*/
|
31
|
+
cappruby_file_hash = { };
|
32
|
+
|
33
|
+
/**
|
34
|
+
Loaded from the application as "compiled ruby code"
|
35
|
+
|
36
|
+
- file is the filepath of the "ruby file" : used for require()
|
37
|
+
- content is the compiled ruby, as javascript. It is enclosed in a function()
|
38
|
+
so to run it (on require), simply execute the content e.g. c();
|
39
|
+
*/
|
40
|
+
function cappruby_file(file, content) {
|
41
|
+
cappruby_file_hash[file] = content;
|
42
|
+
};
|
@@ -0,0 +1,106 @@
|
|
1
|
+
/*
|
2
|
+
* geometry.js
|
3
|
+
* cappruby
|
4
|
+
*
|
5
|
+
* Created by Adam Beynon.
|
6
|
+
* Copyright 2010 Adam Beynon.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
|
27
|
+
cr_cRect = nil;
|
28
|
+
cr_cPoint = nil;
|
29
|
+
cr_cSize = nil;
|
30
|
+
|
31
|
+
function cr_rect_new(x, y, w, h) {
|
32
|
+
var r = CPRectMake(x, y, w, h);
|
33
|
+
r.isa = cr_cRect;
|
34
|
+
return r;
|
35
|
+
};
|
36
|
+
|
37
|
+
function cr_point_new(x, y) {
|
38
|
+
var r = CPPointMake(x, y);
|
39
|
+
r.isa = cr_cPoint;
|
40
|
+
return r;
|
41
|
+
};
|
42
|
+
|
43
|
+
function cr_size_new(w, h) {
|
44
|
+
var r = CPSizeMake(w, h);
|
45
|
+
r.isa = cr_cSize;
|
46
|
+
return r;
|
47
|
+
};
|
48
|
+
|
49
|
+
/**
|
50
|
+
Array#to_rect
|
51
|
+
|
52
|
+
Takes an array, of length 4, and returns a CPRect.
|
53
|
+
|
54
|
+
[a, b, c, d].to_rect
|
55
|
+
=> { origin: { x: a, y: b }, size: { width: c, height: d } }
|
56
|
+
*/
|
57
|
+
function cr_array_to_rect(ary, sel) {
|
58
|
+
return cr_rect_new(ary[0], ary[1], ary[2], ary[3]);
|
59
|
+
};
|
60
|
+
|
61
|
+
/**
|
62
|
+
Array#to_point
|
63
|
+
|
64
|
+
Takes an array, of length 2, and returns a CPPoint.
|
65
|
+
|
66
|
+
[a, b].to_point
|
67
|
+
=> { x: a, y: b }
|
68
|
+
*/
|
69
|
+
function cr_array_to_point(ary, sel) {
|
70
|
+
return cr_point_new(ary[0], ary[1]);
|
71
|
+
};
|
72
|
+
|
73
|
+
/**
|
74
|
+
Array#to_point
|
75
|
+
|
76
|
+
Takes an array, of length 2, and returns a CPSize.
|
77
|
+
|
78
|
+
[a, b].to_size
|
79
|
+
=> { width: a, height: b }
|
80
|
+
*/
|
81
|
+
function cr_array_to_size(ary, sel) {
|
82
|
+
return cr_size_new(ary[0], ary[1]);
|
83
|
+
};
|
84
|
+
|
85
|
+
function Init_Mappings_Geometry() {
|
86
|
+
|
87
|
+
cr_cRect = rb_define_class("CPRect", rb_cBasicObject);
|
88
|
+
cr_cPoint = rb_define_class("CPPoint", rb_cBasicObject);
|
89
|
+
cr_cSize = rb_define_class("CPSize", rb_cBasicObject);
|
90
|
+
|
91
|
+
rb_define_singleton_method(cr_cRect, "new", function(cls, sel, x, y, w, h) {
|
92
|
+
return cr_rect_new(x, y, w, h);
|
93
|
+
}, 4);
|
94
|
+
|
95
|
+
rb_define_singleton_method(cr_cPoint, "new", function(cls, sel, x, y) {
|
96
|
+
return cr_point_new(x, y);
|
97
|
+
}, 2);
|
98
|
+
|
99
|
+
rb_define_singleton_method(cr_cSize, "new", function(cls, sel, w, h) {
|
100
|
+
return cr_size_new(w, h);
|
101
|
+
}, 2);
|
102
|
+
|
103
|
+
rb_define_method(rb_cArray, "to_rect", cr_array_to_rect, 0);
|
104
|
+
rb_define_method(rb_cArray, "to_point", cr_array_to_point, 0);
|
105
|
+
rb_define_method(rb_cArray, "to_size", cr_array_to_size, 0);
|
106
|
+
};
|