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
@@ -6,47 +6,47 @@ module YARD
6
6
  # This is the base command class used to implement custom commands for
7
7
  # a server. A command will be routed to by the {Router} class and return
8
8
  # a Rack-style response.
9
- #
9
+ #
10
10
  # == Attribute Initializers
11
11
  # All attributes can be initialized via options passed into the {#initialize}
12
- # method. When creating a custom command, the {Adapter#options} will
12
+ # method. When creating a custom command, the {Adapter#options} will
13
13
  # automatically be mapped to attributes by the same name on your class.
14
- #
14
+ #
15
15
  # class MyCommand < Base
16
16
  # attr_accessor :myattr
17
17
  # end
18
- #
18
+ #
19
19
  # Adapter.new(libs, {:myattr => 'foo'}).start
20
- #
20
+ #
21
21
  # # when a request comes in, cmd.myattr == 'foo'
22
- #
22
+ #
23
23
  # == Subclassing Notes
24
24
  # To implement a custom command, override the {#run} method, not {#call}.
25
25
  # In your implementation, you should set the body and status for requests.
26
26
  # See details in the +#run+ method documentation.
27
- #
27
+ #
28
28
  # Note that if your command deals directly with libraries, you should
29
29
  # consider subclassing the more specific {LibraryCommand} class instead.
30
- #
30
+ #
31
31
  # @abstract
32
32
  # @see #run
33
33
  class Base
34
34
  # @group Basic Command and Adapter Options
35
-
35
+
36
36
  # @return [Hash] the options passed to the command's constructor
37
37
  attr_accessor :command_options
38
-
38
+
39
39
  # @return [Adapter] the server adapter
40
40
  attr_accessor :adapter
41
41
 
42
42
  # @return [Boolean] whether to cache
43
43
  attr_accessor :caching
44
-
44
+
45
45
  # @group Attributes Set Per Request
46
46
 
47
47
  # @return [Request] request object
48
48
  attr_accessor :request
49
-
49
+
50
50
  # @return [String] the path after the command base URI
51
51
  attr_accessor :path
52
52
 
@@ -58,13 +58,13 @@ module YARD
58
58
 
59
59
  # @return [String] the response body. Defaults to empty string.
60
60
  attr_accessor :body
61
-
61
+
62
62
  # @group Instance Method Summary
63
63
 
64
- # Creates a new command object, setting attributes named by keys
64
+ # Creates a new command object, setting attributes named by keys
65
65
  # in the options hash. After initialization, the options hash
66
66
  # is saved in {#command_options} for further inspection.
67
- #
67
+ #
68
68
  # @example Creating a Command
69
69
  # cmd = DisplayObjectCommand.new(:caching => true, :library => mylib)
70
70
  # cmd.library # => mylib
@@ -79,7 +79,7 @@ module YARD
79
79
  end
80
80
 
81
81
  # The main method called by a router with a request object.
82
- #
82
+ #
83
83
  # @note This command should not be overridden by subclasses. Implement
84
84
  # the callback method {#run} instead.
85
85
  # @param [Adapter Dependent] request the request object
@@ -101,13 +101,13 @@ module YARD
101
101
  not_found if status == 404
102
102
  [status, headers, body.is_a?(Array) ? body : [body]]
103
103
  end
104
-
104
+
105
105
  # @group Abstract Methods
106
106
 
107
107
  # Subclass this method to implement a custom command. This method
108
- # should set the {#status} and {#body}, and optionally modify the
108
+ # should set the {#status} and {#body}, and optionally modify the
109
109
  # {#headers}. Note that +#status+ defaults to 200.
110
- #
110
+ #
111
111
  # @example A custom command
112
112
  # class ErrorCommand < Base
113
113
  # def run
@@ -116,7 +116,7 @@ module YARD
116
116
  # self.headers['Conten-Type'] = 'text/plain'
117
117
  # end
118
118
  # end
119
- #
119
+ #
120
120
  # @abstract
121
121
  # @return [void]
122
122
  def run
@@ -124,12 +124,12 @@ module YARD
124
124
  end
125
125
 
126
126
  protected
127
-
127
+
128
128
  # @group Helper Methods
129
-
129
+
130
130
  # Renders a specific object if provided, or a regular template rendering
131
131
  # if object is not provided.
132
- #
132
+ #
133
133
  # @todo This method is dependent on +#options+, it should be in {LibraryCommand}.
