rubyosa19 0.5.4 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/rdoc-osa DELETED
@@ -1,232 +0,0 @@
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)