From 4a281cd5cf8f722d73a4f50612e8c460f57fddd7 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 17 Feb 2013 13:32:15 +0000 Subject: Rename Library/Contributions/cmds -> cmd. --- Library/Contributions/cmd/brew-server | 208 ++++++++++++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100755 Library/Contributions/cmd/brew-server (limited to 'Library/Contributions/cmd/brew-server') diff --git a/Library/Contributions/cmd/brew-server b/Library/Contributions/cmd/brew-server new file mode 100755 index 000000000..a87322409 --- /dev/null +++ b/Library/Contributions/cmd/brew-server @@ -0,0 +1,208 @@ +#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby + +## brew server: Run a local webserver for browsing available and installed brews. +# Note: this external command is ruby, but set up as a shell script, so that it gets exec'd. +# This is required for sinatra's run-loop to take over. + +$:.unshift(ENV['HOMEBREW_LIBRARY_PATH']) + +require 'global' +require 'formula' + +require 'rubygems' + +begin + require 'sinatra' +rescue LoadError + onoe 'Sinatra required but not found' + puts 'To install: /usr/bin/gem install sinatra' + exit 1 +end + +require 'cgi' + + +def link_to_formula name + "#{name}" +end + +def css_style + "" # No CSS defined yet. +end + +def search_form + <<-EOS +
+ Search: +
+ EOS +end + +def html_page + body = <<-HTML + + + Homebrew Menu + #{css_style} + + +
+ + +
+ HTML + yield body + body += <<-HTML +
+
+ + + HTML + return body +end + +get '/' do + return html_page do |s| + s << <<-HTML +
#{search_form}
+
+ +
+ HTML + end +end + +get '/search' do + q = params['q'] + results = search_brews(q) + + s = <<-HTML + + + Search Results + #{css_style} + + +

Results

+ #{search_form} +

Searched for “#{q}”

+ + + + HTML + + return s +end + +get '/formula/:name' do + klass = Formula.factory(params[:name]) + + installed = klass.installed? ? "Installed at" : "Not installed." + installed_dd = klass.installed? ? "#{klass.prefix}" : "" + + s = "" + s << <<-HTML + + + Formula: #{klass.name} + #{css_style} + + +
Back to menu
+

#{klass.name}

+
+
Version
+
#{klass.version}
+ +
Homepage
+
#{klass.homepage}
+ +
Download
+
#{klass.url}
+ +
#{installed}
+
#{installed_dd}
+ HTML + + unless klass.deps.count == 0 + s << <<-HTML +
Depends on + HTML + klass.deps.each do |dep| + s << "
#{link_to_formula(dep.name)}
" + end + end + + used_by = Formula.select{|ff| ff.deps.include?(klass.name)}.map{|f| f.name}.flatten.uniq.sort + unless used_by.empty? + s << <<-HTML +
Used by + HTML + if used_by != nil + used_by.each do |name| + s << "
#{link_to_formula(name)}
" + end + end + end + + s += <<-HTML +
+ + + HTML + + return s +end + + +def installed_formulae + Formula.select{|formula| formula.installed?} +end + +get '/installed' do + + s = <<-HTML + + + Installed formulae + #{css_style} + + +

Installed Fomulas

+ +
Back to menu
+ + + HTML + + return s +end + + +puts "View our tasting menu at http://localhost:4567/\nUse \"Control-C\" to exit.\n\n" -- cgit v1.2.3