yard 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of yard might be problematic. Click here for more details.

Files changed (204) hide show
  1. data/LICENSE +1 -1
  2. data/README.markdown +200 -0
  3. data/Rakefile +6 -1
  4. data/benchmarks/format_args.rb +46 -0
  5. data/benchmarks/parsing.rb +13 -1
  6. data/benchmarks/rdoc_vs_yardoc.rb +10 -0
  7. data/benchmarks/ripper_parser.rb +12 -0
  8. data/docs/CODE_OBJECTS.markdown +121 -0
  9. data/docs/FAQ.markdown +34 -0
  10. data/docs/GENERATORS.markdown +211 -0
  11. data/docs/GETTING_STARTED.markdown +263 -0
  12. data/docs/GLOSSARY.markdown +13 -0
  13. data/docs/HANDLERS.markdown +158 -0
  14. data/docs/OVERVIEW.markdown +64 -0
  15. data/docs/PARSER.markdown +180 -0
  16. data/docs/TAGS.markdown +181 -0
  17. data/docs/WHATSNEW.markdown +96 -0
  18. data/docs/images/code-objects-class-diagram.png +0 -0
  19. data/docs/images/handlers-class-diagram.png +0 -0
  20. data/docs/images/overview-class-diagram.png +0 -0
  21. data/docs/images/parser-class-diagram.png +0 -0
  22. data/docs/images/tags-class-diagram.png +0 -0
  23. data/lib/yard.rb +4 -1
  24. data/lib/yard/autoload.rb +79 -31
  25. data/lib/yard/cli/yard_graph.rb +8 -2
  26. data/lib/yard/cli/yardoc.rb +61 -8
  27. data/lib/yard/code_objects/base.rb +78 -135
  28. data/lib/yard/code_objects/class_object.rb +9 -8
  29. data/lib/yard/code_objects/constant_object.rb +1 -0
  30. data/lib/yard/code_objects/extended_method_object.rb +9 -0
  31. data/lib/yard/code_objects/method_object.rb +18 -5
  32. data/lib/yard/code_objects/module_object.rb +8 -1
  33. data/lib/yard/code_objects/namespace_object.rb +25 -16
  34. data/lib/yard/code_objects/proxy.rb +22 -22
  35. data/lib/yard/core_ext/file.rb +1 -1
  36. data/lib/yard/core_ext/string.rb +0 -4
  37. data/lib/yard/core_ext/symbol_hash.rb +3 -2
  38. data/lib/yard/docstring.rb +180 -0
  39. data/lib/yard/generators/base.rb +33 -13
  40. data/lib/yard/generators/class_generator.rb +4 -2
  41. data/lib/yard/generators/constants_generator.rb +3 -2
  42. data/lib/yard/generators/full_doc_generator.rb +76 -9
  43. data/lib/yard/generators/helpers/base_helper.rb +18 -1
  44. data/lib/yard/generators/helpers/filter_helper.rb +2 -2
  45. data/lib/yard/generators/helpers/html_helper.rb +94 -39
  46. data/lib/yard/generators/helpers/html_syntax_highlight_helper.rb +49 -0
  47. data/lib/yard/generators/helpers/markup_helper.rb +86 -0
  48. data/lib/yard/generators/helpers/method_helper.rb +23 -7
  49. data/lib/yard/generators/method_generator.rb +15 -3
  50. data/lib/yard/generators/method_listing_generator.rb +3 -3
  51. data/lib/yard/generators/mixins_generator.rb +8 -2
  52. data/lib/yard/generators/module_generator.rb +3 -2
  53. data/lib/yard/generators/overloads_generator.rb +20 -0
  54. data/lib/yard/generators/quick_doc_generator.rb +3 -9
  55. data/lib/yard/generators/root_generator.rb +32 -0
  56. data/lib/yard/generators/source_generator.rb +2 -17
  57. data/lib/yard/generators/tags_generator.rb +34 -6
  58. data/lib/yard/generators/uml_generator.rb +16 -6
  59. data/lib/yard/handlers/base.rb +88 -253
  60. data/lib/yard/handlers/processor.rb +72 -0
  61. data/lib/yard/handlers/ruby/alias_handler.rb +38 -0
  62. data/lib/yard/handlers/ruby/attribute_handler.rb +69 -0
  63. data/lib/yard/handlers/ruby/base.rb +72 -0
  64. data/lib/yard/handlers/ruby/class_condition_handler.rb +70 -0
  65. data/lib/yard/handlers/ruby/class_handler.rb +74 -0
  66. data/lib/yard/handlers/ruby/class_variable_handler.rb +11 -0
  67. data/lib/yard/handlers/ruby/constant_handler.rb +12 -0
  68. data/lib/yard/handlers/ruby/exception_handler.rb +22 -0
  69. data/lib/yard/handlers/ruby/extend_handler.rb +19 -0
  70. data/lib/yard/handlers/{alias_handler.rb → ruby/legacy/alias_handler.rb} +3 -4
  71. data/lib/yard/handlers/{attribute_handler.rb → ruby/legacy/attribute_handler.rb} +2 -2
  72. data/lib/yard/handlers/ruby/legacy/base.rb +198 -0
  73. data/lib/yard/handlers/{class_handler.rb → ruby/legacy/class_handler.rb} +18 -6
  74. data/lib/yard/handlers/{class_variable_handler.rb → ruby/legacy/class_variable_handler.rb} +1 -1
  75. data/lib/yard/handlers/{constant_handler.rb → ruby/legacy/constant_handler.rb} +2 -2
  76. data/lib/yard/handlers/{exception_handler.rb → ruby/legacy/exception_handler.rb} +3 -3
  77. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +18 -0
  78. data/lib/yard/handlers/ruby/legacy/method_handler.rb +31 -0
  79. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +28 -0
  80. data/lib/yard/handlers/{module_handler.rb → ruby/legacy/module_handler.rb} +1 -1
  81. data/lib/yard/handlers/{visibility_handler.rb → ruby/legacy/visibility_handler.rb} +1 -1
  82. data/lib/yard/handlers/{yield_handler.rb → ruby/legacy/yield_handler.rb} +4 -4
  83. data/lib/yard/handlers/ruby/method_condition_handler.rb +7 -0
  84. data/lib/yard/handlers/ruby/method_handler.rb +48 -0
  85. data/lib/yard/handlers/ruby/mixin_handler.rb +25 -0
  86. data/lib/yard/handlers/ruby/module_handler.rb +9 -0
  87. data/lib/yard/handlers/ruby/visibility_handler.rb +18 -0
  88. data/lib/yard/handlers/ruby/yield_handler.rb +28 -0
  89. data/lib/yard/parser/ruby/ast_node.rb +263 -0
  90. data/lib/yard/parser/{ruby_lex.rb → ruby/legacy/ruby_lex.rb} +258 -259
  91. data/lib/yard/parser/{statement.rb → ruby/legacy/statement.rb} +8 -4
  92. data/lib/yard/parser/ruby/legacy/statement_list.rb +262 -0
  93. data/lib/yard/parser/{token_list.rb → ruby/legacy/token_list.rb} +1 -1
  94. data/lib/yard/parser/ruby/ruby_parser.rb +307 -0
  95. data/lib/yard/parser/source_parser.rb +76 -45
  96. data/lib/yard/rake/yardoc_task.rb +6 -1
  97. data/lib/yard/registry.rb +45 -19
  98. data/lib/yard/serializers/file_system_serializer.rb +8 -3
  99. data/lib/yard/tags/default_factory.rb +70 -10
  100. data/lib/yard/tags/default_tag.rb +12 -0
  101. data/lib/yard/tags/library.rb +65 -26
  102. data/lib/yard/tags/option_tag.rb +12 -0
  103. data/lib/yard/tags/overload_tag.rb +62 -0
  104. data/lib/yard/tags/ref_tag.rb +7 -0
  105. data/lib/yard/tags/ref_tag_list.rb +27 -0
  106. data/lib/yard/tags/tag.rb +1 -0
  107. data/lib/yard/tags/tag_format_error.rb +6 -0
  108. data/spec/cli/yardoc_spec.rb +43 -0
  109. data/spec/code_objects/base_spec.rb +56 -68
  110. data/spec/code_objects/class_object_spec.rb +18 -6
  111. data/spec/code_objects/constants_spec.rb +2 -0
  112. data/spec/code_objects/method_object_spec.rb +33 -5
  113. data/spec/code_objects/module_object_spec.rb +66 -8
  114. data/spec/code_objects/namespace_object_spec.rb +37 -17
  115. data/spec/code_objects/proxy_spec.rb +13 -2
  116. data/spec/core_ext/string_spec.rb +14 -2
  117. data/spec/core_ext/symbol_hash_spec.rb +9 -3
  118. data/spec/docstring_spec.rb +139 -0
  119. data/spec/generators/full_doc_generator_spec.rb +29 -0
  120. data/spec/generators/helpers/html_helper_spec.rb +74 -0
  121. data/spec/generators/helpers/markup_helper_spec.rb +95 -0
  122. data/spec/handlers/alias_handler_spec.rb +16 -3
  123. data/spec/handlers/attribute_handler_spec.rb +1 -1
  124. data/spec/handlers/base_spec.rb +15 -141
  125. data/spec/handlers/class_condition_handler_spec.rb +49 -0
  126. data/spec/handlers/class_handler_spec.rb +44 -3
  127. data/spec/handlers/class_variable_handler_spec.rb +1 -1
  128. data/spec/handlers/constant_handler_spec.rb +1 -1
  129. data/spec/handlers/examples/alias_handler_001.rb.txt +7 -3
  130. data/spec/handlers/examples/class_condition_handler_001.rb.txt +61 -0
  131. data/spec/handlers/examples/class_handler_001.rb.txt +33 -0
  132. data/spec/handlers/examples/exception_handler_001.rb.txt +1 -1
  133. data/spec/handlers/examples/extend_handler_001.rb.txt +8 -0
  134. data/spec/handlers/examples/method_condition_handler_001.rb.txt +10 -0
  135. data/spec/handlers/examples/method_handler_001.rb.txt +16 -4
  136. data/spec/handlers/examples/mixin_handler_001.rb.txt +10 -2
  137. data/spec/handlers/examples/module_handler_001.rb.txt +4 -0
  138. data/spec/handlers/examples/visibility_handler_001.rb.txt +1 -1
  139. data/spec/handlers/exception_handler_spec.rb +2 -2
  140. data/spec/handlers/extend_handler_spec.rb +15 -0
  141. data/spec/handlers/legacy_base_spec.rb +128 -0
  142. data/spec/handlers/method_condition_handler_spec.rb +14 -0
  143. data/spec/handlers/method_handler_spec.rb +38 -5
  144. data/spec/handlers/mixin_handler_spec.rb +15 -7
  145. data/spec/handlers/module_handler_spec.rb +5 -1
  146. data/spec/handlers/processor_spec.rb +19 -0
  147. data/spec/handlers/ruby/base_spec.rb +90 -0
  148. data/spec/handlers/ruby/legacy/base_spec.rb +53 -0
  149. data/spec/handlers/spec_helper.rb +22 -16
  150. data/spec/handlers/visibility_handler_spec.rb +4 -4
  151. data/spec/handlers/yield_handler_spec.rb +1 -1
  152. data/spec/parser/ruby/ast_node_spec.rb +15 -0
  153. data/spec/parser/ruby/legacy/statement_list_spec.rb +145 -0
  154. data/spec/parser/{token_list_spec.rb → ruby/legacy/token_list_spec.rb} +4 -4
  155. data/spec/parser/source_parser_spec.rb +0 -15
  156. data/spec/rake/yardoc_task_spec.rb +48 -0
  157. data/spec/registry_spec.rb +28 -2
  158. data/spec/serializers/file_system_serializer_spec.rb +7 -1
  159. data/spec/spec_helper.rb +1 -1
  160. data/spec/tags/default_factory_spec.rb +135 -0
  161. data/spec/tags/default_tag_spec.rb +11 -0
  162. data/spec/tags/overload_tag_spec.rb +35 -0
  163. data/spec/tags/ref_tag_list_spec.rb +53 -0
  164. data/templates/default/attributes/html/header.erb +17 -5
  165. data/templates/default/attributes/text/header.erb +1 -1
  166. data/templates/default/fulldoc/html/all_files.erb +19 -0
  167. data/templates/default/fulldoc/html/all_methods.erb +8 -7
  168. data/templates/default/fulldoc/html/all_namespaces.erb +4 -1
  169. data/templates/default/fulldoc/html/app.js +1 -1
  170. data/templates/default/fulldoc/html/{readme.erb → file.erb} +2 -2
  171. data/templates/default/fulldoc/html/header.erb +1 -1
  172. data/templates/default/fulldoc/html/index.erb +4 -3
  173. data/templates/default/fulldoc/html/style.css +13 -3
  174. data/templates/default/fulldoc/html/syntax_highlight.css +8 -5
  175. data/templates/default/method/text/header.erb +1 -0
  176. data/templates/default/method/text/title.erb +1 -0
  177. data/templates/default/methodsignature/html/main.erb +10 -8
  178. data/templates/default/methodsignature/text/main.erb +4 -1
  179. data/templates/default/methodsummary/html/summary.erb +8 -4
  180. data/templates/default/methodsummary/text/summary.erb +4 -1
  181. data/templates/default/mixins/html/header.erb +3 -3
  182. data/templates/default/overloads/html/header.erb +8 -0
  183. data/templates/default/overloads/text/header.erb +8 -0
  184. data/templates/default/root/html/header.erb +4 -0
  185. data/templates/default/tags/html/example.erb +20 -0
  186. data/templates/default/tags/html/option.erb +27 -0
  187. data/templates/default/tags/html/param.erb +21 -0
  188. data/templates/default/tags/html/tags.erb +4 -1
  189. data/templates/default/tags/html/todo.erb +8 -0
  190. data/templates/default/tags/text/example.erb +14 -0
  191. data/templates/default/tags/text/header.erb +3 -3
  192. data/templates/default/tags/text/option.erb +5 -0
  193. data/templates/default/tags/text/param.erb +9 -0
  194. data/templates/default/uml/dot/dependencies.erb +1 -1
  195. data/templates/default/uml/dot/info.erb +1 -1
  196. data/templates/default/uml/dot/superclasses.erb +2 -2
  197. data/templates/javadoc/methodsummary/html/summary.erb +2 -2
  198. data/templates/javadoc/mixins/html/header.erb +3 -3
  199. metadata +108 -139
  200. data/README +0 -211
  201. data/lib/yard/handlers/method_handler.rb +0 -27
  202. data/lib/yard/handlers/mixin_handler.rb +0 -16
  203. data/lib/yard/parser/statement_list.rb +0 -167
  204. data/lib/yard/tags/merbdoc_factory.rb +0 -47
