yard 0.6.8 → 0.7.0

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 (224) hide show
  1. data/.yardopts +1 -0
  2. data/ChangeLog +723 -0
  3. data/README.md +16 -6
  4. data/docs/CodeObjects.md +10 -16
  5. data/docs/GettingStarted.md +232 -32
  6. data/docs/Glossary.md +1 -2
  7. data/docs/Handlers.md +10 -16
  8. data/docs/Overview.md +14 -13
  9. data/docs/Parser.md +13 -22
  10. data/docs/Tags.md +209 -16
  11. data/docs/Templates.md +237 -26
  12. data/docs/WhatsNew.md +178 -2
  13. data/lib/yard.rb +13 -10
  14. data/lib/yard/autoload.rb +22 -18
  15. data/lib/yard/cli/command.rb +13 -12
  16. data/lib/yard/cli/command_parser.rb +20 -19
  17. data/lib/yard/cli/config.rb +19 -19
  18. data/lib/yard/cli/diff.rb +46 -21
  19. data/lib/yard/cli/gems.rb +11 -11
  20. data/lib/yard/cli/graph.rb +13 -13
  21. data/lib/yard/cli/help.rb +1 -1
  22. data/lib/yard/cli/list.rb +22 -0
  23. data/lib/yard/cli/server.rb +17 -17
  24. data/lib/yard/cli/stats.rb +32 -32
  25. data/lib/yard/cli/yardoc.rb +181 -135
  26. data/lib/yard/cli/yri.rb +29 -29
  27. data/lib/yard/code_objects/base.rb +101 -101
  28. data/lib/yard/code_objects/class_object.rb +20 -20
  29. data/lib/yard/code_objects/constant_object.rb +1 -1
  30. data/lib/yard/code_objects/extended_method_object.rb +5 -5
  31. data/lib/yard/code_objects/extra_file_object.rb +89 -0
  32. data/lib/yard/code_objects/macro_object.rb +215 -0
  33. data/lib/yard/code_objects/method_object.rb +30 -30
  34. data/lib/yard/code_objects/module_object.rb +1 -1
  35. data/lib/yard/code_objects/namespace_object.rb +39 -39
  36. data/lib/yard/code_objects/proxy.rb +38 -38
  37. data/lib/yard/code_objects/root_object.rb +1 -1
  38. data/lib/yard/config.rb +40 -40
  39. data/lib/yard/core_ext/array.rb +2 -2
  40. data/lib/yard/core_ext/file.rb +11 -11
  41. data/lib/yard/core_ext/insertion.rb +10 -10
  42. data/lib/yard/core_ext/module.rb +2 -2
  43. data/lib/yard/core_ext/string.rb +2 -2
  44. data/lib/yard/core_ext/symbol_hash.rb +14 -14
  45. data/lib/yard/docstring.rb +122 -54
  46. data/lib/yard/globals.rb +2 -2
  47. data/lib/yard/handlers/base.rb +216 -127
  48. data/lib/yard/handlers/processor.rb +65 -27
  49. data/lib/yard/handlers/ruby/alias_handler.rb +6 -3
  50. data/lib/yard/handlers/ruby/attribute_handler.rb +7 -6
  51. data/lib/yard/handlers/ruby/base.rb +50 -31
  52. data/lib/yard/handlers/ruby/class_condition_handler.rb +11 -11
  53. data/lib/yard/handlers/ruby/class_handler.rb +10 -10
  54. data/lib/yard/handlers/ruby/class_variable_handler.rb +3 -3
  55. data/lib/yard/handlers/ruby/constant_handler.rb +7 -7
  56. data/lib/yard/handlers/ruby/exception_handler.rb +2 -2
  57. data/lib/yard/handlers/ruby/extend_handler.rb +1 -1
  58. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +8 -5
  59. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +6 -5
  60. data/lib/yard/handlers/ruby/legacy/base.rb +42 -27
  61. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +9 -9
  62. data/lib/yard/handlers/ruby/legacy/class_handler.rb +13 -12
  63. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +3 -6
  64. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +5 -8
  65. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -1
  66. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -0
  67. data/lib/yard/handlers/ruby/legacy/macro_handler.rb +40 -0
  68. data/lib/yard/handlers/ruby/legacy/method_handler.rb +10 -10
  69. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +4 -3
  70. data/lib/yard/handlers/ruby/legacy/module_handler.rb +2 -1
  71. data/lib/yard/handlers/ruby/legacy/private_constant_handler.rb +4 -4
  72. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +2 -1
  73. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +3 -3
  74. data/lib/yard/handlers/ruby/macro_handler.rb +41 -0
  75. data/lib/yard/handlers/ruby/macro_handler_methods.rb +130 -0
  76. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -1
  77. data/lib/yard/handlers/ruby/method_handler.rb +13 -13
  78. data/lib/yard/handlers/ruby/mixin_handler.rb +4 -4
  79. data/lib/yard/handlers/ruby/module_handler.rb +2 -1
  80. data/lib/yard/handlers/ruby/private_constant_handler.rb +4 -4
  81. data/lib/yard/handlers/ruby/struct_handler_methods.rb +11 -11
  82. data/lib/yard/handlers/ruby/visibility_handler.rb +1 -1
  83. data/lib/yard/handlers/ruby/yield_handler.rb +5 -5
  84. data/lib/yard/logging.rb +11 -11
  85. data/lib/yard/parser/base.rb +8 -8
  86. data/lib/yard/parser/c_parser.rb +42 -33
  87. data/lib/yard/parser/ruby/ast_node.rb +62 -61
  88. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +66 -66
  89. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +4 -4
  90. data/lib/yard/parser/ruby/legacy/statement.rb +11 -11
  91. data/lib/yard/parser/ruby/legacy/statement_list.rb +15 -15
  92. data/lib/yard/parser/ruby/legacy/token_list.rb +9 -9
  93. data/lib/yard/parser/ruby/ruby_parser.rb +51 -37
  94. data/lib/yard/parser/source_parser.rb +271 -46
  95. data/lib/yard/rake/yardoc_task.rb +18 -17
  96. data/lib/yard/registry.rb +64 -64
  97. data/lib/yard/registry_store.rb +34 -34
  98. data/lib/yard/rubygems/backports.rb +8 -0
  99. data/lib/yard/rubygems/backports/LICENSE.txt +57 -0
  100. data/lib/yard/rubygems/backports/MIT.txt +20 -0
  101. data/lib/yard/rubygems/backports/gem.rb +8 -0
  102. data/lib/yard/rubygems/backports/source_index.rb +353 -0
  103. data/lib/yard/rubygems/specification.rb +2 -2
  104. data/lib/yard/serializers/base.rb +20 -20
  105. data/lib/yard/serializers/file_system_serializer.rb +28 -24
  106. data/lib/yard/serializers/process_serializer.rb +3 -3
  107. data/lib/yard/serializers/stdout_serializer.rb +6 -6
  108. data/lib/yard/serializers/yardoc_serializer.rb +17 -17
  109. data/lib/yard/server/adapter.rb +12 -12
  110. data/lib/yard/server/commands/base.rb +26 -26
  111. data/lib/yard/server/commands/display_file_command.rb +3 -2
  112. data/lib/yard/server/commands/display_object_command.rb +5 -5
  113. data/lib/yard/server/commands/frames_command.rb +1 -1
  114. data/lib/yard/server/commands/library_command.rb +7 -7
  115. data/lib/yard/server/commands/library_index_command.rb +2 -2
  116. data/lib/yard/server/commands/list_command.rb +8 -8
  117. data/lib/yard/server/commands/search_command.rb +8 -8
  118. data/lib/yard/server/commands/static_file_command.rb +3 -3
  119. data/lib/yard/server/doc_server_helper.rb +6 -3
  120. data/lib/yard/server/doc_server_serializer.rb +1 -1
  121. data/lib/yard/server/library_version.rb +45 -45
  122. data/lib/yard/server/rack_adapter.rb +10 -10
  123. data/lib/yard/server/router.rb +28 -28
  124. data/lib/yard/server/static_caching.rb +5 -5
  125. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +3 -3
  126. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +1 -1
  127. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +2 -2
  128. data/lib/yard/server/templates/default/layout/html/headers.erb +13 -8
  129. data/lib/yard/server/templates/default/layout/html/setup.rb +7 -0
  130. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +2 -2
  131. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +14 -4
  132. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +2 -2
  133. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +2 -2
  134. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +1 -1
  135. data/lib/yard/server/templates/doc_server/search/html/search.erb +1 -1
  136. data/lib/yard/server/webrick_adapter.rb +2 -2
  137. data/lib/yard/tags/default_factory.rb +19 -19
  138. data/lib/yard/tags/default_tag.rb +1 -1
  139. data/lib/yard/tags/library.rb +68 -63
  140. data/lib/yard/tags/option_tag.rb +1 -1
  141. data/lib/yard/tags/overload_tag.rb +9 -9
  142. data/lib/yard/tags/ref_tag_list.rb +2 -2
  143. data/lib/yard/tags/tag.rb +7 -7
  144. data/lib/yard/templates/engine.rb +31 -31
  145. data/lib/yard/templates/erb_cache.rb +1 -1
  146. data/lib/yard/templates/helpers/base_helper.rb +46 -32
  147. data/lib/yard/templates/helpers/filter_helper.rb +2 -2
  148. data/lib/yard/templates/helpers/html_helper.rb +120 -81
  149. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -4
  150. data/lib/yard/templates/helpers/markup/rdoc_markup.rb +9 -9
  151. data/lib/yard/templates/helpers/markup_helper.rb +37 -30
  152. data/lib/yard/templates/helpers/method_helper.rb +7 -7
  153. data/lib/yard/templates/helpers/text_helper.rb +7 -7
  154. data/lib/yard/templates/helpers/uml_helper.rb +3 -3
  155. data/lib/yard/templates/section.rb +14 -14
  156. data/lib/yard/templates/template.rb +54 -54
  157. data/lib/yard/verifier.rb +27 -27
  158. data/spec/cli/list_spec.rb +8 -0
  159. data/spec/cli/yardoc_spec.rb +58 -10
  160. data/spec/code_objects/extra_file_object_spec.rb +132 -0
  161. data/spec/code_objects/macro_object_spec.rb +154 -0
  162. data/spec/docstring_spec.rb +90 -0
  163. data/spec/handlers/base_spec.rb +22 -0
  164. data/spec/handlers/examples/macro_handler_001.rb.txt +73 -0
  165. data/spec/handlers/examples/method_handler_001.rb.txt +17 -0
  166. data/spec/handlers/macro_handler_spec.rb +140 -0
  167. data/spec/handlers/method_handler_spec.rb +28 -0
  168. data/spec/handlers/processor_spec.rb +4 -0
  169. data/spec/handlers/spec_helper.rb +1 -1
  170. data/spec/parser/c_parser_spec.rb +47 -16
  171. data/spec/parser/examples/extrafile.c.txt +8 -0
  172. data/spec/parser/examples/multifile.c.txt +6 -0
  173. data/spec/parser/ruby/ruby_parser_spec.rb +5 -0
  174. data/spec/parser/source_parser_spec.rb +235 -0
  175. data/spec/rake/yardoc_task_spec.rb +22 -17
  176. data/spec/serializers/file_system_serializer_spec.rb +6 -0
  177. data/spec/server/commands/library_command_spec.rb +39 -0
  178. data/spec/spec_helper.rb +14 -0
  179. data/spec/templates/examples/method001.html +6 -6
  180. data/spec/templates/examples/method002.html +4 -4
  181. data/spec/templates/examples/method003.html +10 -10
  182. data/spec/templates/examples/method005.html +2 -2
  183. data/spec/templates/examples/module001.dot +2 -0
  184. data/spec/templates/examples/module001.html +76 -37
  185. data/spec/templates/examples/module001.txt +1 -1
  186. data/spec/templates/helpers/base_helper_spec.rb +7 -2
  187. data/spec/templates/helpers/html_helper_spec.rb +49 -5
  188. data/spec/templates/helpers/markup_helper_spec.rb +9 -8
  189. data/spec/templates/module_spec.rb +7 -0
  190. data/spec/templates/onefile_spec.rb +47 -0
  191. data/templates/default/fulldoc/html/css/style.css +7 -5
  192. data/templates/default/fulldoc/html/full_list.erb +13 -10
  193. data/templates/default/fulldoc/html/full_list_files.erb +1 -1
  194. data/templates/default/fulldoc/html/js/app.js +16 -14
  195. data/templates/default/fulldoc/html/js/full_list.js +7 -6
  196. data/templates/default/fulldoc/html/setup.rb +78 -17
  197. data/templates/default/layout/html/files.erb +1 -1
  198. data/templates/default/layout/html/headers.erb +11 -7
  199. data/templates/default/layout/html/search.erb +4 -4
  200. data/templates/default/layout/html/setup.rb +28 -8
  201. data/templates/default/module/html/inherited_attributes.erb +17 -0
  202. data/templates/default/module/setup.rb +1 -1
  203. data/templates/default/onefile/html/files.erb +2 -2
  204. data/templates/default/onefile/html/layout.erb +1 -1
  205. data/templates/default/onefile/html/setup.rb +7 -5
  206. data/templates/default/tags/html/option.erb +1 -1
  207. data/templates/default/tags/html/tag.erb +3 -3
  208. data/templates/guide/class/html/setup.rb +1 -0
  209. data/templates/guide/docstring/html/setup.rb +1 -0
  210. data/templates/guide/fulldoc/html/css/style.css +91 -0
  211. data/templates/guide/fulldoc/html/js/app.js +33 -0
  212. data/templates/guide/fulldoc/html/setup.rb +54 -0
  213. data/templates/guide/layout/html/layout.erb +81 -0
  214. data/templates/guide/layout/html/setup.rb +24 -0
  215. data/templates/guide/method/html/header.erb +18 -0
  216. data/templates/guide/method/html/setup.rb +21 -0
  217. data/templates/guide/module/html/header.erb +7 -0
  218. data/templates/guide/module/html/method_list.erb +5 -0
  219. data/templates/guide/module/html/setup.rb +26 -0
  220. data/templates/guide/tags/html/setup.rb +8 -0
  221. metadata +40 -7
  222. data/lib/yard/handlers/ruby/legacy/process_handler.rb +0 -13
  223. data/lib/yard/handlers/ruby/process_handler.rb +0 -18
  224. data/spec/handlers/process_handler_spec.rb +0 -17
