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
data/lib/jsduck/return_values.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
module JsDuck
|
2
|
-
|
3
|
-
# Auto-detector return values and @chainable tags.
|
4
|
-
#
|
5
|
-
# Adds @chainable tag when doc-comment contains @return {OwnerClass}
|
6
|
-
# this. Also the other way around: when @chainable found, adds
|
7
|
-
# appropriate @return.
|
8
|
-
class ReturnValues
|
9
|
-
# Only this static method of this class should be called.
|
10
|
-
def self.auto_detect(relations)
|
11
|
-
ReturnValues.new(relations).process_all!
|
12
|
-
end
|
13
|
-
|
14
|
-
def initialize(relations)
|
15
|
-
@relations = relations
|
16
|
-
@cls = nil
|
17
|
-
end
|
18
|
-
|
19
|
-
def process_all!
|
20
|
-
@relations.each do |cls|
|
21
|
-
@cls = cls
|
22
|
-
cls.find_members(:tagname => :method, :local => true, :static => false).each do |m|
|
23
|
-
process(m)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def process(m)
|
31
|
-
if constructor?(m)
|
32
|
-
add_return_new(m)
|
33
|
-
elsif chainable?(m)
|
34
|
-
add_return_this(m)
|
35
|
-
elsif returns_this?(m)
|
36
|
-
add_chainable(m)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def constructor?(m)
|
41
|
-
m[:name] == "constructor"
|
42
|
-
end
|
43
|
-
|
44
|
-
def chainable?(m)
|
45
|
-
m[:meta][:chainable]
|
46
|
-
end
|
47
|
-
|
48
|
-
def returns_this?(m)
|
49
|
-
m[:return] && m[:return][:type] == @cls[:name] && m[:return][:doc] =~ /\Athis\b/
|
50
|
-
end
|
51
|
-
|
52
|
-
def add_chainable(m)
|
53
|
-
m[:meta][:chainable] = true
|
54
|
-
end
|
55
|
-
|
56
|
-
def add_return_this(m)
|
57
|
-
if m[:return][:type] == "undefined" && m[:return][:doc] == ""
|
58
|
-
m[:return] = {:type => @cls[:name], :doc => "this"}
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def add_return_new(m)
|
63
|
-
if m[:return][:type] == "undefined" || m[:return][:type] == "Object"
|
64
|
-
# Create a whole new :return hash.
|
65
|
-
# If we were to just change the :type field it would modify
|
66
|
-
# the type of all the inherited constructor docs.
|
67
|
-
m[:return] = {:type => @cls[:name], :doc => m[:return][:doc]}
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
data/lib/jsduck/serializer.rb
DELETED
@@ -1,262 +0,0 @@
|
|
1
|
-
module JsDuck
|
2
|
-
|
3
|
-
# Transforms Esprima AST into string
|
4
|
-
class Serializer
|
5
|
-
|
6
|
-
# Turns AST node into string
|
7
|
-
def to_s(ast)
|
8
|
-
case ast["type"]
|
9
|
-
when "Program"
|
10
|
-
ast["body"].map {|s| to_s(s) }.join
|
11
|
-
|
12
|
-
# Statements
|
13
|
-
|
14
|
-
when "BlockStatement"
|
15
|
-
"{" + ast["body"].map {|s| to_s(s) }.join + "}"
|
16
|
-
|
17
|
-
when "BreakStatement"
|
18
|
-
"break" + (ast["label"] ? " " + to_s(ast["label"]) : "") + ";"
|
19
|
-
|
20
|
-
when "ContinueStatement"
|
21
|
-
"continue" + (ast["label"] ? " " + to_s(ast["label"]) : "") + ";"
|
22
|
-
|
23
|
-
when "DoWhileStatement"
|
24
|
-
"do " + to_s(ast["body"]) + " while (" + to_s(ast["test"]) + ");"
|
25
|
-
|
26
|
-
when "DebuggerStatement"
|
27
|
-
"debugger;"
|
28
|
-
|
29
|
-
when "EmptyStatement"
|
30
|
-
";"
|
31
|
-
|
32
|
-
when "ExpressionStatement"
|
33
|
-
to_s(ast["expression"]) + ";"
|
34
|
-
|
35
|
-
when "ForStatement"
|
36
|
-
init = ast["init"] ? to_s(ast["init"]).sub(/;\Z/, "") : ""
|
37
|
-
test = ast["test"] ? to_s(ast["test"]) : ""
|
38
|
-
update = ast["update"] ? to_s(ast["update"]) : ""
|
39
|
-
"for (" + init + "; " + test + "; " + update + ") " + to_s(ast["body"])
|
40
|
-
|
41
|
-
when "ForInStatement"
|
42
|
-
left = to_s(ast["left"]).sub(/;\Z/, "")
|
43
|
-
right = to_s(ast["right"])
|
44
|
-
"for (" + left + " in " + right + ") " + to_s(ast["body"])
|
45
|
-
|
46
|
-
when "IfStatement"
|
47
|
-
alternate = ast["alternate"] ? " else " + to_s(ast["alternate"]) : ""
|
48
|
-
"if (" + to_s(ast["test"]) + ") " + to_s(ast["consequent"]) + alternate
|
49
|
-
|
50
|
-
when "LabeledStatement"
|
51
|
-
to_s(ast["label"]) + ": " + to_s(ast["body"])
|
52
|
-
|
53
|
-
when "ReturnStatement"
|
54
|
-
arg = ast["argument"] ? to_s(ast["argument"]) : ""
|
55
|
-
"return " + arg + ";"
|
56
|
-
|
57
|
-
when "SwitchStatement"
|
58
|
-
"switch (" + to_s(ast["discriminant"]) + ") {" + ast["cases"].map {|c| to_s(c) }.join + "}"
|
59
|
-
|
60
|
-
when "SwitchCase"
|
61
|
-
test = ast["test"] ? "case " + to_s(ast["test"]) : "default"
|
62
|
-
test + ": " + ast["consequent"].map {|c| to_s(c) }.join
|
63
|
-
|
64
|
-
when "ThrowStatement"
|
65
|
-
"throw " + to_s(ast["argument"]) + ";"
|
66
|
-
|
67
|
-
when "TryStatement"
|
68
|
-
handlers = ast["handlers"].map {|h| to_s(h) }.join
|
69
|
-
finalizer = ast["finalizer"] ? " finally " + to_s(ast["finalizer"]) : ""
|
70
|
-
"try " + to_s(ast["block"]) + handlers + finalizer
|
71
|
-
|
72
|
-
when "CatchClause"
|
73
|
-
param = ast["param"] ? to_s(ast["param"]) : ""
|
74
|
-
" catch (" + param + ") " + to_s(ast["body"])
|
75
|
-
|
76
|
-
when "WhileStatement"
|
77
|
-
"while (" + to_s(ast["test"]) + ") " + to_s(ast["body"])
|
78
|
-
|
79
|
-
when "WithStatement"
|
80
|
-
"with (" + to_s(ast["object"]) + ") " + to_s(ast["body"])
|
81
|
-
|
82
|
-
|
83
|
-
# Declarations
|
84
|
-
|
85
|
-
when "FunctionDeclaration"
|
86
|
-
function(ast)
|
87
|
-
|
88
|
-
when "VariableDeclaration"
|
89
|
-
ast["kind"] + " " + list(ast["declarations"]) + ";"
|
90
|
-
|
91
|
-
when "VariableDeclarator"
|
92
|
-
if ast["init"]
|
93
|
-
to_s(ast["id"]) + " = " + to_s(ast["init"])
|
94
|
-
else
|
95
|
-
to_s(ast["id"])
|
96
|
-
end
|
97
|
-
|
98
|
-
# Expressions
|
99
|
-
|
100
|
-
when "AssignmentExpression"
|
101
|
-
parens(ast, ast["left"]) + " " + ast["operator"] + " " + to_s(ast["right"])
|
102
|
-
|
103
|
-
when "ArrayExpression"
|
104
|
-
"[" + list(ast["elements"]) + "]"
|
105
|
-
|
106
|
-
when "BinaryExpression"
|
107
|
-
binary(ast)
|
108
|
-
|
109
|
-
when "CallExpression"
|
110
|
-
call(ast)
|
111
|
-
|
112
|
-
when "ConditionalExpression"
|
113
|
-
parens(ast, ast["test"]) + " ? " + to_s(ast["consequent"]) + " : " + to_s(ast["alternate"])
|
114
|
-
|
115
|
-
when "FunctionExpression"
|
116
|
-
function(ast)
|
117
|
-
|
118
|
-
when "LogicalExpression"
|
119
|
-
binary(ast)
|
120
|
-
|
121
|
-
when "MemberExpression"
|
122
|
-
if ast["computed"]
|
123
|
-
parens(ast, ast["object"]) + "[" + to_s(ast["property"]) + "]"
|
124
|
-
else
|
125
|
-
parens(ast, ast["object"]) + "." + to_s(ast["property"])
|
126
|
-
end
|
127
|
-
|
128
|
-
when "NewExpression"
|
129
|
-
"new " + call(ast)
|
130
|
-
|
131
|
-
when "ObjectExpression"
|
132
|
-
"{" + list(ast["properties"]) + "}"
|
133
|
-
|
134
|
-
when "Property"
|
135
|
-
to_s(ast["key"]) + ": " + to_s(ast["value"])
|
136
|
-
|
137
|
-
when "SequenceExpression"
|
138
|
-
list(ast["expressions"])
|
139
|
-
|
140
|
-
when "ThisExpression"
|
141
|
-
"this"
|
142
|
-
|
143
|
-
when "UnaryExpression"
|
144
|
-
ast["operator"] + parens(ast, ast["argument"])
|
145
|
-
|
146
|
-
when "UpdateExpression"
|
147
|
-
if ast["prefix"]
|
148
|
-
ast["operator"] + parens(ast, ast["argument"])
|
149
|
-
else
|
150
|
-
parens(ast, ast["argument"]) + ast["operator"]
|
151
|
-
end
|
152
|
-
|
153
|
-
# Basics
|
154
|
-
|
155
|
-
when "Identifier"
|
156
|
-
ast["name"]
|
157
|
-
|
158
|
-
when "Literal"
|
159
|
-
ast["raw"]
|
160
|
-
|
161
|
-
else
|
162
|
-
throw "Unknown node type: "+ast["type"]
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
private
|
167
|
-
|
168
|
-
# serializes function declaration or expression
|
169
|
-
def function(ast)
|
170
|
-
params = list(ast["params"])
|
171
|
-
id = ast["id"] ? to_s(ast["id"]) : ""
|
172
|
-
"function " + id + "(" + params + ") " + to_s(ast["body"])
|
173
|
-
end
|
174
|
-
|
175
|
-
# serializes list of comma-separated items
|
176
|
-
def list(array)
|
177
|
-
array.map {|x| to_s(x) }.join(", ")
|
178
|
-
end
|
179
|
-
|
180
|
-
# serializes call- and new-expression
|
181
|
-
def call(ast)
|
182
|
-
parens(ast, ast["callee"]) + "(" + list(ast["arguments"]) + ")"
|
183
|
-
end
|
184
|
-
|
185
|
-
# Handles both binary- and logical-expression
|
186
|
-
def binary(ast)
|
187
|
-
parens(ast, ast["left"]) + " " + ast["operator"] + " " + parens(ast, ast["right"])
|
188
|
-
end
|
189
|
-
|
190
|
-
# serializes child node and wraps it inside parenthesis if the
|
191
|
-
# precedence rules compared to parent node would require so.
|
192
|
-
def parens(parent, child)
|
193
|
-
if precedence(parent) >= precedence(child)
|
194
|
-
to_s(child)
|
195
|
-
else
|
196
|
-
"(" + to_s(child) + ")"
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
# Returns the precedence of operator represented by given AST node
|
201
|
-
def precedence(ast)
|
202
|
-
p = PRECEDENCE[ast["type"]]
|
203
|
-
if p.is_a? Fixnum
|
204
|
-
p
|
205
|
-
elsif p.is_a? Hash
|
206
|
-
p[ast["operator"]]
|
207
|
-
else
|
208
|
-
0
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
# Precedence rules of JavaScript operators.
|
213
|
-
#
|
214
|
-
# Taken from: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Operator_Precedence
|
215
|
-
#
|
216
|
-
PRECEDENCE = {
|
217
|
-
"SequenceExpression" => 17,
|
218
|
-
"AssignmentExpression" => 16,
|
219
|
-
"ConditionalExpression" => 15,
|
220
|
-
"LogicalExpression" => {
|
221
|
-
"||" => 14,
|
222
|
-
"&&" => 13,
|
223
|
-
},
|
224
|
-
"BinaryExpression" => {
|
225
|
-
"|" => 12,
|
226
|
-
"^" => 11,
|
227
|
-
"&" => 10,
|
228
|
-
|
229
|
-
"==" => 9,
|
230
|
-
"!=" => 9,
|
231
|
-
"===" => 9,
|
232
|
-
"!==" => 9,
|
233
|
-
|
234
|
-
"<" => 8,
|
235
|
-
"<=" => 8,
|
236
|
-
">" => 8,
|
237
|
-
">=" => 8,
|
238
|
-
"in" => 8,
|
239
|
-
"instanceof" => 8,
|
240
|
-
|
241
|
-
"<<" => 7,
|
242
|
-
">>" => 7,
|
243
|
-
">>>" => 7,
|
244
|
-
|
245
|
-
"+" => 6,
|
246
|
-
"-" => 6,
|
247
|
-
|
248
|
-
"*" => 5,
|
249
|
-
"/" => 5,
|
250
|
-
"%" => 5,
|
251
|
-
},
|
252
|
-
"UnaryExpression" => 4,
|
253
|
-
"UpdateExpression" => 3,
|
254
|
-
"CallExpression" => 2,
|
255
|
-
"MemberExpression" => 1,
|
256
|
-
"NewExpression" => 1,
|
257
|
-
}
|
258
|
-
|
259
|
-
end
|
260
|
-
|
261
|
-
end
|
262
|
-
|
data/lib/jsduck/shortener.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'jsduck/util/html'
|
3
|
-
require 'jsduck/util/singleton'
|
4
|
-
|
5
|
-
module JsDuck
|
6
|
-
|
7
|
-
# Little helper for shortening text
|
8
|
-
class Shortener
|
9
|
-
include Util::Singleton
|
10
|
-
|
11
|
-
# Maximum length for text that doesn't get shortened.
|
12
|
-
# The accessor is used for testing purposes only.
|
13
|
-
attr_accessor :max_length
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@max_length = 120
|
17
|
-
end
|
18
|
-
|
19
|
-
# Shortens text
|
20
|
-
#
|
21
|
-
# 116 chars is also where ext-doc makes its cut, but unlike
|
22
|
-
# ext-doc we only make the cut when there's more than 120 chars.
|
23
|
-
#
|
24
|
-
# This way we don't get stupid expansions like:
|
25
|
-
#
|
26
|
-
# Blah blah blah some text...
|
27
|
-
#
|
28
|
-
# expanding to:
|
29
|
-
#
|
30
|
-
# Blah blah blah some text.
|
31
|
-
#
|
32
|
-
def shorten(input)
|
33
|
-
sent = first_sentence(Util::HTML.strip_tags(input).strip)
|
34
|
-
# Use u-modifier to correctly count multi-byte characters
|
35
|
-
chars = sent.scan(/./mu)
|
36
|
-
if chars.length > @max_length
|
37
|
-
chars[0..(@max_length-4)].join + "..."
|
38
|
-
else
|
39
|
-
sent + " ..."
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Returns the first sentence inside a string.
|
44
|
-
def first_sentence(str)
|
45
|
-
str.sub(/\A(.+?(\.|。))\s.*\Z/mu, "\\1")
|
46
|
-
end
|
47
|
-
|
48
|
-
# Returns true when input should get shortened.
|
49
|
-
def too_long?(input)
|
50
|
-
stripped = Util::HTML.strip_tags(input).strip
|
51
|
-
# for sentence v/s full - compare byte length
|
52
|
-
# for full v/s max - compare char length
|
53
|
-
first_sentence(stripped).length < stripped.length || stripped.scan(/./mu).length > @max_length
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'jsduck/meta_tag_renderer'
|
2
|
-
|
3
|
-
module JsDuck
|
4
|
-
|
5
|
-
# Performs the rendering of member signatures.
|
6
|
-
class SignatureRenderer
|
7
|
-
# Initializes the renderer for rendering members of the given
|
8
|
-
# class.
|
9
|
-
def initialize(cls)
|
10
|
-
@cls = cls
|
11
|
-
end
|
12
|
-
|
13
|
-
# Renders signature of the given member.
|
14
|
-
def render(member)
|
15
|
-
# Keep the code simpler by not passing around the member hash
|
16
|
-
@m = member
|
17
|
-
|
18
|
-
return [
|
19
|
-
render_new,
|
20
|
-
render_link,
|
21
|
-
render_type,
|
22
|
-
render_meta,
|
23
|
-
]
|
24
|
-
end
|
25
|
-
|
26
|
-
private
|
27
|
-
|
28
|
-
def render_new
|
29
|
-
constructor? ? "<strong class='new-keyword'>new</strong>" : ""
|
30
|
-
end
|
31
|
-
|
32
|
-
def render_link
|
33
|
-
"<a href='#{render_url}' class='name #{render_expandable}'>#{render_name}</a>"
|
34
|
-
end
|
35
|
-
|
36
|
-
def render_url
|
37
|
-
"#!/api/#{@m[:owner]}-#{@m[:id]}"
|
38
|
-
end
|
39
|
-
|
40
|
-
def render_expandable
|
41
|
-
@m[:shortDoc] ? "expandable" : "not-expandable"
|
42
|
-
end
|
43
|
-
|
44
|
-
def render_name
|
45
|
-
constructor? ? @cls[:name] : @m[:name]
|
46
|
-
end
|
47
|
-
|
48
|
-
def constructor?
|
49
|
-
@m[:tagname] == :method && @m[:name] == "constructor"
|
50
|
-
end
|
51
|
-
|
52
|
-
def render_type
|
53
|
-
if like_property?
|
54
|
-
render_property_type
|
55
|
-
else
|
56
|
-
render_params + render_return
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def like_property?
|
61
|
-
@m[:tagname] == :cfg || @m[:tagname] == :property || @m[:tagname] == :css_var
|
62
|
-
end
|
63
|
-
|
64
|
-
def render_property_type
|
65
|
-
"<span> : #{@m[:html_type]}</span>"
|
66
|
-
end
|
67
|
-
|
68
|
-
def render_params
|
69
|
-
ps = @m[:params].map {|p| render_single_param(p) }.join(", ")
|
70
|
-
"( <span class='pre'>#{ps}</span> )"
|
71
|
-
end
|
72
|
-
|
73
|
-
def render_single_param(param)
|
74
|
-
param[:optional] ? "["+param[:name]+"]" : param[:name]
|
75
|
-
end
|
76
|
-
|
77
|
-
def render_return
|
78
|
-
method_with_return? ? (" : " + @m[:return][:html_type]) : ""
|
79
|
-
end
|
80
|
-
|
81
|
-
def method_with_return?
|
82
|
-
@m[:tagname] == :method && @m[:return][:type] != "undefined"
|
83
|
-
end
|
84
|
-
|
85
|
-
def render_meta
|
86
|
-
MetaTagRenderer.render_signature(@m)
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|