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,99 @@
1
+ require 'jsduck/util/html'
2
+ require 'jsduck/util/singleton'
3
+
4
+ module JsDuck
5
+ module Render
6
+
7
+ # Renders params, return values and everything else that can have
8
+ # nested subproperties.
9
+ class Subproperties
10
+ include Util::Singleton
11
+
12
+ # Renders object properties, which could also be functions in
13
+ # which case they will be rendered with parameters and return
14
+ # value.
15
+ def render(item)
16
+ doc = []
17
+
18
+ if item[:type] == "Function"
19
+ params = item[:properties]
20
+ # If the name of last property is "return" remove it from
21
+ # properties list and format as a return value afterwards.
22
+ if item[:properties].last[:name] == "return"
23
+ ret = params.last
24
+ params = params.slice(0, params.length-1)
25
+ end
26
+
27
+ doc << render_params(params)
28
+ doc << render_return(ret) if ret
29
+ else
30
+ doc << render_list(item[:properties])
31
+ end
32
+
33
+ doc
34
+ end
35
+
36
+ def render_params(params)
37
+ return [
38
+ '<h3 class="pa">Parameters</h3>',
39
+ render_list(params),
40
+ ]
41
+ end
42
+
43
+ def render_list(params)
44
+ return [
45
+ "<ul>",
46
+ params.map {|p| render_single_param(p) },
47
+ "</ul>",
48
+ ]
49
+ end
50
+
51
+ def render_single_param(p)
52
+ return [
53
+ "<li>",
54
+ "<span class='pre'>#{p[:name]}</span> : ",
55
+ p[:html_type],
56
+ p[:optional] ? " (optional)" : "",
57
+ "<div class='sub-desc'>",
58
+ p[:doc],
59
+ p[:default] ? "<p>Defaults to: <code>#{Util::HTML.escape(p[:default])}</code></p>" : "",
60
+ p[:properties] && p[:properties].length > 0 ? render(p) : "",
61
+ "</div>",
62
+ "</li>",
63
+ ]
64
+ end
65
+
66
+ def render_return(ret)
67
+ return [
68
+ "<h3 class='pa'>Returns</h3>",
69
+ "<ul>",
70
+ "<li>",
71
+ "<span class='pre'>#{ret[:html_type]}</span>",
72
+ "<div class='sub-desc'>",
73
+ ret[:doc],
74
+ ret[:properties] && ret[:properties].length > 0 ? render(ret) : "",
75
+ "</div>",
76
+ "</li>",
77
+ "</ul>",
78
+ ]
79
+ end
80
+
81
+ def render_throws(throws)
82
+ return [
83
+ "<h3 class='pa'>Throws</h3>",
84
+ "<ul>",
85
+ throws.map do |thr|
86
+ [
87
+ "<li>",
88
+ "<span class='pre'>#{thr[:html_type]}</span>",
89
+ "<div class='sub-desc'>#{thr[:doc]}</div>",
90
+ "</li>",
91
+ ]
92
+ end,
93
+ "</ul>",
94
+ ]
95
+ end
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,38 @@
1
+ require 'jsduck/tag_registry'
2
+
3
+ module JsDuck
4
+ module Render
5
+
6
+ # Performs the rendering of tags.
7
+ class Tags
8
+ # Renders tags of a particular section.
9
+ #
10
+ # Takes member or class hash.
11
+ # Returns array of rendered HTML.
12
+ def self.render(member)
13
+ TagRegistry.html_renderers.map do |tag|
14
+ if member[tag.tagname]
15
+ tag.to_html(member)
16
+ else
17
+ nil
18
+ end
19
+ end
20
+ end
21
+
22
+ # Renders the signatures for a class member.
23
+ # Returns a string.
24
+ def self.render_signature(member)
25
+ html = []
26
+ TagRegistry.signatures.each do |s|
27
+ if member[s[:tagname]]
28
+ title = s[:tooltip] ? "title='#{s[:tooltip]}'" : ""
29
+ html << "<span class='#{s[:tagname]}' #{title}>#{s[:long]}</span>"
30
+ end
31
+ end
32
+ '<span class="signature">' + html.join + "</span>"
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -1,5 +1,6 @@
1
1
  require 'jsduck/icons'