@@ -2,10 +2,10 @@ require 'ostruct'
2
2
 
3
3
  module YARD
4
4
  module Templates
5
- # This module manages all creation, handling and rendering of {Template}
6
- # objects.
7
- #
8
- # * To create a template object at a path, use {template}.
5
+ # This module manages all creation, handling and rendering of {Template}
6
+ # objects.
7
+ #
8
+ # * To create a template object at a path, use {template}.
9
9
  # * To render a template, call {render}.
10
10
  # * To register a template path in the lookup paths, call {register_template_path}.
11
11
  module Engine
@@ -14,19 +14,19 @@ module YARD
14
14
  attr_accessor :template_paths
15
15
 
16
16
  # Registers a new template path in {template_paths}
17
- #
17
+ #
18
18
  # @param [String] path a new template path
19
- # @return [void]
19
+ # @return [void]
20
20
  def register_template_path(path)
21
21
  template_paths.push path
22
22
  end
23
-
24
- # Creates a template module representing the path. Searches on disk
25
- # for the first directory named +path+ (joined by '/') within the
26
- # template paths and builds a template module for. All other matching
27
- # directories in other template paths will be included in the
23
+
24
+ # Creates a template module representing the path. Searches on disk
25
+ # for the first directory named +path+ (joined by '/') within the
26
+ # template paths and builds a template module for. All other matching
27
+ # directories in other template paths will be included in the
28
28
  # generated module as mixins (for overriding).
