Refactoring of Wiki.search.

This commit is contained in:
Sirupsen
2010-08-29 14:30:30 +02:00
parent 49d88a0370
commit 45eb364a6d
+9 -12
View File
@@ -214,20 +214,17 @@ module Gollum
# #
# Returns an Array with Objects of page name and count of matches # Returns an Array with Objects of page name and count of matches
def search(query) def search(query)
search_command = "cd #{$path} && git grep -c '#{query}' master" search_output = `cd #{$path} && git grep -c '#{query}' master`
command_output = `#{search_command}`
results = [] search_output.split("\n").collect do |line|
command_output.each_line do |line| result = line.split(':')
result = line.split(":") file_name = result[1]
file = result[1]
count = result[2].to_i {
name = file.split(".")[0] :count => result[2].to_i,
results << { :name => file_name.split('.').first
:name => name,
:count => count
} }
end end
results
end end
# Public: All of the versions that have touched the Page. # Public: All of the versions that have touched the Page.