2
2
  require 'jsduck/class_name'
3
+ require 'jsduck/tag_registry'
3
4
 
4
5
  module JsDuck
5
6
 
@@ -8,7 +9,7 @@ module JsDuck
8
9
  class SearchData
9
10
  # Given list of classes and other assets, returns an array of
10
11
  # hashes describing the search data.
11
- def create(classes, assets, opts)
12
+ def create(classes, assets)
12
13
  list = []
13
14
 
14
15
  classes.each do |cls|
@@ -24,14 +25,13 @@ module JsDuck
24
25
  end
25
26
  end
26
27
 
27
- # add all local members, but skip hidden members and constructors
28
+ # add all local members, but skip constructors
28
29
  cls[:members].each do |m|
29
- list << member_node(m, cls) unless m[:meta][:hide] || constructor?(m)
30
+ list << member_node(m, cls) unless m[:name] == ClassName.short(cls[:name])
30
31
  end
31
32
  end
32
33
 
33
- # Don't include guides data when separate guides search engine is provided
34
- assets.guides.each_item {|g| list << guide_node(g) } unless opts.search[:url]
34
+ assets.guides.each_item {|g| list << guide_node(g) }
35
35
 
36
36
  assets.videos.each_item {|v| list << video_node(v) }
37
37
 
@@ -42,17 +42,13 @@ module JsDuck
42
42
 
43
43
  private
44
44
 
45
- def constructor?(m)
46
- m[:tagname] == :method && m[:name] == "constructor"
47
- end
48
-
49
45
  def alias_node(key, name, cls)
50
46
  return {
51
47
  :name => name,
52
48
  :fullName => alias_display_name(key)+": "+name,
53
49
  :icon => Icons::class_icon(cls) + "-redirect",
54
50
  :url => "#!/api/" + cls[:name],
55
- :meta => cls[:meta],
51
+ :meta => combine_meta(cls),
56
52
  :sort => 0,
57
53
  }
58
54
  end
@@ -63,7 +59,7 @@ module JsDuck
63
59
  :fullName => cls[:name],
64
60
  :icon => Icons::class_icon(cls),
65
61
  :url => "#!/api/" + cls[:name],
66
- :meta => cls[:meta],
62
+ :meta => combine_meta(cls),
67
63
  :sort => 1,
68
64
  }
69
65
  end
@@ -75,7 +71,7 @@ module JsDuck
75
71
  :type => :class,
76
72
  :icon => Icons::class_icon(cls) + "-redirect",
77
73
  :url => "#!/api/" + cls[:name],
78
- :meta => cls[:meta],
74
+ :meta => combine_meta(cls),
79
75
  :sort => 2,
80
76
  }
81
77
  end
@@ -86,7 +82,7 @@ module JsDuck
86
82
  :fullName => cls[:name] + "." + member[:name],
87
83
  :icon => "icon-" + member[:tagname].to_s,
88
84
  :url => "#!/api/" + cls[:name] + "-" + member[:id],
89
- :meta => member[:meta],
85
+ :meta => combine_meta(member),
90
86
  :sort => 3,
91
87
  }
92
88
  end
@@ -124,6 +120,16 @@ module JsDuck
124
120
  }
125
121
  end
126
122
 
123
+ # Add data for builtin tags with signatures to :meta field.
124
+ def combine_meta(hash)
125
+ meta = {}
126
+ TagRegistry.signatures.each do |s|
127
+ name = s[:tagname]
128
+ meta[name] = hash[name] if hash[name]
129
+ end
130
+ meta
131
+ end
132
+
127
133
  # Some alias types are shown differently.
128
134
  # e.g. instead of "widget:" we show "xtype:"
129
135
  def alias_display_name(key)
@@ -1,4 +1,3 @@
1
- require 'jsduck/source/file_parser'
2
1
  require 'jsduck/util/html'
3
2
 
4
3
  module JsDuck
@@ -14,16 +13,15 @@ module JsDuck
14
13
  attr_reader :docs