29
- #
29
+ #
30
30
  # @param [Array<String, Symbol>] path a list of path components
31
31
  # @raise [ArgumentError] if the path does not exist within one of the
32
32
  # {template_paths} on disk.
@@ -36,16 +36,16 @@ module YARD
36
36
  from_template = path.shift if path.first.is_a?(Template)
37
37
  path = path.join('/')
38
38
  full_paths = find_template_paths(from_template, path)
39
-
39
+
40
40
  path = File.cleanpath(path).gsub('../', '')
41
41
  raise ArgumentError, "No such template for #{path}" if full_paths.empty?
42
42
  mod = template!(path, full_paths)
43
43
 
44
44
  mod
45
45
  end
46
-
46
+
47
47
  # Forces creation of a template at +path+ within a +full_path+.
48
- #
48
+ #
49
49
  # @param [String] path the path name of the template
50
50
  # @param [Array<String>] full_paths the full path on disk of the template
51
51
  # @return [Template] the template module representing the +path+
@@ -63,12 +63,12 @@ module YARD
63
63
 
64
64
  # Renders a template on a {CodeObjects::Base code object} using
65
65
  # a set of default (overridable) options. Either the +:object+
66
- # or +:type+ keys must be provided.
67
- #
66
+ # or +:type+ keys must be provided.
67
+ #
68
68
  # If a +:serializer+ key is provided and +:serialize+ is not set to
69
69
  # false, the rendered contents will be serialized through the {Serializers::Base}
70
70
  # object. See {with_serializer}.
71
- #
71
+ #
72
72
  # @example Renders an object with html formatting
73
73
  # Engine.render(:format => :html, :object => obj)
74
74
  # @example Renders without an object
@@ -81,18 +81,18 @@ module YARD
81
81
  def render(options = {})
82
82
  set_default_options(options)
83
83
  mod = template(options[:template], options[:type], options[:format])
84
-
84
+
85
85
  if options[:serialize] != false
86
86
  with_serializer(options[:object], options[:serializer]) { mod.run(options) }
