bean 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+
data/README ADDED
@@ -0,0 +1,4 @@
1
+ Bean
2
+ ====
3
+
4
+ Bean is a few simple extensions to the Cocoa framework class to make them more Rubyish.
data/bean.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("./lib")
3
+ require 'bean/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'bean'
7
+ s.version = Bean::VERSION
8
+
9
+ s.authors = ['dan sinclair']
10
+ s.email = ['dj2@everburning.com']
11
+
12
+ s.homepage = 'http://github.com/dj2/Bean.git'
13
+ s.summary = 'Cocoa Additions for MacRuby Applications'
14
+ s.description = s.summary
15
+
16
+ s.required_ruby_version = '>=1.9.2'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.require_paths = ['lib']
20
+ end
@@ -0,0 +1,16 @@
1
+ class NSNotificationCenter
2
+ def self.post(options)
3
+ NSNotificationCenter.defaultCenter.postNotificationName(options[:name],
4
+ object:options[:object],
5
+ userInfo:options[:info])
6
+ end
7
+
8
+ def self.observe(name, &blk)
9
+ @observers ||= []
10
+ @observers << Class.new do
11
+ define_method("call_#{name}") { |notice| blk.call(notice) }
12
+ end.new
13
+
14
+ NSNotificationCenter.defaultCenter.addObserver(@observers.last, selector:"call_#{name}:", name:name, object:nil)
15
+ end
16
+ end
@@ -0,0 +1,16 @@
1
+ class NSTableView
2
+ alias dataSource= setDataSource
3
+ alias reload reloadData
4
+
5
+ def on_double_click(&blk)
6
+ @on_double_action = blk
7
+ def self.performDoubleAction(sender); @on_double_action.call(sender, self.clickedColumn, self.clickedRow); end
8
+ setDoubleAction("performDoubleAction:")
9
+ end
10
+
11
+ def on_click(&blk)
12
+ @on_action = blk
13
+ def self.performAction(sender); @on_action.call(sender, self.clickedColumn, self.clickedRow); end
14
+ setAction("performAction:")
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ class NSTextField
2
+ alias to_s stringValue
3
+ alias to_f floatValue
4
+ alias to_i intValue
5
+ alias to_o objectValue
6
+ end
@@ -0,0 +1,8 @@
1
+ class NSToolbarItem
2
+ def on_click(&blk)
3
+ @on_action = blk
4
+ def self.performAction(sender); @on_action.call(sender); end
5
+ setAction("performAction:")
6
+ setTarget(self)
7
+ end
8
+ end
@@ -0,0 +1,42 @@
1
+ class NSURLConnection
2
+ def initWithRequest(req, &blk)
3
+ @error = nil
4
+ @response = nil
5
+
6
+ @on_error = nil
7
+ @on_success = blk
8
+ @data = NSMutableData.data
9
+
10
+ initWithRequest(req, delegate:self)
11
+ end
12
+
13
+ def connection(conn, didReceiveResponse:resp)
14
+ @data.setLength(0)
15
+ end
16
+
17
+ def connection(conn, didReceiveData:rcv)
18
+ @data.appendData(rcv)
19
+ end
20
+
21
+ def connection(conn, didFailWithError:error)
22
+ return unless @on_error
23
+ @on_error.call(error)
24
+ @error = error
25
+ end
26
+
27
+ def connectionDidFinishLoading(conn)
28
+ @response = NSString.alloc.initWithData(@data, encoding:NSUTF8StringEncoding)
29
+ @on_success.call(@response) if @on_success
30
+ @data = nil
31
+ end
32
+
33
+ def on_error(&blk)
34
+ @on_error = blk
35
+ @on_error.call(@error) if @error
36
+ end
37
+
38
+ def on_success(&blk)
39
+ @on_success = blk
40
+ @on_success.call(@response) if @response
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ class NSUserDefaults
2
+ def self.[]=(key,value)
3
+ standardUserDefaults[key] = value
4
+ end
5
+
6
+ def self.[](key)
7
+ standardUserDefaults[key]
8
+ end
9
+
10
+ def delete(key)
11
+ standardUserDefaults.delete(key)
12
+ end
13
+
14
+ def []=(key, value)
15
+ if value
16
+ setObject(value, forKey:key.to_s)
17
+ else
18
+ delete(key.to_s)
19
+ end
20
+ sync
21
+ end
22
+
23
+ def [](key)
24
+ objectForKey(key.to_s)
25
+ end
26
+
27
+ def delete(key)
28
+ removeObjectForKey(key)
29
+ sync
30
+ end
31
+
32
+ private
33
+
34
+ def sync
35
+ puts "Failed to synchronize" unless synchronize
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ class NSView
2
+ alias hidden? isHidden
3
+ end
@@ -0,0 +1,11 @@
1
+ class NSXMLNode
2
+ alias to_xml XMLString
3
+
4
+ def [](key)
5
+ childAtIndex(key)
6
+ end
7
+
8
+ def length
9
+ childCount
10
+ end
11
+ end
@@ -0,0 +1,21 @@
1
+ class TableDataSource
2
+ attr_reader :data
3
+
4
+ def initialize(data)
5
+ @data = data
6
+ end
7
+
8
+ def numberOfRowsInTableView(tableView)
9
+ data.length
10
+ end
11
+
12
+ def tableView(view, objectValueForTableColumn:column, row:i)
13
+ ident = column.identifier
14
+
15
+ if data[i].respond_to?(:[])
16
+ data[i][ident.intern]
17
+ elsif data[i].respond_to?(ident.to_sym)
18
+ data[i].send(ident.to_sym)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Bean
2
+ VERSION = '0.0.1'
3
+ end
data/lib/bean.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'bean/nsnotificationcenter_additions'
2
+ require 'bean/nstableview_additions'
3
+ require 'bean/nstextfield_additions'
4
+ require 'bean/nstoolbaritem_additions'
5
+ require 'bean/nsurl_connection_additions'
6
+ require 'bean/nsuserdefaults_additions'
7
+ require 'bean/nsview_additions'
8
+ require 'bean/nsxmlnode_additions'
9
+
10
+ require 'bean/table_data_source'
11
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bean
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - dan sinclair
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-25 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Cocoa Additions for MacRuby Applications
23
+ email:
24
+ - dj2@everburning.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - README
34
+ - bean.gemspec
35
+ - lib/bean.rb
36
+ - lib/bean/nsnotificationcenter_additions.rb
37
+ - lib/bean/nstableview_additions.rb
38
+ - lib/bean/nstextfield_additions.rb
39
+ - lib/bean/nstoolbaritem_additions.rb
40
+ - lib/bean/nsurl_connection_additions.rb
41
+ - lib/bean/nsuserdefaults_additions.rb
42
+ - lib/bean/nsview_additions.rb
43
+ - lib/bean/nsxmlnode_additions.rb
44
+ - lib/bean/table_data_source.rb
45
+ - lib/bean/version.rb
46
+ has_rdoc: true
47
+ homepage: http://github.com/dj2/Bean.git
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 55
61
+ segments:
62
+ - 1
63
+ - 9
64
+ - 2
65
+ version: 1.9.2
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ requirements: []
76
+
77
+ rubyforge_project:
78
+ rubygems_version: 1.3.7
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: Cocoa Additions for MacRuby Applications
82
+ test_files: []
83
+