15
14
  attr_reader :html_filename
16
15
 
17
- def initialize(contents, filename="", options={})
16
+ def initialize(contents, docs, filename="")
18
17
  @contents = contents
18
+ @docs = docs
19
19
  @filename = filename
20
20
  @html_filename = ""
21
21
  @links = {}
22
22
 
23
- @docs = Source::FileParser.new.parse(@contents, @filename, options)
24
-
25
23
  @docs.map do |docset|
26
- link(docset[:linenr], docset)
24
+ link(docset)
27
25
  end
28
26
  end
29
27
 
@@ -76,20 +74,13 @@ module JsDuck
76
74
  private
77
75
 
78
76
  # Creates two-way link between sourcefile and doc-object.
79
- # If doc-object is class, links also the contained cfgs and constructor.
80
77
  # Returns the modified doc-object after done.
81
- def link(linenr, doc)
78
+ def link(docset)
79
+ file = docset[:files].first
80
+ linenr = file[:linenr]
82
81
  @links[linenr] = [] unless @links[linenr]
83
- file = {
84
- :filename => @filename,
85
- :linenr => linenr,
86
- }
87
- @links[linenr] << {:doc => doc, :file => file}
88
- doc[:files] = [file]
89
- if doc[:tagname] == :class
90
- doc[:members].each {|m| link(linenr, m) }
91
- end
92
- doc
82
+ @links[linenr] << {:doc => docset, :file => file}
83
+ docset
93
84
  end
94
85
 
95
86
  end
@@ -1,14 +1,11 @@
1
- require "jsduck/meta_tag"
1
+ require "jsduck/tag/boolean_tag"
2
2
 
3
3
  module JsDuck::Tag
4
- # Implementation of @abstract tag
5
- class Abstract < JsDuck::MetaTag
4
+ class Abstract < BooleanTag
6
5
  def initialize
7
- @name = "abstract"
8
- @key = :abstract
6
+ @pattern = "abstract"
9
7
  @signature = {:long => "abstract", :short => "ABS"}
10
- @boolean = true
8
+ super
11
9
  end
12
10
  end
13
11
  end