134
134
  # @param [CodeObjects::Base, nil] object calls {CodeObjects::Base#format} if
135
135
  # an object is provided, or {Templates::Engine.render} if object is nil. Both
@@ -145,9 +145,9 @@ module YARD
145
145
  cache object
146
146
  end
147
147
  end
148
-
148
+
149
149
  # Override this method to implement custom caching mechanisms for
150
- #
150
+ #
151
151
  # @example Caching to memory
152
152
  # $memory_cache = {}
153
153
  # def cache(data)
@@ -169,7 +169,7 @@ module YARD
169
169
 
170
170
  # Sets the body and headers (but not status) for a 404 response. Does
171
171
  # nothing if the body is already set.
172
- #
172
+ #
173
173
  # @return [void]
174
174
  def not_found
175
175
  return unless body.empty?
@@ -2,7 +2,7 @@ module YARD
2
2
  module Server
3
3
  module Commands
4
4
  # Displays a README or extra file.
5
- #
5
+ #
6
6
  # @todo Implement better support for detecting binary (image) filetypes
7
7
  class DisplayFileCommand < LibraryCommand
8
8
  def run
@@ -13,7 +13,8 @@ module YARD
13
13
  headers['Content-Type'] = StaticFileCommand::DefaultMimeTypes[$1.downcase] || 'text/html'
14
14
  render IO.read(filename)
15
15
  else
16
- options.update(:object => Registry.root, :type => :layout, :file => filename)
16
+ file = CodeObjects::ExtraFileObject.new(filename)
17
+ options.update(:object => Registry.root, :type => :layout, :file => file)
17
18
  render
18
19
  end
19
20
  end
@@ -5,7 +5,7 @@ module YARD
5
5
  class DisplayObjectCommand < LibraryCommand
6
6
  def run
7
7
  return index if path.empty?
8
-
8
+
9
9
  if object = Registry.at(object_path)
10
10
  options.update(:type => :layout)
11
11
  render(object)
@@ -13,7 +13,7 @@ module YARD
13
13
  self.status = 404
14
14
  end
15
15
  end
16
-
16
+
17
17
  def index
18
18
  Registry.load_all
19
19
 
@@ -29,14 +29,14 @@ module YARD
29
29
  )
30
30
  render
31
31
  end
32
-
32
+
33
33
  def not_found
34
34
  super
35
35
  self.body = "Could not find object: #{object_path}"
36
36
  end
37
-
37
+
38
38
  private
39
-
39
+
40
40
  def object_path
41
41
  return @object_path if @object_path
42
42
  if path == "toplevel"
@@ -4,7 +4,7 @@ module YARD
4
4
  # Displays an object wrapped in frames
5
5
  class FramesCommand < DisplayObjectCommand
6
6
  include DocServerHelper
7
-
7
+
8
8
  def run
