yard 0.5.8 → 0.6.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 (211) hide show
  1. data/.yardopts +2 -0
  2. data/ChangeLog +1064 -0
  3. data/README.md +103 -42
  4. data/Rakefile +3 -2
  5. data/benchmarks/parsing.rb +2 -1
  6. data/bin/yard +4 -0
  7. data/bin/yard-graph +1 -1
  8. data/bin/yard-server +4 -0
  9. data/docs/GettingStarted.md +8 -8
  10. data/docs/Handlers.md +5 -5
  11. data/docs/Overview.md +5 -5
  12. data/docs/Parser.md +1 -1
  13. data/docs/Tags.md +1 -1
  14. data/docs/Templates.md +27 -6
  15. data/docs/WhatsNew.md +222 -2
  16. data/lib/rubygems_plugin.rb +1 -0
  17. data/lib/yard.rb +7 -1
  18. data/lib/yard/autoload.rb +46 -6
  19. data/lib/yard/cli/{base.rb → command.rb} +20 -6
  20. data/lib/yard/cli/command_parser.rb +87 -0
  21. data/lib/yard/cli/diff.rb +176 -0
  22. data/lib/yard/cli/gems.rb +74 -0
  23. data/lib/yard/cli/{yard_graph.rb → graph.rb} +9 -8
  24. data/lib/yard/cli/help.rb +18 -0
  25. data/lib/yard/cli/server.rb +137 -0
  26. data/lib/yard/cli/stats.rb +210 -0
  27. data/lib/yard/cli/yardoc.rb +315 -116
  28. data/lib/yard/cli/yri.rb +45 -4
  29. data/lib/yard/code_objects/base.rb +73 -30
  30. data/lib/yard/code_objects/class_object.rb +9 -1
  31. data/lib/yard/code_objects/method_object.rb +11 -0
  32. data/lib/yard/code_objects/namespace_object.rb +8 -2
  33. data/lib/yard/code_objects/proxy.rb +2 -2
  34. data/lib/yard/core_ext/array.rb +3 -49
  35. data/lib/yard/core_ext/file.rb +7 -0
  36. data/lib/yard/core_ext/insertion.rb +60 -0
  37. data/lib/yard/docstring.rb +34 -7
  38. data/lib/yard/globals.rb +2 -2
  39. data/lib/yard/handlers/base.rb +101 -20
  40. data/lib/yard/handlers/processor.rb +23 -7
  41. data/lib/yard/handlers/ruby/alias_handler.rb +1 -0
  42. data/lib/yard/handlers/ruby/attribute_handler.rb +8 -0
  43. data/lib/yard/handlers/ruby/base.rb +71 -2
  44. data/lib/yard/handlers/ruby/class_condition_handler.rb +10 -0
  45. data/lib/yard/handlers/ruby/class_handler.rb +7 -4
  46. data/lib/yard/handlers/ruby/class_variable_handler.rb +1 -0
  47. data/lib/yard/handlers/ruby/constant_handler.rb +1 -0
  48. data/lib/yard/handlers/ruby/exception_handler.rb +1 -0
  49. data/lib/yard/handlers/ruby/extend_handler.rb +2 -3
  50. data/lib/yard/handlers/ruby/legacy/alias_handler.rb +1 -0
  51. data/lib/yard/handlers/ruby/legacy/attribute_handler.rb +2 -0
  52. data/lib/yard/handlers/ruby/legacy/base.rb +15 -2
  53. data/lib/yard/handlers/ruby/legacy/class_condition_handler.rb +5 -0
  54. data/lib/yard/handlers/ruby/legacy/class_handler.rb +7 -4
  55. data/lib/yard/handlers/ruby/legacy/class_variable_handler.rb +1 -0
  56. data/lib/yard/handlers/ruby/legacy/constant_handler.rb +1 -0
  57. data/lib/yard/handlers/ruby/legacy/exception_handler.rb +1 -0
  58. data/lib/yard/handlers/ruby/legacy/extend_handler.rb +1 -3
  59. data/lib/yard/handlers/ruby/legacy/method_handler.rb +7 -3
  60. data/lib/yard/handlers/ruby/legacy/mixin_handler.rb +2 -1
  61. data/lib/yard/handlers/ruby/legacy/module_handler.rb +1 -0
  62. data/lib/yard/handlers/ruby/legacy/process_handler.rb +1 -0
  63. data/lib/yard/handlers/ruby/legacy/visibility_handler.rb +1 -0
  64. data/lib/yard/handlers/ruby/legacy/yield_handler.rb +1 -0
  65. data/lib/yard/handlers/ruby/method_condition_handler.rb +1 -0
  66. data/lib/yard/handlers/ruby/method_handler.rb +5 -1
  67. data/lib/yard/handlers/ruby/mixin_handler.rb +2 -1
  68. data/lib/yard/handlers/ruby/module_handler.rb +1 -0
  69. data/lib/yard/handlers/ruby/process_handler.rb +7 -1
  70. data/lib/yard/handlers/ruby/struct_handler_methods.rb +3 -0
  71. data/lib/yard/handlers/ruby/visibility_handler.rb +8 -2
  72. data/lib/yard/handlers/ruby/yield_handler.rb +1 -0
  73. data/lib/yard/logging.rb +7 -1
  74. data/lib/yard/parser/base.rb +1 -0
  75. data/lib/yard/parser/c_parser.rb +2 -0
  76. data/lib/yard/parser/ruby/ast_node.rb +82 -63
  77. data/lib/yard/parser/ruby/legacy/ruby_lex.rb +36 -10
  78. data/lib/yard/parser/ruby/legacy/ruby_parser.rb +1 -0
  79. data/lib/yard/parser/ruby/legacy/statement.rb +9 -5
  80. data/lib/yard/parser/ruby/legacy/statement_list.rb +20 -11
  81. data/lib/yard/parser/ruby/ruby_parser.rb +18 -1
  82. data/lib/yard/parser/source_parser.rb +6 -1
  83. data/lib/yard/registry.rb +284 -278
  84. data/lib/yard/registry_store.rb +4 -2
  85. data/lib/yard/serializers/base.rb +30 -13
  86. data/lib/yard/serializers/file_system_serializer.rb +10 -1
  87. data/lib/yard/server/adapter.rb +51 -0
  88. data/lib/yard/server/commands/base.rb +98 -0
  89. data/lib/yard/server/commands/display_file_command.rb +20 -0
  90. data/lib/yard/server/commands/display_object_command.rb +50 -0
  91. data/lib/yard/server/commands/frames_command.rb +31 -0
  92. data/lib/yard/server/commands/library_command.rb +83 -0
  93. data/lib/yard/server/commands/library_index_command.rb +23 -0
  94. data/lib/yard/server/commands/list_command.rb +44 -0
  95. data/lib/yard/server/commands/search_command.rb +67 -0
  96. data/lib/yard/server/commands/static_file_command.rb +45 -0
  97. data/lib/yard/server/doc_server_helper.rb +22 -0
  98. data/lib/yard/server/doc_server_serializer.rb +29 -0
  99. data/lib/yard/server/library_version.rb +86 -0
  100. data/lib/yard/server/rack_adapter.rb +38 -0
  101. data/lib/yard/server/router.rb +110 -0
  102. data/lib/yard/server/static_caching.rb +16 -0
  103. data/lib/yard/server/templates/default/fulldoc/html/css/custom.css +78 -0
  104. data/lib/yard/server/templates/default/fulldoc/html/images/processing.gif +0 -0
  105. data/lib/yard/server/templates/default/fulldoc/html/js/autocomplete.js +12 -0
  106. data/lib/yard/server/templates/default/fulldoc/html/js/live.js +32 -0
  107. data/lib/yard/server/templates/default/layout/html/breadcrumb.erb +46 -0
  108. data/lib/yard/server/templates/default/layout/html/headers.erb +11 -0
  109. data/lib/yard/server/templates/doc_server/frames/html/frames.erb +13 -0
  110. data/lib/yard/server/templates/doc_server/frames/html/setup.rb +3 -0
  111. data/lib/yard/server/templates/doc_server/full_list/html/full_list.erb +34 -0
  112. data/lib/yard/server/templates/doc_server/full_list/html/setup.rb +10 -0
  113. data/lib/yard/server/templates/doc_server/library_list/html/contents.erb +13 -0
  114. data/lib/yard/server/templates/doc_server/library_list/html/headers.erb +26 -0
  115. data/lib/yard/server/templates/doc_server/library_list/html/library_list.erb +12 -0
  116. data/lib/yard/server/templates/doc_server/library_list/html/setup.rb +3 -0
  117. data/lib/yard/server/templates/doc_server/library_list/html/title.erb +2 -0
  118. data/lib/yard/server/templates/doc_server/processing/html/processing.erb +51 -0
  119. data/lib/yard/server/templates/doc_server/processing/html/setup.rb +3 -0
  120. data/lib/yard/server/templates/doc_server/search/html/search.erb +19 -0
  121. data/lib/yard/server/templates/doc_server/search/html/setup.rb +8 -0
  122. data/lib/yard/server/webrick_adapter.rb +38 -0
  123. data/lib/yard/tags/default_factory.rb +0 -5
  124. data/lib/yard/tags/library.rb +61 -22
  125. data/lib/yard/tags/tag.rb +26 -4
  126. data/lib/yard/templates/engine.rb +12 -1
  127. data/lib/yard/templates/erb_cache.rb +2 -1
  128. data/lib/yard/templates/helpers/base_helper.rb +96 -3
  129. data/lib/yard/templates/helpers/filter_helper.rb +5 -0
  130. data/lib/yard/templates/helpers/html_helper.rb +204 -94
  131. data/lib/yard/templates/helpers/html_syntax_highlight_helper.rb +4 -0
  132. data/lib/yard/templates/helpers/markup_helper.rb +58 -3
  133. data/lib/yard/templates/helpers/method_helper.rb +7 -0
  134. data/lib/yard/templates/helpers/module_helper.rb +5 -0
  135. data/lib/yard/templates/helpers/text_helper.rb +10 -1
  136. data/lib/yard/templates/helpers/uml_helper.rb +13 -0
  137. data/lib/yard/templates/section.rb +106 -0
  138. data/lib/yard/templates/template.rb +20 -19
  139. data/lib/yard/verifier.rb +21 -2
  140. data/spec/cli/command_parser_spec.rb +43 -0
  141. data/spec/cli/diff_spec.rb +170 -0
  142. data/spec/cli/help_spec.rb +22 -0
  143. data/spec/cli/server_spec.rb +140 -0
  144. data/spec/cli/stats_spec.rb +75 -0
  145. data/spec/cli/yardoc_spec.rb +438 -182
  146. data/spec/cli/yri_spec.rb +13 -1
  147. data/spec/code_objects/base_spec.rb +51 -6
  148. data/spec/code_objects/class_object_spec.rb +15 -1
  149. data/spec/code_objects/method_object_spec.rb +29 -0
  150. data/spec/code_objects/namespace_object_spec.rb +150 -129
  151. data/spec/core_ext/array_spec.rb +4 -23
  152. data/spec/core_ext/insertion_spec.rb +37 -0
  153. data/spec/docstring_spec.rb +63 -0
  154. data/spec/handlers/attribute_handler_spec.rb +4 -0
  155. data/spec/handlers/base_spec.rb +98 -26
  156. data/spec/handlers/class_handler_spec.rb +5 -1
  157. data/spec/handlers/examples/attribute_handler_001.rb.txt +5 -0
  158. data/spec/handlers/examples/class_handler_001.rb.txt +4 -0
  159. data/spec/handlers/examples/module_handler_001.rb.txt +6 -1
  160. data/spec/handlers/examples/visibility_handler_001.rb.txt +4 -0
  161. data/spec/handlers/method_handler_spec.rb +5 -0
  162. data/spec/handlers/module_handler_spec.rb +4 -0
  163. data/spec/handlers/visibility_handler_spec.rb +6 -0
  164. data/spec/parser/source_parser_spec.rb +24 -0
  165. data/spec/registry_spec.rb +44 -8
  166. data/spec/server/adapter_spec.rb +38 -0
  167. data/spec/server/commands/base_spec.rb +87 -0
  168. data/spec/server/commands/static_file_command_spec.rb +67 -0
  169. data/spec/server/doc_server_serializer_spec.rb +58 -0
  170. data/spec/server/router_spec.rb +115 -0
  171. data/spec/server/spec_helper.rb +17 -0
  172. data/spec/server/static_caching_spec.rb +39 -0
  173. data/spec/server/webrick_servlet_spec.rb +20 -0
  174. data/spec/templates/constant_spec.rb +40 -0
  175. data/spec/templates/engine_spec.rb +9 -5
  176. data/spec/templates/examples/class002.html +1 -3
  177. data/spec/templates/examples/constant001.txt +25 -0
  178. data/spec/templates/examples/constant002.txt +7 -0
  179. data/spec/templates/examples/constant003.txt +11 -0
  180. data/spec/templates/examples/module001.txt +1 -1
  181. data/spec/templates/examples/module002.html +319 -0
  182. data/spec/templates/helpers/base_helper_spec.rb +2 -2
  183. data/spec/templates/helpers/html_helper_spec.rb +93 -3
  184. data/spec/templates/helpers/html_syntax_highlight_helper_spec.rb +5 -0
  185. data/spec/templates/helpers/markup_helper_spec.rb +94 -67
  186. data/spec/templates/helpers/shared_signature_examples.rb +9 -0
  187. data/spec/templates/helpers/text_helper_spec.rb +12 -0
  188. data/spec/templates/module_spec.rb +21 -4
  189. data/spec/templates/section_spec.rb +146 -0
  190. data/spec/templates/template_spec.rb +9 -20
  191. data/templates/default/class/setup.rb +5 -5
  192. data/templates/default/constant/text/header.erb +11 -0
  193. data/templates/default/constant/text/setup.rb +3 -0
  194. data/templates/default/fulldoc/html/css/style.css +29 -3
  195. data/templates/default/fulldoc/html/js/app.js +67 -1
  196. data/templates/default/fulldoc/html/js/full_list.js +3 -8
  197. data/templates/default/fulldoc/html/js/jquery.js +150 -15
  198. data/templates/default/fulldoc/html/setup.rb +9 -0
  199. data/templates/default/layout/html/footer.erb +1 -1
  200. data/templates/default/layout/html/setup.rb +7 -25
  201. data/templates/default/method_details/html/source.erb +1 -1
  202. data/templates/default/module/html/attribute_summary.erb +2 -2
  203. data/templates/default/module/html/method_summary.erb +2 -2
  204. data/templates/default/module/setup.rb +27 -4
  205. data/templates/default/onefile/html/files.erb +5 -0
  206. data/templates/default/onefile/html/layout.erb +22 -0
  207. data/templates/default/onefile/html/readme.erb +3 -0
  208. data/templates/default/onefile/html/setup.rb +40 -0
  209. data/templates/default/root/html/setup.rb +1 -0
  210. data/templates/default/tags/setup.rb +26 -33
  211. metadata +80 -10
