FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
flashdevelop/External/Tools/AS2API/as2api.rb at master · SandersAlex/flashdevelop · GitHub
SandersAlex
flashdevelop
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
flashdevelop
/
External
/
Tools
/
AS2API
/
as2api.rb
Copy path
More file actions
More file actions
Latest commit
History
History
History
294 lines (251 loc) · 7.54 KB
Breadcrumbs
flashdevelop
/
External
/
Tools
/
AS2API
/
as2api.rb
Copy path
File metadata and controls
294 lines (251 loc) · 7.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
#!/usr/bin/ruby -w
require
'documenter'
require
'getoptlong'
require
'set'
require
'output/html/driver'
require
'output/html/diff'
Conf
=
Struct
.
new
(
:output_dir
,
:classpath
,
:oldrev_classpath
,
:package_filters
,
:title
,
:progress_listener
,
:input_encoding
,
:draw_diagrams
,
:dot_exe
,
:sources
,
:format_html
)
SourceFile
=
Struct
.
new
(
:prefix
,
:suffix
)
class
PackageFilter
def
initialize
(
package_spec
)
@package_spec
=
Regexp
.
new
(
"^"
+
package_spec
.
gsub
(
/
\.
/
,
"/"
)
+
"/[^/]+$"
)
end
def
matches?
(
source_file
)
@package_spec
=~
source_file
end
end
class
PackageGlobFilter
def
initialize
(
package_spec
)
@package_spec
=
Regexp
.
new
(
"^"
+
package_spec
.
gsub
(
/
\.
/
,
"/"
)
)
end
def
matches?
(
source_file
)
@package_spec
=~
source_file
end
end
# allows classes in the default (top-level) namespace
class
DefaultPackageFilter
def
matches?
(
source_file
)
source_file
=~
/^[^
\/
]+$/
end
end
class
VerboseProgressListener
<
NullProgressListener
def
parsing_sources
(
total_files
)
@total
=
total_files
$stderr
.
puts
(
"Parsing
#{
total_files
}
source files:"
)
yield
progress_bar
(
total_files
)
# ensure we see '100%'
puts
end
def
parse_source
(
file_number
,
file_name
)
progress_bar
(
file_number
)
end
def
generating_pages
(
total_pages
)
@total
=
total_pages
$stderr
.
puts
(
"Generating
#{
total_pages
}
HTML pages:"
)
yield
progress_bar
(
total_pages
)
# ensure we see '100%'
puts
end
def
generate_page
(
file_number
,
file_name
)
progress_bar
(
file_number
)
end
private
WIDTH
=
38
def
progress_bar
(
count
)
size
=
count
*
WIDTH
/
@total
$stderr
.
print
"[
#{
'='
*
size
}
#{
' '
*
(
WIDTH
-
size
)
}
]
#{
count
*
100
/
@total
}
%
\r
"
end
end
class
CLI
def
parse_opts
opts
=
GetoptLong
.
new
(
[
"--help"
,
"-h"
,
GetoptLong
::
NO_ARGUMENT
]
,
[
"--output-dir"
,
"-d"
,
GetoptLong
::
REQUIRED_ARGUMENT
]
,
[
"--classpath"
,
GetoptLong
::
REQUIRED_ARGUMENT
]
,
[
"--oldrev-classpath"
,
GetoptLong
::
REQUIRED_ARGUMENT
]
,
[
"--title"
,
GetoptLong
::
REQUIRED_ARGUMENT
]
,
[
"--progress"
,
GetoptLong
::
NO_ARGUMENT
]
,
[
"--encoding"
,
GetoptLong
::
REQUIRED_ARGUMENT
]
,
[
"--draw-diagrams"
,
GetoptLong
::
NO_ARGUMENT
]
,
[
"--dot-exe"
,
GetoptLong
::
REQUIRED_ARGUMENT
]
,
[
"--sources"
,
GetoptLong
::
NO_ARGUMENT
]
,
[
"--format-html"
,
GetoptLong
::
NO_ARGUMENT
]
)
conf
=
Conf
.
new
conf
.
classpath
=
[
]
conf
.
oldrev_classpath
=
[
]
conf
.
package_filters
=
[
]
conf
.
draw_diagrams
=
false
conf
.
dot_exe
=
"dot"
# i.e. assume 'dot' is in our PATH
opts
.
each
do
|
opt
,
arg
|
case
opt
when
"--output-dir"
conf
.
output_dir
=
File
.
expand_path
(
arg
)
when
"--classpath"
conf
.
classpath
.
concat
(
arg
.
split
(
File
::
PATH_SEPARATOR
)
)
when
"--oldrev-classpath"
conf
.
oldrev_classpath
.
concat
(
arg
.
split
(
File
::
PATH_SEPARATOR
)
)
when
"--title"
conf
.
title
=
arg
when
"--help"
usage
exit
(
0
)
when
"--progress"
conf
.
progress_listener
=
VerboseProgressListener
.
new
when
"--encoding"
conf
.
input_encoding
=
arg
when
"--draw-diagrams"
conf
.
draw_diagrams
=
true
when
"--dot-exe"
conf
.
dot_exe
=
arg
when
"--sources"
conf
.
sources
=
true
when
"--format-html"
conf
.
format_html
=
true
end
end
if
ARGV
.
empty?
usage
error
(
"No packages specified"
)
end
ARGV
.
each
do
|
package_spec
|
conf
.
package_filters
<<
to_filter
(
package_spec
)
end
conf
.
progress_listener
=
NullProgressListener
.
new
if
conf
.
progress_listener
.
nil?
conf
.
classpath
<<
"."
if
conf
.
classpath
.
empty?
conf
.
output_dir
=
"apidoc"
if
conf
.
output_dir
.
nil?
conf
end
def
to_filter
(
package_spec
)
case
package_spec
when
/
\.
\*
$/
PackageGlobFilter
.
new
(
$`
)
when
/
\(
default
\)
/i
DefaultPackageFilter
.
new
else
PackageFilter
.
new
(
package_spec
)
end
end
def
process_file?
(
name
)
@conf
.
package_filters
.
each
do
|
filter
|
return
true
if
filter
.
matches?
(
name
)
end
false
end
def
find_sources
(
classpath
)
result
=
[
]
ignored_packages
=
Set
.
new
classpath
.
each
do
|
path
|
found_sources
=
false
each_source
(
File
.
expand_path
(
path
)
)
do
|
source
|
if
process_file?
(
source
)
result
<<
SourceFile
.
new
(
path
,
source
)
else
dirname
=
File
.
dirname
(
source
)
if
ignored_packages
.
add?
(
dirname
)
warn
(
"package
#{
dirname
.
gsub
(
/
\/
/
,
'.'
)
.
inspect
}
will not be documented"
)
end
end
found_sources
=
true
end
unless
found_sources
warn
(
"
#{
path
.
inspect
}
contains no ActionScript files"
)
end
end
result
end
def
parse_file
(
file
,
type_agregator
)
File
.
open
(
File
.
join
(
file
.
prefix
,
file
.
suffix
)
)
do
|
io
|
begin
is_utf8
=
detect_bom?
(
io
)
type
=
simple_parse
(
io
,
file
.
suffix
)
type
.
input_file
=
file
type
.
source_utf8
=
is_utf8
type_agregator
.
add_type
(
type
)
rescue
=>
e
$stderr
.
puts
"
#{
file
.
suffix
}
:
#{
e
.
message
}
\n
#{
e
.
backtrace
.
join
(
"
\n
"
)
}
"
end
end
end
def
parse_all
(
files
,
classpath
)
type_agregator
=
GlobalTypeAggregator
.
new
(
classpath
)
@conf
.
progress_listener
.
parsing_sources
(
files
.
length
)
do
files
.
each_with_index
do
|
file
,
index
|
@conf
.
progress_listener
.
parse_source
(
index
,
file
)
parse_file
(
file
,
type_agregator
)
end
end
type_agregator
end
def
main
@conf
=
parse_opts
files
=
find_sources
(
@conf
.
classpath
)
error
(
"No source files matching specified packages"
)
if
files
.
empty?
type_agregator
=
parse_all
(
files
,
@conf
.
classpath
)
type_agregator
.
resolve_types
document_types
(
@conf
,
type_agregator
)
unless
@conf
.
oldrev_classpath
.
empty?
old_files
=
find_sources
(
@conf
.
oldrev_classpath
)
error
(
"No source files matching specified packages in oldrev-classpath"
)
if
old_files
.
empty?
old_type_agregator
=
parse_all
(
old_files
,
@conf
.
oldrev_classpath
)
old_type_agregator
.
resolve_types
diff
=
APIDiff
.
new
api_changes
=
diff
.
diff
(
old_type_agregator
,
type_agregator
)
generate_diffs
(
@conf
,
api_changes
)
end
end
def
usage
puts
<<-END
Usage:
#{
$0
}
[options] <package spec> ...
Each package spec can be given as:
com.example.pkg
Document types in the package 'com.example.pkg'.
com.example.pkg.*
Document types in the package 'com.example.pkg', and any other packages
with the same prefix (e.g. 'com.example.pkg.utils.extra' types too).
Where options include:
--classpath <path>
A list of paths, delimited by '
#{
File
::
PATH_SEPARATOR
}
'. Each path will
be searched for packages matching the given <package spec> list. If
no classpath is specified, only the current directory is searched.
--output-dir <path>
The directory into which generated HTML files will be placed (the
directory will be created, if required. If no output directory is
specified the default 'apidocs' is used.
--progress
Print feedback showing how far tasks have progressed
--title <text>
Put the given text into the titles of generated HTML pages
--encoding <name>
The encoding of the source files to be parsed.
--draw-diagrams
Causes class/interface inheritance diagrams to be generated for each
package (requires that you have http://www.graphviz.org/).
--dot-exe <filename>
Specify the location of the 'dot' tool from Graphviz, if it is not
available via the standard PATH.
--sources
Generate an HTML page for the source code of each input file
END
end
def
error
(
msg
)
$stderr
.
puts
(
"error:
#{
msg
}
"
)
exit
(
-
1
)
end
def
warn
(
msg
)
$stderr
.
puts
(
"warning:
#{
msg
}
"
)
end
end
CLI
.
new
.
main
(
)
# vim:shiftwidth=2:softtabstop=2
Back
|
FazBrowse Home
|
New Git URL