9
9
  main_url = request.path.gsub(/^(.+)?\/frames(?:\/(#{path}))?$/, '\1/\2')
10
10
  if path =~ %r{^file/}
@@ -5,7 +5,7 @@ module YARD
5
5
  # Some commands do not, but most (like {DisplayObjectCommand}) do. If your
6
6
  # command deals with libraries directly, subclass this class instead.
7
7
  # See {Base} for notes on how to subclass a command.
8
- #
8
+ #
9
9
  # @abstract
10
10
  class LibraryCommand < Base
11
11
  # @return [LibraryVersion] the object containing library information
@@ -19,14 +19,14 @@ module YARD
19
19
 
20
20
  # @return [Boolean] whether router should route for multiple libraries
21
21
  attr_accessor :single_library
22
-
23
- # @return [Boolean] whether to reparse data
22
+
23
+ # @return [Boolean] whether to reparse data
24
24
  attr_accessor :incremental
25
25
 
26
26
  # Needed to synchronize threads in {#setup_yardopts}
27
27
  # @private
28
28
  @@library_chdir_lock = Mutex.new
29
-
29
+
30
30
  def initialize(opts = {})
31
31
  super
32
32
  self.serializer = DocServerSerializer.new(self)
@@ -48,7 +48,7 @@ module YARD
48
48
  rescue LibraryNotPreparedError
49
49
  not_prepared
50
50
  end
51
-
51
+
52
52
  private
53
53
 
54
54
  def setup_library
@@ -84,13 +84,13 @@ module YARD
84
84
  Registry.load_yardoc(library.yardoc_file)
85
85
  Thread.current[:__yard_last_yardoc__] = library.yardoc_file
86
86
  end
87
-
87
+
88
88
  def not_prepared
89
89
  self.caching = false
90
90
  options.update(:path => request.path, :template => :doc_server, :type => :processing)
91
91
  [302, {'Content-Type' => 'text/html'}, [render]]
92
92
  end
93
-
93
+
94
94
  # @private
95
95
  @@last_yardoc = nil
96
96
  end
@@ -4,10 +4,10 @@ module YARD
4
4
  # Returns the index of libraries served by the server.
5
5
  class LibraryIndexCommand < Base
6
6
  attr_accessor :options
7
-
7
+
8
8
  def run
9
9
  return unless path.empty?
10
-
10
+
11
11
  self.options = SymbolHash.new(false).update(
12
12
  :markup => :rdoc,
13
13
  :format => :html,
@@ -4,40 +4,40 @@ module YARD
4
4
  # Returns a list of objects of a specific type
5
5
  class ListCommand < LibraryCommand
6
6
  include Templates::Helpers::BaseHelper
7
-
7
+
8
8
  def items; raise NotImplementedError end
9
9
  def type; raise NotImplementedError end
10
10
 
11
11
  def run
12
- options.update(:items => items, :template => :doc_server,
12
+ options.update(:items => items, :template => :doc_server,
13
13
  :list_type => request.path.split('/').last, :type => :full_list)
14
14
  render
15
15
  end
16
16
  end
17
-
17
+
18
18
  # Returns the list of classes / modules in a library
19
19
  class ListClassesCommand < ListCommand
20
20
  def type; :class end
21
-
21
+
22
22
  def items
23
23
  Registry.load_all
24
24
  run_verifier(Registry.all(:class, :module))
25
25
  end
26
26
  end
27
-
27
+
28
28
  # Returns the list of methods in a library
29
29
  class ListMethodsCommand < ListCommand
30
30
  include Templates::Helpers::ModuleHelper
31
-
31
+
32
32
  def type; :methods end
33
-
33
+
34
34
  def items
35
35
  Registry.load_all
36
36
  items = Registry.all(:method).sort_by {|m| m.name.to_s }
37
37
  prune_method_listing(items)
38
38
  end
39
39
  end
40
-
40
+
41
41
  # Returns the list of README/extra files in a library
42
42
  class ListFilesCommand < ListCommand
43
43
  def type; :files end
@@ -5,7 +5,7 @@ module YARD
5
5
  # the results as HTML or plaintext
6
6
  class SearchCommand < LibraryCommand
7
7
  attr_accessor :results, :query
8
-
8
+
9
9
  def run
10
10
  Registry.load_all
11
11
  self.query = request.query['q']
@@ -16,16 +16,16 @@ module YARD
16
16
  search_for_object
17
17
  request.xhr? ? serve_xhr : serve_normal
18
18
  end
19
-
19
+
20
20
  def visible_results
21
21
  results[0, 10]
22
22
  end
23
-
23
+
24
24
  private
25
-
25
+
26
26
  def serve_xhr
27
27
  self.headers['Content-Type'] = 'text/plain'
28
- self.body = visible_results.map {|o|
28
+ self.body = visible_results.map {|o|
29
29
  [(o.type == :method ? o.name(true) : o.name).to_s,
30
30
  o.path,
31
31
  o.namespace.root? ? '' : o.namespace.path,
@@ -33,7 +33,7 @@ module YARD
33
33
  ].join(",")
34
34
  }.join("\n")
35
35
  end
36
-
36
+
37
37
  def serve_normal
38
38
  options.update(
39
39
  :visible_results => visible_results,
@@ -44,7 +44,7 @@ module YARD
44
44
  )
45
45
  self.body = Templates::Engine.render(options)
46
46
  end
47
-
47
+
48
48
  def search_for_object
49
49
  splitquery = query.split(/\s+/).map {|c| c.downcase }.reject {|m| m.empty? }
50
50
  self.results = Registry.all.select {|o|
@@ -57,7 +57,7 @@ module YARD
57
57
  !(query =~ /[#.]/) && query.include?("::")
58
58
  when :class, :module, :constant, :class_variable
59
59
  query =~ /[#.]/
60
- end
60
+ end
61
61
  }.sort_by {|o|
62
62
  name = (o.type == :method ? o.name(true) : o.name).to_s
63
63
  name.length.to_f / query.length.to_f
@@ -17,7 +17,7 @@ module YARD
17
17
  File.join(YARD::TEMPLATE_ROOT, 'default', 'fulldoc', 'html'),
18
18
  File.join(File.dirname(__FILE__), '..', 'templates', 'default', 'fulldoc', 'html')
19
19
  ]
20
-
20
+
21
21
  def run
22
22
  path = File.cleanpath(request.path).gsub(%r{^(../)+}, '')
23
23
  ([adapter.document_root] + STATIC_PATHS.reverse).compact.each do |path_prefix|
@@ -32,9 +32,9 @@ module YARD
32
32
  favicon?
33
33
  self.status = 404
34
34
  end
35
-
35
+
36
36
  private
37
-
37
+
38
38
  # Return an empty favicon.ico if it does not exist so that
39
39
  # browsers don't complain.
40
40
  def favicon?
@@ -18,10 +18,13 @@ module YARD
18
18
  # @param (see Templates::Helpers::HtmlHelper#url_for_file)
19
19
  # @return (see Templates::Helpers::HtmlHelper#url_for_file)
20
20
  def url_for_file(filename, anchor = nil)
21
- "/#{base_path(router.docs_prefix)}/file/" + filename.sub(%r{^#{@library.source_path.to_s}/}, '') +
21
+ if filename.is_a?(CodeObjects::ExtraFileObject)
22
+ filename = filename.filename
23
+ end
24
+ "/#{base_path(router.docs_prefix)}/file/" + filename.sub(%r{^#{@library.source_path.to_s}/}, '') +
22
25
  (anchor ? "##{anchor}" : "")
23
26
  end
24
-
27
+
25
28
  # @example The base path for a library 'foo'
26
29
  # base_path('docs') # => 'docs/foo'
27
30
  # @param [String] path the path prefix for a base path URI
@@ -29,7 +32,7 @@ module YARD
29
32
  def base_path(path)
30
33
  path + (@single_library ? '' : "/#{@library}")
31
34
  end
32
-
35
+
33
36
  # @return [Router] convenience method for accessing the router
34
37
  def router; @adapter.router end
35
38
  end
@@ -6,7 +6,7 @@ module YARD
6
6
  # static relative paths to files on disk.
7
7
  class DocServerSerializer < Serializers::FileSystemSerializer
8
8
  include WEBrick::HTTPUtils
9
-
9
+
10
10
  def initialize(command)
11
11
  super(:command => command, :extension => '')
12
12
  end
@@ -3,37 +3,37 @@ require 'fileutils'
3
3
  module YARD
4
4
  module Server
5
5
  # This exception is raised when {LibraryVersion#prepare!} fails, or discovers
6
- # that the library is not "prepared" to be served by
6
+ # that the library is not "prepared" to be served by
7
7
  class LibraryNotPreparedError < RuntimeError; end
8
-
8
+
9
9
  # A library version encapsulates a library's documentation at a specific version.
10
10
  # Although the version is optional, this allows for creating multiple documentation
11
11
  # points for a specific library, each representing a unique version. The term
12
- # "library" used in other parts of the YARD::Server documentation refers to
12
+ # "library" used in other parts of the YARD::Server documentation refers to
13
13
  # objects of this class unless otherwise noted.
14
- #
14
+ #
15
15
  # A library points to a location where a {#yardoc_file} is located so that
16
16
  # its documentation may be loaded and served. Optionally, a {#source_path} is
17
- # given to point to a location where any extra files (and {YARD::CLI::Yardoc .yardopts})
18
- # should be loaded from. Both of these methods may not be known immediately,
19
- # since the yardoc file may not be built until later. Resolving the yardoc
17
+ # given to point to a location where any extra files (and {YARD::CLI::Yardoc .yardopts})
18
+ # should be loaded from. Both of these methods may not be known immediately,
19
+ # since the yardoc file may not be built until later. Resolving the yardoc
20
20
  # file and source path are dependent on the specific library "source type" used.
21
21
  # Source types (known as "library source") are discussed in detail below.
22
- #
22
+ #
23
23
  # == Using with Adapters
24
24
  # A list of libraries need to be passed into adapters upon creation. In
25
25
  # most cases, you will never do this manually, but if you use a {RackMiddleware},
26
26
  # you will need to pass in this list yourself. To build this list of libraries,
27
27
  # you should create a hash of library names mapped to an *Array* of LibraryVersion
28
28
  # objects. For example:
29
- #
30
- # {'mylib' => [LibraryVersion.new('mylib', '1.0', ...),
29
+ #
30
+ # {'mylib' => [LibraryVersion.new('mylib', '1.0', ...),
31
31
  # LibraryVersion.new('mylib', '2.0', ...)]}
32
- #
32
+ #
33
33
  # Note that you can also use {Adapter#add_library} for convenience.
34
- #
34
+ #
35
35
  # The "array" part is required, even for just one library version.
36
- #
36
+ #
37
37
  # == Library Sources
38
38
  # The {#source} method represents the library source type, ie. where the
39
39
  # library "comes from". It might come from "disk", or it might come from a
@@ -43,73 +43,73 @@ module YARD
43
43
  # is controlled through the {#prepare!} method, which prepares the yardoc file
44
44
  # given a specific library source. We will see how this works in detail in
45
45
  # the following section.
46
- #
46
+ #
47
47
  # == Implementing a Custom Library Source
48
- # YARD can be extended to support custom library sources in order to
48
+ # YARD can be extended to support custom library sources in order to
49
49
  # build or retrieve a yardoc file at runtime from many different locations.
50
- #
50
+ #
51
51
  # To implement this behaviour, two methods must be added to the +LibraryVersion+
52
52
  # class, +#load_yardoc_from_SOURCE+ and +#source_path_for_SOURCE+. In both
53
53
  # cases, "SOURCE" represents the source type used in {#source} when creating
54
54
  # the library object. The +#source_path_for_SOURCE+ method is called upon
55
- # creation and should return the location where the source code for the library
55
+ # creation and should return the location where the source code for the library
56
56
  # lives. The load method is called from {#prepare!} if there is no yardoc file
57
57
  # and should set {#yardoc_file}. Below is a full example for
58
58
  # implementing a custom library source, +:http+, which reads packaged .yardoc
59
59
  # databases from zipped archives off of an HTTP server.
60
- #
60
+ #
61
61
  # @example Implementing a Custom Library Source
62
62
  # # Adds the source type "http" for .yardoc files zipped on HTTP servers
63
63
  # class LibraryVersion
64
64
  # def load_yardoc_from_http
65
65
  # return if yardoc_file # we have the library
66
- #
66
+ #
67
67
  # # otherwise download it in a thread and return immediately
68
- # Thread.new do
68
+ # Thread.new do
69
69
  # # zip/unzip method implementations are not shown
70
70
  # download_zip_file("http://mysite.com/yardocs/#{self}.zip")
71
71
  # unzip_file_to("/path/to/yardocs/#{self}")
72
72
  # self.yardoc_file = "/path/to/yardocs/#{self}/.yardoc"
73
73
  # self.source_path = self.yardoc_file
74
74
  # end
75
- #
75
+ #
76
76
  # # tell the server it's not ready yet (but it might be next time)
77
77
  # raise LibraryNotPreparedError
78
78
  # end
79
- #
79
+ #
80
80
  # # we set this later
81
81
  # def source_path_for_http; nil end
82
82
  # end
83
- #
83
+ #
84
84
  # # Creating a library of this source type:
85
85
  # LibraryVersion.new('name', '1.0', nil, :http)
86
- #
86
+ #
87
87
  class LibraryVersion
88
88
  # @return [String] the name of the library
89
89
  attr_accessor :name
90
-
90
+
91
91
  # @return [String] the version of the specific library
92
92
  attr_accessor :version
93
-
93
+
94
94
  # @return [String] the location of the yardoc file used to load the object
95
95
  # information from.
96
96
  # @return [nil] if no yardoc file exists yet. In this case, {#prepare!} will
97
97
  # be called on this library to build the yardoc file.
98
98
  attr_accessor :yardoc_file
99
-
99
+
100
100
  # @return [Symbol] the source type representing where the yardoc should be
101
101
  # loaded from. Defaults are +:disk+ and +:gem+, though custom sources
102
102
  # may be implemented. This value is used to inform {#prepare!} about how
103
103
  # to load the necessary data in order to display documentation for an object.
104
104
  # @see LibraryVersion LibraryVersion documentation for "Implementing a Custom Library Source"
105
105
  attr_accessor :source
106
-
106
+
107
107
  # @return [String] the location of the source code for a library. This
108
108
  # value is filled by calling +#source_path_for_SOURCE+ on this class.
109
109
  # @return [nil] if there is no source code
110
110
  # @see LibraryVersion LibraryVersion documentation for "Implementing a Custom Library Source"
111
111
  attr_accessor :source_path
112
-
112
+
113
113
  # @param [String] name the name of the library
114
114
  # @param [String] version the specific (usually, but not always, numeric) library
115
115
  # version
@@ -124,7 +124,7 @@ module YARD
124
124
  self.source = source
125
125
  self.source_path = load_source_path
126
126
  end
127
-
127
+
128
128
  # @param [Boolean] url_format if true, returns the string in a URI-compatible
129
129
  # format (for appending to a URL). Otherwise, it is given in a more human
130
130
  # readable format.
@@ -132,29 +132,29 @@ module YARD
132
132
  def to_s(url_format = true)
133
133
  version ? "#{name}#{url_format ? '/' : '-'}#{version}" : "#{name}"
134
134
  end
135
-
135
+
136
136
  # @return [Fixnum] used for Hash mapping.
137
137
  def hash; to_s.hash end
138
-
138
+
139
139
  # @return [Boolean] whether another LibraryVersion is equal to this one
140
140
  def eql?(other)
141
- other.is_a?(LibraryVersion) && other.name == name &&
141
+ other.is_a?(LibraryVersion) && other.name == name &&
142
142
  other.version == version && other.yardoc_file == yardoc_file
143
143
  end
144
144
  alias == eql?
145
145
  alias equal? eql?
146
-
146
+
147
147
  # @note You should not directly override this method. Instead, implement
148
148
  # +load_yardoc_from_SOURCENAME+ when implementing loading for a specific
149
149
  # source type. See the {LibraryVersion} documentation for "Implementing
150
150
  # a Custom Library Source"
151
- #
152
- # Prepares a library to be displayed by the server. This callback is
151
+ #
152
+ # Prepares a library to be displayed by the server. This callback is
153
153
  # performed before each request on a library to ensure that it is loaded
154
154
  # and ready to be viewed. If any steps need to be performed prior to loading,
155
155
  # they are performed through this method (though they should be implemented
156
156
  # through the +load_yardoc_from_SOURCE+ method).
157
- #
157
+ #
158
158
  # @raise [LibraryNotPreparedError] if the library is not ready to be
159
159
  # displayed. Usually when raising this error, you would simultaneously
160
160
  # begin preparing the library for subsequent requests, although this
@@ -164,7 +164,7 @@ module YARD
164
164
  meth = "load_yardoc_from_#{source}"
165
165
  send(meth) if respond_to?(meth)
166
166
  end
167
-
167
+
168
168
  # @return [Gem::Specification] a gemspec object for a given library. Used
169
169
  # for :gem source types.
170
170
  # @return [nil] if there is no installed gem for the library
@@ -172,7 +172,7 @@ module YARD
172
172
  ver = version ? "= #{version}" : ">= 0"
173
173
  Gem.source_index.find_name(name, ver).first
174
174
  end
175
-
175
+
176
176
  protected
177
177
 
178
178
  # Called when a library of source type "disk" is to be prepared. In this
@@ -181,11 +181,11 @@ module YARD
181
181
  def load_yardoc_from_disk
182
182
  nil
183
183
  end
184
-
184
+
185
185
  # Called when a library of source type "gem" is to be prepared. In this
186
186
  # case, the {#yardoc_file} needs to point to the correct location for
187
187
  # the installed gem. The yardoc file is built if it has not been done.
188
- #
188
+ #
189
189
  # @raise [LibraryNotPreparedError] if the gem does not have an existing
190
190
  # yardoc file.
191
191
  def load_yardoc_from_gem
@@ -205,19 +205,19 @@ module YARD
205
205
  raise LibraryNotPreparedError
206
206
  end
207
207
  end
208
-
208
+
209
209
  # @return [String] the source path for a disk source
210
210
  def source_path_for_disk
211
211
  File.dirname(yardoc_file) if yardoc_file
212
212
  end
213
-
213
+
214
214
  # @return [String] the source path for a gem source
215
215
  def source_path_for_gem
216
216
  gemspec.full_gem_path if gemspec
217
217
  end
218
-
218
+
219
219
  private
220
-
220
+
221
221
  def load_source_path
222
222
  meth = "source_path_for_#{source}"
223
223
  send(meth) if respond_to?(meth)