@@ -11,11 +11,13 @@ module YARD
11
11
  def initialize
12
12
  @file = nil
13
13
  @checksums = {}
14
- @store = { :root => CodeObjects::RootObject.new(nil, :root) }
14
+ @store = {}
15
15
  @proxy_types = {}
16
16
  @notfound = {}
17
17
  @loaded_objects = 0
18
18
  @available_objects = 0
19
+ @store[:root] = CodeObjects::RootObject.allocate
20
+ @store[:root].send(:initialize, nil, :root)
19
21
  end
20
22
 
21
23
  # Gets a {CodeObjects::Base} from the store
@@ -94,6 +96,7 @@ module YARD
94
96
  # @param [String, nil] file the name of the yardoc db to load
95
97
  # @return [Boolean] whether the database was loaded
96
98
  # @see #load_all
99
+ # @since 0.5.1
97
100
  def load!(file = nil)
98
101
  if load(file)
99
102
  load_all
@@ -180,7 +183,6 @@ module YARD
180
183
  def load_yardoc
181
184
  return false unless @file
182
185
  if File.directory?(@file) # new format
183
- Registry.objects.replace({})
184
186
  @loaded_objects = 0
185
187
  @available_objects = all_disk_objects.size
186
188
  load_proxy_types
@@ -19,6 +19,8 @@ module YARD
19
19
  # @return [SymbolHash] the serializer options
