jsduck 3.1.0 → 3.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -9
- data/Rakefile +31 -230
- data/jsduck.gemspec +2 -2
- data/lib/jsduck/accessors.rb +14 -6
- data/lib/jsduck/aggregator.rb +9 -4
- data/lib/jsduck/app.rb +1 -0
- data/lib/jsduck/app_data.rb +14 -7
- data/lib/jsduck/app_exporter.rb +3 -3
- data/lib/jsduck/class.rb +8 -5
- data/lib/jsduck/class_formatter.rb +1 -3
- data/lib/jsduck/css_parser.rb +1 -1
- data/lib/jsduck/doc_formatter.rb +140 -36
- data/lib/jsduck/doc_parser.rb +27 -44
- data/lib/jsduck/index_html.rb +0 -3
- data/lib/jsduck/inherit_doc.rb +20 -4
- data/lib/jsduck/js_parser.rb +1 -1
- data/lib/jsduck/lint.rb +15 -0
- data/lib/jsduck/logger.rb +9 -7
- data/lib/jsduck/merger.rb +18 -16
- data/lib/jsduck/meta_tag.rb +28 -5
- data/lib/jsduck/meta_tag_loader.rb +38 -21
- data/lib/jsduck/meta_tag_registry.rb +79 -0
- data/lib/jsduck/options.rb +69 -12
- data/lib/jsduck/renderer.rb +10 -38
- data/lib/jsduck/search_data.rb +53 -3
- data/lib/jsduck/tag/abstract.rb +14 -0
- data/lib/jsduck/{author_tag.rb → tag/author.rb} +2 -2
- data/lib/jsduck/tag/deprecated.rb +33 -0
- data/lib/jsduck/{doc_author_tag.rb → tag/docauthor.rb} +2 -2
- data/lib/jsduck/tag/markdown.rb +12 -0
- data/lib/jsduck/tag/preventable.rb +28 -0
- data/lib/jsduck/tag/protected.rb +14 -0
- data/lib/jsduck/tag/readonly.rb +14 -0
- data/lib/jsduck/tag/required.rb +21 -0
- data/lib/jsduck/tag/static.rb +14 -0
- data/lib/jsduck/tag/template.rb +23 -0
- data/opt/example.js +149 -0
- metadata +17 -9
- data/opt/extjs-welcome.html +0 -74
- data/opt/touch-iframe.html +0 -85
- data/opt/touch-welcome.html +0 -122
data/lib/jsduck/options.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
|
-
require 'jsduck/
|
2
|
+
require 'jsduck/meta_tag_registry'
|
3
3
|
require 'jsduck/logger'
|
4
4
|
|
5
5
|
module JsDuck
|
@@ -11,7 +11,6 @@ module JsDuck
|
|
11
11
|
attr_accessor :output_dir
|
12
12
|
attr_accessor :ignore_global
|
13
13
|
attr_accessor :external_classes
|
14
|
-
attr_accessor :meta_tags
|
15
14
|
|
16
15
|
# Customizing output
|
17
16
|
attr_accessor :title
|
@@ -70,10 +69,9 @@ module JsDuck
|
|
70
69
|
# Special anything-goes type
|
71
70
|
"Mixed",
|
72
71
|
]
|
73
|
-
@meta_tags = []
|
74
72
|
@meta_tag_paths = []
|
75
73
|
|
76
|
-
@version = "3.1
|
74
|
+
@version = "3.2.1"
|
77
75
|
|
78
76
|
# Customizing output
|
79
77
|
@title = "Sencha Docs - Ext JS"
|
@@ -107,6 +105,10 @@ module JsDuck
|
|
107
105
|
@local_storage_db = "docs"
|
108
106
|
@touch_examples_ui = false
|
109
107
|
@ext_namespaces = ["Ext"]
|
108
|
+
|
109
|
+
# enable all warnings except :link_auto
|
110
|
+
Logger.instance.set_warning(:all, true)
|
111
|
+
Logger.instance.set_warning(:link_auto, false)
|
110
112
|
end
|
111
113
|
|
112
114
|
# Make options object behave like hash.
|
@@ -120,11 +122,11 @@ module JsDuck
|
|
120
122
|
read_filenames(canonical(fname))
|
121
123
|
end
|
122
124
|
validate
|
123
|
-
|
125
|
+
MetaTagRegistry.instance.load([:builtins] + @meta_tag_paths)
|
124
126
|
end
|
125
127
|
|
126
128
|
def create_option_parser
|
127
|
-
|
129
|
+
optparser = OptionParser.new do | opts |
|
128
130
|
opts.banner = "Usage: jsduck [options] files/dirs...\n\n"
|
129
131
|
|
130
132
|
opts.on('-o', '--output=PATH',
|
@@ -157,7 +159,9 @@ module JsDuck
|
|
157
159
|
end
|
158
160
|
|
159
161
|
opts.on('--no-warnings',
|
160
|
-
"Turns off all warnings.
|
162
|
+
"Turns off all warnings.",
|
163
|
+
"(Deprecated, use --warnings=-all instead.)", " ") do
|
164
|
+
Logger.instance.warn(nil, "--no-warnings is deprecated. Use --warnings=-all instead.")
|
161
165
|
Logger.instance.set_warning(:all, false)
|
162
166
|
end
|
163
167
|
|
@@ -177,8 +181,8 @@ module JsDuck
|
|
177
181
|
|
178
182
|
opts.on('--footer=TEXT',
|
179
183
|
"Custom footer text for the documentation.",
|
180
|
-
"Defaults to: 'Generated with JSDuck.'", " ") do |text|
|
181
|
-
@footer = text
|
184
|
+
"Defaults to: 'Generated with JSDuck {VERSION}.'", " ") do |text|
|
185
|
+
@footer = text.gsub(/\{VERSION\}/, @version)
|
182
186
|
end
|
183
187
|
|
184
188
|
opts.on('--head-html=HTML', "HTML to append to the <head> section of index.html.", " ") do |html|
|
@@ -277,8 +281,10 @@ module JsDuck
|
|
277
281
|
|
278
282
|
opts.on('--warnings=+A,-B,+C', Array,
|
279
283
|
"Turns warnings selectively on/off.",
|
280
|
-
"
|
281
|
-
"
|
284
|
+
" ",
|
285
|
+
" +all - to turn on all warnings",
|
286
|
+
" ",
|
287
|
+
"By default these warnings are turned +on/-off:",
|
282
288
|
" ",
|
283
289
|
*Logger.instance.doc_warnings) do |warnings|
|
284
290
|
warnings.each do |op|
|
@@ -332,6 +338,17 @@ module JsDuck
|
|
332
338
|
@ext_namespaces = ns
|
333
339
|
end
|
334
340
|
|
341
|
+
opts.on('--config=PATH',
|
342
|
+
"Loads config options from JSON file.", " ") do |path|
|
343
|
+
path = canonical(path)
|
344
|
+
config = read_json_config(path)
|
345
|
+
# treat paths inside JSON config relative to the location of
|
346
|
+
# config file. When done, switch back to current working dir.
|
347
|
+
@working_dir = File.dirname(path)
|
348
|
+
optparser.parse!(config).each {|fname| read_filenames(canonical(fname)) }
|
349
|
+
@working_dir = nil
|
350
|
+
end
|
351
|
+
|
335
352
|
opts.on('-h', '--help[=full]',
|
336
353
|
"Short help or --help=full for all available options.", " ") do |v|
|
337
354
|
if v == 'full'
|
@@ -378,6 +395,31 @@ module JsDuck
|
|
378
395
|
exit
|
379
396
|
end
|
380
397
|
end
|
398
|
+
|
399
|
+
return optparser
|
400
|
+
end
|
401
|
+
|
402
|
+
# Reads JSON configuration from file and returns an array of
|
403
|
+
# config options that can be feeded into optparser.
|
404
|
+
def read_json_config(fname)
|
405
|
+
config = []
|
406
|
+
json = JsonDuck.read(fname)
|
407
|
+
json.each_pair do |key, value|
|
408
|
+
if key == "--"
|
409
|
+
# filenames
|
410
|
+
config += Array(value).map(&:to_s)
|
411
|
+
elsif value == true
|
412
|
+
# simple switch
|
413
|
+
config += [key.to_s]
|
414
|
+
else
|
415
|
+
# An option with value or with multiple values.
|
416
|
+
# In the latter case, add the option multiple times.
|
417
|
+
Array(value).each do |v|
|
418
|
+
config += [key.to_s, v.to_s]
|
419
|
+
end
|
420
|
+
end
|
421
|
+
end
|
422
|
+
config
|
381
423
|
end
|
382
424
|
|
383
425
|
# scans directory for .js files or simply adds file to input files list
|
@@ -385,6 +427,8 @@ module JsDuck
|
|
385
427
|
if File.exists?(fname)
|
386
428
|
if File.directory?(fname)
|
387
429
|
Dir[fname+"/**/*.{js,css,scss}"].each {|f| @input_files << f }
|
430
|
+
elsif fname =~ /\.jsb3$/
|
431
|
+
@input_files += extract_jsb_files(fname)
|
388
432
|
else
|
389
433
|
@input_files << fname
|
390
434
|
end
|
@@ -393,13 +437,26 @@ module JsDuck
|
|
393
437
|
end
|
394
438
|
end
|
395
439
|
|
440
|
+
# Extracts files of first build in jsb file
|
441
|
+
def extract_jsb_files(jsb_file)
|
442
|
+
json = JSON.parse(IO.read(jsb_file))
|
443
|
+
basedir = File.dirname(jsb_file)
|
444
|
+
|
445
|
+
return json["builds"][0]["packages"].map do |package_id|
|
446
|
+
package = json["packages"].find {|p| p["id"] == package_id }
|
447
|
+
(package ? package["files"] : []).map do |file|
|
448
|
+
File.expand_path(basedir + "/" + file["path"] + file["name"])
|
449
|
+
end
|
450
|
+
end.flatten
|
451
|
+
end
|
452
|
+
|
396
453
|
# Converts relative path to full path
|
397
454
|
#
|
398
455
|
# Especially important for running on Windows where C:\foo\bar
|
399
456
|
# pathnames are converted to C:/foo/bar which ruby can work on
|
400
457
|
# more easily.
|
401
458
|
def canonical(path)
|
402
|
-
File.expand_path(path)
|
459
|
+
File.expand_path(path, @working_dir)
|
403
460
|
end
|
404
461
|
|
405
462
|
# Runs checks on the options
|
data/lib/jsduck/renderer.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'jsduck/meta_tag_registry'
|
1
2
|
require 'cgi'
|
2
3
|
|
3
4
|
module JsDuck
|
@@ -5,12 +6,13 @@ module JsDuck
|
|
5
6
|
# Ruby-side implementation of class docs Renderer.
|
6
7
|
# Uses PhantomJS to run Docs.Renderer JavaScript.
|
7
8
|
class Renderer
|
8
|
-
# List of meta-tag implementations
|
9
|
-
attr_accessor :meta_tags
|
10
|
-
|
11
9
|
def render(cls)
|
12
10
|
@cls = cls
|
13
11
|
|
12
|
+
# Set doc-formatter context to this class
|
13
|
+
MetaTagRegistry.instance.formatter.class_context = @cls[:name]
|
14
|
+
MetaTagRegistry.instance.formatter.doc_context = @cls[:files][0]
|
15
|
+
|
14
16
|
return [
|
15
17
|
"<div>",
|
16
18
|
render_sidebar,
|
@@ -38,8 +40,8 @@ module JsDuck
|
|
38
40
|
def render_meta_data(meta_data)
|
39
41
|
return if meta_data.size == 0
|
40
42
|
|
41
|
-
|
42
|
-
contents = meta_data[tag.
|
43
|
+
MetaTagRegistry.instance.tags.map do |tag|
|
44
|
+
contents = meta_data[tag.key]
|
43
45
|
if contents
|
44
46
|
tag.to_html(contents)
|
45
47
|
else
|
@@ -221,20 +223,8 @@ module JsDuck
|
|
221
223
|
end
|
222
224
|
|
223
225
|
after = ""
|
224
|
-
|
225
|
-
after += "<strong class='
|
226
|
-
end
|
227
|
-
if m[:static]
|
228
|
-
after += "<strong class='static signature'>static</strong>"
|
229
|
-
end
|
230
|
-
if m[:deprecated]
|
231
|
-
after += "<strong class='deprecated signature'>deprecated</strong>"
|
232
|
-
end
|
233
|
-
if m[:required]
|
234
|
-
after += "<strong class='required signature'>required</strong>"
|
235
|
-
end
|
236
|
-
if m[:template]
|
237
|
-
after += "<strong class='template signature'>template</strong>"
|
226
|
+
MetaTagRegistry.instance.signatures.each do |s|
|
227
|
+
after += "<strong class='#{s[:key]} signature'>#{s[:long]}</strong>" if m[:meta][s[:key]]
|
238
228
|
end
|
239
229
|
|
240
230
|
uri = "#!/api/#{m[:owner]}-#{m[:id]}"
|
@@ -259,25 +249,7 @@ module JsDuck
|
|
259
249
|
doc << "<p>Defaults to: <code>" + CGI.escapeHTML(m[:default]) + "</code></p>"
|
260
250
|
end
|
261
251
|
|
262
|
-
|
263
|
-
v = m[:deprecated][:version] ? "since " + m[:deprecated][:version] : ""
|
264
|
-
doc << [
|
265
|
-
"<div class='signature-box deprecated'>",
|
266
|
-
"<p>This #{m[:tagname]} has been <strong>deprecated</strong> #{v}</p>",
|
267
|
-
m[:deprecated][:text],
|
268
|
-
"</div>",
|
269
|
-
]
|
270
|
-
end
|
271
|
-
|
272
|
-
if m[:template]
|
273
|
-
doc << [
|
274
|
-
"<div class='signature-box template'>",
|
275
|
-
"<p>This is a template method. A hook into the functionality of this class.",
|
276
|
-
"Feel free to override it in child classes.</p>",
|
277
|
-
"</div>",
|
278
|
-
]
|
279
|
-
end
|
280
|
-
|
252
|
+
MetaTagRegistry.instance.formatter.doc_context = m[:files][0]
|
281
253
|
doc << render_meta_data(m[:meta])
|
282
254
|
|
283
255
|
doc << render_params_and_return(m)
|
data/lib/jsduck/search_data.rb
CHANGED
@@ -10,6 +10,17 @@ module JsDuck
|
|
10
10
|
list = []
|
11
11
|
docs.each do |cls|
|
12
12
|
list << class_node(cls)
|
13
|
+
|
14
|
+
cls[:alternateClassNames].each do |name|
|
15
|
+
list << alt_node(name, cls)
|
16
|
+
end
|
17
|
+
|
18
|
+
cls[:aliases].each_pair do |key, items|
|
19
|
+
items.each do |name|
|
20
|
+
list << alias_node(key, name, cls)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
13
24
|
[:members, :statics].each do |group|
|
14
25
|
cls[group].each_key do |type|
|
15
26
|
cls.members(type, group).each do |m|
|
@@ -24,13 +35,39 @@ module JsDuck
|
|
24
35
|
list
|
25
36
|
end
|
26
37
|
|
38
|
+
# Creates structure representing one alias
|
39
|
+
def alias_node(key, name, cls)
|
40
|
+
return {
|
41
|
+
:cls => alias_display_name(key)+": "+name,
|
42
|
+
:member => name,
|
43
|
+
:type => :class,
|
44
|
+
:icon => :subclass,
|
45
|
+
:id => cls.full_name,
|
46
|
+
:sort => 0,
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
27
50
|
# Creates structure representing one class
|
28
51
|
def class_node(cls)
|
29
52
|
return {
|
30
53
|
:cls => cls.full_name,
|
31
54
|
:member => cls.short_name,
|
32
55
|
:type => :class,
|
33
|
-
:
|
56
|
+
:icon => :class,
|
57
|
+
:id => cls.full_name,
|
58
|
+
:sort => 1,
|
59
|
+
}
|
60
|
+
end
|
61
|
+
|
62
|
+
# Creates structure representing one alternate classname
|
63
|
+
def alt_node(name, cls)
|
64
|
+
return {
|
65
|
+
:cls => name,
|
66
|
+
:member => Class.short_name(name),
|
67
|
+
:type => :class,
|
68
|
+
:icon => :subclass,
|
69
|
+
:id => cls.full_name,
|
70
|
+
:sort => 2,
|
34
71
|
}
|
35
72
|
end
|
36
73
|
|
@@ -39,9 +76,22 @@ module JsDuck
|
|
39
76
|
return {
|
40
77
|
:cls => cls.full_name,
|
41
78
|
:member => member[:name],
|
42
|
-
:type => member
|
43
|
-
:
|
79
|
+
:type => :member,
|
80
|
+
:icon => member[:tagname],
|
81
|
+
:id => cls.full_name + "-" + member[:id],
|
82
|
+
:sort => 3,
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
# Some alias types are shown differently.
|
87
|
+
# e.g. instead of "widget:" we show "xtype:"
|
88
|
+
def alias_display_name(key)
|
89
|
+
titles = {
|
90
|
+
"widget" => "xtype",
|
91
|
+
"plugin" => "ptype",
|
92
|
+
"feature" => "ftype",
|
44
93
|
}
|
94
|
+
titles[key] || key
|
45
95
|
end
|
46
96
|
|
47
97
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "jsduck/meta_tag"
|
2
|
+
|
3
|
+
module JsDuck::Tag
|
4
|
+
# Implementation of @abstract tag
|
5
|
+
class Abstract < JsDuck::MetaTag
|
6
|
+
def initialize
|
7
|
+
@name = "abstract"
|
8
|
+
@key = :abstract
|
9
|
+
@signature = {:long => "abstract", :short => "ABS"}
|
10
|
+
@boolean = true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "jsduck/meta_tag"
|
2
|
+
|
3
|
+
module JsDuck::Tag
|
4
|
+
# Implementation of @deprecated tag
|
5
|
+
class Deprecated < JsDuck::MetaTag
|
6
|
+
def initialize
|
7
|
+
@name = "deprecated"
|
8
|
+
@key = :deprecated
|
9
|
+
@signature = {:long => "deprecated", :short => "DEP"}
|
10
|
+
@multiline = true
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_value(contents)
|
14
|
+
text = contents[0]
|
15
|
+
if text =~ /\A([0-9.]+)(.*)\Z/
|
16
|
+
{:version => $1, :text => $2.strip}
|
17
|
+
else
|
18
|
+
{:text => text || ""}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_html(depr)
|
23
|
+
v = depr[:version] ? "since " + depr[:version] : ""
|
24
|
+
<<-EOHTML
|
25
|
+
<div class='signature-box deprecated'>
|
26
|
+
<p>This member has been <strong>deprecated</strong> #{v}</p>
|
27
|
+
#{format(depr[:text])}
|
28
|
+
</div>
|
29
|
+
EOHTML
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "jsduck/meta_tag"
|
2
|
+
|
3
|
+
module JsDuck::Tag
|
4
|
+
# Implementation of @preventable tag
|
5
|
+
class Preventable < JsDuck::MetaTag
|
6
|
+
def initialize
|
7
|
+
@name = "preventable"
|
8
|
+
@key = :preventable
|
9
|
+
@signature = {:long => "preventable", :short => "PREV"}
|
10
|
+
end
|
11
|
+
|
12
|
+
# @preventable is optionally followed by some method name, but we
|
13
|
+
# don't document it.
|
14
|
+
def to_value(contents)
|
15
|
+
true
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_html(v)
|
19
|
+
<<-EOHTML
|
20
|
+
<div class='signature-box preventable'>
|
21
|
+
<p>This action following this event is <b>preventable</b>.
|
22
|
+
When any of the listeners returns false, the action is cancelled.</p>
|
23
|
+
</div>
|
24
|
+
EOHTML
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|