Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a0465aa
Showing
10 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
namespace :gembox do | ||
|
||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# To use with thin | ||
# thin start -p PORT -R config.ru | ||
|
||
require File.join(File.dirname(__FILE__), 'gembox.rb') | ||
|
||
disable :run | ||
set :env, :production | ||
run Sinatra.application |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require File.join(File.dirname(__FILE__), 'lib', 'gembox') | ||
|
||
Gembox::Gems.load | ||
|
||
helpers do | ||
def link_to(text, link = nil) | ||
link ||= text | ||
"<a href=\"#{link}\">#{text}</a>" | ||
end | ||
|
||
def escape(text) | ||
CGI.escapeHTML(text) | ||
end | ||
end | ||
|
||
set :public, 'public' | ||
set :views, 'views' | ||
|
||
get '/' do | ||
@gems = Gembox::Gems.local_gems | ||
haml :index | ||
end | ||
|
||
get '/gems/?' do | ||
|
||
end | ||
|
||
get '/gems/:name' do | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module Gembox | ||
class Gems | ||
|
||
class << self | ||
attr_accessor :source_index | ||
|
||
def load | ||
@source_index ||= ::Gem.source_index | ||
local_gems | ||
end | ||
|
||
def local_gems | ||
@local_gems ||= group_gems | ||
end | ||
|
||
protected | ||
def group_gems | ||
gem_hash = Hash.new {|h,k| h[k] = [] } | ||
source_index.gems.each do |gem_with_version, spec| | ||
gem_hash[spec.name] << spec | ||
end | ||
gem_hash | ||
end | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'test_helper' | ||
|
||
describe "Gembox App" do | ||
|
||
describe 'getting /' do | ||
before do | ||
get '/' | ||
end | ||
|
||
should 'load the index' do | ||
should.be.ok | ||
end | ||
|
||
should "display gem list" do | ||
body.should have_element('#gems') | ||
end | ||
|
||
should "display list of installed gems" do | ||
body.should have_element('.gem', /sinatra/) | ||
end | ||
end | ||
|
||
describe 'getting gems/ with layout = false' do | ||
before do | ||
get '/gems/?layout=false' | ||
end | ||
|
||
should "load" do | ||
should.be.ok | ||
end | ||
|
||
should "not display layout" do | ||
body.should.not have_element('html') | ||
end | ||
|
||
should "display gem list" do | ||
body.should have_element('#gems') | ||
end | ||
end | ||
|
||
describe 'getting gems/:name' do | ||
before do | ||
get '/gems/sinatra' | ||
end | ||
|
||
should "display only specific gem" do | ||
body.should.not have_element('.gem', /rack/) | ||
end | ||
|
||
should "display link to gems website" do | ||
body.should have_element('a', 'http://sinatra.rubyforge.org') | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require 'test_helper' | ||
|
||
describe 'Gembox::Gems' do | ||
|
||
describe '#load' do | ||
before do | ||
Gembox::Gems.load | ||
end | ||
|
||
should "load local gems" do | ||
Gembox::Gems.local_gems.should.be.an instance_of(Hash) | ||
end | ||
|
||
should "load source index into source_index" do | ||
Gembox::Gems.source_index.should.be.an instance_of(Gem::SourceIndex) | ||
end | ||
end | ||
|
||
describe "#local_gems" do | ||
before do | ||
Gembox::Gems.load | ||
@gems = Gembox::Gems.local_gems | ||
end | ||
|
||
should "return hash of gems" do | ||
@gems.should.be.an instance_of(Hash) | ||
end | ||
|
||
should "only have one entry per gem" do | ||
@gems.should.has_key? 'sinatra' | ||
@gems.should.not.has_key? 'sinatra-0.9.0.5' | ||
end | ||
|
||
should "have an array of spec versions per gem name" do | ||
@gems['sinatra'].should.be.an instance_of(Array) | ||
@gems['sinatra'].first.should.be.an instance_of(Gem::Specification) | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'rubygems' | ||
require 'sinatra' | ||
require 'sinatra/test/bacon' | ||
|
||
require File.join(File.dirname(__FILE__), '..', 'gembox.rb') | ||
|
||
require 'nokogiri' | ||
|
||
|
||
module TestHelper | ||
|
||
def instance_of(klass) | ||
lambda {|obj| obj.is_a?(klass) } | ||
end | ||
|
||
# HTML matcher for bacon | ||
# | ||
# it 'should display document' do | ||
# body.should have_element('#document') | ||
# end | ||
# | ||
# With content matching: | ||
# | ||
# it 'should display loaded document' do | ||
# body.should have_element('#document .title', /My Document/) | ||
# end | ||
def have_element(search, content = nil) | ||
lambda do |obj| | ||
doc = Nokogiri.parse(obj.to_s) | ||
node_set = doc.search(search) | ||
if node_set.empty? | ||
false | ||
else | ||
collected_content = node_set.collect {|t| t.content }.join(' ') | ||
case content | ||
when Regexp | ||
collected_content =~ content | ||
when String | ||
collected_content.include?(content) | ||
when nil | ||
true | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
||
end | ||
|
||
Bacon::Context.send(:include, TestHelper) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
%h2 Installed Gems | ||
#gems | ||
-@gems.sort.each do |gem_name, spec| | ||
.gem | ||
=link_to(gem_name, "/gems/#{gem_name}") | ||
.versions | ||
%span Versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
%html{:xmlns=> "http://www.w3.org/1999/xhtml", 'xml:lang' => "en", :lang => "en"} | ||
%head | ||
%meta{'http-equiv' => "Content-Type", 'content' => "text/html; charset=utf-8"} | ||
%title gembox | ||
%body | ||
= yield |