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
@@ -0,0 +1,21 @@
1
+ module JsDuck
2
+ module Js
3
+
4
+ # Helpers for handling the parsing of Ext.define definitions
5
+ class Utils
6
+ # When the value is string, returns the string, otherwise nil
7
+ def self.make_string(ast)
8
+ str = ast.to_value
9
+ str.is_a?(String) ? str : nil
10
+ end
11
+
12
+ # When the value is string or array of strings, returns array of
13
+ # strings. In any other case, returns empty array.
14
+ def self.make_string_list(ast)
15
+ strings = Array(ast.to_value)
16
+ strings.all? {|s| s.is_a?(String) } ? strings : []
17
+ end
18
+ end
19
+
20
+ end
21
+ end
data/lib/jsduck/logger.rb CHANGED
@@ -10,14 +10,8 @@ module JsDuck
10
10
  # Set to true to enable verbose logging
11
11
  attr_accessor :verbose
12
12
 
13
- # Set true to force colored output.
14
- # Set false to force no colors.
15
- attr_accessor :colors
16
-
17
13
  def initialize
18
14
  @verbose = false
19
- @colors = nil
20
-
21
15
  @warning_docs = [
22
16
  [:global, "Member doesn't belong to any class"],
23
17
  [:inheritdoc, "@inheritdoc referring to unknown class or member"],
@@ -34,11 +28,12 @@ module JsDuck
34
28
  [:dup_param, "Method has two parameters with the same name"],
35
29
  [:dup_member, "Class has two members with the same name"],
36
30
  [:req_after_opt, "Required parameter comes after optional"],
31
+ [:param_count, "Less parameters documented than detected from code"],
37
32
  [:subproperty, "@param foo.bar where foo param doesn't exist"],
38
33
  [:sing_static, "Singleton class member marked as @static"],
39
34
  [:type_syntax, "Syntax error in {type definition}"],
40
35
  [:type_name, "Unknown type referenced in {type definition}"],
41
- [:enum, "Enum defined without any values in it"],
36
+ [:enum, "Enum with invalid values of no values at all"],
42
37
 
43
38
  [:image, "{@img} referring to missing file"],
44
39
  [:image_unused, "An image exists in --images dir that's not used"],
@@ -140,11 +135,6 @@ module JsDuck
140
135
  $stderr.puts error.backtrace
141
136
  end
142
137
 
143
- # True when at least one warning was logged.
144
- def warnings_logged?
145
- @shown_warnings.length > 0
146
- end
147
-
148
138
  private
149
139
 
150
140
  COLORS = {
@@ -165,7 +155,7 @@ module JsDuck
165
155
  # Only does color output when STDERR is attached to TTY
166
156
  # i.e. is not piped/redirected.
167
157
  def paint(color_name, msg)
168
- if @colors == false || @colors == nil && (Util::OS.windows? || !$stderr.tty?)
158
+ if Util::OS.windows? || !$stderr.tty?
169
159
  msg
170
160
  else
171
161
  COLORS[color_name] + msg + CLEAR
@@ -38,7 +38,7 @@ module JsDuck
38
38
 
39
39
  # Returns array of all local members (excludes inherited ones)
40
40
  def all_local
41
- local_by_id.values.reject {|m| m[:meta] && m[:meta][:hide] }
41
+ local_by_id.values.reject {|m| m[:hide] }
42
42
  end
43
43
 
44
44
  # Clears the search cache.
@@ -67,7 +67,7 @@ module JsDuck
67
67
  end
68
68
 
69
69
  # Exclude all non-inheritable static members
70
- @global_map_by_id.delete_if {|id, m| m[:meta][:static] && !m[:inheritable] }
70
+ @global_map_by_id.delete_if {|id, m| m[:static] && !m[:inheritable] }
71
71
 
72
72
  merge!(@global_map_by_id, local_by_id)
73
73
  end
@@ -93,7 +93,7 @@ module JsDuck
93
93
  # merges second members hash into first one
94
94
  def merge!(hash1, hash2)
95
95
  hash2.each_pair do |name, m|
96
- if m[:meta] && m[:meta][:hide]
96
+ if m[:hide]
97
97
  if hash1[name]
98
98
  hash1.delete(name)
99
99
  else
@@ -133,7 +133,6 @@ module JsDuck
133
133
  new[:overrides] << {
134
134
  :name => old[:name],
135
135
  :owner => old[:owner],
136
- :id => old[:id],
137
136
  }
138
137
  end
139
138
  end
data/lib/jsduck/merger.rb CHANGED
@@ -1,178 +1,58 @@
1
1
  require 'jsduck/class'
2
+ require 'jsduck/tag_registry'
2
3
 
3
4
  module JsDuck
4
5
 
5
6
  # Takes data from comment and code that follows it and combines
6
7
  # these two pieces of information into one. The code comes from
7
- # JsDuck::Ast and comment from JsDuck::DocAst.
8
+ # JsDuck::JS::Ast and comment from JsDuck::Doc::Processor.
8
9
  #
9
10
  # The main method merge() produces a hash as a result.
10
11
  class Merger
11
12
 
12
13
  # Takes a docset and merges the :comment and :code inside it,
13
14
  # producing hash as a result.
14
- def merge(docset)
15
+ def merge(docset, filename="", linenr=0)
15
16
  docs = docset[:comment]
16
17
  code = docset[:code]
17
18
 
18
- case docset[:tagname]
19
- when :class
20
- result = merge_class(docs, code)
21
- when :method, :event, :css_mixin
22
- result = merge_like_method(docs, code)
23
- when :cfg, :property, :css_var
24
- result = merge_like_property(docs, code)
25
- end
26
-
27
- result[:linenr] = docset[:linenr]
28
-
29
- result
30
- end
31
-
32
- private
33
-
34
- def merge_class(docs, code)
35
- h = do_merge(docs, code, {
36
- :mixins => [],
37
- :alternateClassNames => [],
38
- :requires => [],
39
- :uses => [],
40
- :singleton => false,
41
- })
42
-
43
- # Ignore extending of the Object class
44
- h[:extends] = nil if h[:extends] == "Object"
45
-
46
- h[:aliases] = build_aliases_hash(h[:aliases] || [])
47
-
48
- # Used by Aggregator to determine if we're dealing with Ext4 code
49
- h[:code_type] = code[:code_type] if code[:code_type]
50
-
51
- h[:enum] = merge_enum(docs, code) if docs[:enum]
52
-
53
- h[:members] = []
54
-
55
- h
56
- end
57
-
58
- def merge_like_method(docs, code)
59
- h = do_merge(docs, code)
60
- h[:params] = merge_params(docs, code)
61
- h[:meta][:chainable] = code[:chainable] if code[:chainable]
62
- h
63
- end
64
-
65
- def merge_like_property(docs, code)
66
- h = do_merge(docs, code)
67
-
68
- h[:type] = merge_if_code_matches(:type, docs, code)
69
- if h[:type] == nil
70
- h[:type] = code[:tagname] == :method ? "Function" : "Object"
71
- end
72
-
73
- h[:default] = merge_if_code_matches(:default, docs, code)
74
- h
75
- end
76
-
77
- # --- helpers ---
19
+ h = {
20
+ :tagname => docset[:tagname],
21
+ :files => [{:filename => filename, :linenr => linenr}],
22
+ }
78
23
 
79
- def do_merge(docs, code, defaults={})
80
- h = {}
81
- docs.each_pair do |key, value|
82
- h[key] = docs[key] || code[key] || defaults[key]
83
- end
24
+ invoke_merge_in_tags(h, docs, code)
25
+ general_merge(h, docs, code)
84
26
 
85
- h[:name] = merge_name(docs, code)
27
+ # Needs to be calculated last, as it relies on the existance of
28
+ # :name, :static and :tagname fields.
86
29
  h[:id] = JsDuck::Class.member_id(h)
87
30
 
88
- # Copy private to meta
89
- h[:meta][:private] = h[:private] if h[:private]
90
-
91
- # Copy :static and :inheritable flags from code if present
92
- h[:meta][:static] = true if code[:meta] && code[:meta][:static]
93
- h[:inheritable] = true if code[:inheritable]
94
-
95
- # Remember auto-detection info
96
- h[:autodetected] = code[:autodetected] if code[:autodetected]
97
-
98
31
  h
99
32
  end
100
33
 
101
- # Given array of full alias names like "foo.bar", "foo.baz"
102
- # build hash like {"foo" => ["bar", "baz"]}
103
- def build_aliases_hash(aliases)
104
- hash={}
105
- aliases.each do |a|
106
- if a =~ /^([^.]+)\.(.+)$/
107
- if hash[$1]
108
- hash[$1] << $2
109
- else
110
- hash[$1] = [$2]
111
- end
112
- end
113
- end
114
- hash
115
- end
34
+ private
116
35
 
117
- def merge_params(docs, code)
118
- explicit = docs[:params] || []
119
- implicit = code_matches_doc?(docs, code) ? (code[:params] || []) : []
120
- # Override implicit parameters with explicit ones
121
- # But if explicit ones exist, don't append the implicit ones.
122
- params = []
123
- (explicit.length > 0 ? explicit.length : implicit.length).times do |i|
124
- im = implicit[i] || {}
125
- ex = explicit[i] || {}
126
- params << {
127
- :type => ex[:type] || im[:type] || "Object",
128
- :name => ex[:name] || im[:name] || "",
129
- :doc => ex[:doc] || im[:doc] || "",
130
- :optional => ex[:optional] || false,
131
- :default => ex[:default],
132
- :properties => ex[:properties] || [],
133
- }
36
+ # Invokes the #merge methods of tags registered for the given
37
+ # merge context.
38
+ def invoke_merge_in_tags(h, docs, code)
39
+ TagRegistry.mergers(h[:tagname]).each do |tag|
40
+ tag.merge(h, docs, code)
134
41
  end
135
- params
136
42
  end
137
43
 
138
- def merge_name(docs, code)
139
- if docs[:name]
140
- docs[:name]
141
- elsif code[:name]
142
- if docs[:tagname] == :class
143
- code[:name]
144
- else
145
- code[:name].split(/\./).last
146
- end
147
- else
148
- ""
44
+ # Applies default merge algorithm to the rest of the data.
45
+ def general_merge(h, docs, code)
46
+ # Merge in all items in docs that don't occour already in result.
47
+ docs.each_pair do |key, value|
48
+ h[key] = value unless h.has_key?(key)
149
49
  end
150
- end
151
-
152
- def merge_if_code_matches(key, docs, code, default=nil)
153
- if docs[key]
154
- docs[key]
155
- elsif code[key] && code_matches_doc?(docs, code)
156
- code[key]
157
- else
158
- default
50
+ # Then add all in the items from code not already in result.
51
+ code.each_pair do |key, value|
52
+ h[key] = value unless h.has_key?(key)
159
53
  end
160
54
  end
161
55
 
162
- # True if the name detected from code matches with explicitly documented name.
163
- # Also true when no explicit name documented.
164
- def code_matches_doc?(docs, code)
165
- return docs[:name] == nil || docs[:name] == code[:name]
166
- end
167
-
168
- # Takes the :enum always from docs, but the :doc_only can come
169
- # from either code or docs.
170
- def merge_enum(docs, code)
171
- enum = docs[:enum]
172
- enum[:doc_only] = docs[:enum][:doc_only] || (code[:enum] && code[:enum][:doc_only])
173
- enum
174
- end
175
-
176
56
  end
177
57
 
178
58
  end
@@ -1,10 +1,11 @@
1
1
  require 'jsduck/option_parser'
2
- require 'jsduck/meta_tag_registry'
3
2
  require 'jsduck/logger'
4
3
  require 'jsduck/util/json'
5
4
  require 'jsduck/util/os'
6
5
  require 'jsduck/util/io'
7
6
  require 'jsduck/util/parallel'
7
+ require 'jsduck/tag_registry'
8
+ require 'jsduck/js/ext_patterns'
8
9
 
9
10
  module JsDuck
10
11
 
@@ -23,7 +24,6 @@ module JsDuck
23
24
  attr_accessor :footer
24
25
  attr_accessor :head_html
25
26
  attr_accessor :body_html
26
- attr_accessor :message
27
27
  attr_accessor :welcome
28
28
  attr_accessor :guides
29
29
  attr_accessor :videos
@@ -40,11 +40,9 @@ module JsDuck
40
40
  attr_accessor :tests
41
41
  attr_accessor :comments_url
42
42
  attr_accessor :comments_domain
43
- attr_accessor :search
44
43
  attr_accessor :ignore_html
45
44
 
46
45
  # Debugging
47
- attr_accessor :warnings_exit_nonzero
48
46
  attr_accessor :template_dir
49
47
  attr_accessor :template_links
50
48
  attr_accessor :extjs_path
@@ -92,17 +90,15 @@ module JsDuck
92
90
  "Mixed",
93
91
  ]
94
92
  @ext4_events = nil
95
- @meta_tag_paths = []
96
93
 
97
- @version = "4.10.4"
94
+ @version = "5.0.0.beta01"
98
95
 
99
96
  # Customizing output
100
97
  @title = "Documentation - JSDuck"
101
98
  @header = "<strong>Documentation</strong> JSDuck"
102
- @footer = format_footer("Generated on {DATE} by {JSDUCK} {VERSION}.")
99
+ @footer = "Generated with <a href='https://github.com/senchalabs/jsduck'>JSDuck</a> #{@version}."
103
100
  @head_html = ""
104
101
  @body_html = ""
105
- @message = ""
106
102
  @welcome = nil
107
103
  @guides = nil
108
104
  @videos = nil
@@ -110,6 +106,7 @@ module JsDuck
110
106
  @categories_path = nil
111
107
  @source = true
112
108
  @images = []
109
+ @custom_tag_paths = []
113
110
  @link_tpl = '<a href="#!/api/%c%-%m" rel="%c%-%m" class="docClass">%a</a>'
114
111
  # Note that we wrap image template inside <p> because {@img} often
115
112
  # appears inline within text, but that just looks ugly in HTML
@@ -121,11 +118,9 @@ module JsDuck
121
118
  @tests = false
122
119
  @comments_url = nil
123
120
  @comments_domain = nil
124
- @search = {}
125
121
  @ignore_html = {}
126
122
 
127
123
  # Debugging
128
- @warnings_exit_nonzero = false
129
124
  @root_dir = File.dirname(File.dirname(File.dirname(__FILE__)))
130
125
  @template_dir = @root_dir + "/template-min"
131
126
  @template_links = false
@@ -133,7 +128,6 @@ module JsDuck
133
128
  @data_path = nil # This gets assigned in JsDuck::WebWriter after writing the data file.
134
129
  @local_storage_db = "docs"
135
130
  @touch_examples_ui = false
136
- @ext_namespaces = ["Ext"]
137
131
  @imports = []
138
132
  @new_since = nil
139
133
 
@@ -143,31 +137,29 @@ module JsDuck
143
137
  # enable all warnings except :link_auto
144
138
  Logger.set_warning(:all, true)
145
139
  Logger.set_warning(:link_auto, false)
146
-
147
- @optparser = create_option_parser
140
+ Logger.set_warning(:param_count, false)
148
141
  end
149
142
 
150
143
  # Make options object behave like hash.
151
144
  # This allows us to substitute it with hash in unit tests.
152
145
  def [](key)
153
- send(key)
146
+ instance_variable_get("@#{key}")
147
+ end
148
+ def []=(key, value)
149
+ instance_variable_set("@#{key}", value)
154
150
  end
155
151
 
156
152
  def parse!(argv)
157
- parse_options(argv)
158
- auto_detect_config_file
153
+ create_option_parser.parse!(argv).each do |fname|
154
+ read_filenames(canonical(fname))
155
+ end
159
156
  validate
160
157
 
161
- reg = MetaTagRegistry.new
162
- reg.load([:builtins] + @meta_tag_paths)
163
- reg[:new].create_tooltip!(@imports, @new_since)
164
- MetaTagRegistry.instance = reg
158
+ @custom_tag_paths.each {|path| TagRegistry.load_from(path) }
165
159
  end
166
160
 
167
- private
168
-
169
161
  def create_option_parser
170
- return JsDuck::OptionParser.new do | opts |
162
+ optparser = JsDuck::OptionParser.new do | opts |
171
163
  opts.banner = "Usage: jsduck [options] files/dirs..."
172
164
  opts.separator ""
173
165
  opts.separator "For example:"
@@ -235,9 +227,6 @@ module JsDuck
235
227
  "",
236
228
  "An alternative to listing all options on command line.",
237
229
  "",
238
- "When the current directory contains jsduck.json file",
239
- "then options are automatically read from there.",
240
- "",
241
230
  "See also: https://github.com/senchalabs/jsduck/wiki/Config-file") do |path|
