forked from melito/homebrew-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.rb
74 lines (64 loc) · 1.69 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
require "rubygems"
require "sinatra"
require "sequel"
require "pp"
HOMEBREW_LOCATION = `brew --prefix`.chomp!
DB = Sequel.connect("sqlite://dev.db")
require "models/all"
helpers do
def partial(template, options={})
options.merge!(:layout => false)
if collection = options.delete(:collection) then
collection.inject([]) do |buffer, member|
buffer << erb(template.to_sym, options.merge(:layout => false, :locals => {template.to_sym => member}))
end.join("\n")
else
erb(template.to_sym, options)
end
end
end
get '/' do
erb :index
end
get '/formula' do
@formulas = Formula.all
erb "formula/index".to_sym
end
get '/formula/:id' do
@formula = Formula[params['id']]
erb "formula/show".to_sym
end
get '/search' do
erb "search/index".to_sym
end
post '/search' do
p params
@formulas = Formula.filter(:name.like "%#{params['search']}%")
pp @formulas
erb "search/results".to_sym
end
get '/checkout/:id' do
@formula = Formula[params['id']]
Dir.chdir(HOMEBREW_LOCATION) do
cmd = "git checkout #{@formula.branch_path} Library/Formula/#{@formula.name}.rb"
if system(cmd)
"Successfully checked out formula"
else
"Failed to check out formula :( x Infinity"
end
end
end
get '/install/:id' do
@formula = Formula[params['id']]
Dir.chdir(HOMEBREW_LOCATION) do
cmd = "git checkout #{@formula.branch_path} Library/Formula/#{@formula.name}.rb"
if system(cmd)
cmd = %Q{osascript -e 'tell app "Terminal" to do script "brew install #{@formula.name}"'}
if system(cmd)
"Successfully opened terminal window. It's in Terminal.app's hands now."
end
else
"Failed to checkout formula"
end
end
end