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.
Files changed (183) hide show
  1. data/.travis.yml +0 -1
  2. data/README.md +32 -6
  3. data/Rakefile +10 -18
  4. data/bin/compare +5 -5
  5. data/bin/jsduck +2 -3
  6. data/jsduck.gemspec +3 -4
  7. data/lib/jsduck/aggregator.rb +21 -80
  8. data/lib/jsduck/app.rb +7 -14
  9. data/lib/jsduck/app_data.rb +4 -5
  10. data/lib/jsduck/assets.rb +4 -7
  11. data/lib/jsduck/base_type.rb +53 -0
  12. data/lib/jsduck/batch_parser.rb +8 -87
  13. data/lib/jsduck/batch_processor.rb +77 -0
  14. data/lib/jsduck/categories/auto.rb +83 -0
  15. data/lib/jsduck/categories/class_name.rb +63 -0
  16. data/lib/jsduck/categories/factory.rb +113 -0
  17. data/lib/jsduck/categories/file.rb +75 -0
  18. data/lib/jsduck/class.rb +3 -9
  19. data/lib/jsduck/class_doc_expander.rb +1 -1
  20. data/lib/jsduck/css/lexer.rb +203 -0
  21. data/lib/jsduck/css/parser.rb +121 -0
  22. data/lib/jsduck/doc/comment.rb +40 -0
  23. data/lib/jsduck/doc/map.rb +23 -0
  24. data/lib/jsduck/doc/parser.rb +128 -0
  25. data/lib/jsduck/doc/processor.rb +52 -0
  26. data/lib/jsduck/doc/scanner.rb +76 -0
  27. data/lib/jsduck/doc/standard_tag_parser.rb +154 -0
  28. data/lib/jsduck/doc/subproperties.rb +64 -0
  29. data/lib/jsduck/docs_code_comparer.rb +31 -0
  30. data/lib/jsduck/export_writer.rb +2 -2
  31. data/lib/jsduck/exporter/app.rb +16 -4
  32. data/lib/jsduck/exporter/full.rb +2 -2
  33. data/lib/jsduck/format/batch.rb +58 -0
  34. data/lib/jsduck/format/class.rb +62 -0
  35. data/lib/jsduck/format/doc.rb +172 -0
  36. data/lib/jsduck/format/html_stack.rb +109 -0
  37. data/lib/jsduck/format/shortener.rb +55 -0
  38. data/lib/jsduck/format/subproperties.rb +64 -0
  39. data/lib/jsduck/guides.rb +32 -14
  40. data/lib/jsduck/index_html.rb +3 -1
  41. data/lib/jsduck/inline/auto_link.rb +2 -2
  42. data/lib/jsduck/inline/link.rb +4 -3
  43. data/lib/jsduck/inline/link_renderer.rb +2 -2
  44. data/lib/jsduck/inline/video.rb +8 -2
  45. data/lib/jsduck/js/ast.rb +361 -0
  46. data/lib/jsduck/js/esprima.rb +39 -0
  47. data/lib/jsduck/{esprima → js/esprima}/esprima.js +0 -0
  48. data/lib/jsduck/js/evaluator.rb +70 -0
  49. data/lib/jsduck/js/ext_patterns.rb +70 -0
  50. data/lib/jsduck/js/function.rb +206 -0
  51. data/lib/jsduck/js/node.rb +194 -0
  52. data/lib/jsduck/js/node_array.rb +36 -0
  53. data/lib/jsduck/js/parser.rb +223 -0
  54. data/lib/jsduck/js/serializer.rb +263 -0
  55. data/lib/jsduck/js/utils.rb +21 -0
  56. data/lib/jsduck/logger.rb +3 -13
  57. data/lib/jsduck/members_index.rb +3 -4
  58. data/lib/jsduck/merger.rb +25 -145
  59. data/lib/jsduck/options.rb +29 -132
  60. data/lib/jsduck/parser.rb +76 -0
  61. data/lib/jsduck/process/accessors.rb +133 -0
  62. data/lib/jsduck/process/circular_deps.rb +58 -0
  63. data/lib/jsduck/process/enums.rb +91 -0
  64. data/lib/jsduck/process/ext4_events.rb +43 -0
  65. data/lib/jsduck/process/global_members.rb +36 -0
  66. data/lib/jsduck/process/ignored_classes.rb +16 -0
  67. data/lib/jsduck/process/importer.rb +58 -0
  68. data/lib/jsduck/process/inherit_doc.rb +197 -0
  69. data/lib/jsduck/process/lint.rb +135 -0
  70. data/lib/jsduck/process/overrides.rb +99 -0
  71. data/lib/jsduck/process/return_values.rb +72 -0
  72. data/lib/jsduck/process/versions.rb +102 -0
  73. data/lib/jsduck/relations.rb +5 -0
  74. data/lib/jsduck/render/class.rb +144 -0
  75. data/lib/jsduck/render/sidebar.rb +97 -0
  76. data/lib/jsduck/render/signature.rb +94 -0
  77. data/lib/jsduck/render/subproperties.rb +99 -0
  78. data/lib/jsduck/render/tags.rb +38 -0
  79. data/lib/jsduck/search_data.rb +19 -13
  80. data/lib/jsduck/source/file.rb +8 -17
  81. data/lib/jsduck/tag/abstract.rb +4 -7
  82. data/lib/jsduck/tag/accessor.rb +10 -0
  83. data/lib/jsduck/tag/alias.rb +61 -0
  84. data/lib/jsduck/tag/alternate_class_names.rb +17 -0
  85. data/lib/jsduck/tag/aside.rb +28 -31
  86. data/lib/jsduck/tag/author.rb +9 -5
  87. data/lib/jsduck/tag/boolean_tag.rb +24 -0
  88. data/lib/jsduck/tag/cfg.rb +45 -0
  89. data/lib/jsduck/tag/chainable.rb +5 -7
  90. data/lib/jsduck/tag/class.rb +28 -0
  91. data/lib/jsduck/tag/class_list_tag.rb +40 -0
  92. data/lib/jsduck/tag/constructor.rb +24 -0
  93. data/lib/jsduck/tag/css_mixin.rb +17 -0
  94. data/lib/jsduck/tag/css_var.rb +29 -0
  95. data/lib/jsduck/tag/default.rb +31 -0
  96. data/lib/jsduck/tag/deprecated.rb +13 -27
  97. data/lib/jsduck/tag/deprecated_tag.rb +58 -0
  98. data/lib/jsduck/tag/doc.rb +32 -0
  99. data/lib/jsduck/tag/docauthor.rb +4 -5
  100. data/lib/jsduck/tag/enum.rb +70 -0
  101. data/lib/jsduck/tag/event.rb +28 -0
  102. data/lib/jsduck/tag/evented.rb +10 -0
  103. data/lib/jsduck/tag/extends.rb +45 -0
  104. data/lib/jsduck/tag/ftype.rb +18 -0
  105. data/lib/jsduck/tag/hide.rb +4 -11
  106. data/lib/jsduck/tag/ignore.rb +6 -7
  107. data/lib/jsduck/tag/inheritable.rb +10 -0
  108. data/lib/jsduck/tag/inheritdoc.rb +48 -0
  109. data/lib/jsduck/tag/markdown.rb +8 -6
  110. data/lib/jsduck/tag/member.rb +24 -0
  111. data/lib/jsduck/tag/method.rb +35 -0
  112. data/lib/jsduck/tag/mixins.rb +26 -0
  113. data/lib/jsduck/tag/name.rb +36 -0
  114. data/lib/jsduck/tag/new.rb +13 -27
  115. data/lib/jsduck/tag/override.rb +37 -0
  116. data/lib/jsduck/tag/overrides.rb +29 -0
  117. data/lib/jsduck/tag/param.rb +87 -0
  118. data/lib/jsduck/tag/preventable.rb +19 -10
  119. data/lib/jsduck/tag/private.rb +28 -13
  120. data/lib/jsduck/tag/property.rb +39 -0
  121. data/lib/jsduck/tag/protected.rb +5 -7
  122. data/lib/jsduck/tag/ptype.rb +18 -0
  123. data/lib/jsduck/tag/readonly.rb +4 -7
  124. data/lib/jsduck/tag/removed.rb +21 -29
  125. data/lib/jsduck/tag/required.rb +11 -9
  126. data/lib/jsduck/tag/requires.rb +12 -0
  127. data/lib/jsduck/tag/return.rb +47 -0
  128. data/lib/jsduck/tag/since.rb +19 -11
  129. data/lib/jsduck/tag/singleton.rb +15 -0
  130. data/lib/jsduck/tag/static.rb +5 -7
  131. data/lib/jsduck/tag/subproperties.rb +23 -0
  132. data/lib/jsduck/tag/tag.rb +208 -0
  133. data/lib/jsduck/tag/template.rb +14 -9
  134. data/lib/jsduck/tag/throws.rb +38 -0
  135. data/lib/jsduck/tag/type.rb +48 -0
  136. data/lib/jsduck/tag/uses.rb +12 -0
  137. data/lib/jsduck/tag/xtype.rb +30 -0
  138. data/lib/jsduck/tag_loader.rb +39 -0
  139. data/lib/jsduck/tag_registry.rb +189 -0
  140. data/lib/jsduck/type_parser.rb +3 -3
  141. data/lib/jsduck/web_writer.rb +2 -2
  142. data/lib/jsduck/welcome.rb +1 -1
  143. metadata +578 -538
  144. data/lib/jsduck/accessors.rb +0 -136
  145. data/lib/jsduck/ast.rb +0 -524
  146. data/lib/jsduck/auto_categories.rb +0 -80
  147. data/lib/jsduck/batch_formatter.rb +0 -60
  148. data/lib/jsduck/categories.rb +0 -73
  149. data/lib/jsduck/categories_class_name.rb +0 -37
  150. data/lib/jsduck/circular_deps.rb +0 -56
  151. data/lib/jsduck/class_formatter.rb +0 -102
  152. data/lib/jsduck/columns.rb +0 -56
  153. data/lib/jsduck/css_lexer.rb +0 -201
  154. data/lib/jsduck/css_parser.rb +0 -119
  155. data/lib/jsduck/doc_ast.rb +0 -319
  156. data/lib/jsduck/doc_formatter.rb +0 -142
  157. data/lib/jsduck/doc_parser.rb +0 -611
  158. data/lib/jsduck/doc_type.rb +0 -59
  159. data/lib/jsduck/enum.rb +0 -73
  160. data/lib/jsduck/esprima.rb +0 -51
  161. data/lib/jsduck/evaluator.rb +0 -69
  162. data/lib/jsduck/ext_patterns.rb +0 -58
  163. data/lib/jsduck/file_categories.rb +0 -76
  164. data/lib/jsduck/function_ast.rb +0 -206
  165. data/lib/jsduck/guide_anchors.rb +0 -32
  166. data/lib/jsduck/guide_toc.rb +0 -49
  167. data/lib/jsduck/html_stack.rb +0 -105
  168. data/lib/jsduck/importer.rb +0 -121
  169. data/lib/jsduck/inherit_doc.rb +0 -193
  170. data/lib/jsduck/js_parser.rb +0 -221
  171. data/lib/jsduck/lint.rb +0 -133
  172. data/lib/jsduck/meta_tag.rb +0 -88
  173. data/lib/jsduck/meta_tag_loader.rb +0 -67
  174. data/lib/jsduck/meta_tag_registry.rb +0 -111
  175. data/lib/jsduck/meta_tag_renderer.rb +0 -34
  176. data/lib/jsduck/news.rb +0 -128
  177. data/lib/jsduck/override.rb +0 -87
  178. data/lib/jsduck/renderer.rb +0 -361
  179. data/lib/jsduck/return_values.rb +0 -72
  180. data/lib/jsduck/serializer.rb +0 -262
  181. data/lib/jsduck/shortener.rb +0 -58
  182. data/lib/jsduck/signature_renderer.rb +0 -91
  183. data/lib/jsduck/source/file_parser.rb +0 -72
