cappruby 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -10,7 +10,8 @@ begin
10
10
  gem.email = "adam@adambeynon.com"
11
11
  gem.homepage = "http://github.com/adambeynon/cappruby"
12
12
  gem.authors = ["Adam Beynon"]
13
- gem.add_development_dependency "vienna", ">= 0"
13
+ gem.add_dependency "vienna", ">= 0.0.5"
14
+ gem.add_development_dependency "racc", ">= 1.4.6"
14
15
  end
15
16
  Jeweler::GemcutterTasks.new
16
17
  rescue LoadError
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
data/cappruby.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{cappruby}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam Beynon"]
12
- s.date = %q{2010-01-30}
12
+ s.date = %q{2010-02-01}
13
13
  s.default_executable = %q{cappruby}
14
14
  s.description = %q{cappruby}
15
15
  s.email = %q{adam@adambeynon.com}
@@ -23,7 +23,10 @@ Gem::Specification.new do |s|
23
23
  "demos/simple_app/config/build.yml",
24
24
  "demos/simple_app/lib/application.rb",
25
25
  "demos/simple_app/lib/menu.rb",
26
+ "demos/twitter_client/config/build.yml",
27
+ "demos/twitter_client/lib/application.rb",
26
28
  "framework/array.js",
29
+ "framework/button.js",
27
30
  "framework/cappruby.js",
28
31
  "framework/class.js",
29
32
  "framework/enumerator.js",
@@ -36,12 +39,16 @@ Gem::Specification.new do |s|
36
39
  "framework/object.js",
37
40
  "framework/objj_additions.js",
38
41
  "framework/proc.js",
42
+ "framework/slider.js",
39
43
  "framework/string.js",
40
44
  "framework/variable.js",
41
45
  "framework/vm.js",
42
46
  "framework/window.js",
47
+ "gen/app/config/build.yml",
48
+ "gen/app/lib/application.rb",
43
49
  "lib/cappruby.rb",
44
50
  "lib/cappruby/app_builder.rb",
51
+ "lib/cappruby/app_generator.rb",
45
52
  "lib/cappruby/framework_builder.rb",
46
53
  "lib/cappruby/ruby_builder.rb"
47
54
  ]
@@ -56,12 +63,15 @@ Gem::Specification.new do |s|
56
63
  s.specification_version = 3
57
64
 
58
65
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
59
- s.add_development_dependency(%q<vienna>, [">= 0"])
66
+ s.add_runtime_dependency(%q<vienna>, [">= 0.0.5"])
67
+ s.add_development_dependency(%q<racc>, [">= 1.4.6"])
60
68
  else
61
- s.add_dependency(%q<vienna>, [">= 0"])
69
+ s.add_dependency(%q<vienna>, [">= 0.0.5"])
70
+ s.add_dependency(%q<racc>, [">= 1.4.6"])
62
71
  end
63
72
  else
64
- s.add_dependency(%q<vienna>, [">= 0"])
73
+ s.add_dependency(%q<vienna>, [">= 0.0.5"])
74
+ s.add_dependency(%q<racc>, [">= 1.4.6"])
65
75
  end
66
76
  end
67
77
 
@@ -1,29 +1,26 @@
1
1
  class AppController
2
2
 
3
- attr_accessor :adam
4
-
5
3
  def applicationWillFinishLaunching(notification)
6
- puts "Woohoo!"
7
- window :title => "Main Window" do |win|
8
-
9
- end
4
+ main_window
10
5
  end
11
6
 
12
7
  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
8
+
9
+ end
10
+
11
+ # return or build the main window
12
+ def main_window
13
+ @main_window ||= window :title => "Main Window" do |win|
14
+ # A button example
15
+ button :title => "First Button" do |btn|
16
+ btn.on_action { puts "Wow, button was clicked" }
17
+ win << btn
18
+ end
19
+ # A simple slider (doesnt send actions..)
20
+ slider :min => 0, :max => 1000, :value => 900 do |slider|
21
+ win << slider
22
+ end
19
23
  end
20
-
21
- bob = 20
22
-
23
24
  end
24
25
 
25
26
  end
