brew-server: clean up

This commit is contained in:
Jack Nagel 2013-04-03 18:06:34 -05:00
parent e8503e9354
commit d25b4e40c1

View File

@ -21,13 +21,11 @@ end
require 'cgi' require 'cgi'
def link_to_formula name def link_to_formula name
"<a href=\"/formula/#{CGI.escape(name)}\">#{name}</a>" "<a href=\"/formula/#{CGI.escape(name)}\">#{name}</a>"
end end
def css_style def css_style; <<-CSS
<<-CSS
<link href="/bootstrap.min.css" rel="stylesheet"/> <link href="/bootstrap.min.css" rel="stylesheet"/>
<style> <style>
.container { .container {
@ -46,8 +44,7 @@ def css_style
CSS CSS
end end
def search_form def search_form; <<-EOS
<<-EOS
<form action="/search" class="form-search"> <form action="/search" class="form-search">
<div class="input-append"> <div class="input-append">
<input id="search" name="q" type="text" class="input-large"> <input id="search" name="q" type="text" class="input-large">
@ -74,18 +71,20 @@ def html_page(title)
<div id="informations"> <div id="informations">
HTML HTML
yield body yield body
body += <<-HTML
body << <<-HTML
</div> </div>
</div> </div>
</body> </body>
</html> </html>
HTML HTML
return body body
end end
get '/' do get '/' do
return html_page("Homebrew Menu") do |s| html_page("Homebrew Menu") do |s|
s << <<-HTML s << <<-HTML
<div class="row"> <div class="row">
<div class="span12"><div class="row">#{search_form}</div></div> <div class="span12"><div class="row">#{search_form}</div></div>
@ -96,9 +95,11 @@ get '/' do
<div class="row"> <div class="row">
<ul> <ul>
HTML HTML
Formula.names do |name| Formula.names do |name|
s << "<li>#{link_to_formula(name)}</li>" s << "<li>#{link_to_formula(name)}</li>"
end end
s << <<-HTML s << <<-HTML
</ul> </ul>
</div> </div>
@ -110,7 +111,7 @@ get '/search' do
q = params['q'] q = params['q']
results = search_brews(q) results = search_brews(q)
return html_page("Results") do |s| html_page("Results") do |s|
s << <<-HTML s << <<-HTML
<div class="row"> <div class="row">
<div class="span12"> <div class="span12">
@ -137,83 +138,76 @@ get '/search' do
</div> </div>
</div> </div>
HTML HTML
end end
end end
get '/formula/:name' do get '/formula/:name' do
klass = Formula.factory(params[:name]) f = Formula.factory(params[:name])
installed = klass.installed? ? "Installed at" : "Not installed." installed = <<-EOS
installed_dd = klass.installed? ? "<a href=\"file://#{klass.prefix}\">#{klass.prefix}</a>" : "" <dt>Installed at</dt>
<dd><a href=\"file://#{f.prefix}\">#{f.prefix}</a></dd>
EOS
s = "" html_page("Formula: #{f.name}") do |s|
s << html_page("Formula: #{klass.name}") do |s| s << <<-HTML s << <<-HTML
<h1>#{klass.name}</h1> <h1>#{f.name}</h1>
<dl class="dl-horizontal"> <dl class="dl-horizontal">
<dt>Version</dt> <dt>Version</dt>
<dd>#{klass.version}</dd> <dd>#{f.version}</dd>
<dt>Homepage</dt> <dt>Homepage</dt>
<dd><a href="#{klass.homepage}">#{klass.homepage}</a></dd> <dd><a href="#{f.homepage}">#{f.homepage}</a></dd>
<dt>Download</dt> <dt>Download</dt>
<dd><a href="#{klass.url}">#{klass.url}</a></dd> <dd><a href="#{f.url}">#{f.url}</a></dd>
<dt>#{installed}</dt> #{installed if f.installed?}
<dd>#{installed_dd}</dd>
HTML HTML
unless klass.deps.count == 0 unless f.deps.empty?
s << <<-HTML s << <<-HTML
<dt>Depends on</td> <dt>Depends on</td>
HTML HTML
klass.deps.each do |dep|
f.deps.each do |dep|
s << "<dd>#{link_to_formula(dep.name)}</dd>" s << "<dd>#{link_to_formula(dep.name)}</dd>"
end end
end end
used_by = Formula.select{|ff| ff.deps.include?(klass)}.map{|f| f.name}.flatten.uniq.sort used_by = Formula.select { |ff| ff.deps.include?(f) }.map(&:name).flatten.uniq.sort
unless used_by.empty? unless used_by.empty?
s << <<-HTML s << <<-HTML
<dt>Used by</td> <dt>Used by</td>
HTML HTML
if used_by != nil
used_by.each do |name| used_by.each do |name|
s << "<dd>#{link_to_formula(name)}</dd>" s << "<dd>#{link_to_formula(name)}</dd>"
end end
end end
end
s += <<-HTML s << <<-HTML
</dl> </dl>
HTML HTML
end end
return s
end
def installed_formulae
Formula.select{|formula| formula.installed?}
end end
get '/installed' do get '/installed' do
html_page("Installed Formulae") do |s|
s = html_page("Installed formulae") do |s| s << <<-HTML s << <<-HTML
<h3>Installed Fomulas:</h3> <h3>Installed Formulae:</h3>
<table class="table"><tr><th>Name</th><th>Version</th></tr> <table class="table"><tr><th>Name</th><th>Version</th></tr>
HTML HTML
installed_formulae.each do |formula| Formula.installed.each do |f|
s << "<tr><td>#{link_to_formula(formula.name)}</td><td>#{formula.version}</td></tr>" s << "<tr><td>#{link_to_formula(f.name)}</td><td>#{f.version}</td></tr>"
end end
s << <<-HTML s << <<-HTML
</table> </table>
HTML HTML
end end
return s
end end
puts "View our tasting menu at http://localhost:4567/\nUse \"Control-C\" to exit.\n\n" puts "View our tasting menu at http://localhost:4567/\nUse \"Control-C\" to exit.\n\n"