lib/code_zauker/webgui.rb in code_zauker-0.0.5 vs lib/code_zauker/webgui.rb in code_zauker-0.0.6
- old
+ new
@@ -1,10 +1,12 @@
#!/usr/bin/env ruby
require 'sinatra'
require "code_zauker/version"
require "code_zauker"
require "erb"
+require 'code_zauker/grep'
+include Grep
# See http://www.sinatrarb.com/intro
get '/' do
# Show the search box...
erb :search
@@ -12,10 +14,25 @@
get '/search' do
# Process the search and show the results...
fs=CodeZauker::FileScanner.new()
files=fs.isearch(params[:q])
- erb :show_results, :locals => {:files => files, :q => params[:q] }
+ util=CodeZauker::Util.new()
+ abstracts=[]
+ files.each do |f|
+ if util.is_pdf?(f)==false
+ askedQuery=params[:q]
+ pattern=/#{Regexp.escape(askedQuery)}/i
+ lines=grep(f,pattern, pre_context=2, post_context=2);
+ desc=""
+ lines.each do |l |
+ hilighted=l.gsub(/(#{Regexp.escape(askedQuery)})/i){ "<b>#{$1}</b>"}
+ desc=desc+ "#{f}:#{hilighted}\n"
+ end
+ abstracts.push(desc)
+ end
+ end
+ erb :show_results, :locals => {:files => abstracts, :q => params[:q] }
end
configure do
staticDir=File.dirname(__FILE__)+ '/../../htdocs'
templateDir=settings.root + '/../../templates'