26
-
27
-
28
-
29
-
File without changes
@@ -0,0 +1,23 @@
1
+ # AppController class is the CPApp delegate
2
+ class AppController
3
+
4
+ def applicationWillFinishLaunching(notification)
5
+ main_window
6
+ end
7
+
8
+ def applicationDidFinishLaunching(notification)
9
+
10
+ end
11
+
12
+ # return or build the main window
13
+ def main_window
14
+ @main_window ||= window :title => "Twitter Client" do |win|
15
+
16
+ button :title => "First Button" do |btn|
17
+ btn.on_action { puts "Wow, button was clicked" }
18
+ win << btn
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,74 @@
1
+ /*
2
+ * button.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 cr_mappings_button(self, sel, options) {
28
+ var _$ = cappruby_block; cappruby_block = nil;
29
+ var h = cr_mappings_collate_options('button', options);
30
+
31
+ var btn = objj_msgSend(objj_msgSend(CPButton, "alloc"), "initWithFrame:", CGRectMake(100,100,84,24));
32
+
33
+ if(_$) { // if block given
34
+ cr_yield(_$, [btn]);
35
+ }
36
+
37
+ objj_msgSend(btn, "setTitle:", "My Button");
38
+
39
+ return btn;
40
+ };
41
+
42
+ /**
43
+ CPButton#on_action(&block)
44
+
45
+ When the action event of the button fires, run the block.
46
+
47
+ This method makes a fake target for the button, and adds a single method, to
48
+ act as the action, which essentially calls the proc. The proc will have access
49
+ to the scope in which it was defined.
50
+ */
51
+ function cr_window_on_action(btn, sel) {
52
+ var _$ = cappruby_block; cappruby_block = nil;
53
+ if (!_$) {
54
+ throw "no block given for CPButton#on_action"
55
+ }
56
+
57
+ var target = class_createInstance(rb_cObject);
58
+ rb_define_singleton_method(target, "button_action:",function(self, sel, obj) {
59
+ // call the proc with the "sender" as the param (if needed)
60
+ rb_ivar_get(self, '@button_action')(obj);
61
+ }, 1);
62
+
63
+ rb_ivar_set(target, '@button_action', _$);
64
+
65
+ objj_msgSend(btn, "setTarget:", target);
66
+ objj_msgSend(btn, "setAction:", 'button_action:');
67
+
68
+ return btn;
69
+ };
70
+
71
+ function Init_Mappings_Button() {
72
+ rb_define_method(rb_mKernel, "button:", cr_mappings_button, 1);
73
+ rb_define_method(CPButton, "on_action", cr_window_on_action, 0);
74
+ };
data/framework/mapings.js CHANGED
@@ -82,5 +82,7 @@ function Init_Mappings() {
82
82
  // setup defaults.
83
83
  cr_mappings_default_init();
84
84
  Init_Mappings_Window();
85
+ Init_Mappings_Button();
86
+ Init_Mappings_Slider();
85
87
  Init_Mappings_Geometry();
86
88
  };
@@ -0,0 +1,50 @@
1
+ /*
2
+ * slider.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 cr_mappings_slider(self, sel, options) {
28
+ var _$ = cappruby_block; cappruby_block = nil;
29
+ var h = cr_mappings_collate_options('slider', options);
30
+
31
+ var slider = objj_msgSend(objj_msgSend(CPSlider, "alloc"), "initWithFrame:", CGRectMake(100,200,84,24));
32
+
33
+ if(_$) { // if block given
34
+ cr_yield(_$, [slider]);
35
+ }
36
+
37
+ objj_msgSend(slider, "setMinValue:", rb_hash_delete(h, 'delete:', ID2SYM("min")));
38
+
39
+ objj_msgSend(slider, "setMaxValue:", rb_hash_delete(h, 'delete:', ID2SYM("max")));
40
+
41
+ objj_msgSend(slider, "setValue:", rb_hash_delete(h, 'delete:', ID2SYM("value")));
42
+
43
+ // objj_msgSend(btn, "setTitle:", "My Button");
44
+
45
+ return slider;
46
+ };
47
+
48
+ function Init_Mappings_Slider() {
49
+ rb_define_method(rb_mKernel, "slider:", cr_mappings_slider, 1);
50
+ };
@@ -24,6 +24,14 @@
24
24
  * THE SOFTWARE.
25
25
  */
