lib/yard/server/commands/base.rb in yard-0.9.2 vs lib/yard/server/commands/base.rb in yard-0.9.3

- old
+ new

@@ -85,22 +85,25 @@ # @param [Adapter Dependent] request the request object # @return [Array(Numeric,Hash,Array<String>)] a Rack-style response # of status, headers, and body wrapped in an array. def call(request) self.request = request - self.path ||= request.path[1..-1] + self.path ||= request.path_info[1..-1] self.headers = {'Content-Type' => 'text/html'} self.body = '' self.status = 200 begin run rescue FinishRequest rescue NotFoundError => e self.body = e.message if e.message != e.class.to_s - self.status = 404 + not_found end + + # keep this to support commands setting status manually. not_found if status == 404 + [status, headers, body.is_a?(Array) ? body : [body]] end # @group Abstract Methods @@ -156,23 +159,24 @@ # @param [String] data the data to cache # @return [String] the same cached data (for chaining) # @see StaticCaching def cache(data) if caching && adapter.document_root - path = File.join(adapter.document_root, request.path.sub(/\.html$/, '') + '.html') + path = File.join(adapter.document_root, request.path_info.sub(/\.html$/, '') + '.html') path = path.sub(%r{/\.html$}, '.html') FileUtils.mkdir_p(File.dirname(path)) log.debug "Caching data to #{path}" File.open(path, 'wb') {|f| f.write(data) } end self.body = data end - # Sets the body and headers (but not status) for a 404 response. Does - # nothing if the body is already set. + # Sets the body and headers for a 404 response. Does not modify the + # body if already set. # # @return [void] def not_found + self.status = 404 return unless body.empty? self.body = "Not found: #{request.path}" self.headers['Content-Type'] = 'text/plain' self.headers['X-Cascade'] = 'pass' end