20
20
  attr_reader :options
21
21
 
22
+ # @group Creating a New Serializer
23
+
22
24
  # Creates a new serializer with options
23
25
  #
24
26
  # @param [Hash] opts the options to assign to {#options}
@@ -26,19 +28,7 @@ module YARD
26
28
  @options = SymbolHash.new(false).update(opts)
27
29
  end
28
30
 
29
- # Called before serialization.
30
- #
31
- # @abstract Should run code before serialization. Should return false
32
- # if serialization should not occur.
33
- # @return [Boolean] whether or not serialization should occur
34
- def before_serialize; end
35
-
36
- # Called after serialization.
37
- #
38
- # @abstract Should run code after serialization.
39
- # @param [String] data the data that was serialized.
40
- # @return [void]
41
- def after_serialize(data); end
31
+ # @group Serializing an Object
42
32
 
43
33
  # Serializes an object.
44
34
  #
@@ -58,6 +48,33 @@ module YARD
58
48
  # @param [CodeObjects::Base] object the object to return a path for
59
49
  # @return [String] the serialized path of an object
60
50
  def serialized_path(object) end
51
+
52
+ # Returns whether an object has been serialized
53
+ #
54
+ # @abstract This method should return whether the endpoint already exists.
55
+ # For instance, a file system serializer would check if the file exists
56
+ # on disk. You will most likely use +#basepath+ and {#serialized_path} to
57
+ # get the endpoint's location.
58
+ # @param [CodeObjects::Base] object the object to check existence of
59
+ # @return [Boolean] whether the endpoint exists.
60
+ # @since 0.6.0
61
+ def exists?(object) false end
62
+
63
+ # @group Callbacks
64
+
65
+ # Called before serialization.
66
+ #
67
+ # @abstract Should run code before serialization. Should return false
68
+ # if serialization should not occur.
69
+ # @return [Boolean] whether or not serialization should occur
70
+ def before_serialize; end
71
+
72
+ # Called after serialization.
73
+ #
74
+ # @abstract Should run code after serialization.
75
+ # @param [String] data the data that was serialized.
76
+ # @return [void]
77
+ def after_serialize(data); end
61
78
  end