@@ -48,5 +48,22 @@ module YARD::Generators::Helpers
48
48
  object.type.to_s.capitalize
49
49
  end
50
50
  end
51
+
52
+ def format_object_title(object)
53
+ case object
54
+ when YARD::CodeObjects::RootObject
55
+ "Top Level Namespace"
56
+ else
57
+ format_object_type(object) + ": " + object.path
58
+ end
59
+ end
60
+
61
+ def overloads(method)
62
+ if method.has_tag?(:overload)
63
+ method.tags(:overload)
64
+ else
65
+ [method]
66
+ end
67
+ end
51
68
  end
52
- end
69
+ end
@@ -2,7 +2,7 @@ module YARD
2
2
  module Generators::Helpers
3
3
  module FilterHelper
4
4
  def is_method?(object)
5
- object.is_a?(CodeObjects::MethodObject)
5
+ object.type == :method
6
6
  end
7
7
 
8
8
  def is_namespace?(object)
@@ -18,4 +18,4 @@ module YARD
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -1,12 +1,12 @@
1
1
  require 'cgi'
2
- require 'rdoc/markup/simple_markup'
3
- require 'rdoc/markup/simple_markup/to_html'
4
2
 
5
3
  module YARD
6
4
  module Generators::Helpers
7
5
  module HtmlHelper