@@ -1,221 +0,0 @@
1
- require 'jsduck/esprima'
2
- require 'jsduck/logger'
3
-
4
- module JsDuck
5
-
6
- # JavaScript parser that internally uses Esprima.js
7
- class JsParser
8
-
9
- # Initializes the parser with JavaScript source code to be parsed.
10
- def initialize(input, options = {})
11
- @input = input
12
-
13
- # Initialize line number counting
14
- @start_index = 0
15
- @start_linenr = 1
16
- end
17
-
18
- # Parses JavaScript source code and returns array of hashes like this:
19
- #
20
- # {
21
- # :comment => "The contents of the comment",
22
- # :code => {...AST data structure for code following the comment...},
23
- # :linenr => 12, // Beginning with 1
24
- # :type => :doc_comment, // or :plain_comment
25
- # }
26
- #
27
- def parse
28
- @ast = Esprima.parse(@input)
29
-
30
- @ast["comments"] = merge_comments(@ast["comments"])
31
- locate_comments
32
- end
33
-
34
- private
35
-
36
- # Merges consecutive line-comments and Establishes links between
37
- # comments, so we can easily use comment["next"] to get to the
38
- # next comment.
39
- def merge_comments(original_comments)
40
- result = []
41
-
42
- comment = original_comments[0]
43
- i = 0
44
-
45
- while comment
46
- i += 1
47
- next_comment = original_comments[i]
48
-
49
- if next_comment && mergeable?(comment, next_comment)
50
- # Merge next comment to current one
51
- comment["value"] += "\n" + next_comment["value"]
52
- comment["range"][1] = next_comment["range"][1]
53
- else
54
- # Create a link and continue with next comment
55
- comment["next"] = next_comment
56
- result << comment
57
- comment = next_comment
58
- end
59
- end
60
-
61
- result
62
- end
63
-
64
- # Two comments can be merged if they are both line-comments and
65
- # they are separated only by whitespace (only one newline at the
66
- # end of the first comment is allowed)
67
- def mergeable?(c1, c2)
68
- if c1["type"] == "Line" && c2["type"] == "Line"
69
- /\A(\r\n|\n|\r)?[ \t]*\Z/ =~ @input.slice((c1["range"][1])..(c2["range"][0]-1))
70
- else
71
- false
72
- end
73
- end
74
-
75
- def locate_comments
76
- @ast["comments"].map do |comment|
77
- # Detect comment type and strip * at the beginning of doc-comment
78
- value = comment["value"]
79
- if comment["type"] == "Block" && value =~ /\A\*/
80
- type = :doc_comment
81
- value = value.slice(1, value.length-1)
82
- else
83
- type = :plain_comment
84
- end
85
-
86
- {
87
- :comment => value,
88
- :code => stuff_after(comment),
89
- :linenr => line_number(comment["range"][0]),
90
- :type => type,
91
- }
92
- end
93
- end
94
-
95
- # Given index inside input string, returns the corresponding line number
96
- def line_number(index)
97
- # To speed things up, remember the index until which we counted,
98
- # then next time just begin counting from there. This way we
99
- # only count each line once.
100
- @start_linenr = @input[@start_index...index].count("\n") + @start_linenr
101
- @start_index = index
102
- return @start_linenr
103
- end
104
-
105
- # Sees if there is some code following the comment.
106
- # Returns the code found. But if the comment is instead
107
- # followed by another comment, returns nil.
108
- def stuff_after(comment)
109
- code = code_after(comment["range"], @ast)
110
- if code && comment["next"]
111
- return code["range"][0] < comment["next"]["range"][0] ? code : nil
112
- else
113
- code
114
- end
115
- end
116
-
117
- # Looks for code following the given range.
118
- #
119
- # The second argument is the parent node within which we perform
120
- # our search.
121
- def code_after(range, parent)
122
- # Look through all child nodes of parent...
123
- child_nodes(parent).each do |node|
124
- if less(range, node["range"])
125
- # If node is after our range, then that's it. There could
126
- # be comments in our way, but that's taken care of in
127
- # #stuff_after method.
128
- return node
129
- elsif within(range, node["range"])
130
- # Our range is within the node --> recurse
131
- return code_after(range, node)
132
- end
133
- end
134
-
135
- return nil
136
- end
137
-
138
-
139
- # True if range A is less than range B
140
- def less(a, b)
141
- return a[1] <= b[0]
142
- end
143
-
144
- # True if range A is greater than range B
145
- def greater(a, b)
146
- return a[0] >= b[1]
147
- end
148
-
149
- # True if range A is within range B
150
- def within(a, b)
151
- return b[0] <= a[0] && a[1] <= b[1]
152
- end
153
-
154
-
155
- # Returns array of child nodes of given node
156
- def child_nodes(node)
157
- properties = NODE_TYPES[node["type"]]
158
-
159
- unless properties
160
- Logger.fatal("Unknown node type: "+node["type"])
161
- exit(1)
162
- end
163
-
164
- properties.map {|p| node[p] }.compact.flatten
165
- end
166
-
167
- # All possible node types in Esprima-created abstract syntax tree
168
- #
169
- # Each node type maps to list of properties of that node into
170
- # which we can recurse for further parsing.
171
- NODE_TYPES = {
172
- "Program" => ["body"],
173
-
174
- "BlockStatement" => ["body"],
175
- "BreakStatement" => [],
176
- "ContinueStatement" => [],
177
- "DoWhileStatement" => ["body", "test"],
178
- "DebuggerStatement" => [],
179
- "EmptyStatement" => [],
180
- "ExpressionStatement" => ["expression"],
181
- "ForStatement" => ["init", "test", "update", "body"],
182
- "ForInStatement" => ["left", "right", "body"],
183
- "IfStatement" => ["test", "consequent", "alternate"],
184
- "LabeledStatement" => ["body"],
185
- "ReturnStatement" => ["argument"],
186
- "SwitchStatement" => ["discriminant", "cases"],
187
- "SwitchCase" => ["test", "consequent"],
188
- "ThrowStatement" => ["argument"],
189
- "TryStatement" => ["block", "handlers", "finalizer"],
190
- "CatchClause" => ["param", "body"],
191
- "WhileStatement" => ["test", "body"],
192
- "WithStatement" => ["object", "body"],
193
-
194
- "FunctionDeclaration" => ["id", "params", "body"],
195
- "VariableDeclaration" => ["declarations"],
196
- "VariableDeclarator" => ["id", "init"],
197
-
198
- "AssignmentExpression" => ["left", "right"],
199
- "ArrayExpression" => ["elements"],
200
- "BinaryExpression" => ["left", "right"],
201
- "CallExpression" => ["callee", "arguments"],
202
- "ConditionalExpression" => ["test", "consequent", "alternate"],
203
- "FunctionExpression" => ["body"],
204
-
205
- "LogicalExpression" => ["left", "right"],
206
- "MemberExpression" => ["object", "property"],
207
- "NewExpression" => ["callee", "arguments"],
208
- "ObjectExpression" => ["properties"],
209
- "Property" => ["key", "value"],
210
-
211
- "SequenceExpression" => ["expressions"],
212
- "ThisExpression" => [],
213
- "UnaryExpression" => ["argument"],
214
- "UpdateExpression" => ["argument"],
215
-
216
- "Identifier" => [],
217
- "Literal" => [],
218
- }
219
-
220
- end
221
- end
data/lib/jsduck/lint.rb DELETED
@@ -1,133 +0,0 @@
1
- require 'jsduck/logger'
2
- require 'jsduck/class'
3
-
4
- module JsDuck
5
-
6
- # Reports bugs and problems in documentation
7
- class Lint
8
- attr_accessor :relations
9
-
10
- def initialize(relations)
11
- @relations = relations
12
- end
13
-
14
- # Runs the linter
15
- def run
16
- warn_no_doc
17
- warn_unnamed
18
- warn_optional_params
19
- warn_duplicate_params
20
- warn_duplicate_members
21
- warn_singleton_statics
22
- warn_empty_enums
23
- end
24
-
25
- # print warning for each member or parameter with no name
26
- def warn_unnamed
27
- each_member do |member|
28
- if !member[:name] || member[:name] == ""
29
- warn(:name_missing, "Unnamed #{member[:tagname]}", member)
30
- end
31
- (member[:params] || []).each do |p|
32
- if !p[:name] || p[:name] == ""
33
- warn(:name_missing, "Unnamed parameter", member)
34
- end
35
- end
36
- end
37
- end
38
-
39
- # print warning for each class or public member with no name
40
- def warn_no_doc
41
- @relations.each do |cls|
42
- if cls[:doc] == ""
43
- warn(:no_doc, "No documentation for #{cls[:name]}", cls)
44
- end
45
- end
46
- each_member do |member|
47
- if member[:doc] == "" && !member[:private] && !member[:meta][:hide] && !JsDuck::Class.constructor?(member)
48
- warn(:no_doc, "No documentation for #{member[:owner]}##{member[:name]}", member)
49
- end
50
- end
51
- end
52
-
53
- # print warning for each non-optional parameter that follows an optional parameter
54
- def warn_optional_params
55
- each_member do |member|
56
- if member[:tagname] == :method
57
- optional_found = false
58
- member[:params].each do |p|
59
- if optional_found && !p[:optional]
60
- warn(:req_after_opt, "Optional param followed by regular param #{p[:name]}", member)
61
- end
62
- optional_found = optional_found || p[:optional]
63
- end
64
- end
65
- end
66
- end
67
-
68
- # print warnings for duplicate parameter names
69
- def warn_duplicate_params
70
- each_member do |member|
71
- params = {}
72
- (member[:params] || []).each do |p|
73
- if params[p[:name]]
74
- warn(:dup_param, "Duplicate parameter name #{p[:name]}", member)
75
- end
76
- params[p[:name]] = true
77
- end
78
- end
79
- end
80
-
81
- # print warnings for duplicate member names
82
- def warn_duplicate_members
83
- @relations.each do |cls|
84
- members = {:members => {}, :statics => {}}
85
- cls.all_local_members.each do |m|
86
- group = (m[:meta] && m[:meta][:static]) ? :statics : :members
87
- type = m[:tagname]
88
- name = m[:name]
89
- hash = members[group][type] || {}
90
- if hash[name]
91
- warn(:dup_member, "Duplicate #{type} name #{name}", hash[name])
92
- warn(:dup_member, "Duplicate #{type} name #{name}", m)
93
- end
94
- hash[name] = m
95
- members[group][type] = hash
96
- end
97
- end
98
- end
99
-
100
- # Print warnings for static members in singleton classes
101
- def warn_singleton_statics
102
- @relations.each do |cls|
103
- if cls[:singleton]
104
- cls.find_members({:local => true, :static => true}).each do |m|
105
- warn(:sing_static, "Static members don't make sense in singleton class #{cls[:name]}", m)
106
- end
107
- end
108
- end
109
- end
110
-
111
- # print warnings for enums with no values
112
- def warn_empty_enums
113
- @relations.each do |cls|
114
- if cls[:enum] && cls[:members].length == 0
115
- warn(:enum, "Enum #{cls[:name]} defined without values in it", cls)
116
- end
117
- end
118
- end
119
-
120
- # Loops through all members of all classes
121
- def each_member(&block)
122
- @relations.each {|cls| cls.all_local_members.each(&block) }
123
- end
124
-
125
- # Prints warning + filename and linenumber from doc-context
126
- def warn(type, msg, member)
127
- context = member[:files][0]
128
- Logger.warn(type, msg, context[:filename], context[:linenr])
129
- end
130
-
131
- end
132
-
133
- end
@@ -1,88 +0,0 @@
1
- module JsDuck
2
-
3
- # Abstract base class for all meta tag implementations.
4
- #
5
- # Child classes must define value for @name attribute. They can
6
- # also provide @multiline, and override #to_html method.
7
- class MetaTag
8
- # Name of the tag (required)
9
- attr_reader :name
10
-
11
- # The key under which to store this tag. Must be a symbol. When
12
- # not provided then :name is converted to symbol and used as key.
13
- attr_accessor :key
14
-
15
- # The text to display in member signature. Must be a hash
16
- # defining the short and long versions of the signature text:
17
- #
18
- # {:long => "something", :short => "SOM"}
19
- #
20
- # Additionally the hash can contain a :tooltip which is the text
21
- # to be shown when the signature bubble is hovered over in docs.
22
- attr_reader :signature
23
-
24
- # True to include all lines up to next @tag as part of this meta-tag
25
- attr_reader :multiline
26
-
27
- # True to ignore any text after the @tag, just record the
28
- # existance of the tag.
29
- attr_reader :boolean
30
-
31
- # Whether to render the tag before other content (:top) or after
32
- # it (:bottom). Defaults to :bottom.
33
- attr_accessor :position
34
-
35
- # Here the appropriate class or member will be injected,
36
- # so the to_value and to_html methods can for produce
37
- # different output based on whether the tag is inside class,
38
- # method, event, etc.
39
- attr_accessor :context
40
-
41
- # Here the Assets object will be injected, so the Tag implementation
42
- # can access guides, videos, etc when he needs to.
43
- attr_accessor :assets
44
-
45
- # It gets passed an array of contents gathered from all meta-tags
46
- # of given type. It should return the value to be stored for this
47
- # meta-tag at :key. The returned value is also passed to #to_html
48
- # method. Returning nil will cause the tag to be ignored. By
49
- # default the contents are returned unchanged.
50
- def to_value(contents)
51
- contents
52
- end
53
-
54
- # Override this to transform the content of meta-tag to HTML to be
55
- # included into documentation.
56
- #
57
- # It gets passed the value returned by #to_value method. It should
58
- # return an HTML string to inject into document. For help in that
59
- # it can use the #format method to easily support Markdown and
60
- # {@link/img} tags inside the contents of meta-tag.
61
- #
62
- # By default the method returns nil, which means the tag will not
63
- # be rendered at all.
64
- def to_html(contents)
65
- end
66
-
67
- # This is used to inject the formatter object for #markdown method
68
- attr_accessor :formatter
69
-
70
- # Helper method to format the text in standard JsDuck way.
71
- # This means running it through Markdown engine and expanding
72
- # {@link} and {@img} tags.
73
- def format(text)
74
- @formatter.format(text)
75
- end
76
-
77
- # Returns all descendants of MetaTag class.
78
- def self.descendants
79
- result = []
80
- ObjectSpace.each_object(::Class) do |cls|
81
- result << cls if cls < self
82
- end
83
- result
84
- end
85
-
86
- end
87
-
88
- end
@@ -1,67 +0,0 @@
1
- require "jsduck/meta_tag"
2
-
3
- module JsDuck
4
-
5
- # Loader for built-in and user-defined meta-tags.
6
- class MetaTagLoader
7
- attr_reader :meta_tags
8
-
9
- def initialize
10
- @classes = []
11
- @meta_tags = []
12
- end
13
-
14
- # Loads user-defined meta-tags from given path.
15
- #
16
- # * If path is a directory, loads all *.rb files in it.
17
- # * If path is the symbol :builtins, loads the builtin
18
- # tags from ./tag dir.
19
- # * Otherwise loads tags from the single file.
20
- def load(path)
21
- if path == :builtins
22
- load(File.dirname(__FILE__) + "/tag")
23
- elsif File.directory?(path)
24
- # Sort paths, so they are always loaded in the same order.
25
- # This is important for signatures to always be rendered in
26
- # the same order.
27
- Dir[path+"/**/*.rb"].sort.each {|file| load_file(file) }
28
- else
29
- load_file(path)
30
- end
31
- end
32
-
33
- private
34
-
35
- # Loads just one file.
36
- def load_file(file)
37
- require(file)
38
- init_remaining
39
- end
40
-
41
- # Instantiates meta tag classes that haven't been instantiated
42
- # already. This is called after each meta-tags file is loaded so
43
- # that the list of meta-tags will be in order specified from
44
- # command line.
45
- def init_remaining
46
- MetaTag.descendants.each do |cls|
47
- if !@classes.include?(cls)
48
- @classes << cls
49
- newtag = create_tag(cls)
50
- @meta_tags = @meta_tags.find_all {|t| t.name != newtag.name }
51
- @meta_tags << newtag
52
- end
53
- end
54
- end
55
-
56
- # Instanciates tag class.
57
- # When .key is missing, creates it from .name
58
- # When .position is missing, defaults to :bottom
59
- def create_tag(cls)
60
- tag = cls.new
61
- tag.key = tag.name.to_sym unless tag.key
62
- tag.position = :bottom unless tag.position
63
- tag
64
- end
65
- end
66
-
67
- end