62
79
  end
63
80
  end
@@ -1,5 +1,6 @@
1
1
  module YARD
2
2
  module Serializers
3
+ # Implements a serializer that reads from and writes to the filesystem.
3
4
  class FileSystemSerializer < Base
4
5
  # The base path to write data to.
5
6
  # @return [String] a base path
@@ -29,7 +30,7 @@ module YARD
29
30
  @extension = (options.has_key?(:extension) ? options[:extension] : 'html').to_s
30
31
  end
31
32
 
32
- # Serializes object with data to its serialized path (prefixed by the {#basepath}).
33
+ # Serializes object with data to its serialized path (prefixed by the +#basepath+).
33
34
  #
34
35
  # @return [String] the written data (for chaining)
35
36
  def serialize(object, data)
@@ -74,6 +75,14 @@ module YARD
74
75
 
75
76
  File.join(fspath)
76
77
  end
78
+
79
+ # Checks the disk for an object and returns whether it was serialized.
80
+ #
81
+ # @param [CodeObjects::Base] object the object to check
82
+ # @return [Boolean] whether an object has been serialized to disk
83
+ def exists?(object)
84
+ File.exist?(File.join(basepath, serialized_path(object)))
85
+ end
77
86
  end
78
87
  end
79
88
  end
@@ -0,0 +1,51 @@
1
+ module YARD
2
+ module Server
3
+ class FinishRequest < RuntimeError; end
4
+ class NotFoundError < RuntimeError; end
5
+
6
+ class Adapter
7
+ # @return [String] the location where static files are located, if any
8
+ attr_accessor :document_root
9
+
10
+ attr_accessor :libraries
11
+
12
+ attr_accessor :options
13
+
14
+ attr_accessor :server_options
15
+
16
+ attr_accessor :router
17
+
18
+ def self.setup
19
+ Templates::Template.extra_includes |= [YARD::Server::DocServerHelper]
20
+ Templates::Engine.template_paths |= [File.dirname(__FILE__) + '/templates']
21
+ end
22
+
23
+ def self.shutdown
24
+ Templates::Template.extra_includes -= [YARD::Server::DocServerHelper]
25
+ Templates::Engine.template_paths -= [File.dirname(__FILE__) + '/templates']
26
+ end
27
+
28
+ def initialize(libs, opts = {}, server_opts = {})
29
+ self.class.setup
30
+ self.libraries = libs
31
+ self.options = opts
32
+ self.server_options = server_opts
33
+ self.document_root = server_options[:DocumentRoot]
34
+ self.router = (options[:router] || Router).new(self)
35
+ options[:adapter] = self
36
+ log.debug "Serving libraries using #{self.class}: #{libraries.keys.join(', ')}"
37
+ log.debug "Caching on" if options[:caching]
38
+ log.debug "Document root: #{document_root}" if document_root
39
+ end
40
+
41
+ def add_library(library)
42
+ libraries[library.name] ||= []
43
+ libraries[library.name] |= [library]
44
+ end
45
+
46
+ def start
47
+ raise NotImplementedError
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,98 @@
1
+ require 'fileutils'
2
+
3
+ module YARD
4
+ module Server
5
+ module Commands
6
+ class Base
7
+ # @return [Hash] the options passed to the command's constructor
8
+ attr_accessor :command_options
9
+
10
+ # @return [Request] request object
11
+ attr_accessor :request
12
+
13
+ # @return [String] the path after the command base URI
14
+ attr_accessor :path
15
+
16
+ # @return [Hash{String => String}] response headers
17
+ attr_accessor :headers
18
+
19
+ # @return [Numeric] status code
20
+ attr_accessor :status
21
+
22
+ # @return [String] the response body
23
+ attr_accessor :body
24
+
25
+ # @return [Adapter] the server adapter
26
+ attr_accessor :adapter
27
+
28
+ # @return [Boolean] whether to cache
29
+ attr_accessor :caching
30
+
31
+ def initialize(opts = {})
32
+ opts.each do |key, value|
33
+ send("#{key}=", value) if respond_to?("#{key}=")
34
+ end
35
+ self.command_options = opts
36
+ end
37
+
38
+ def call(request)
39
+ self.request = request
40
+ self.path ||= request.path[1..-1]
41
+ self.headers = {'Content-Type' => 'text/html'}
42
+ self.body = ''
43
+ self.status = 200
44
+ begin
45
+ run
46
+ rescue FinishRequest
47
+ rescue NotFoundError => e
48
+ self.body = e.message if e.message != e.class.to_s
49
+ self.status = 404
50
+ end
51
+ not_found if status == 404
52
+ [status, headers, body.is_a?(Array) ? body : [body]]
53
+ end
54
+
55
+ def run
56
+ raise NotImplementedError
57
+ end
58
+
59
+ def not_found
60
+ return unless body.empty?
61
+ self.body = "Not found: #{request.path}"
62
+ self.headers['Content-Type'] = 'text/plain'
63
+ self.headers['X-Cascade'] = 'pass'
64
+ end
65
+
66
+ protected
67
+
68
+ def cache(data)
69
+ if caching && adapter.document_root
70
+ path = File.join(adapter.document_root, request.path.sub(/\.html$/, '') + '.html')
71
+ path = path.sub(%r{/\.html$}, '.html')
72
+ FileUtils.mkdir_p(File.dirname(path))
73
+ log.debug "Caching data to #{path}"
74
+ File.open(path, 'wb') {|f| f.write(data) }
75
+ end
76
+ self.body = data
77
+ end
78
+
79
+ def render(object = nil)
80
+ case object
81
+ when CodeObjects::Base
82
+ cache object.format(options)
83
+ when nil
84
+ cache Templates::Engine.render(options)
85
+ else
86
+ cache object
87
+ end
88
+ end
89
+
90
+ def redirect(url)
91
+ headers['Location'] = url
92
+ self.status = 302
93
+ raise FinishRequest
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,20 @@
1
+ module YARD
2
+ module Server
3
+ module Commands
4
+ class DisplayFileCommand < LibraryCommand
5
+ def run
6
+ ppath = library.source_path
7
+ filename = File.cleanpath(File.join(library.source_path, path))
8
+ raise NotFoundError if !File.file?(filename)
9
+ if filename =~ /\.(jpe?g|gif|png|bmp)$/i
10
+ headers['Content-Type'] = StaticFileCommand::DefaultMimeTypes[$1.downcase] || 'text/html'
11
+ render IO.read(filename)
12
+ else
13
+ options.update(:object => Registry.root, :type => :layout, :file => filename)
14
+ render
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,50 @@
1
+ module YARD
2
+ module Server
3
+ module Commands
4
+ class DisplayObjectCommand < LibraryCommand
5
+ def run
6
+ return index if path.empty?
7
+
8
+ if object = Registry.at(object_path)
9
+ options.update(:type => :layout)
10
+ render(object)
11
+ else
12
+ self.status = 404
13
+ end
14
+ end
15
+
16
+ def index
17
+ Registry.load_all
18
+
19
+ title = options[:title]
20
+ unless title
21
+ title = "Documentation for #{library.name} #{library.version ? '(' + library.version + ')' : ''}"
22
+ end
23
+ options.update(
24
+ :object => '_index.html',
25
+ :objects => Registry.all(:module, :class),
26
+ :title => title,
27
+ :type => :layout
28
+ )
29
+ render
30
+ end
31
+
32
+ def not_found
33
+ super
34
+ self.body = "Could not find object: #{object_path}"
35
+ end
36
+
37
+ private
38
+
39
+ def object_path
40
+ return @object_path if @object_path
41
+ if path == "toplevel"
42
+ @object_path = :root
43
+ else
44
+ @object_path = path.sub(':', '#').gsub('/', '::').sub(/^toplevel\b/, '').sub(/\.html$/, '')
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,31 @@
1
+ module YARD
2
+ module Server
3
+ module Commands
4
+ class FramesCommand < DisplayObjectCommand
5
+ include DocServerHelper
6
+
7
+ def run
8
+ main_url = request.path.gsub(/^(.+)?\/frames\/(#{path})$/, '\1/\2')
9
+ if path =~ %r{^file/}
10
+ page_title = "File: #{$'}"
11
+ elsif !path.empty?
12
+ page_title = "Object: #{object_path}"
13
+ elsif options[:files] && options[:files].size > 0
14
+ page_title = "File: #{options[:files].first.sub(/^#{library.source_path}\/?/, '')}"
15
+ main_url = url_for_file(options[:files].first)
16
+ elsif !path || path.empty?
17
+ page_title = "Documentation for #{library.name} #{library.version ? '(' + library.version + ')' : ''}"
18
+ end
19
+
20
+ options.update(
21
+ :page_title => page_title,
22
+ :main_url => main_url,
23
+ :template => :doc_server,
24
+ :type => :frames
25
+ )
26
+ render
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,83 @@
1
+ module YARD
2
+ module Server
3
+ module Commands
4
+ class LibraryCommand < Base
5
+ # @return [LibraryVersion] the object containing library information
6
+ attr_accessor :library
7
+
8
+ # @return [Hash{Symbol => Object}] default options for the library
9
+ attr_accessor :options
10
+
11
+ # @return [Serializers::Base] the serializer used to perform file linking
12
+ attr_accessor :serializer
13
+
14
+ # @return [Boolean] whether router should route for multiple libraries
15
+ attr_accessor :single_library
16
+
17
+ # @return [Boolean] whether to reparse data
18
+ attr_accessor :incremental
19
+
20
+ def initialize(opts = {})
21
+ super
22
+ self.serializer = DocServerSerializer.new(self)
23
+ end
24
+
25
+ def call(request)
26
+ self.options = SymbolHash.new(false).update(
27
+ :serialize => false,
28
+ :serializer => serializer,
29
+ :library => library,
30
+ :adapter => adapter,
31
+ :single_library => single_library,
32
+ :markup => :rdoc,
33
+ :format => :html
34
+ )
35
+ setup_library
36
+ super
37
+ rescue LibraryNotPreparedError
38
+ not_prepared(request)
39
+ end
40
+
41
+ private
42
+
43
+ def setup_library
44
+ library.prepare!
45
+ load_yardoc
46
+ setup_yardopts
47
+ true
48
+ end
49
+
50
+ def setup_yardopts
51
+ Dir.chdir(library.source_path)
52
+ yardoc = CLI::Yardoc.new
53
+ if incremental
54
+ yardoc.run('-c', '-n', '--no-stats')
55
+ else
56
+ yardoc.parse_arguments
57
+ end
58
+ yardoc.options.delete(:serializer)
59
+ yardoc.options[:files].unshift(*Dir.glob(library.source_path + '/README*'))
60
+ options.update(yardoc.options.to_hash)
61
+ end
62
+
63
+ def load_yardoc
64
+ if @@last_yardoc == library.yardoc_file
65
+ log.debug "Reusing yardoc file: #{library.yardoc_file}"
66
+ return
67
+ end
68
+ Registry.clear
69
+ Registry.load_yardoc(library.yardoc_file)
70
+ @@last_yardoc = library.yardoc_file
71
+ end
72
+
73
+ def not_prepared(request)
74
+ self.caching = false
75
+ options.update(:path => request.path, :template => :doc_server, :type => :processing)
76
+ [302, {'Content-Type' => 'text/html'}, [render]]
77
+ end
78
+
79
+ @@last_yardoc = nil
80
+ end
81
+ end
82
+ end
83
+ end