14
-
@@ -0,0 +1,10 @@
1
+ require "jsduck/tag/boolean_tag"
2
+
3
+ module JsDuck::Tag
4
+ class Accessor < BooleanTag
5
+ def initialize
6
+ @pattern = "accessor"
7
+ super
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,61 @@
1
+ require "jsduck/tag/inheritdoc"
2
+ require "jsduck/js/utils"
3
+
4
+ module JsDuck::Tag
5
+ class Alias < Inheritdoc
6
+ def initialize
7
+ @pattern = "alias"
8
+ @tagname = :aliases
9
+ @ext_define_pattern = "alias"
10
+ @ext_define_default = {:aliases => []}
11
+ @merge_context = :class
12
+ end
13
+
14
+ # For backwards compatibility decide whether the @alias was used
15
+ # as @inheritdoc (@alias used to have the meaning of @inheritdoc
16
+ # before) or as a real Ext4 style alias definition.
17
+ def parse_doc(p)
18
+ if p.look(/([\w.]+)?#\w+/)
19
+ parse_as_inheritdoc(p)
20
+ else
21
+ parse_as_alias(p)
22
+ end
23
+ end
24
+
25
+ # @alias widget.foo
26
+ def parse_as_alias(p)
27
+ {
28
+ :tagname => :aliases,
29
+ :name => p.ident_chain,
30
+ }
31
+ end
32
+
33
+ def process_doc(h, tags, pos)
34
+ h[:aliases] = tags.map {|tag| tag[:name] }
35
+ end
36
+
37
+ def parse_ext_define(cls, ast)
38
+ cls[:aliases] += JsDuck::Js::Utils.make_string_list(ast)
39
+ end
40
+
41
+ def merge(h, docs, code)
42
+ h[:aliases] = build_aliases_hash(docs[:aliases] || code[:aliases] || [])
43
+ end
44
+
45
+ # Given array of full alias names like "foo.bar", "foo.baz"
46
+ # build hash like {"foo" => ["bar", "baz"]}
47
+ def build_aliases_hash(aliases)
48
+ hash={}
49
+ aliases.each do |a|
50
+ if a =~ /^([^.]+)\.(.+)$/
51
+ if hash[$1]
52
+ hash[$1] << $2
53
+ else
54
+ hash[$1] = [$2]
55
+ end
56
+ end
57
+ end
58
+ hash
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,17 @@
1
+ require "jsduck/tag/class_list_tag"
2
+
3
+ module JsDuck::Tag
4
+ class AlternateClassNames < ClassListTag
5
+ def initialize
6
+ @pattern = ["alternateClassName", "alternateClassNames"]
7
+ @tagname = :alternateClassNames
8
+ @ext_define_pattern = "alternateClassName"
9
+ @ext_define_default = {:alternateClassNames => []}
10
+ @merge_context = :class
11
+ end
12
+
13
+ def merge(h, docs, code)
14
+ h[@tagname] = docs[@tagname] || code[@tagname] || []
15
+ end
16
+ end
17
+ end
@@ -1,38 +1,33 @@
1
- require "jsduck/meta_tag"
1
+ require "jsduck/tag/tag"
2
2
  require "jsduck/logger"
3
3
 
4
4
  module JsDuck::Tag
5
- # Implementation of @aside tag.
6
- class Aside < JsDuck::MetaTag
5
+ class Aside < Tag
7
6
  def initialize
8
- @name = "aside"
9
- @key = :aside
10
- @position = :top
11
- @allowed_types = {
12
- :guide => true,
13
- :video => true,
14
- :example => true,
7
+ @pattern = "aside"
8
+ @tagname = :aside
9
+ @html_position = POS_ASIDE
10
+ end
11
+
12
+ # Parses: @aside [ guide | video| example ] name
13
+ def parse_doc(p)
14
+ {
15
+ :tagname => :aside,
16
+ :type => aside_type(p),
17
+ :name => p.hw.ident,
15
18
  }
16
19
  end
17
20
 
18
- def to_value(asides)
19
- asides.map do |line|
20
- if line =~ /\A(\w+) +([^ ].*)\Z/
21
- type = $1.to_sym
22
- name = $2.strip
23
- if @allowed_types[type]
24
- {:type => type, :name => name}
25
- else
26
- warn("Unknown @aside type: #{type}")
27
- end
28
- else
29
- warn("Bad syntax: @aside #{line}")
30
- end
31
- end.compact
21
+ def aside_type(p)
22
+ p.look(/\w+/) ? p.ident.to_sym : nil
32
23
  end
33
24
 
34
- def to_html(asides)
35
- asides.map do |aside|
25
+ def process_doc(h, tags, pos)
26
+ h[:aside] = tags
27
+ end
28
+
29
+ def to_html(context)
30
+ context[:aside].map do |aside|
36
31
  type = aside[:type]
37
32
  name = aside[:name]
38
33
  assets_group = get_assets_group(type)
@@ -49,11 +44,14 @@ module JsDuck::Tag
49
44
  </div>
50
45
  EOHTML
51
46
  else
52
- warn("Unknown @aside name: #{type} #{name}")
47
+ warn("Unknown @aside name: #{type} #{name}", context)
53
48
  end
54
49
  end.compact
55
50
  end
56
51
 
52
+ # special accessor for @aside alone through which assets are set
53
+ attr_accessor :assets
54
+
57
55
  def get_assets_group(type)
58
56
  case type
59
57
  when :guide then @assets.guides
@@ -63,12 +61,11 @@ module JsDuck::Tag
63
61
  end
64
62
  end
65
63
 
66
- def warn(msg)
67
- ctx = @context ? @context[:files][0] : {}
68
- JsDuck::Logger.warn(:aside, msg, ctx[:filename], ctx[:linenr])
64
+ def warn(msg, context)
65
+ file = context[:files][0]
66
+ JsDuck::Logger.warn(:aside, msg, file[:filename], file[:linenr])
69
67
  nil
70
68
  end
71
69
 
72
70
  end
73
71
  end
74
-