242
231
  path = canonical(path)
243
232
  if File.exists?(path)
@@ -249,7 +238,7 @@ module JsDuck
249
238
  # treat paths inside JSON config relative to the location of
250
239
  # config file. When done, switch back to current working dir.
251
240
  @working_dir = File.dirname(path)
252
- parse_options(config)
241
+ optparser.parse!(config).each {|fname| read_filenames(canonical(fname)) }
253
242
  @working_dir = nil
254
243
  end
255
244
 
@@ -276,14 +265,11 @@ module JsDuck
276
265
  opts.on('--footer=TEXT',
277
266
  "Custom footer text for the documentation.",
278
267
  "",
279
- "The text can contain various placeholders:",
280
- "",
281
- " {DATE} - current date and time.",
282
- " {JSDUCK} - link to JSDuck homepage.",
283
- " {VERSION} - JSDuck version number.",
268
+ "Defaults to: 'Generated with JSDuck {VERSION}.'",
284
269
  "",
285
- "Defaults to: 'Generated on {DATE} by {JSDUCK} {VERSION}.'") do |text|
286
- @footer = format_footer(text)
270
+ "'{VERSION}' is a placeholder that will get substituted",
271
+ "with the current version of JSDuck. See --version.") do |text|
272
+ @footer = text.gsub(/\{VERSION\}/, @version)
287
273
  end
