diff --git a/lib/gollum/frontend/app.rb b/lib/gollum/frontend/app.rb index e4cb0991..6acb1006 100644 --- a/lib/gollum/frontend/app.rb +++ b/lib/gollum/frontend/app.rb @@ -128,6 +128,13 @@ module Precious end end + get '/search' do + @q = params[:q] + @search_command = "cd #{$path} && git grep -c '#{@q}' master" + @results = `#{@search_command}` + mustache :search + end + get '/*' do show_page_or_file(params[:splat].first) end diff --git a/lib/gollum/frontend/templates/page.mustache b/lib/gollum/frontend/templates/page.mustache index 24956273..87e70be4 100644 --- a/lib/gollum/frontend/templates/page.mustache +++ b/lib/gollum/frontend/templates/page.mustache @@ -1,7 +1,9 @@
- Home | Edit +
+ Home | Edit | +

{{title}}

diff --git a/lib/gollum/frontend/templates/search.mustache b/lib/gollum/frontend/templates/search.mustache new file mode 100644 index 00000000..964452dc --- /dev/null +++ b/lib/gollum/frontend/templates/search.mustache @@ -0,0 +1,20 @@ +
+
+
+
+ Home | +
+
+

Search for “{{search_string}}”

+
+

Searched with {{search_command}}

+ {{#has_results}} + + {{/has_results}} +
+
+
diff --git a/lib/gollum/frontend/views/search.rb b/lib/gollum/frontend/views/search.rb new file mode 100644 index 00000000..84938b5d --- /dev/null +++ b/lib/gollum/frontend/views/search.rb @@ -0,0 +1,30 @@ +module Precious + module Views + class Search < Layout + attr_reader :content, :page, :footer, :search_command + + def search_string + @q + end + + def has_results + !results.empty? + end + + def results + ret = [] + @results.each_line do |line| + result = line.split(":") + file = result[1] + count = result[2].to_i + name = file.split(".")[0] + ret << { + :name => name, + :count => count + } + end + ret + end + end + end +end