class YARD::Server::Commands::SearchCommand
Performs a search over the objects inside of a library and returns the results as HTML or plaintext
Attributes
query[RW]
results[RW]
Public Instance Methods
run()
click to toggle source
# File lib/yard/server/commands/search_command.rb, line 13 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(url_for(found)) end search_for_object request.xhr? ? serve_xhr : serve_normal end
visible_results()
click to toggle source
# File lib/yard/server/commands/search_command.rb, line 24 def visible_results results[0, 10] end
Private Instance Methods
search_for_object()
click to toggle source
# File lib/yard/server/commands/search_command.rb, line 57 def search_for_object splitquery = query.split(/\s+/).map {|c| c.downcase }.reject {|m| m.empty? } self.results = run_verifier(Registry.all).select {|o| o.path.downcase.include?(query.downcase) }.reject {|o| name = (o.type == :method ? o.name(true) : o.name).to_s.downcase !name.include?(query.downcase) || case o.type when :method !(query =~ /[#.]/) && query.include?("::") when :class, :module, :constant, :class_variable query =~ /[#.]/ end }.sort_by {|o| name = (o.type == :method ? o.name(true) : o.name).to_s name.length.to_f / query.length.to_f } end
serve_normal()
click to toggle source
# File lib/yard/server/commands/search_command.rb, line 46 def serve_normal options.update( :visible_results => visible_results, :query => query, :results => results, :template => :doc_server, :type => :search ) self.body = Templates::Engine.render(options) end
serve_xhr()
click to toggle source
# File lib/yard/server/commands/search_command.rb, line 35 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, url_for(o) ].join(",") }.join("\n") end
url_for(object)
click to toggle source
# File lib/yard/server/commands/search_command.rb, line 30 def url_for(object) File.join('', base_path(router.docs_prefix), serializer.serialized_path(object)) end