288
274
 
289
275
  opts.on('--head-html=HTML',
@@ -306,15 +292,6 @@ module JsDuck
306
292
  @body_html += html
307
293
  end
308
294
 
309
- opts.on('--message=HTML',
310
- "(Warning) message to show prominently.",
311
- "",
312
- "Useful for warning users that they are viewing an old",
313
- "version of the docs, and prividing a link to the new",
314
- "version.") do |html|
315
- @message += html
316
- end
317
-
318
295
  opts.on('--welcome=PATH',
319
296
  "File with content for welcome page.",
320
297
  "",
@@ -401,7 +378,7 @@ module JsDuck
401
378
  "a @new tag (unless --new-since option is used).",
402
379
  "",
403
380
  "See also: https://github.com/senchalabs/jsduck/wiki/@since") do |v|
404
- if v =~ /\A(.*?):(.*)\Z/
381
+ if v =~ /\A(.*?):(.*)\z/
405
382
  @imports << {:version => $1, :path => canonical($2)}
406
383
  else
407
384
  @imports << {:version => v}
@@ -428,8 +405,6 @@ module JsDuck
428
405
  end
429
406
 
430
407
  opts.on('--comments-domain=STRING',
431
- "A name identifying the subset of comments.",
432
- "",
433
408
  "A string consisting of <name>/<version>.",
434
409
  "",
435
410
  "For example: ext-js/4",
@@ -438,51 +413,20 @@ module JsDuck
438
413
  @comments_domain = domain
439
414
  end
440
415
 
441
- opts.on('--search-url=URL',
442
- "Address of guides search server.",
443
- "",
444
- "When supplied, the search for guides is performed through this",
445
- "external service and the results merged together with API search.",
446
- "The search server must respond to JSONP requests.",
447
- "",
448
- "For example: http://sencha.com/docsearch",
449
- "",
450
- "Must be used together with --search-domain option.",
451
- "",
452
- "This option is EXPERIMENTAL.") do |url|
453
- @search[:url] = url
454
- end
455
-
456
- opts.on('--search-domain=STRING',
457
- "A name identifying the subset to search from.",
458
- "",
459
- "A string consisting of <name>/<version>.",
460
- "",
461
- "Tells the search engine which product and version",
462
- "to include into search.",
463
- "",
464
- "For example: Ext JS/4.2.0",
465
- "",
466
- "Must be used together with --search-url option.",
467
- "",
468
- "This option is EXPERIMENTAL.") do |domain|
469
- @search[:product], @search[:version] = domain.split(/\//)
470
- end
471
-
472
416
  opts.separator ""
473
417
  opts.separator "Tweaking:"
474
418
  opts.separator ""
475
419
 
476
- opts.on('--meta-tags=PATH',
477
- "Path to custom meta-tag implementations.",
420
+ opts.on('--tags=PATH',
421
+ "Path to custom tag implementations.",
478
422
  "",
479
423
  "Can be a path to single Ruby file or a directory.",
480
424
  "",
481
425
  "This option can be used repeatedly to include multiple",
482
- "meta tags from different places.",
426
+ "tags from different places.",
483
427
  "",
484
428
  "See also: https://github.com/senchalabs/jsduck/wiki/Custom-tags") do |path|
485
- @meta_tag_paths << canonical(path)
429
+ @custom_tag_paths << canonical(path)
486
430
  end
487
431
 
488
432
  opts.on('--ignore-global',
@@ -590,8 +534,8 @@ module JsDuck
590
534
  "In such case pass --ext-namespaces=Ext,YourNS option",
591
535
  "and JSDuck will recognize both Ext.define() and",
592
536
  "YourNs.define() plus few other things that depend on",
593
- "Ext namespace like Ext.emptyFn.") do |ns|
594
- @ext_namespaces = ns
537
+ "Ext namespace like Ext.emptyFn.") do |namespaces|
538
+ Js::ExtPatterns.set(namespaces)
595
539
  end
596
540
 
597
541
  opts.on('--touch-examples-ui',
@@ -624,7 +568,7 @@ module JsDuck
624
568
  opts.on('-v', '--verbose',
625
569
  "Turns on excessive logging.",
626
570
  "",
627
- "Log messages are written to STDERR.") do
571
+ "Log messages are writted to STDERR.") do
628
572
  Logger.verbose = true
629
573
  end
630
574
 
@@ -646,26 +590,6 @@ module JsDuck
646
590
  end
647
591
  end
648
592
 
649
- opts.on('--warnings-exit-nonzero',
650
- "Exits with non-zero exit code on warnings.",
651
- "",
652
- "By default JSDuck only exits with non-zero exit code",
653
- "when a fatal error is encountered (code 1).",
654
- "",
655
- "With this option the exit code will be 2 when any warning",
656
- "gets printed.") do
657
- @warnings_exit_nonzero = true
658
- end
659
-
660
- opts.on('--[no-]color',
661
- "Turn on/off colorized terminal output.",
662
- "",
663
- "By default the colored output is on, but gets disabled",
664
- "automatically when output is not an interactive terminal",
665
- "(or when running on Windows system).") do |on|
666
- Logger.colors = on
667
- end
668
-
669
593
  opts.on('-p', '--processes=COUNT',
670
594
  "The number of parallel processes to use.",
671
595
  "",
@@ -704,14 +628,6 @@ module JsDuck
704
628
  @template_links = true
705
629
  end
706
630
 
707
- opts.on('-d', '--debug',
708
- "Same as --template=template --template-links.",
709
- "",
710
- "Useful shorthand during development.") do
711
- @template_dir = canonical("template")
712
- @template_links = true
713
- end
714
-
715
631
  opts.on('--extjs-path=PATH',
716
632
  "Path for main ExtJS JavaScript file.",
717
633
  "",
@@ -753,20 +669,8 @@ module JsDuck
753
669
  exit
754
670
  end
755
671
  end
756
- end
757
-
758
- # Parses the given command line options
759
- # (could have also been read from config file)
760
- def parse_options(options)
761
- @optparser.parse!(options).each {|fname| read_filenames(canonical(fname)) }
762
- end
763
672
 
764
- # Reads jsduck.json file in current directory
765
- def auto_detect_config_file
766
- fname = Dir.pwd + "/jsduck.json"
767
- if File.exists?(fname)
768
- parse_options(read_json_config(fname))
769
- end
673
+ return optparser
770
674
  end
771
675
 
772
676
  # Reads JSON configuration from file and returns an array of
@@ -829,13 +733,6 @@ module JsDuck
829
733
  File.expand_path(path, @working_dir)
830
734
  end
831
735
 
832
- # Replace special placeholders in footer text
833
- def format_footer(text)
834
- jsduck = "<a href='https://github.com/senchalabs/jsduck'>JSDuck</a>"
835
- date = Time.new.strftime('%a %d %b %Y %H:%M:%S')
836
- text.gsub(/\{VERSION\}/, @version).gsub(/\{JSDUCK\}/, jsduck).gsub(/\{DATE\}/, date)
837
- end
838
-
839
736
  # Runs checks on the options
840
737
  def validate
841
738
  if @input_files.length == 0 && !@welcome && !@guides && !@videos && !@examples