26
26
 
27
+ function rb_ivar_set(obj, id, val) {
28
+ return obj[id] = val;
29
+ };
30
+
31
+ function rb_ivar_get(obj, id) {
32
+ return obj[id];
33
+ };
34
+
27
35
  function rb_const_set(klass, id, val) {
28
36
  klass[id] = val;
29
37
  };
data/framework/window.js CHANGED
@@ -45,7 +45,7 @@ function cr_mappings_window(self, sel, options) {
45
45
  }
46
46
 
47
47
  objj_msgSend(win, "orderFront:", self);
48
-
48
+
49
49
  return win;
50
50
  };
51
51
 
File without changes
@@ -0,0 +1,23 @@
1
+ # AppController class is the CPApp delegate
2
+ class AppController
3
+
4
+ def applicationWillFinishLaunching(notification)
5
+ main_window
6
+ end
7
+
8
+ def applicationDidFinishLaunching(notification)
9
+
10
+ end
11
+
12
+ # return or build the main window
13
+ def main_window
14
+ @main_window ||= window :title => "__APPLICATION_TITLE__" do |win|
15
+
16
+ button :title => "First Button" do |btn|
17
+ btn.on_action { puts "Wow, button was clicked" }
18
+ win << btn
19
+ end
20
+ end
21
+ end
22
+
23
+ end
@@ -55,7 +55,7 @@ module CappRuby
55
55
  write_main_j_file
56
56
  write_index_html_file
57
57
 
58
- File.symlink(File.join(@app_root, 'frameworks'), File.join(build_dir, 'Frameworks')) unless File.exist? File.join(build_dir, 'Frameworks')
58
+ File.symlink(File.join(@app_root, 'Frameworks'), File.join(build_dir, 'Frameworks')) unless File.exist? File.join(build_dir, 'Frameworks')
59
59
  end
60
60
 
61
61
  def info_plist_file
