jsduck 4.10.4 → 5.0.0.beta01
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/README.md +32 -6
- data/Rakefile +10 -18
- data/bin/compare +5 -5
- data/bin/jsduck +2 -3
- data/jsduck.gemspec +3 -4
- data/lib/jsduck/aggregator.rb +21 -80
- data/lib/jsduck/app.rb +7 -14
- data/lib/jsduck/app_data.rb +4 -5
- data/lib/jsduck/assets.rb +4 -7
- data/lib/jsduck/base_type.rb +53 -0
- data/lib/jsduck/batch_parser.rb +8 -87
- data/lib/jsduck/batch_processor.rb +77 -0
- data/lib/jsduck/categories/auto.rb +83 -0
- data/lib/jsduck/categories/class_name.rb +63 -0
- data/lib/jsduck/categories/factory.rb +113 -0
- data/lib/jsduck/categories/file.rb +75 -0
- data/lib/jsduck/class.rb +3 -9
- data/lib/jsduck/class_doc_expander.rb +1 -1
- data/lib/jsduck/css/lexer.rb +203 -0
- data/lib/jsduck/css/parser.rb +121 -0
- data/lib/jsduck/doc/comment.rb +40 -0
- data/lib/jsduck/doc/map.rb +23 -0
- data/lib/jsduck/doc/parser.rb +128 -0
- data/lib/jsduck/doc/processor.rb +52 -0
- data/lib/jsduck/doc/scanner.rb +76 -0
- data/lib/jsduck/doc/standard_tag_parser.rb +154 -0
- data/lib/jsduck/doc/subproperties.rb +64 -0
- data/lib/jsduck/docs_code_comparer.rb +31 -0
- data/lib/jsduck/export_writer.rb +2 -2
- data/lib/jsduck/exporter/app.rb +16 -4
- data/lib/jsduck/exporter/full.rb +2 -2
- data/lib/jsduck/format/batch.rb +58 -0
- data/lib/jsduck/format/class.rb +62 -0
- data/lib/jsduck/format/doc.rb +172 -0
- data/lib/jsduck/format/html_stack.rb +109 -0
- data/lib/jsduck/format/shortener.rb +55 -0
- data/lib/jsduck/format/subproperties.rb +64 -0
- data/lib/jsduck/guides.rb +32 -14
- data/lib/jsduck/index_html.rb +3 -1
- data/lib/jsduck/inline/auto_link.rb +2 -2
- data/lib/jsduck/inline/link.rb +4 -3
- data/lib/jsduck/inline/link_renderer.rb +2 -2
- data/lib/jsduck/inline/video.rb +8 -2
- data/lib/jsduck/js/ast.rb +361 -0
- data/lib/jsduck/js/esprima.rb +39 -0
- data/lib/jsduck/{esprima → js/esprima}/esprima.js +0 -0
- data/lib/jsduck/js/evaluator.rb +70 -0
- data/lib/jsduck/js/ext_patterns.rb +70 -0
- data/lib/jsduck/js/function.rb +206 -0
- data/lib/jsduck/js/node.rb +194 -0
- data/lib/jsduck/js/node_array.rb +36 -0
- data/lib/jsduck/js/parser.rb +223 -0
- data/lib/jsduck/js/serializer.rb +263 -0
- data/lib/jsduck/js/utils.rb +21 -0
- data/lib/jsduck/logger.rb +3 -13
- data/lib/jsduck/members_index.rb +3 -4
- data/lib/jsduck/merger.rb +25 -145
- data/lib/jsduck/options.rb +29 -132
- data/lib/jsduck/parser.rb +76 -0
- data/lib/jsduck/process/accessors.rb +133 -0
- data/lib/jsduck/process/circular_deps.rb +58 -0
- data/lib/jsduck/process/enums.rb +91 -0
- data/lib/jsduck/process/ext4_events.rb +43 -0
- data/lib/jsduck/process/global_members.rb +36 -0
- data/lib/jsduck/process/ignored_classes.rb +16 -0
- data/lib/jsduck/process/importer.rb +58 -0
- data/lib/jsduck/process/inherit_doc.rb +197 -0
- data/lib/jsduck/process/lint.rb +135 -0
- data/lib/jsduck/process/overrides.rb +99 -0
- data/lib/jsduck/process/return_values.rb +72 -0
- data/lib/jsduck/process/versions.rb +102 -0
- data/lib/jsduck/relations.rb +5 -0
- data/lib/jsduck/render/class.rb +144 -0
- data/lib/jsduck/render/sidebar.rb +97 -0
- data/lib/jsduck/render/signature.rb +94 -0
- data/lib/jsduck/render/subproperties.rb +99 -0
- data/lib/jsduck/render/tags.rb +38 -0
- data/lib/jsduck/search_data.rb +19 -13
- data/lib/jsduck/source/file.rb +8 -17
- data/lib/jsduck/tag/abstract.rb +4 -7
- data/lib/jsduck/tag/accessor.rb +10 -0
- data/lib/jsduck/tag/alias.rb +61 -0
- data/lib/jsduck/tag/alternate_class_names.rb +17 -0
- data/lib/jsduck/tag/aside.rb +28 -31
- data/lib/jsduck/tag/author.rb +9 -5
- data/lib/jsduck/tag/boolean_tag.rb +24 -0
- data/lib/jsduck/tag/cfg.rb +45 -0
- data/lib/jsduck/tag/chainable.rb +5 -7
- data/lib/jsduck/tag/class.rb +28 -0
- data/lib/jsduck/tag/class_list_tag.rb +40 -0
- data/lib/jsduck/tag/constructor.rb +24 -0
- data/lib/jsduck/tag/css_mixin.rb +17 -0
- data/lib/jsduck/tag/css_var.rb +29 -0
- data/lib/jsduck/tag/default.rb +31 -0
- data/lib/jsduck/tag/deprecated.rb +13 -27
- data/lib/jsduck/tag/deprecated_tag.rb +58 -0
- data/lib/jsduck/tag/doc.rb +32 -0
- data/lib/jsduck/tag/docauthor.rb +4 -5
- data/lib/jsduck/tag/enum.rb +70 -0
- data/lib/jsduck/tag/event.rb +28 -0
- data/lib/jsduck/tag/evented.rb +10 -0
- data/lib/jsduck/tag/extends.rb +45 -0
- data/lib/jsduck/tag/ftype.rb +18 -0
- data/lib/jsduck/tag/hide.rb +4 -11
- data/lib/jsduck/tag/ignore.rb +6 -7
- data/lib/jsduck/tag/inheritable.rb +10 -0
- data/lib/jsduck/tag/inheritdoc.rb +48 -0
- data/lib/jsduck/tag/markdown.rb +8 -6
- data/lib/jsduck/tag/member.rb +24 -0
- data/lib/jsduck/tag/method.rb +35 -0
- data/lib/jsduck/tag/mixins.rb +26 -0
- data/lib/jsduck/tag/name.rb +36 -0
- data/lib/jsduck/tag/new.rb +13 -27
- data/lib/jsduck/tag/override.rb +37 -0
- data/lib/jsduck/tag/overrides.rb +29 -0
- data/lib/jsduck/tag/param.rb +87 -0
- data/lib/jsduck/tag/preventable.rb +19 -10
- data/lib/jsduck/tag/private.rb +28 -13
- data/lib/jsduck/tag/property.rb +39 -0
- data/lib/jsduck/tag/protected.rb +5 -7
- data/lib/jsduck/tag/ptype.rb +18 -0
- data/lib/jsduck/tag/readonly.rb +4 -7
- data/lib/jsduck/tag/removed.rb +21 -29
- data/lib/jsduck/tag/required.rb +11 -9
- data/lib/jsduck/tag/requires.rb +12 -0
- data/lib/jsduck/tag/return.rb +47 -0
- data/lib/jsduck/tag/since.rb +19 -11
- data/lib/jsduck/tag/singleton.rb +15 -0
- data/lib/jsduck/tag/static.rb +5 -7
- data/lib/jsduck/tag/subproperties.rb +23 -0
- data/lib/jsduck/tag/tag.rb +208 -0
- data/lib/jsduck/tag/template.rb +14 -9
- data/lib/jsduck/tag/throws.rb +38 -0
- data/lib/jsduck/tag/type.rb +48 -0
- data/lib/jsduck/tag/uses.rb +12 -0
- data/lib/jsduck/tag/xtype.rb +30 -0
- data/lib/jsduck/tag_loader.rb +39 -0
- data/lib/jsduck/tag_registry.rb +189 -0
- data/lib/jsduck/type_parser.rb +3 -3
- data/lib/jsduck/web_writer.rb +2 -2
- data/lib/jsduck/welcome.rb +1 -1
- metadata +578 -538
- data/lib/jsduck/accessors.rb +0 -136
- data/lib/jsduck/ast.rb +0 -524
- data/lib/jsduck/auto_categories.rb +0 -80
- data/lib/jsduck/batch_formatter.rb +0 -60
- data/lib/jsduck/categories.rb +0 -73
- data/lib/jsduck/categories_class_name.rb +0 -37
- data/lib/jsduck/circular_deps.rb +0 -56
- data/lib/jsduck/class_formatter.rb +0 -102
- data/lib/jsduck/columns.rb +0 -56
- data/lib/jsduck/css_lexer.rb +0 -201
- data/lib/jsduck/css_parser.rb +0 -119
- data/lib/jsduck/doc_ast.rb +0 -319
- data/lib/jsduck/doc_formatter.rb +0 -142
- data/lib/jsduck/doc_parser.rb +0 -611
- data/lib/jsduck/doc_type.rb +0 -59
- data/lib/jsduck/enum.rb +0 -73
- data/lib/jsduck/esprima.rb +0 -51
- data/lib/jsduck/evaluator.rb +0 -69
- data/lib/jsduck/ext_patterns.rb +0 -58
- data/lib/jsduck/file_categories.rb +0 -76
- data/lib/jsduck/function_ast.rb +0 -206
- data/lib/jsduck/guide_anchors.rb +0 -32
- data/lib/jsduck/guide_toc.rb +0 -49
- data/lib/jsduck/html_stack.rb +0 -105
- data/lib/jsduck/importer.rb +0 -121
- data/lib/jsduck/inherit_doc.rb +0 -193
- data/lib/jsduck/js_parser.rb +0 -221
- data/lib/jsduck/lint.rb +0 -133
- data/lib/jsduck/meta_tag.rb +0 -88
- data/lib/jsduck/meta_tag_loader.rb +0 -67
- data/lib/jsduck/meta_tag_registry.rb +0 -111
- data/lib/jsduck/meta_tag_renderer.rb +0 -34
- data/lib/jsduck/news.rb +0 -128
- data/lib/jsduck/override.rb +0 -87
- data/lib/jsduck/renderer.rb +0 -361
- data/lib/jsduck/return_values.rb +0 -72
- data/lib/jsduck/serializer.rb +0 -262
- data/lib/jsduck/shortener.rb +0 -58
- data/lib/jsduck/signature_renderer.rb +0 -91
- data/lib/jsduck/source/file_parser.rb +0 -72
@@ -1,111 +0,0 @@
|
|
1
|
-
require "jsduck/meta_tag_loader"
|
2
|
-
|
3
|
-
module JsDuck
|
4
|
-
|
5
|
-
# Access to meta-tags
|
6
|
-
class MetaTagRegistry
|
7
|
-
|
8
|
-
@@instance = nil
|
9
|
-
|
10
|
-
# Returns singleton instance of MetaTagRegistry.
|
11
|
-
# By default this will be auto-loaded with builtin tags.
|
12
|
-
def self.instance
|
13
|
-
if !@@instance
|
14
|
-
@@instance = MetaTagRegistry.new
|
15
|
-
@@instance.load([:builtins])
|
16
|
-
end
|
17
|
-
@@instance
|
18
|
-
end
|
19
|
-
|
20
|
-
# Allows injecting another MetaTagRegistry to be used as a global instance.
|
21
|
-
def self.instance=(instance)
|
22
|
-
@@instance = instance
|
23
|
-
end
|
24
|
-
|
25
|
-
|
26
|
-
def initialize
|
27
|
-
@tags = []
|
28
|
-
@map = {}
|
29
|
-
end
|
30
|
-
|
31
|
-
# Loads meta-tags from the given paths. See MetaTagLoader#load
|
32
|
-
# for details.
|
33
|
-
#
|
34
|
-
# This should only be called once. Calling it twice will override
|
35
|
-
# the previously loaded tags.
|
36
|
-
def load(paths)
|
37
|
-
loader = MetaTagLoader.new
|
38
|
-
paths.each {|p| loader.load(p) }
|
39
|
-
register(loader.meta_tags)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Registers MetaTag instances.
|
43
|
-
#
|
44
|
-
# NB! This is for testing purposes only, elsewhere always use #load.
|
45
|
-
def register(tags)
|
46
|
-
@tags = tags
|
47
|
-
register_keys
|
48
|
-
end
|
49
|
-
|
50
|
-
# Returns array of all available tag instances.
|
51
|
-
# When position provided, returns only tags in that position
|
52
|
-
def tags(position=nil)
|
53
|
-
return @tags unless position
|
54
|
-
|
55
|
-
unless @position_map
|
56
|
-
@position_map = {}
|
57
|
-
@tags.each do |t|
|
58
|
-
@position_map[t.position] = [] unless @position_map[t.position]
|
59
|
-
@position_map[t.position] << t
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
@position_map[position] || []
|
64
|
-
end
|
65
|
-
|
66
|
-
# Accesses tag by key or name
|
67
|
-
def [](name)
|
68
|
-
@map[name]
|
69
|
-
end
|
70
|
-
|
71
|
-
# Returns the formatter assigned to tags
|
72
|
-
def formatter
|
73
|
-
@formatter
|
74
|
-
end
|
75
|
-
|
76
|
-
# Sets the doc-formatter for all tags
|
77
|
-
def formatter=(doc_formatter)
|
78
|
-
@formatter = doc_formatter
|
79
|
-
@tags.each {|tag| tag.formatter = doc_formatter }
|
80
|
-
end
|
81
|
-
|
82
|
-
# Gives access to assets for all tags
|
83
|
-
def assets=(assets)
|
84
|
-
@tags.each {|tag| tag.assets = assets }
|
85
|
-
end
|
86
|
-
|
87
|
-
# Returns array of attributes to be shown in member signatures
|
88
|
-
# (and in order they should be shown in).
|
89
|
-
def signatures
|
90
|
-
if !@signatures
|
91
|
-
@signatures = @tags.find_all(&:signature).map do |tag|
|
92
|
-
s = tag.signature
|
93
|
-
s[:key] = tag.key
|
94
|
-
s
|
95
|
-
end
|
96
|
-
end
|
97
|
-
@signatures
|
98
|
-
end
|
99
|
-
|
100
|
-
private
|
101
|
-
|
102
|
-
def register_keys
|
103
|
-
@map = {}
|
104
|
-
@tags.each do |tag|
|
105
|
-
@map[tag.key] = tag
|
106
|
-
@map[tag.name] = tag
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require 'jsduck/meta_tag_registry'
|
2
|
-
|
3
|
-
module JsDuck
|
4
|
-
|
5
|
-
# Performs the rendering of meta tags.
|
6
|
-
class MetaTagRenderer
|
7
|
-
|
8
|
-
# Renders full meta tags of a particular section.
|
9
|
-
#
|
10
|
-
# Returns array of rendered HTML or nil if no meta data.
|
11
|
-
def self.render(meta_data, position)
|
12
|
-
return if meta_data.size == 0
|
13
|
-
|
14
|
-
MetaTagRegistry.instance.tags(position).map do |tag|
|
15
|
-
meta_data[tag.key]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Renders the meta-tag signatures for a class member.
|
20
|
-
# Returns a string.
|
21
|
-
def self.render_signature(member)
|
22
|
-
html = []
|
23
|
-
MetaTagRegistry.instance.signatures.each do |s|
|
24
|
-
if member[:meta][s[:key]]
|
25
|
-
title = s[:tooltip] ? "title='#{s[:tooltip]}'" : ""
|
26
|
-
html << "<strong class='#{s[:key]} signature' #{title}>#{s[:long]}</strong>"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
html.join
|
30
|
-
end
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
data/lib/jsduck/news.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'jsduck/util/null_object'
|
2
|
-
require 'jsduck/columns'
|
3
|
-
|
4
|
-
module JsDuck
|
5
|
-
|
6
|
-
class News
|
7
|
-
# Creates News object from relations data when --import option
|
8
|
-
# specified.
|
9
|
-
def self.create(relations, doc_formatter, opts)
|
10
|
-
if opts[:imports].length > 0
|
11
|
-
News.new(relations, doc_formatter)
|
12
|
-
else
|
13
|
-
Util::NullObject.new(:to_html => "")
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
# Generates list of new classes & members in this version.
|
18
|
-
def initialize(relations, doc_formatter)
|
19
|
-
@doc_formatter = doc_formatter
|
20
|
-
@columns = Columns.new(:members)
|
21
|
-
@new_items = filter_new_items(relations)
|
22
|
-
end
|
23
|
-
|
24
|
-
# Returns the HTML
|
25
|
-
def to_html(style="")
|
26
|
-
return [
|
27
|
-
"<div id='news-content' style='#{style}'>",
|
28
|
-
"<div class='section'>",
|
29
|
-
"<h1>New in this version</h1>",
|
30
|
-
render_columns(@new_items),
|
31
|
-
"<div style='clear:both'></div>",
|
32
|
-
"</div>",
|
33
|
-
"</div>",
|
34
|
-
].flatten.join("\n")
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def filter_new_items(relations)
|
40
|
-
classes = []
|
41
|
-
new_items = []
|
42
|
-
|
43
|
-
relations.each do |cls|
|
44
|
-
if !cls[:meta][:private]
|
45
|
-
if cls[:meta][:new]
|
46
|
-
classes << cls
|
47
|
-
else
|
48
|
-
members = filter_new_members(cls)
|
49
|
-
if members.length > 0
|
50
|
-
new_items << {:name => cls[:name], :members => members}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
new_items.sort! {|a, b| a[:name] <=> b[:name] }
|
57
|
-
|
58
|
-
# Place the new classes section at the beginning
|
59
|
-
if classes.length > 0
|
60
|
-
new_items.unshift({:name => "New classes", :members => classes})
|
61
|
-
end
|
62
|
-
|
63
|
-
new_items
|
64
|
-
end
|
65
|
-
|
66
|
-
def filter_new_members(cls)
|
67
|
-
members = []
|
68
|
-
cls.all_local_members.each do |m|
|
69
|
-
members << m if m[:meta][:new] && visible?(m)
|
70
|
-
end
|
71
|
-
members = discard_accessors(members)
|
72
|
-
members.sort! {|a, b| a[:name] <=> b[:name] }
|
73
|
-
end
|
74
|
-
|
75
|
-
def visible?(member)
|
76
|
-
!member[:meta][:private] && !member[:meta][:hide]
|
77
|
-
end
|
78
|
-
|
79
|
-
def discard_accessors(members)
|
80
|
-
accessors = {}
|
81
|
-
members.find_all {|m| m[:accessor] }.each do |cfg|
|
82
|
-
accessors["set" + upcase_first(cfg[:name])] = true
|
83
|
-
accessors["get" + upcase_first(cfg[:name])] = true
|
84
|
-
accessors[cfg[:name].downcase + "change"] = true if cfg[:evented]
|
85
|
-
end
|
86
|
-
|
87
|
-
members.reject {|m| accessors[m[:name]] }
|
88
|
-
end
|
89
|
-
|
90
|
-
def upcase_first(str)
|
91
|
-
str[0,1].upcase + str[1..-1]
|
92
|
-
end
|
93
|
-
|
94
|
-
def render_columns(new_items)
|
95
|
-
align = ["left-column", "middle-column", "right-column"]
|
96
|
-
i = -1
|
97
|
-
return @columns.split(new_items, 3).map do |col|
|
98
|
-
i += 1
|
99
|
-
[
|
100
|
-
"<div class='#{align[i]}'>",
|
101
|
-
render_col(col),
|
102
|
-
"</div>",
|
103
|
-
]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
def render_col(col)
|
108
|
-
return col.map do |item|
|
109
|
-
[
|
110
|
-
"<h3>#{item[:name]}</h3>",
|
111
|
-
"<ul class='links'>",
|
112
|
-
item[:members].map {|m| "<li>" + link(m) + "</li>" },
|
113
|
-
"</ul>",
|
114
|
-
]
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def link(m)
|
119
|
-
if m[:tagname] == :class
|
120
|
-
@doc_formatter.link(m[:name], nil, m[:name])
|
121
|
-
else
|
122
|
-
@doc_formatter.link(m[:owner], m[:name], m[:name], m[:tagname], m[:meta][:static])
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
data/lib/jsduck/override.rb
DELETED
@@ -1,87 +0,0 @@
|
|
1
|
-
module JsDuck
|
2
|
-
|
3
|
-
class Override
|
4
|
-
def initialize(classes_hash)
|
5
|
-
@classes_hash = classes_hash
|
6
|
-
end
|
7
|
-
|
8
|
-
# Applies all override classes to target classes
|
9
|
-
# Returns all the processed override classes.
|
10
|
-
def process_all!
|
11
|
-
overrides = []
|
12
|
-
|
13
|
-
@classes_hash.each_value do |cls|
|
14
|
-
if cls[:override]
|
15
|
-
process(cls)
|
16
|
-
overrides << cls
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
overrides
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# Applies override class to target class
|
26
|
-
def process(override)
|
27
|
-
target = @classes_hash[override[:override]]
|
28
|
-
unless target
|
29
|
-
ctx = override[:files][0]
|
30
|
-
return Logger.warn(:extend, "Class #{override[:override]} not found", ctx[:filename], ctx[:linenr])
|
31
|
-
end
|
32
|
-
|
33
|
-
# Combine comments of classes
|
34
|
-
if override[:doc].length > 0
|
35
|
-
add_doc(target, "**From override #{get_name(override)}:** " + override[:doc])
|
36
|
-
end
|
37
|
-
target[:files] += override[:files]
|
38
|
-
|
39
|
-
# Build lookup table of existing members
|
40
|
-
existing = {}
|
41
|
-
each_member(target) do |m|
|
42
|
-
existing[m[:id]] = m
|
43
|
-
end
|
44
|
-
|
45
|
-
# When the same member exists in overridden class, just append
|
46
|
-
# the docs. Otherwise add the member as a whole to the class.
|
47
|
-
each_member(override) do |m|
|
48
|
-
ex = existing[m[:id]]
|
49
|
-
if ex
|
50
|
-
if m[:doc].length > 0
|
51
|
-
add_doc(ex, "**From override #{get_name(override)}:** " + m[:doc])
|
52
|
-
else
|
53
|
-
add_doc(ex, "**Overridden in #{get_name(override)}.**")
|
54
|
-
end
|
55
|
-
ex[:files] += m[:files]
|
56
|
-
else
|
57
|
-
add_member(target, m)
|
58
|
-
add_doc(m, "**Defined in override #{get_name(override)}.**")
|
59
|
-
m[:owner] = target[:name]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
# helpers
|
65
|
-
|
66
|
-
def get_name(override)
|
67
|
-
if override[:name] != ""
|
68
|
-
override[:name]
|
69
|
-
else
|
70
|
-
override[:files][0][:filename]
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def each_member(cls)
|
75
|
-
cls[:members].each {|m| yield m }
|
76
|
-
end
|
77
|
-
|
78
|
-
def add_member(cls, m)
|
79
|
-
cls[:members] << m
|
80
|
-
end
|
81
|
-
|
82
|
-
def add_doc(m, doc)
|
83
|
-
m[:doc] = (m[:doc] + "\n\n" + doc).strip
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
data/lib/jsduck/renderer.rb
DELETED
@@ -1,361 +0,0 @@
|
|
1
|
-
require 'jsduck/util/html'
|
2
|
-
require 'jsduck/meta_tag_renderer'
|
3
|
-
require 'jsduck/signature_renderer'
|
4
|
-
|
5
|
-
module JsDuck
|
6
|
-
|
7
|
-
# Ruby-side implementation of class docs Renderer.
|
8
|
-
# Uses PhantomJS to run Docs.Renderer JavaScript.
|
9
|
-
class Renderer
|
10
|
-
def initialize(opts)
|
11
|
-
@opts = opts
|
12
|
-
end
|
13
|
-
|
14
|
-
def render(cls)
|
15
|
-
@cls = cls
|
16
|
-
@signature = SignatureRenderer.new(cls)
|
17
|
-
|
18
|
-
return [
|
19
|
-
"<div>",
|
20
|
-
render_sidebar,
|
21
|
-
"<div class='doc-contents'>",
|
22
|
-
render_meta_data(@cls[:html_meta], :top),
|
23
|
-
render_private_class_notice,
|
24
|
-
@cls[:doc],
|
25
|
-
render_enum_class_notice,
|
26
|
-
render_meta_data(@cls[:html_meta], :bottom),
|
27
|
-
"</div>",
|
28
|
-
"<div class='members'>",
|
29
|
-
render_all_sections,
|
30
|
-
"</div>",
|
31
|
-
"</div>",
|
32
|
-
].flatten.compact.join
|
33
|
-
end
|
34
|
-
|
35
|
-
def render_private_class_notice
|
36
|
-
return if !@cls[:private]
|
37
|
-
return [
|
38
|
-
"<p class='private'><strong>NOTE</strong> ",
|
39
|
-
"This is a private utility class for internal use by the framework. ",
|
40
|
-
"Don't rely on its existence.</p>",
|
41
|
-
]
|
42
|
-
end
|
43
|
-
|
44
|
-
def render_enum_class_notice
|
45
|
-
return if !@cls[:enum]
|
46
|
-
|
47
|
-
if @cls[:enum][:doc_only]
|
48
|
-
first = @cls[:members][:property][0] || {:name => 'foo', :default => '"foo"'}
|
49
|
-
[
|
50
|
-
"<p class='enum'><strong>ENUM:</strong> ",
|
51
|
-
"This enumeration defines a set of String values. ",
|
52
|
-
"It exists primarily for documentation purposes - ",
|
53
|
-
"in code use the actual string values like #{first[:default]}, ",
|
54
|
-
"don't reference them through this class like #{@cls[:name]}.#{first[:name]}.</p>",
|
55
|
-
]
|
56
|
-
else
|
57
|
-
[
|
58
|
-
"<p class='enum'><strong>ENUM:</strong> ",
|
59
|
-
"This enumeration defines a set of #{@cls[:enum][:type]} values.</p>",
|
60
|
-
]
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
def render_meta_data(meta_data, position)
|
65
|
-
MetaTagRenderer.render(meta_data, position)
|
66
|
-
end
|
67
|
-
|
68
|
-
def render_sidebar
|
69
|
-
items = [
|
70
|
-
render_alternate_class_names,
|
71
|
-
render_tree,
|
72
|
-
render_dependencies(:mixins, "Mixins"),
|
73
|
-
render_dependencies(:parentMixins, "Inherited mixins"),
|
74
|
-
render_dependencies(:requires, "Requires"),
|
75
|
-
render_dependencies(:subclasses, "Subclasses"),
|
76
|
-
render_dependencies(:mixedInto, "Mixed into"),
|
77
|
-
render_dependencies(:uses, "Uses"),
|
78
|
-
@opts.source ? render_files : nil,
|
79
|
-
]
|
80
|
-
if items.compact.length > 0
|
81
|
-
return ['<pre class="hierarchy">', items, '</pre>']
|
82
|
-
else
|
83
|
-
return nil
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
def render_alternate_class_names
|
88
|
-
return if @cls[:alternateClassNames].length == 0
|
89
|
-
return [
|
90
|
-
"<h4>Alternate names</h4>",
|
91
|
-
@cls[:alternateClassNames].map {|name| "<div class='alternate-class-name'>#{name}</div>" },
|
92
|
-
]
|
93
|
-
end
|
94
|
-
|
95
|
-
def render_dependencies(type, title)
|
96
|
-
return if !@cls[type] || @cls[type].length == 0
|
97
|
-
return [
|
98
|
-
"<h4>#{title}</h4>",
|
99
|
-
@cls[type].map {|name| "<div class='dependency'>#{name.exists? ? render_link(name) : name}</div>" },
|
100
|
-
]
|
101
|
-
end
|
102
|
-
|
103
|
-
def render_files
|
104
|
-
return if @cls[:files].length == 0 || @cls[:files][0][:filename] == ""
|
105
|
-
return [
|
106
|
-
"<h4>Files</h4>",
|
107
|
-
@cls[:files].map do |file|
|
108
|
-
url = "source/" + file[:href]
|
109
|
-
title = File.basename(file[:filename])
|
110
|
-
"<div class='dependency'><a href='#{url}' target='_blank'>#{title}</a></div>"
|
111
|
-
end
|
112
|
-
]
|
113
|
-
end
|
114
|
-
|
115
|
-
# Take care of the special case where class has parent for which we have no docs.
|
116
|
-
# In that case the "extends" property exists but "superclasses" is empty.
|
117
|
-
# We still create the tree, but without links in it.
|
118
|
-
def render_tree
|
119
|
-
return if !@cls[:extends] || @cls[:extends] == "Object"
|
120
|
-
|
121
|
-
return [
|
122
|
-
"<h4>Hierarchy</h4>",
|
123
|
-
render_class_tree(@cls[:superclasses] + [@cls[:name]])
|
124
|
-
]
|
125
|
-
end
|
126
|
-
|
127
|
-
def render_class_tree(classes, i=0)
|
128
|
-
return "" if classes.length <= i
|
129
|
-
|
130
|
-
name = classes[i]
|
131
|
-
return [
|
132
|
-
"<div class='subclass #{i == 0 ? 'first-child' : ''}'>",
|
133
|
-
classes.length-1 == i ? "<strong>#{name}</strong>" : (name.exists? ? render_link(name) : name),
|
134
|
-
render_class_tree(classes, i+1),
|
135
|
-
"</div>",
|
136
|
-
]
|
137
|
-
end
|
138
|
-
|
139
|
-
def render_link(cls_name, member=nil)
|
140
|
-
id = member ? cls_name + "-" + member[:id] : cls_name
|
141
|
-
label = member ? cls_name + "." + member[:name] : cls_name
|
142
|
-
return "<a href='#!/api/#{id}' rel='#{id}' class='docClass'>#{label}</a>"
|
143
|
-
end
|
144
|
-
|
145
|
-
def render_all_sections
|
146
|
-
sections = [
|
147
|
-
{:type => :property, :title => "Properties"},
|
148
|
-
{:type => :method, :title => "Methods"},
|
149
|
-
{:type => :event, :title => "Events"},
|
150
|
-
{:type => :css_var, :title => "CSS Variables"},
|
151
|
-
{:type => :css_mixin, :title => "CSS Mixins"},
|
152
|
-
]
|
153
|
-
|
154
|
-
render_configs_section + sections.map {|sec| render_section(sec) }
|
155
|
-
end
|
156
|
-
|
157
|
-
def render_configs_section
|
158
|
-
configs = @cls[:members][:cfg] + @cls[:statics][:cfg]
|
159
|
-
|
160
|
-
if configs.length > 0
|
161
|
-
required, optional = configs.partition {|c| c[:meta][:required] }
|
162
|
-
return [
|
163
|
-
"<div class='members-section'>",
|
164
|
-
required.length == 0 ? "<div class='definedBy'>Defined By</div>" : "",
|
165
|
-
"<h3 class='members-title icon-cfg'>Config options</h3>",
|
166
|
-
render_subsection(required, "Required Config options"),
|
167
|
-
render_subsection(optional, required.length > 0 ? "Optional Config options" : nil),
|
168
|
-
"</div>",
|
169
|
-
]
|
170
|
-
else
|
171
|
-
return []
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
def render_section(sec)
|
176
|
-
members = @cls[:members][sec[:type]]
|
177
|
-
statics = @cls[:statics][sec[:type]]
|
178
|
-
|
179
|
-
# Skip rendering empty sections
|
180
|
-
if members.length > 0 || statics.length > 0
|
181
|
-
return [
|
182
|
-
"<div class='members-section'>",
|
183
|
-
statics.length == 0 ? "<div class='definedBy'>Defined By</div>" : "",
|
184
|
-
"<h3 class='members-title icon-#{sec[:type]}'>#{sec[:title]}</h3>",
|
185
|
-
render_subsection(members, statics.length > 0 ? "Instance #{sec[:title]}" : nil),
|
186
|
-
render_subsection(statics, "Static #{sec[:title]}"),
|
187
|
-
"</div>",
|
188
|
-
]
|
189
|
-
else
|
190
|
-
return []
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
def render_subsection(members, title)
|
195
|
-
return if members.length == 0
|
196
|
-
index = 0
|
197
|
-
return [
|
198
|
-
"<div class='subsection'>",
|
199
|
-
title ? "<div class='definedBy'>Defined By</div><h4 class='members-subtitle'>#{title}</h3>" : "",
|
200
|
-
members.map {|m| index += 1; render_member(m, index == 1) },
|
201
|
-
"</div>",
|
202
|
-
]
|
203
|
-
end
|
204
|
-
|
205
|
-
def render_member(m, is_first)
|
206
|
-
# use classname "first-child" when it's first member in its category
|
207
|
-
first_child = is_first ? "first-child" : ""
|
208
|
-
# shorthand to owner class
|
209
|
-
owner = m[:owner]
|
210
|
-
# is this method inherited from parent?
|
211
|
-
inherited = (owner != @cls[:name])
|
212
|
-
|
213
|
-
return [
|
214
|
-
"<div id='#{m[:id]}' class='member #{first_child} #{inherited ? 'inherited' : 'not-inherited'}'>",
|
215
|
-
# leftmost column: expand button
|
216
|
-
"<a href='#' class='side expandable'>",
|
217
|
-
"<span> </span>",
|
218
|
-
"</a>",
|
219
|
-
# member name and type + link to owner class and source
|
220
|
-
"<div class='title'>",
|
221
|
-
"<div class='meta'>",
|
222
|
-
inherited ? "<a href='#!/api/#{owner}' rel='#{owner}' class='defined-in docClass'>#{owner}</a>" :
|
223
|
-
"<span class='defined-in' rel='#{owner}'>#{owner}</span>",
|
224
|
-
"<br/>",
|
225
|
-
@opts.source ? "<a href='source/#{m[:files][0][:href]}' target='_blank' class='view-source'>view source</a>" : "",
|
226
|
-
"</div>",
|
227
|
-
# method params signature or property type signature
|
228
|
-
render_signature(m),
|
229
|
-
"</div>",
|
230
|
-
# short and long descriptions
|
231
|
-
"<div class='description'>",
|
232
|
-
"<div class='short'>",
|
233
|
-
m[:shortDoc] ? m[:shortDoc] : m[:doc],
|
234
|
-
"</div>",
|
235
|
-
"<div class='long'>",
|
236
|
-
render_long_doc(m),
|
237
|
-
"</div>",
|
238
|
-
"</div>",
|
239
|
-
"</div>",
|
240
|
-
]
|
241
|
-
end
|
242
|
-
|
243
|
-
def render_signature(m)
|
244
|
-
@signature.render(m)
|
245
|
-
end
|
246
|
-
|
247
|
-
def render_long_doc(m)
|
248
|
-
doc = []
|
249
|
-
|
250
|
-
doc << render_meta_data(m[:html_meta], :top)
|
251
|
-
|
252
|
-
doc << m[:doc]
|
253
|
-
|
254
|
-
if m[:default] && m[:default] != "undefined"
|
255
|
-
doc << "<p>Defaults to: <code>" + Util::HTML.escape(m[:default]) + "</code></p>"
|
256
|
-
end
|
257
|
-
|
258
|
-
doc << render_meta_data(m[:html_meta], :bottom)
|
259
|
-
|
260
|
-
doc << render_params_and_return(m)
|
261
|
-
|
262
|
-
if m[:overrides]
|
263
|
-
overrides = m[:overrides].map {|o| render_link(o[:owner], o) }.join(", ")
|
264
|
-
doc << "<p>Overrides: #{overrides}</p>"
|
265
|
-
end
|
266
|
-
|
267
|
-
doc
|
268
|
-
end
|
269
|
-
|
270
|
-
# Handles both rendering of method parameters and return value.
|
271
|
-
# Plus the rendering of object properties, which could also be
|
272
|
-
# functions in which case they too will be rendered with
|
273
|
-
# parameters and return value.
|
274
|
-
def render_params_and_return(item)
|
275
|
-
doc = []
|
276
|
-
|
277
|
-
if item[:params] && item[:params].length > 0
|
278
|
-
params = item[:params]
|
279
|
-
elsif item[:properties] && item[:properties].length > 0
|
280
|
-
params = item[:properties]
|
281
|
-
# If the name of last property is "return"
|
282
|
-
# remove it from params list and handle it separately afterwards
|
283
|
-
if params.last[:name] == "return"
|
284
|
-
ret = params.last
|
285
|
-
params = params.slice(0, params.length-1)
|
286
|
-
end
|
287
|
-
end
|
288
|
-
|
289
|
-
if params
|
290
|
-
if item[:type] == "Function" || item[:tagname] == :method || item[:tagname] == :event
|
291
|
-
doc << '<h3 class="pa">Parameters</h3>'
|
292
|
-
end
|
293
|
-
doc << [
|
294
|
-
"<ul>",
|
295
|
-
params.map {|p| render_long_param(p) },
|
296
|
-
"</ul>",
|
297
|
-
]
|
298
|
-
end
|
299
|
-
|
300
|
-
if item[:return]
|
301
|
-
doc << render_return(item[:return])
|
302
|
-
elsif ret
|
303
|
-
doc << render_return(ret)
|
304
|
-
end
|
305
|
-
|
306
|
-
if item[:throws]
|
307
|
-
doc << render_throws(item[:throws])
|
308
|
-
end
|
309
|
-
|
310
|
-
doc
|
311
|
-
end
|
312
|
-
|
313
|
-
def render_long_param(p)
|
314
|
-
return [
|
315
|
-
"<li>",
|
316
|
-
"<span class='pre'>#{p[:name]}</span> : ",
|
317
|
-
p[:html_type],
|
318
|
-
p[:optional] ? " (optional)" : "",
|
319
|
-
"<div class='sub-desc'>",
|
320
|
-
p[:doc],
|
321
|
-
p[:default] ? "<p>Defaults to: <code>#{Util::HTML.escape(p[:default])}</code></p>" : "",
|
322
|
-
p[:properties] && p[:properties].length > 0 ? render_params_and_return(p) : "",
|
323
|
-
"</div>",
|
324
|
-
"</li>",
|
325
|
-
]
|
326
|
-
end
|
327
|
-
|
328
|
-
def render_return(ret)
|
329
|
-
return if ret[:type] == "undefined"
|
330
|
-
return [
|
331
|
-
"<h3 class='pa'>Returns</h3>",
|
332
|
-
"<ul>",
|
333
|
-
"<li>",
|
334
|
-
"<span class='pre'>#{ret[:html_type]}</span>",
|
335
|
-
"<div class='sub-desc'>",
|
336
|
-
ret[:doc],
|
337
|
-
ret[:properties] && ret[:properties].length > 0 ? render_params_and_return(ret) : "",
|
338
|
-
"</div>",
|
339
|
-
"</li>",
|
340
|
-
"</ul>",
|
341
|
-
]
|
342
|
-
end
|
343
|
-
|
344
|
-
def render_throws(throws)
|
345
|
-
return [
|
346
|
-
"<h3 class='pa'>Throws</h3>",
|
347
|
-
"<ul>",
|
348
|
-
throws.map do |thr|
|
349
|
-
[
|
350
|
-
"<li>",
|
351
|
-
"<span class='pre'>#{thr[:html_type]}</span>",
|
352
|
-
"<div class='sub-desc'>#{thr[:doc]}</div>",
|
353
|
-
"</li>",
|
354
|
-
]
|
355
|
-
end,
|
356
|
-
"</ul>",
|
357
|
-
]
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
end
|