lib/yard/server/commands/search_command.rb in yard-0.7.5 vs lib/yard/server/commands/search_command.rb in yard-0.8.0

- old
+ new

@@ -4,19 +4,20 @@ # Performs a search over the objects inside of a library and returns # the results as HTML or plaintext class SearchCommand < LibraryCommand include Templates::Helpers::BaseHelper include Templates::Helpers::ModuleHelper + include DocServerHelper attr_accessor :results, :query def run Registry.load_all self.query = request.query['q'] redirect("/#{adapter.router.docs_prefix}/#{single_library ? library : ''}") if query.nil? || query =~ /\A\s*\Z/ if found = Registry.at(query) - redirect(serializer.serialized_path(found)) + redirect(url_for(found)) end search_for_object request.xhr? ? serve_xhr : serve_normal end @@ -24,16 +25,21 @@ results[0, 10] end private + def url_for(object) + File.join('', base_path(router.docs_prefix), + serializer.serialized_path(object)) + end + def serve_xhr self.headers['Content-Type'] = 'text/plain' self.body = visible_results.map {|o| [(o.type == :method ? o.name(true) : o.name).to_s, o.path, o.namespace.root? ? '' : o.namespace.path, - serializer.serialized_path(o) + url_for(o) ].join(",") }.join("\n") end def serve_normal