@@ -0,0 +1,80 @@
1
+ #
2
+ # application_generator.rb
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
+ module CappRuby
28
+
29
+ class AppGenerator
30
+
31
+ def initialize(args)
32
+ @app_name = args[0]
33
+ @app_title = (@app_name.split('_').collect { |p| p.capitalize }).join ' '
34
+ @app_root = File.join(Dir.getwd, @app_name)
35
+
36
+ if File.exists? @app_root
37
+ puts "#{@app_name} already exists. Choose a different path"
38
+ exit
39
+ end
40
+ end
41
+
42
+ # all source files
43
+ def source_files
44
+ File.join(CappRuby::ROOTPATH, 'gen', 'app')
45
+ end
46
+
47
+ # do generate
48
+ def gen!
49
+ puts "Generating project: '#{@app_title}' in '#{@app_name}'"
50
+ FileUtils.mkdir_p @app_root
51
+
52
+ Dir.glob(File.join(source_files, '**', '*')) do |f|
53
+ relative = f[source_files.length..-1]
54
+ if File.directory? f
55
+ FileUtils.mkdir_p File.join(@app_root, relative)
56
+ else
57
+ File.open(File.join(@app_root, relative), 'w') do |o|
58
+ t = File.read f
59
+ t.gsub!(/__APPLICATION_NAME__/, @app_name)
60
+ t.gsub!(/__APPLICATION_TITLE__/, @app_title)
61
+ o.write t
62
+ end
63
+ end
64
+ end
65
+
66
+ puts "Generating capp frameworks (might take a few secs)"
67
+ gen_capp_frameworks
68
+ end
69
+
70
+ # capp frameworks
71
+ def gen_capp_frameworks
72
+ if %x{which capp} == ""
73
+ puts "Capp is not installed. Required for frameworks. Generating anyway."
74
+ else
75
+ %x{capp gen #{@app_name} -f}
76
+ end
77
+ end
78
+
79
+ end
80
+ end
@@ -287,7 +287,7 @@ module CappRuby
287
287
 
288
288
  def generate_call call, context
289
289
  # capture "function calls"
290
- if call[:meth].match /^[A-Z](.*)$/
290
+ if call[:meth].match(/^[A-Z](.*)$/)
291
291
  return generate_function_call call, context
292
292
  end
293
293
  # capture objj
@@ -408,7 +408,7 @@ module CappRuby
408
408
  def gen_call_should_use_colon?(c)
409
409
  # basically, if a "special" method using ruby only things, then dont use
410
410
  # a colon
411
- return false if c[:meth].match /(\<|\!|\?\>\=\!)/
411
+ return false if c[:meth].match(/(\<|\!|\?\>\=\!)/)
412
412
 
413
413
  args_len = 0
414
414
  if c[:call_args] and c[:call_args][:args]
@@ -490,5 +490,22 @@ module CappRuby
490
490
 
491
491
  write ";" if context[:full_stmt]
492
492
  end
493
+
494
+ def generate_op_asgn(stmt, context)
495
+ write "return " if context[:full_stmt] and context[:last_stmt]
496
+
497
+ if stmt[:lhs].node == :ivar
498
+ write %{(function(asgn)\{if(asgn!==nil && asgn!==undefined)\{}
499
+ write %{return asgn;\}else\{}
500
+ write "rb_ivar_set(_a, '#{stmt[:lhs][:name]}',"
501
+ generate_stmt stmt[:rhs], :full_stmt => false, :last_stmt => false
502
+ write ")"
503
+ write %{\}\})(rb_ivar_get(_a,"#{stmt[:lhs][:name]}"))}
504
+ else
505
+ abort "bad op_asgn lhs: #{stmt[:lhs].node}"
506
+ end
507
+
508
+ write ";" if context[:full_stmt]
509
+ end
493
510
  end
494
511
  end
data/lib/cappruby.rb CHANGED
@@ -44,8 +44,15 @@ module CappRuby
44
44
 
45
45
  case cmd
46
46
  when "gen"
47
- gen args
47
+ if args.length == 0
48
+ print_usage
49
+ exit
50
+ end
51
+
52
+ require_libs
53
+ AppGenerator.new(args).gen!
48
54
  when "build"
55
+
49
56
  require_libs
50
57
  AppBuilder.new(args).build!
51
58
  when "-f"
@@ -61,10 +68,6 @@ module CappRuby
61
68
  puts "Usage: cappruby gen <app name>"
62
69
  end
63
70
 
64
- def self.gen(args)
65
- puts "gen.."
66
- end
67
-
68
71
  def self.require_libs
69
72
  libs = File.join(File.dirname(__FILE__), 'cappruby', '**', '*.rb')
70
73
  Dir.glob(libs).each { |f| require f }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cappruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Beynon
@@ -9,18 +9,28 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-30 00:00:00 +00:00
12
+ date: 2010-02-01 00:00:00 +00:00
13
13
  default_executable: cappruby
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: vienna
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.5
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: racc
17
27
  type: :development
18
28
  version_requirement:
19
29
  version_requirements: !ruby/object:Gem::Requirement
20
30
  requirements:
21
31
  - - ">="
22
32
  - !ruby/object:Gem::Version
23
- version: "0"
33
+ version: 1.4.6
24
34
  version:
25
35
  description: cappruby
26
36
  email: adam@adambeynon.com
@@ -39,7 +49,10 @@ files:
39
49
  - demos/simple_app/config/build.yml
40
50
  - demos/simple_app/lib/application.rb
41
51
  - demos/simple_app/lib/menu.rb
52
+ - demos/twitter_client/config/build.yml
53
+ - demos/twitter_client/lib/application.rb
42
54
  - framework/array.js
55
+ - framework/button.js
43
56
  - framework/cappruby.js
44
57
  - framework/class.js
45
58
  - framework/enumerator.js
@@ -52,12 +65,16 @@ files:
52
65
  - framework/object.js
53
66
  - framework/objj_additions.js
54
67
  - framework/proc.js
68
+ - framework/slider.js
55
69
  - framework/string.js
56
70
  - framework/variable.js
57
71
  - framework/vm.js
58
72
  - framework/window.js
73
+ - gen/app/config/build.yml
74
+ - gen/app/lib/application.rb
59
75
  - lib/cappruby.rb
60
76
  - lib/cappruby/app_builder.rb
77
+ - lib/cappruby/app_generator.rb
61
78
  - lib/cappruby/framework_builder.rb
62
79
  - lib/cappruby/ruby_builder.rb
63
80
  has_rdoc: true