Skip to content

Commit

Permalink
added file category support
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyong committed Jul 18, 2012
1 parent 93148da commit bb47b31
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ gem 'sinatra'
gem 'haml'
gem 'shotgun'
gem 'json'
gem 'mime-types'
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ GEM
specs:
haml (3.1.4)
json (1.5.4)
mime-types (1.19)
rack (1.1.0)
shotgun (0.9)
rack (>= 1.0)
Expand All @@ -17,6 +18,7 @@ PLATFORMS
DEPENDENCIES
haml
json
mime-types
rack (= 1.1)
shotgun
sinatra
15 changes: 12 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'benchmark'
require 'json'
require 'mime/types'

set :haml, :format => :html5

Expand All @@ -16,12 +17,20 @@
cmd += databases.map { |db| "../data/locate/picb_#{db}.db" }.join(":")

cmd += " -i" unless params["case"]
cmd += " --regex" if params["regexp"]
cmd += " --regex" if params["regexp"] || params["category"] != "all"

keyword = params["keyword"].strip
if !params["regexp"] && keyword !~ /\*/ && keyword =~ /\s/
keyword.gsub!(/\s+/, "*")
keyword = "*" + keyword + "*"
if params["category"] == "all"
keyword.gsub!(/\s+/, "*")
keyword = "*" + keyword + "*"
elsif params["category"] != "all"
keyword.gsub!(/\s+/, '.*')
end
end

if params["category"] != "all"
keyword += '.*\.(' + (params["category"] == "application" ? "app|" : "") + MIME::Types[/^#{params["category"]}/, :complete => true].map { |t| t.extensions.join("|") }.join("|") + ')$'
end

cmd += " '" + keyword + "'"
Expand Down
13 changes: 13 additions & 0 deletions views/index.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
%p#logo Voodoo
.center
%form{:name => "form", :action => "/search", :method => "post"}
%p
%input#all{:type => 'radio', :name => 'category', :value => 'all'}
%label{:for => "all"} All
%input#app{:type => 'radio', :name => 'category', :value => 'application'}
%label{:for => "app"} Application
%input#audio{:type => 'radio', :name => 'category', :value => 'audio'}
%label{:for => "audio"} Audio
%input#image{:type => 'radio', :name => 'category', :value => 'image'}
%label{:for => "image"} Image
%input#text{:type => 'radio', :name => 'category', :value => 'text'}
%label{:for => "text"} Text
%input#video{:type => 'radio', :name => 'category', :value => 'video'}
%label{:for => "video"} Video
%p
%input#search{:type => "text", :name => "keyword", :size => "35"}
%input{:type => "submit", :value => "Search"}
Expand Down

0 comments on commit bb47b31

Please sign in to comment.