87
87
  else
88
88
  mod.run(options)
89
89
  end
90
90
  end
91
-
92
- # Passes a set of objects to the +:fulldoc+ template for full documentation generation.
93
- # This is called by {CLI::Yardoc} to most commonly perform HTML
91
+
92
+ # Passes a set of objects to the +:fulldoc+ template for full documentation generation.
93
+ # This is called by {CLI::Yardoc} to most commonly perform HTML
94
94
  # documentation generation.
95
- #
95
+ #
96
96
  # @param [Array<CodeObjects::Base>] objects a list of {CodeObjects::Base}
97
97
  # objects to pass to the template
98
98
  # @param [Hash] options (see {render})
@@ -104,7 +104,7 @@ module YARD
104
104
  end
105
105
 
106
106
  # Serializes the results of a block with a +serializer+ object.
107
- #
107
+ #
108
108
  # @param [CodeObjects::Base] object the code object to serialize
109
109
  # @param [Serializers::Base] serializer the serializer object
110
110
  # @yield a block whose result will be serialize
@@ -119,11 +119,11 @@ module YARD
119
119
  end
120
120
  output
121
121
  end
122
-
122
+
123
123
  private
124
-
124
+
125
125
  # Sets default options on the options hash
126
- #
126
+ #
127
127
  # @param [Hash] options the options hash
128
128
  # @option options [Symbol] :format (:text) the default format
129
129
  # @option options [Symbol] :type (nil) the :object's type, if provided
@@ -138,7 +138,7 @@ module YARD
138
138
 
139
139
  # Searches through the registered {template_paths} and returns
140
140
  # all full directories that have the +path+ within them on disk.
141
- #
141
+ #
142
142
  # @param [Template] from_template if provided, allows a relative
143
143
  # path to be specified from this template's full path.
144
144
  # @param [String] path the path component to search for in the
@@ -148,7 +148,7 @@ module YARD
148
148
  def find_template_paths(from_template, path)
149
149
  paths = template_paths.dup
150
150
  paths = from_template.full_paths + paths if from_template
151
-
151
+
152
152
  paths.inject([]) do |acc, tp|
153
153
  full_path = File.cleanpath(File.join(tp, path))
154
154
  acc.unshift(full_path) if File.directory?(full_path)
@@ -157,7 +157,7 @@ module YARD
157
157
  end
158
158
 
159
159
  # The name of the module that represents a +path+
160
- #
160
+ #
161
161
  # @param [String] the path toe generate a module name for
162
162
  # @return [String] the module name
163
163
  def template_module_name(path)
@@ -167,7 +167,7 @@ module YARD
167
167
 
168
168
  self.template_paths = []
169
169
  end
170
-
170
+
171
171
  Engine.register_template_path(File.join(YARD::ROOT, '..', 'templates'))
172
172
  end
173
173
  end
@@ -9,7 +9,7 @@ module YARD
9
9
  erb = yield.src
