rubyosa19 0.5.0 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1,16 @@
1
+ Maintainer & Author:
2
+ Laurent Sansonetti <lsansonetti@apple.com>
3
+
4
+ Contributors:
5
+ Aaron Patterson <aaron.patterson@gmail.com>
6
+ Carlos Villela <carlos.villela@gmail.com>
7
+ James MacAulay <jmacaulay@gmail.com>
8
+ Justin Palmer <encytemedia@gmail.com>
9
+ Michael Pruett <michael@68k.org>
10
+ Michail Pishchagin <mblsha@gmail.com>
11
+ Mike Naberezny <mike@maintainable.com>
12
+ Sebastian Delmont <sd@notso.net>
13
+ Stefan Saasen <s@juretta.com>
14
+ Terry Donoghue <donoghue@apple.com>
15
+ Vincent Isambart <vincent.isambart@gmail.com>
16
+ Wes Rogers <wesrog@gmail.com>
data/COPYRIGHT ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2006-2007, Apple Inc. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+ 3. Neither the name of Apple Inc. ("Apple") nor the names of
12
+ its contributors may be used to endorse or promote products derived
13
+ from this software without specific prior written permission.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
16
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
+ ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
19
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24
+ IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25
+ POSSIBILITY OF SUCH DAMAGE.
data/README.markdown ADDED
@@ -0,0 +1,61 @@
1
+ Introduction
2
+ ============
3
+
4
+ RubyOSA is a bridge that connects Ruby to the Apple Event Manager
5
+ infrastructure.
6
+
7
+ It automatically populates the API (classes, methods, constants) according
8
+ to the target application's scriptable definition.
9
+
10
+ RubyOSA is an alternative to RubyAEOSA, and meant to replace it.
11
+
12
+ RubyOSA is licensied under a BSD license, see the COPYRIGHT file for more
13
+ information.
14
+
15
+ More information on the [project home page](http://rubyosa.rubyforge.org).
16
+
17
+ Requirements
18
+ ============
19
+
20
+ * Mac OS X 10.4.X or greater
21
+ * ruby 1.8.X or greater
22
+ * libxml-ruby 0.3.8 or greater
23
+
24
+ Install
25
+ =======
26
+ The plain old way:
27
+
28
+ $ ruby extconf.rb
29
+ $ make
30
+ $ sudo make install
31
+ $ sudo make install-extras
32
+
33
+ `make install` will only install the core of the bridge, while
34
+ `make install-extras` will install some additional tools such as the rdoc-osa
35
+ utility.
36
+
37
+ Otherwise, if you are reading GitHub, use the gem:
38
+
39
+ sudo gem install sstephenson-rubyosa
40
+
41
+ or
42
+
43
+ sudo gem install pbosetti-rubyosa
44
+
45
+ Support
46
+ =======
47
+
48
+ A tutorial is available online at [http://rubyosa.rubyforge.org/tutorial.html](http://rubyosa.rubyforge.org/tutorial.html).
49
+
50
+ Sample code is available in the `sample' sub-directory.
51
+
52
+ The rdoc-osa tool can be used to generate API reference documentation
53
+ for the given application. See its --help flag for more information
54
+ about how to use it.
55
+
56
+ Feel free to send feedback to rubyosa-discuss@rubyforge.org.
57
+
58
+ You can also file bugs, patches and feature requests to [the tracker](http://rubyforge.org/tracker/?group_id=1845.)
59
+
60
+ When reporting a bug, please set the AEDebugSends and AEDebugReceives
61
+ environment variables to 1 and attach the logs.
data/bin/rdoc-osa ADDED
@@ -0,0 +1,232 @@
1
+ #!/usr/bin/env ruby
2
+ # RDoc frontend for RubyOSA. Generate API reference documentation for the
3
+ # given application, based on the descriptions in the sdef(5).
4
+ #
5
+ # Copyright (c) 2006-2007, Apple Inc. All rights reserved.
6
+ #
7
+ # Redistribution and use in source and binary forms, with or without
8
+ # modification, are permitted provided that the following conditions
9
+ # are met:
10
+ # 1. Redistributions of source code must retain the above copyright
11
+ # notice, this list of conditions and the following disclaimer.
12
+ # 2. Redistributions in binary form must reproduce the above copyright
13
+ # notice, this list of conditions and the following disclaimer in the
14
+ # documentation and/or other materials provided with the distribution.
15
+ # 3. Neither the name of Apple Inc. ("Apple") nor the names of
16
+ # its contributors may be used to endorse or promote products derived
17
+ # from this software without specific prior written permission.
18
+ #
19
+ # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND
20
+ # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22
+ # ARE DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR
23
+ # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25
+ # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
+ # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
+ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
28
+ # IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
+ # POSSIBILITY OF SUCH DAMAGE.
30
+
31
+ require 'tmpdir'
32
+ require 'rbconfig'
33
+ require 'rbosa'
34
+
35
+ def usage
36
+ STDERR.puts <<-EOS
37
+ Usage: #{$0} [--addition] [--name | --path | --bundle_id | --signature] <criterion> [rdoc-options...]
38
+ Examples:
39
+ # Generate HTML documentation for iTunes:
40
+ #{$0} --name iTunes
41
+ # Generate RI documentation for iTunes:
42
+ #{$0} --name iTunes --ri
43
+ # Generate HTML documentation for the StandardAdditions scriptable addition:
44
+ #{$0} --addition --name StandardAdditions
45
+ See rdoc --help for additional options.
46
+ EOS
47
+ exit 1
48
+ end
49
+
50
+ def unique_tmp_path(base, extension='', dir=Dir.tmpdir)
51
+ i = 0
52
+ loop do
53
+ p = File.join(dir, "#{base}-#{i}-#{Process.pid}" + extension)
54
+ return p unless File.exists?(p)
55
+ i += 1
56
+ end
57
+ end
58
+
59
+ usage unless ARGV.length >= 2
60
+ addition = key = criterion = nil
61
+ while arg = ARGV.shift
62
+ case arg
63
+ when '--addition'
64
+ addition = true
65
+ when '--name', '--path', '--bundle_id', '--signature'
66
+ if key
67
+ $stderr.puts "You cannot use --name, --path, --bundle_id or --signature more than once."
68
+ exit 1
69
+ end
70
+ key = arg[2..-1].intern
71
+ criterion = ARGV.shift
72
+ usage if criterion.nil?
73
+ else
74
+ if key and criterion
75
+ ARGV.unshift(arg)
76
+ break
77
+ end
78
+ usage
79
+ end
80
+ end
81
+
82
+ DOC_NOT_AVAILABLE = 'Documentation not available.'
83
+
84
+ app = app_name = nil
85
+
86
+ if addition
87
+ app_name = criterion if key == :name
88
+ mod = Module.new
89
+ OSA.const_set('TheApplication', mod)
90
+ klass = Class.new(OSA::Element)
91
+ mod.const_set('Application', klass)
92
+ klass.class_eval do
93
+ include OSA::EventDispatcher
94
+ METHODS_DESCRIPTION = []
95
+ DESCRIPTION = 'The application class.'
96
+ end
97
+ app = klass.new.merge(key => criterion)
98
+ else
99
+ app = OSA.app(key => criterion)
100
+ app_name = if app.respond_to?(:name)
101
+ app.name
102
+ else
103
+ if key != :name
104
+ STDERR.puts "Can't guess the application name, because the application doesn't have a #name method. Please use `--name' instead."
105
+ exit 1
106
+ else
107
+ criterion
108
+ end
109
+ end
110
+ end
111
+
112
+ mod = OSA.const_get(app.class.name.scan(/^OSA::(.+)::Application$/).to_s)
113
+ fake_ruby_src = mod.constants.map do |const_name|
114
+ obj = mod.const_get(const_name)
115
+ case obj
116
+ when Class
117
+ # Class.
118
+ methods_desc = obj.const_get('METHODS_DESCRIPTION').map do |method|
119
+ args_doc, args_def, args_def_opt = '', '', ''
120
+ if method.args and !method.args.empty?
121
+ args_doc_ary, args_def_ary, args_def_opt_ary = [], [], []
122
+ method.args.each do |x|
123
+ arg = x.name
124
+ desc = x.description
125
+ desc = DOC_NOT_AVAILABLE if desc.empty?
126
+ args_doc_ary << " # #{arg}::\n # #{desc}" + (x.optional? ? ' Optional. Can be passed as a Hash key/value.' : '')
127
+ if x.optional?
128
+ args_def_ary << x.name + '=nil'
129
+ args_def_opt_ary << ':' + x.name + ' => nil'
130
+ else
131
+ args_def_ary << x.name
132
+ args_def_opt_ary << x.name
133
+ end
134
+ end
135
+ args_doc = args_doc_ary.join("\n")
136
+ args_def = '(' + args_def_ary.join(', ') + ')'
137
+ args_def_opt = '(' + args_def_opt_ary.join(', ') + ')'
138
+ end
139
+ if method.result
140
+ args_doc << "\n" unless args_doc.empty?
141
+ desc = method.result.description
142
+ desc = DOC_NOT_AVAILABLE if desc.empty?
143
+ args_doc << " # Returns::\n # #{desc}\n"
144
+ end
145
+ <<EOS
146
+ # call-seq:
147
+ # #{method.name + args_def}
148
+ # #{args_def_opt != args_def ? method.name + args_def_opt : ''}
149
+ #
150
+ # #{method.description}
151
+ #{args_doc}
152
+ def #{method.name}#{args_def}; end
153
+ EOS
154
+ end
155
+ <<EOS
156
+ # #{(obj.const_get('DESCRIPTION') || 'n/a')}
157
+ class #{obj.name} < #{obj.superclass}
158
+ #{methods_desc.join.rstrip}
159
+ end
160
+
161
+ EOS
162
+ when Module
163
+ # Enumeration group.
164
+ next unless obj.const_defined?(:DESCRIPTION)
165
+ enums_desc = obj.const_get(:DESCRIPTION).map do |item|
166
+ <<EOS
167
+ # #{item.description}
168
+ #{item.name} = '#{obj.const_get(item.name).code}'
169
+ EOS
170
+ end
171
+ <<EOS
172
+ module #{mod.name}::#{const_name}
173
+ #{enums_desc}
174
+ end
175
+
176
+ EOS
177
+ end
178
+ end.
179
+ join
180
+
181
+ header = if addition
182
+ <<EOS
183
+ # This documentation describes the RubyOSA API for the #{criterion} scriptable addition. It has been automatically generated.
184
+ #
185
+ # In order to use this API you have to merge the scriptable addition into an application object. For instance:
186
+ #
187
+ # OSA.app('iTunes').merge(#{app_name ? "'#{app_name}'" : ":#{key} => '#{criterion}'"})
188
+ #
189
+ # The module OSA::TheApplication is fake, everything inside will be defined in the module of the application you are controlling (for iTunes, in OSA::ITunes).
190
+ EOS
191
+ else
192
+ <<EOS
193
+ # This documentation describes the RubyOSA API for the #{app_name} application. It has been automatically generated.
194
+ #
195
+ # The main class is #{mod.name}::Application, of which an instance is created likewise:
196
+ #
197
+ # OSA.app('#{app_name}')
198
+ EOS
199
+ end
200
+
201
+ header << <<EOS
202
+ #
203
+ # For more information about RubyOSA, please visit the project homepage: http://rubyosa.rubyforge.org.
204
+ module OSA; end
205
+ # The #{app_name} module.
206
+ module #{mod.name}; end
207
+ EOS
208
+
209
+ fake_ruby_src = header << fake_ruby_src
210
+
211
+ rdoc_flags = ''
212
+ datadir = if Config.respond_to?(:datadir)
213
+ Config.datadir('rubyosa')
214
+ else
215
+ File.join(Config::CONFIG['datadir'], 'rubyosa')
216
+ end
217
+ template = File.join(datadir, 'rdoc_html.rb')
218
+ if File.exists?(template)
219
+ rdoc_flags << " --template '#{template}' "
220
+ end
221
+ rdoc_flags << " --title '#{app_name} RubyOSA API' "
222
+ rdoc_flags << ' --main OSA '
223
+ rdoc_flags << ARGV.join(' ')
224
+
225
+ path = unique_tmp_path(app_name, '.rb')
226
+ File.open(path, 'w') { |io| io.puts fake_ruby_src }
227
+ line = "rdoc #{rdoc_flags} \"#{path}\""
228
+ unless system(line)
229
+ STDERR.puts "Error when executing `#{line}' : #{$?}"
230
+ exit 1
231
+ end
232
+ File.unlink(path)