8
- SimpleMarkup = SM::SimpleMarkup.new
9
- SimpleMarkupHtml = SM::ToHtml.new
6
+ include MarkupHelper
7
+ include HtmlSyntaxHighlightHelper
8
+
9
+ SimpleMarkupHtml = RUBY19 ? RDoc::Markup::ToHtml.new : SM::ToHtml.new
10
10
 
11
11
  def h(text)
12
12
  CGI.escapeHTML(text.to_s)
@@ -16,23 +16,70 @@ module YARD
16
16
  CGI.escape(text.to_s)
17
17
  end
18
18
 
19
- def htmlify(text)
20
- html = resolve_links SimpleMarkup.convert(text, SimpleMarkupHtml)
21
- html = html.gsub(/<pre>(.+?)<\/pre>/m) { '<pre class="code">' + html_syntax_highlight(CGI.unescapeHTML($1)) + '</pre>' }
19
+ def htmlify(text, markup = options[:markup])
20
+ return text unless markup
21
+ load_markup_provider(markup)
22
+
23
+ case markup
24
+ when :markdown, :textile
25
+ # TODO: other libraries might be more complex
26
+ html = markup_class(markup).new(text).to_html
27
+ when :rdoc
28
+ html = MarkupHelper::SimpleMarkup.convert(text, SimpleMarkupHtml)
29
+ html = fix_dash_dash(html)
30
+ html = fix_typewriter(html)
31
+ end
32
+
33
+ html = resolve_links(html)
34
+ html = html.gsub(/<pre>(?:\s*<code>)?(.+?)(?:<\/code>\s*)?<\/pre>/m) do
35
+ str = $1
36
+ str = html_syntax_highlight(CGI.unescapeHTML(str)) unless options[:no_highlight]
37
+ %Q{<pre class="code">#{str}</pre>}
38
+ end
22
39
  html
23
40
  end
41
+
42
+ # @todo Refactor into own SimpleMarkup subclass
43
+ def fix_typewriter(text)
44
+ text.gsub(/\+(?! )([^\+]{1,900})(?! )\+/, '<tt>\1</tt>')
45
+ end
46
+
47
+ # Don't allow -- to turn into &#8212; element. The chances of this being
48
+ # some --option is far more likely than the typographical meaning.
49
+ #
50
+ # @todo Refactor into own SimpleMarkup subclass
51
+ def fix_dash_dash(text)
52
+ text.gsub(/&#8212;(?=\S)/, '--')
53
+ end
24
54
 
25
55
  def resolve_links(text)
26
- text.gsub(/(\s)\{(\S+?)(?:\s(.+?))?\}(?=(?:[\s\.,:!;\?][^<>]*)?<\/(?!pre))/) do
27
- name = $2
28
- title = $3 || $2
29
- obj = P(current_object, name)
30
- if obj.is_a?(CodeObjects::Proxy)
31
- log.warn "In documentation for #{current_object.path}: Cannot resolve link to #{obj.path} from text:"
32
- log.warn '...' + text[/(.{0,20}\{#{Regexp.quote name}.*?\}.{0,20})/, 1].gsub(/\n/,"\n\t") + '...'
56
+ code_tags = 0
57
+ text.gsub(/<(\/)?(pre|code)|(\s|>|^)\{(\S+?)(?:\s(.*?\S))?\}(?=[\W<]|.+<\/|$)/) do |str|
58
+ tag = $2
59
+ closed = $1
60
+ if tag
61
+ code_tags += (closed ? -1 : 1)
62
+ next str
33
63
  end
64
+ next str unless code_tags == 0
65
+
66
+ sp, name = $3, $4
67
+ title = $5 || name
68
+
69
+ if name.include?("://")
70
+ sp + link_url(name, title, :target => '_parent')
71
+ elsif name =~ /^file:(\S+?)(?:#(\S+))?$/
72
+ sp + link_file($1, title == name ? $1 : title, $2)
73
+ else
74
+ obj = Registry.resolve(current_object, name, true, true)
75
+ if obj.is_a?(CodeObjects::Proxy)
76
+ match = text[/(.{0,20}\{.*?#{Regexp.quote name}.*?\}.{0,20})/, 1]
77
+ log.warn "In file `#{current_object.file}':#{current_object.line}: Cannot resolve link to #{obj.path} from text" + (match ? ":" : ".")
78
+ log.warn '...' + match.gsub(/\n/,"\n\t") + '...' if match
79
+ end
34
80
 
35
- " <tt>" + linkify(obj, title) + "</tt>"
81
+ "#{sp}<tt>" + linkify(obj, title) + "</tt>"
82
+ end
36
83
  end
37
84
  end
38
85
 
@@ -55,25 +102,42 @@ module YARD
55
102
  # to their respective descriptions.
56
103
  #
57
104
  def format_types(typelist, brackets = true)
105
+ return unless typelist.is_a?(Array)
58
106
  list = typelist.map do |type|
59
107
  "<tt>" + type.gsub(/(^|[<>])\s*([^<>#]+)\s*(?=[<>]|$)/) {|m| h($1) + linkify($2, $2) } + "</tt>"
60
108
  end
61
109
  list.empty? ? "" : (brackets ? "[#{list.join(", ")}]" : list.join(", "))
62
110
  end
111
+
112
+ def link_file(filename, title = nil, anchor = nil)
113
+ link_url(url_for_file(filename, anchor), title)
114
+ end
63
115
 
64
- def link_object(object, otitle = nil, anchor = nil)
65
- object = P(current_object, object) if object.is_a?(String)
116
+ def link_object(object, otitle = nil, anchor = nil, relative = true)
117
+ object = Registry.resolve(current_object, object, true, true) if object.is_a?(String)
66
118
  title = h(otitle ? otitle.to_s : object.path)
67
119
  return title unless serializer
68
120
 
69
121
  return title if object.is_a?(CodeObjects::Proxy)
70
122
 
71
- link = url_for(object, anchor)
72
- link ? "<a href='#{link}' title='#{title}'>#{title}</a>" : title
123
+ link = url_for(object, anchor, relative)
124
+ link ? link_url(link, title) : title
125
+ end
126
+
127
+ def link_url(url, title = nil, params = {})
128
+ params = SymbolHash.new(false).update(
129
+ :href => url,
130
+ :title => title || url
131
+ ).update(params)
132
+ "<a #{tag_attrs(params)}>#{title}</a>"
133
+ end
134
+
135
+ def tag_attrs(opts = {})
136
+ opts.map {|k,v| "#{k}=#{v.to_s.inspect}" if v }.join(" ")
73
137
  end
74
138
 
75
139
  def anchor_for(object)
76
- urlencode case object
140
+ case object
77
141
  when CodeObjects::MethodObject
78
142
  "#{object.name}-#{object.scope}_#{object.type}"
79
143
  when CodeObjects::Base
@@ -110,28 +174,19 @@ module YARD
110
174
  link = objpath
111
175
  end
112
176
 
113
- link + (anchor ? '#' + anchor_for(anchor) : '')
177
+ link + (anchor ? '#' + urlencode(anchor_for(anchor)) : '')
114
178
  end
115
-
116
- def html_syntax_highlight(source)
117
- tokenlist = Parser::TokenList.new(source)
118
- tokenlist.map do |s|
119
- prettyclass = s.class.class_name.sub(/^Tk/, '').downcase
120
- prettysuper = s.class.superclass.class_name.sub(/^Tk/, '').downcase
121
-
122
- case s
123
- when Parser::RubyToken::TkWhitespace, Parser::RubyToken::TkUnknownChar
124
- h s.text
125
- when Parser::RubyToken::TkId
126
- prettyval = h(s.text)
127
- "<span class='#{prettyval} #{prettyclass} #{prettysuper}'>#{prettyval}</span>"
128
- else
129
- "<span class='#{prettyclass} #{prettysuper}'>#{h s.text}</span>"
130
- end
131
- end.join
179
+
180
+ def url_for_file(filename, anchor = nil)
181
+ fromobj = current_object
182
+ if CodeObjects::Base === fromobj && !fromobj.is_a?(CodeObjects::NamespaceObject)
183
+ fromobj = fromobj.namespace
184
+ end
185
+ from = serializer.serialized_path(fromobj)
186
+ link = File.relative_path(from, filename)
187
+ link + '.html' + (anchor ? '#' + urlencode(anchor) : '')
132
188
  end
133
189
  end
134
190
  end
135
191
  end
136
192
 
137
-
@@ -0,0 +1,49 @@
1
+ module YARD
2
+ module Generators
3
+ module Helpers
4
+ module HtmlSyntaxHighlightHelper
5
+ def html_syntax_highlight(source)
6
+ tokenlist = Parser::Ruby::RubyParser.parse(source, "(syntax_highlight)").tokens
7
+ output = ""
8
+ tokenlist.each do |s|
9
+ output << "<span class='tstring'>" if [:tstring_beg, :regexp_beg].include?(s[0])
10
+ case s.first
11
+ when :nl, :ignored_nl, :sp
12
+ output << h(s.last)
13
+ when :ident
14
+ output << "<span class='id #{h(s.last)}'>#{h(s.last)}</span>"
15
+ else
16
+ output << "<span class='#{s.first}'>#{h(s.last)}</span>"
17
+ end
18
+ output << "</span>" if [:tstring_end, :regexp_end].include?(s[0])
19
+ end
20
+ output
21
+ rescue Parser::Ruby::ParserSyntaxError
22
+ source
23
+ end
24
+
25
+ def html_syntax_highlight_legacy(source)
26
+ tokenlist = Parser::Ruby::Legacy::TokenList.new(source)
27
+ tokenlist.map do |s|
28
+ prettyclass = s.class.class_name.sub(/^Tk/, '').downcase
29
+ prettysuper = s.class.superclass.class_name.sub(/^Tk/, '').downcase
30
+
31
+ case s
32
+ when Parser::Ruby::Legacy::RubyToken::TkWhitespace, Parser::Ruby::Legacy::RubyToken::TkUnknownChar
33
+ h s.text
34
+ when Parser::Ruby::Legacy::RubyToken::TkId
35
+ prettyval = h(s.text)
36
+ "<span class='#{prettyval} #{prettyclass} #{prettysuper}'>#{prettyval}</span>"
37
+ else
38
+ "<span class='#{prettyclass} #{prettysuper}'>#{h s.text}</span>"
39
+ end
40
+ end.join
41
+ end
42
+
43
+ if RUBY18
44
+ alias html_syntax_highlight html_syntax_highlight_legacy
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,86 @@
1
+ if RUBY19
2
+ require 'rdoc/markup'
3
+ require 'rdoc/markup/to_html'
4
+ else
5
+ require 'rdoc/markup/simple_markup'
6
+ require 'rdoc/markup/simple_markup/to_html'
7
+ require 'rubygems'
8
+ end
9
+
10
+ module YARD
11
+ module Generators::Helpers
12
+ module MarkupHelper
13
+ MARKUP_PROVIDERS = {
14
+ :markdown => [
15
+ {:lib => :bluecloth, :const => 'BlueCloth'},
16
+ {:lib => :maruku, :const => 'Maruku'},
17
+ {:lib => :"rpeg-markdown", :const => "PEGMarkdown"},
18
+ {:lib => :rdiscount, :const => "RDiscount"}
19
+ ],
20
+ :textile => [
21
+ {:lib => :redcloth, :const => 'RedCloth'}
22
+ ]
23
+ }
24
+
25
+ SimpleMarkup = RUBY19 ? RDoc::Markup.new : SM::SimpleMarkup.new
26
+
27
+ private
28
+
29
+ # Attempts to load the first valid markup provider in {MARKUP_PROVIDERS}.
30
+ # If a provider is specified, immediately try to load it.
31
+ #
32
+ # On success this sets `@markup_provider` and `@markup_class` to
33
+ # the provider name and library constant class/module respectively for
34
+ # the loaded proider.
35
+ #
36
+ # On failure this method will inform the user that no provider could be
37
+ # found and exit the program.
38
+ def load_markup_provider(type = options[:markup])
39
+ return if type == :rdoc || (@markup_cache && @markup_cache[type])
40
+ @markup_cache ||= {}
41
+ @markup_cache[type] ||= {}
42
+
43
+ providers = MARKUP_PROVIDERS[type]
44
+ if options[:markup_provider]
45
+ providers = MARKUP_PROVIDERS[type].select {|p| p[:lib] == options[:markup_provider] }
46
+ end
47
+
48
+ if providers == nil || providers.empty?
49
+ STDERR.puts "Invalid markup type '#{options[:markup]}'"
50
+ exit
51
+ end
52
+
53
+ # Search for provider, return the library class name as const if found
54
+ providers.each do |provider|
55
+ begin require provider[:lib].to_s; rescue LoadError; next end
56
+ @markup_cache[type][:provider] = provider[:lib] # Cache the provider
57
+ @markup_cache[type][:class] = Kernel.const_get(provider[:const])
58
+ return
59
+ end
60
+
61
+ # Show error message telling user to install first potential provider
62
+ name, lib = providers.first[:const], providers.first[:lib]
63
+ STDERR.puts "Missing #{name} gem for #{options[:markup].to_s.capitalize} formatting. Install it with `gem install #{lib}`"
64
+ exit
65
+ end
66
+
67
+ # Gets the markup provider class/module constant for a markup type
68
+ # Call {#load_markup_provider} before using this method.
69
+ #
70
+ # @param [Symbol] the markup type (:rdoc, :markdown, etc.)
71
+ # @return [Class] the markup class
72
+ def markup_class(type = options[:markup])
73
+ type == :rdoc ? SimpleMarkup : @markup_cache[type][:class]
74
+ end
75
+
76
+ # Gets the markup provider name for a markup type
77
+ # Call {#load_markup_provider} before using this method.
78
+ #
79
+ # @param [Symbol] the markup type (:rdoc, :markdown, etc.)
80
+ # @return [Symbol] the markup provider name (usually the gem name of the library)
81
+ def markup_provider(type = options[:markup])
82
+ type == :rdoc ? nil : @markup_cache[type][:provider]
83
+ end
84
+ end
85
+ end
86
+ end
@@ -2,17 +2,18 @@ module YARD
2
2
  module Generators::Helpers
3
3
  module MethodHelper
4
4
  def format_args(object)
5
- if object.signature
6
- h object.signature[/#{Regexp.quote object.name.to_s}\s*(.*)/, 1]
5
+ unless object.parameters.empty?
6
+ args = object.parameters.map {|n, v| v ? "#{n} = #{v}" : n.to_s }.join(", ")
7
+ h("(#{args})")
7
8
  else
8
- h "def #{object.name}"
9
+ ""
9
10
  end
10
11
  end
11
12
 
12
13
  def format_return_types(object)
13
- if object.has_tag?(:return) && !object.tag(:return).types.empty?
14
- format_types [object.tag(:return).types.first], false
15
- end
14
+ return unless object.has_tag?(:return) && object.tag(:return).types
15
+ return if object.tag(:return).types.empty?
16
+ format_types [object.tag(:return).types.first], false
16
17
  end
17
18
 
18
19
  def format_block(object)
@@ -22,6 +23,21 @@ module YARD
22
23
  ""
23
24
  end
24
25
  end
26
+
27
+ def format_lines(object)
28
+ i = -1
29
+ object.source.split(/\n/).map { object.line + (i += 1) }.join("\n")
30
+ end
31
+
32
+ def format_code(object, show_lines = false)
33
+ i = -1
34
+ lines = object.source.split(/\n/)
35
+ longestline = (object.line + lines.size).to_s.length
36
+ lines.map do |line|
37
+ lineno = object.line + (i += 1)
38
+ (" " * (longestline - lineno.to_s.length)) + lineno.to_s + " " + line
39
+ end.join("\n")
40
+ end
25
41
  end
26
42
  end
27
- end
43
+ end
@@ -1,8 +1,11 @@
1
1
  module YARD
2
2
  module Generators
3
3
  class MethodGenerator < Base
4
+ include Helpers::MethodHelper
5
+
4
6
  before_generate :is_method?
5
7
  before_section :aliases, :has_aliases?
8
+ before_section :source, :isnt_overload?
6
9
 
7
10
  def sections_for(object)
8
11
  [
@@ -16,16 +19,25 @@ module YARD
16
19
  G(DeprecatedGenerator),
17
20
  G(DocstringGenerator),
18
21
  G(TagsGenerator),
19
- G(SourceGenerator)
22
+ G(OverloadsGenerator),
23
+ :source
20
24
  ]
21
25
  ]
22
26
  end
23
27
 
24
28
  protected
25
-
29
+
30
+ def source(object)
31
+ render_section(G(SourceGenerator), object)
32
+ end
33
+
26
34
  def has_aliases?(object)
27
35
  !object.aliases.empty?
28
36
  end
37
+
38
+ def isnt_overload?(object)
39
+ !object.is_a?(Tags::OverloadTag)
40
+ end
29
41
  end
30
42
  end
31
- end
43
+ end