10
10
  encoding = erb[/\A(#coding[:=].*\r?\n)/, 1] || ''
11
11
  module_eval "#{encoding}def #{name}; #{erb}; end", filename
12
-
12
+
13
13
  name
14
14
  end
15
15
 
@@ -2,41 +2,41 @@ module YARD::Templates::Helpers
2
2
  # The base helper module included in all templates.
3
3
  module BaseHelper
4
4
  attr_accessor :object, :serializer
5
-
5
+
6
6
  # @group Managing Global Template State
7
-
8
- # An object that keeps track of global state throughout the entire template
7
+
8
+ # An object that keeps track of global state throughout the entire template
9
9
  # rendering process (including any sub-templates).
10
- #
10
+ #
11
11
  # @return [OpenStruct] a struct object that stores state
12
12
  # @since 0.6.0
13
13
  def globals; options[:__globals] end
14
-
14
+
15
15
  # @group Running the Verifier
16
-
17
- # Runs a list of objects against the {Verifier} object passed into the
16
+
17
+ # Runs a list of objects against the {Verifier} object passed into the
18
18
  # template and returns the subset of verified objects.
19
- #
19
+ #
20
20
  # @param [Array<CodeObjects::Base>] list a list of code objects
21
21
  # @return [Array<CodeObjects::Base>] a list of code objects that match
22
22
  # the verifier. If no verifier is supplied, all objects are returned.
23
23
  def run_verifier(list)
24
24
  options[:verifier] ? options[:verifier].run(list) : list
25
25
  end
26
-
26
+
27
27
  # @group Escaping Text
28
-
28
+
29
29
  # Escapes text. This is used a lot by the HtmlHelper and there should
30
30
  # be some helper to "clean up" text for whatever, this is it.
31
31
  def h(text)
32
32
  text
33
33
  end
34
-
34
+
35
35
  # @group Linking Objects and URLs
36
-
36
+
37
37
  # Links objects or URLs. This method will delegate to the correct +link_+
38
38
  # method depending on the arguments passed in.
39
- #
39
+ #
40
40
  # @example Linking a URL
41
41
  # linkify('http://example.com')
42
42
  # @example Including docstring contents of an object
@@ -45,14 +45,18 @@ module YARD::Templates::Helpers
45
45
  # linkify('file:README')
46
46
  # @example Linking an object by path
47
47
  # linkify('YARD::Docstring')
48
- def linkify(*args)
48
+ def linkify(*args)
49
49
  if args.first.is_a?(String)
50
50
  case args.first
51
51
  when %r{://}, /^mailto:/
52
52
  link_url(args[0], args[1], {:target => '_parent'}.merge(args[2]||{}))
53
53
  when /^include:file:(\S+)/
54
54
  file = $1
55
- if File.file?(file)
55
+ relpath = File.relative_path(Dir.pwd, File.expand_path(file))
56
+ if relpath =~ /^\.\./
57
+ log.warn "Cannot include file from path `#{file}'"
58
+ ""
59
+ elsif File.file?(file)
56
60
  link_include_file(file)
57
61
  else
58
62
  log.warn "Cannot find file at `#{file}' for inclusion"
@@ -66,8 +70,17 @@ module YARD::Templates::Helpers
66
70
  log.warn "Cannot find object at `#{path}' for inclusion"
67
71
  ""
68
72
  end
73
+ when /^render:(\S+)/
74
+ path = $1
75
+ if obj = YARD::Registry.resolve(object, path)
76
+ opts = options.dup
77
+ opts.delete(:serializer)
78
+ obj.format(opts)
79
+ else
80
+ ''
81
+ end
69
82
  when /^file:(\S+?)(?:#(\S+))?$/
70
- link_file($1, args[1] ? args[1] : $1, $2)
83
+ link_file($1, args[1] ? args[1] : nil, $2)
71
84
  else
72
85
  link_object(*args)
73
86
  end
@@ -75,7 +88,7 @@ module YARD::Templates::Helpers
75
88
  link_object(*args)
76
89
  end
77
90
  end
78
-
91
+
79
92
  # Includes an object's docstring into output.
80
93
  # @since 0.6.0
81
94
  # @param [CodeObjects::Base] object the object to include
@@ -83,7 +96,7 @@ module YARD::Templates::Helpers
83
96
  def link_include_object(object)
84
97
  object.docstring
85
98
  end
86
-
99
+
87
100
  # Include a file as a docstring in output
88
101
  # @since 0.7.0
89
102
  # @param [String] file the filename to include
@@ -93,13 +106,13 @@ module YARD::Templates::Helpers
93
106
  end
94
107
 
95
108
  # Links to an object with an optional title
96
- #
109
+ #
97
110
  # @param [CodeObjects::Base] object the object to link to
98
111
  # @param [String] title the title to use for the link
99
112
  # @return [String] the linked object
100
113
  def link_object(object, title = nil)
101
114
  return title if title
102
-
115
+
103
116
  case object
104
117
  when YARD::CodeObjects::Base, YARD::CodeObjects::Proxy
105
118
  object.path
@@ -109,9 +122,9 @@ module YARD::Templates::Helpers
109
122
  object
110
123
  end
111
124
  end
112
-
125
+
113
126
  # Links to a URL
114
- #
127
+ #
115
128
  # @param [String] url the URL to link to
116
129
  # @param [String] title the optional title to display the link as
117
130
  # @param [Hash] params optional parameters for the link
@@ -119,22 +132,23 @@ module YARD::Templates::Helpers
119
132
  def link_url(url, title = nil, params = nil)
120
133
  url
121
134
  end
122
-
123
- # Links to an extra file
124
- #
135
+
136
+ # Links to an extra file
137
+ #
125
138
  # @param [String] filename the filename to link to
126
139
  # @param [String] title the title of the link
127
140
  # @param [String] anchor optional anchor
128
141
  # @return [String] the link to the file
129
142
  # @since 0.5.5
130
143
  def link_file(filename, title = nil, anchor = nil)
144
+ return filename.filename if CodeObjects::ExtraFileObject === filename
131
145
  filename
132
146
  end
133
-
147
+
134
148
  # @group Formatting Object Attributes
135
-
149
+
136
150
  # Formats a list of return types for output and links each type.
137
- #
151
+ #
138
152
  # @example Formatting types
139
153
  # format_types(['String', 'Array']) #=> "(String, Array)"
140
154
  # @example Formatting types without surrounding brackets
@@ -154,7 +168,7 @@ module YARD::Templates::Helpers
154
168
  # o = MethodObject.new(:root, :to_s)
155
169
  # format_object_type(o) # => "Method"
156
170
  # @param [CodeObjects::Base] object the object to retrieve the type for
157
- # @return [String] the human-readable formatted {CodeObjects::Base#type #type}
171
+ # @return [String] the human-readable formatted {CodeObjects::Base#type #type}
158
172
  # for the object
159
173
  def format_object_type(object)
160
174
  case object
@@ -164,7 +178,7 @@ module YARD::Templates::Helpers
164
178
  object.type.to_s.capitalize
165
179
  end
166
180
  end
167
-
181
+
168
182
  # @example
169
183
  # s = format_object_title ModuleObject.new(:root, :MyModuleName)
170
184
  # s # => "Module: MyModuleName"
@@ -178,9 +192,9 @@ module YARD::Templates::Helpers
178
192
  format_object_type(object) + ": " + object.path
179
193
  end
180
194
  end
181
-
195
+
182
196
  # Indents and formats source code
183
- #
197
+ #
184
198
  # @param [String] value the input source code
185
199
  # @return [String] formatted source code
186
200
  def format_source(value)
@@ -11,12 +11,12 @@ module YARD
11
11
  def is_namespace?(object)
12
12
  object.is_a?(CodeObjects::NamespaceObject)
13
13
  end
14
-
14
+
15
15
  # @return [Boolean] whether an object is a class
16
16
  def is_class?(object)
17
17
  object.is_a?(CodeObjects::ClassObject)
18
18
  end
19
-
19
+
20
20
  # @return [Boolean] whether an object is a module
21
21
  def is_module?(object)
22
22
  object.is_a?(CodeObjects::ModuleObject)
@@ -6,29 +6,29 @@ module YARD
6
6
  module HtmlHelper
7
7
  include MarkupHelper
8
8
  include HtmlSyntaxHighlightHelper
9
-
9
+
10
10
  # @group Escaping Template Data
11
-
11
+
12
12
  # Escapes HTML entities
13
- #
13
+ #
14
14
  # @param [String] text the text to escape
15
15
  # @return [String] the HTML with escaped entities
16
16
  def h(text)
17
17
  CGI.escapeHTML(text.to_s)
18
18
  end
19
-
19
+
20
20
  # Escapes a URL
21
- #
21
+ #
22
22
  # @param [String] text the URL
23
23
  # @return [String] the escaped URL
24
24
  def urlencode(text)
25
25
  CGI.escape(text.to_s)
26
26
  end
27
-
27
+
28
28
  # @group Converting Markup to HTML
29
29
 
30
30
  # Turns text into HTML using +markup+ style formatting.
31
- #
31
+ #
32
32
  # @param [String] text the text to format
33
33
  # @param [Symbol] markup examples are +:markdown+, +:textile+, +:rdoc+.
34
34
  # To add a custom markup type, see {MarkupHelper}
@@ -38,7 +38,6 @@ module YARD
38
38
  return text unless respond_to?(markup_meth)
39
39
  return "" unless text
40
40
  return text unless markup
41
- load_markup_provider(markup)
42
41
  html = send(markup_meth, text)
43
42
  if html.respond_to?(:encode)
44
43
  html = html.force_encoding(text.encoding) # for libs that mess with encoding
@@ -52,16 +51,21 @@ module YARD
52
51
  end unless markup == :text
53
52
  html
54
53
  end
55
-
54
+
56
55
  # Converts Markdown to HTML
57
56
  # @param [String] text input Markdown text
58
57
  # @return [String] output HTML
59
58
  # @since 0.6.0
60
59
  def html_markup_markdown(text)
61
60
  # TODO: other libraries might be more complex
62
- markup_class(:markdown).new(text).to_html
61
+ provider = markup_class(:markdown)
62
+ if provider.to_s == 'RDiscount'
63
+ markup_class(:markdown).new(text, :autolink).to_html
64
+ else
65
+ markup_class(:markdown).new(text).to_html
66
+ end
63
67
  end
64
-
68
+
65
69
  # Converts Textile to HTML
66
70
  # @param [String] text the input Textile text
67
71
  # @return [String] output HTML
@@ -71,7 +75,7 @@ module YARD
71
75
  doc.hard_breaks = false if doc.respond_to?(:hard_breaks=)
72
76
  doc.to_html
73
77
  end
74
-
78
+
75
79
  # Converts RDoc formatting (SimpleMarkup) to HTML
76
80
  # @param [String] text the input RDoc formatted text
77
81
  # @return [String] output HTML
@@ -81,7 +85,7 @@ module YARD
81
85
  doc.from_path = url_for(object) if doc.respond_to?(:from_path=)
82
86
  doc.to_html
83
87
  end
84
-
88
+
85
89
  # Converts plaintext to HTML
86
90
  # @param [String] text the input text
87
91
  # @return [String] the output HTML
@@ -89,13 +93,13 @@ module YARD
89
93
  def html_markup_text(text)
90
94
  "<pre>" + text + "</pre>"
91
95
  end
92
-
96
+
93
97
  # @return [String] the same text with no markup
94
98
  # @since 0.6.6
95
99
  def html_markup_none(text)
96
100
  h(text).gsub(/(?:\r?\n){2}/, '<br/>')
97
101
  end
98
-
102
+
99
103
  # Converts HTML to HTML
100
104
  # @param [String] text input html
101
105
  # @return [String] output HTML
@@ -104,21 +108,32 @@ module YARD
104
108
  text
105
109
  end
106
110
 
111
+ # Highlights Ruby source. Similar to {#html_syntax_highlight}, but
112
+ # this method is meant to be called from {#htmlify} when markup is
113
+ # set to "ruby".
114
+ #
115
+ # @param [String] source the Ruby source
116
+ # @return [String] the highlighted HTML
117
+ # @since 0.7.0
118
+ def html_markup_ruby(source)
119
+ '<pre class="code">' + html_syntax_highlight(source, :ruby) + '</pre>'
120
+ end
121
+
107
122
  # @return [String] HTMLified text as a single line (paragraphs removed)
108
123
  def htmlify_line(*args)
109
124
  "<div class='inline'>" + htmlify(*args) + "</div>"
110
125
  end
111
-
126
+
112
127
  # @group Syntax Highlighting Source Code
113
-
128
+
114
129
  # Syntax highlights +source+ in language +type+.
115
- #
130
+ #
116
131
  # @note To support a specific language +type+, implement the method
117
132
  # +html_syntax_highlight_TYPE+ in this class.
118
- #
133
+ #
119
134
  # @param [String] source the source code to highlight
120
135
  # @param [Symbol] type the language type (:ruby, :plain, etc). Use
121
- # :plain for no syntax highlighting.
136
+ # :plain for no syntax highlighting.
122
137
  # @return [String] the highlighted source
123
138
  def html_syntax_highlight(source, type = nil)
124
139
  return "" unless source
@@ -131,21 +146,21 @@ module YARD
131
146
  type, source = $1, $'
132
147
  source = $'
133
148
  end
134
-
149
+
135
150
  meth = "html_syntax_highlight_#{type}"
136
151
  respond_to?(meth) ? send(meth, source) : h(source)
137
152
  end
138
-
153
+
139
154
  # @return [String] unhighlighted source
140
155
  def html_syntax_highlight_plain(source)
141
156
  h(source)
142
157
  end
143
-
158
+
144
159
  # @group Linking Objects and URLs
145
160
 
146
161
  # Resolves any text in the form of +{Name}+ to the object specified by
147
162
  # Name. Also supports link titles in the form +{Name title}+.
148
- #
163
+ #
149
164
  # @example Linking to an instance method
150
165
  # resolve_links("{MyClass#method}") # => "<a href='...'>MyClass#method</a>"
151
166
  # @example Linking to a class with a title
@@ -154,42 +169,60 @@ module YARD
154
169
  # @return [String] HTML with linkified references
155
170
  def resolve_links(text)
156
171
  code_tags = 0
157
- text.gsub(/<(\/)?(pre|code|tt)|\{(\S+?)(?:\s(.*?\S))?\}(?=[\W<]|.+<\/|$)/m) do |str|
158
- closed, tag, name, title, match = $1, $2, $3, $4, $&
172
+ text.gsub(/<(\/)?(pre|code|tt)|(\\)?\{(?!\})(\S+?)(?:\s([^\}]*?\S))?\}(?=[\W<]|.+<\/|$)/m) do |str|
173
+ closed, tag, escape, name, title, match = $1, $2, $3, $4, $5, $&
159
174
  if tag
160
175
  code_tags += (closed ? -1 : 1)
161
176
  next str
162
177
  end
163
178
  next str unless code_tags == 0
164
-
179
+
180
+ next(match[1..-1]) if escape
181
+
165
182
  next(match) if name[0,1] == '|'
166
183
  if object.is_a?(String)
167
184
  object
168
185
  else
169
186
  link = linkify(name, title)
170
- if link == name || link == title
187
+ if (link == name || link == title) && (name+' '+link !~ /\A<a\s.*>/)
171
188
  match = /(.+)?(\{#{Regexp.quote name}(?:\s.*?)?\})(.+)?/.match(text)
172
- file = (@file ? @file : object.file) || '(unknown)'
189
+ file = (@file ? @file.filename : object.file) || '(unknown)'
173
190
  line = (@file ? 1 : (object.docstring.line_range ? object.docstring.line_range.first : 1)) + (match ? $`.count("\n") : 0)
174
191
  log.warn "In file `#{file}':#{line}: Cannot resolve link to #{name} from text" + (match ? ":" : ".")
175
192
  log.warn((match[1] ? '...' : '') + match[2].gsub("\n","") + (match[3] ? '...' : '')) if match
176
193
  end
177
-
194
+
178
195
  link
179
196
  end
180
197
  end
181
198
  end
182
-
199
+
183
200
  # (see BaseHelper#link_file)
184
201
  def link_file(filename, title = nil, anchor = nil)
185
- link_url(url_for_file(filename, anchor), title)
202
+ if CodeObjects::ExtraFileObject === filename
203
+ file = filename
204
+ else
205
+ contents = File.file?(filename) ? nil : ''
206
+ file = CodeObjects::ExtraFileObject.new(filename, contents)
207
+ end
208
+ return title || file.title unless serializer
209
+ link_url(url_for_file(file, anchor), title || file.title)
186
210
  end
187
211
 
212
+ # (see BaseHelper#link_include_file)
213
+ def link_include_file(file)
214
+ unless file.is_a?(CodeObjects::ExtraFileObject)
215
+ file = CodeObjects::ExtraFileObject.new(file)
216
+ end
217
+ file.attributes[:markup] ||= markup_for_file('', file.filename)
218
+ htmlify(file.contents, file.attributes[:markup] || options[:markup])
219
+ end
220
+
188
221
  # (see BaseHelper#link_include_object)
189
222
  def link_include_object(obj)
190
223
  htmlify(obj.docstring)
191
224
  end
192
-
225
+
193
226
  # (see BaseHelper#link_object)
194
227
  def link_object(obj, otitle = nil, anchor = nil, relative = true)
195
228
  return otitle if obj.nil?
@@ -205,12 +238,12 @@ module YARD
205
238
  end
206
239
  return title unless serializer
207
240
  return title if obj.is_a?(CodeObjects::Proxy)
208
-
241
+
209
242
  link = url_for(obj, anchor, relative)
210
243
  link = link ? link_url(link, title, :title => "#{obj.path} (#{obj.type})") : title
211
244
  "<span class='object_link'>" + link + "</span>"
212
245
  end
213
-
246
+
214
247
  # (see BaseHelper#link_url)
215
248
  def link_url(url, title = nil, params = {})
216
249
  title ||= url
@@ -222,9 +255,9 @@ module YARD
222
255
  params[:target] ||= '_parent' if url =~ /^(\w+):\/\//
223
256
  "<a #{tag_attrs(params)}>#{title}</a>".gsub(/[\r\n]/, ' ')
224
257
  end
225
-
258
+
226
259
  # @group URL Helpers
227
-
260
+
228
261
  # @param [CodeObjects::Base] object the object to get an anchor for
229
262
  # @return [String] the anchor for a specific object
230
263
  def anchor_for(object)
@@ -241,9 +274,9 @@ module YARD
241
274
  object.to_s
242
275
  end
243
276
  end
244
-
277
+
245
278
  # Returns the URL for an object.
246
- #
279
+ #
247
280
  # @param [String, CodeObjects::Base] obj the object (or object path) to link to
248
281
  # @param [String] anchor the anchor to link to
249
282
  # @param [Boolean] relative use a relative or absolute link
@@ -251,18 +284,18 @@ module YARD
251
284
  def url_for(obj, anchor = nil, relative = true)
252
285
  link = nil
253
286
  return link unless serializer
254
-
287
+
255
288
  if obj.is_a?(CodeObjects::Base) && !obj.is_a?(CodeObjects::NamespaceObject)
256
289
  # If the obj is not a namespace obj make it the anchor.
257
290
  anchor, obj = obj, obj.namespace
258
291
  end
259
-
292
+
260
293
  objpath = serializer.serialized_path(obj)
261
294
  return link unless objpath
262
-
295
+
263
296
  if relative
264
297
  fromobj = object
265
- if object.is_a?(CodeObjects::Base) &&
298
+ if object.is_a?(CodeObjects::Base) &&
266
299
  !object.is_a?(CodeObjects::NamespaceObject)
267
300
  fromobj = fromobj.namespace
268
301
  end
@@ -272,67 +305,69 @@ module YARD
272
305
  else
273
306
  link = objpath
274
307
  end
275
-
308
+
276
309
  link + (anchor ? '#' + urlencode(anchor_for(anchor)) : '')
277
310
  end
278
-
311
+
279
312
  # Returns the URL for a specific file
280
- #
281
- # @param [String] filename the filename to link to
313
+ #
314
+ # @param [String, CodeObjects::ExtraFileObject] filename the filename to link to
282
315
  # @param [String] anchor optional anchor
283
316
  # @return [String] the URL pointing to the file
284
317
  def url_for_file(filename, anchor = nil)
318
+ return '' unless serializer
285
319
  fromobj = object
286
320
  if CodeObjects::Base === fromobj && !fromobj.is_a?(CodeObjects::NamespaceObject)
287
321
  fromobj = fromobj.namespace
288
322
  end
289
323
  from = serializer.serialized_path(fromobj)
290
324
  if filename == options[:readme]
291
- filename = 'index'
325
+ path = 'index.html'
292
326
  else
293
- filename = 'file.' + File.basename(filename).gsub(/\.[^.]+$/, '')
327
+ path = serializer.serialized_path(filename)
294
328
  end
295
- link = File.relative_path(from, filename)
296
- link + '.html' + (anchor ? '#' + urlencode(anchor) : '')
329
+ link = File.relative_path(from, path)
330
+ link += (anchor ? '#' + urlencode(anchor) : '')
331
+ link
297
332
  end
298
-
333
+
299
334
  # @group Formatting Objects and Attributes
300
335
 
301
336
  # Formats a list of objects and links them
302
337
  # @return [String] a formatted list of objects
303
338
  def format_object_name_list(objects)
304
- objects.sort_by {|o| o.name.to_s.downcase }.map do |o|
305
- "<span class='name'>" + linkify(o, o.name) + "</span>"
339
+ objects.sort_by {|o| o.name.to_s.downcase }.map do |o|
340
+ "<span class='name'>" + linkify(o, o.name) + "</span>"
306
341
  end.join(", ")
307
342
  end
308
-
343
+
309
344
  # Formats a list of types from a tag.
310
- #
345
+ #
311
346
  # @param [Array<String>, FalseClass] typelist
312
- # the list of types to be formatted.
313
- #
314
- # @param [Boolean] brackets omits the surrounding
347
+ # the list of types to be formatted.
348
+ #
349
+ # @param [Boolean] brackets omits the surrounding
315
350
  # brackets if +brackets+ is set to +false+.
316
- #
351
+ #
317
352
  # @return [String] the list of types formatted
318
353
  # as [Type1, Type2, ...] with the types linked
319
354
  # to their respective descriptions.
320
- #
355
+ #
321
356
  def format_types(typelist, brackets = true)
322
357
  return unless typelist.is_a?(Array)
323
- list = typelist.map do |type|
358
+ list = typelist.map do |type|
324
359
  type = type.gsub(/([<>])/) { h($1) }
325
360
  type = type.gsub(/([\w:]+)/) { $1 == "lt" || $1 == "gt" ? $1 : linkify($1, $1) }
326
361
  "<tt>" + type + "</tt>"
327
362
  end
328
363
  list.empty? ? "" : (brackets ? "(#{list.join(", ")})" : list.join(", "))
329
364
  end
330
-
365
+
331
366
  # Get the return types for a method signature.
332
- #
367
+ #
333
368
  # @param [CodeObjects::MethodObject] meth the method object
334
369
  # @param [Boolean] link whether to link the types
335
- # @return [String] the signature types
370
+ # @return [String] the signature types
336
371
  # @since 0.5.3
337
372
  def signature_types(meth, link = true)
338
373
  meth = convert_method_to_overload(meth)
@@ -358,19 +393,19 @@ module YARD
358
393
  type = "(#{type}) " unless type.empty?
359
394
  type
360
395
  end
361
-
396
+
362
397
  # Formats the signature of method +meth+.
363
- #
398
+ #
364
399
  # @param [CodeObjects::MethodObject] meth the method object to list
365
400
  # the signature of
366
401
  # @param [Boolean] link whether to link the method signature to the details view
367
402
  # @param [Boolean] show_extras whether to show extra meta-data (visibility, attribute info)
368
- # @param [Boolean] full_attr_name whether to show the full attribute name
403
+ # @param [Boolean] full_attr_name whether to show the full attribute name
369
404
  # ("name=" instead of "name")
370
405
  # @return [String] the formatted method signature
371
406
  def signature(meth, link = true, show_extras = true, full_attr_name = true)
372
407
  meth = convert_method_to_overload(meth)
373
-
408
+
374
409
  type = signature_types(meth, link)
375
410
  scope = meth.scope == :class ? "+" : "-"
376
411
  name = full_attr_name ? meth.name : meth.name.to_s.gsub(/^(\w+)=$/, '\1')
@@ -399,41 +434,45 @@ module YARD
399
434
  title + extras_text
400
435
  end
401
436
  end
402
-
437
+
403
438
  # @group Getting the Character Encoding
404
-
439
+
405
440
  # Returns the current character set. The default value can be overridden
406
441
  # by setting the +LANG+ environment variable or by overriding this
407
442
  # method. In Ruby 1.9 you can also modify this value by setting
408
443
  # +Encoding.default_external+.
409
- #
444
+ #
410
445
  # @return [String] the current character set
411
446
  # @since 0.5.4
412
447
  def charset
413
- return 'utf-8' unless RUBY19 || lang = ENV['LANG']
414
- if RUBY19
415
- lang = Encoding.default_external.name.downcase
448
+ if @file && RUBY19
449
+ lang = @file.contents.encoding.to_s
416
450
  else
417
- lang = lang.downcase.split('.').last
451
+ return 'utf-8' unless RUBY19 || lang = ENV['LANG']
452
+ if RUBY19
453
+ lang = Encoding.default_external.name.downcase
454
+ else
455
+ lang = lang.downcase.split('.').last
456
+ end
418
457
  end
419
458
  case lang
420
459
  when "ascii-8bit", "us-ascii", "ascii-7bit"; 'iso-8859-1'
421
460
  else; lang
422
461
  end
423
462
  end
424
-
463
+
425
464
  # @endgroup
426
-
465
+
427
466
  private
428
467
 
429
468
  # Converts a set of hash options into HTML attributes for a tag
430
- #
469
+ #
431
470
  # @param [Hash{String => String}] opts the tag options
432
471
  # @return [String] the tag attributes of an HTML tag
433
472
  def tag_attrs(opts = {})
434
473
  opts.sort_by {|k, v| k.to_s }.map {|k,v| "#{k}=#{v.to_s.inspect}" if v }.join(" ")
435
474
  end
436
-
475
+
437
476
  # Converts a {CodeObjects::MethodObject} into an overload object
438
477
  # @since 0.5.3
439
478
  def convert_method_to_overload(meth)
@@ -446,4 +485,4 @@ module YARD
446
485
  end
447
486
  end
448
487
  end
449
-
488
+