Skip to content

Commit

Permalink
Rdoc only displays if there is an RDOC directory and the has_rdoc? ge…
Browse files Browse the repository at this point in the history
…m spec option is checked. Closes quirkey#4

Also, gems now reload if the mtime of your gems directory changes
  • Loading branch information
quirkey committed Jul 7, 2009
1 parent 8924783 commit 44673f9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/gembox/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,14 @@ class App < ::Sinatra::Default
end

get %r{/gems/doc/([\w\-\_]+)/?([\d\.]+)?/?(.*)?} do
load_gem_by_version
@rdoc_path = @gem.rdoc_path
if params[:captures].length == 3 && !params[:captures][2].blank?
# we have a path
load_gem_by_version
@rdoc_path = File.join(@gem.installation_path, "doc", @gem.full_name, 'rdoc')
full_path = File.join(@rdoc_path, params[:captures].pop)
content_type File.extname(full_path)
File.read(full_path)
else
load_gem_by_version
@rdoc_path = File.join(@gem.installation_path, "doc", @gem.full_name, 'rdoc')
haml :doc, :layout => false
end
end
Expand Down
9 changes: 9 additions & 0 deletions lib/gembox/extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,14 @@ def files_tree
def on_github?
homepage =~ /github\.com\/([\w\d\-\_]+)\/([\w\d\-\_]+)\/tree/
end

alias :has_rdoc_checked? :has_rdoc?
def has_rdoc?
has_rdoc_checked? && File.exists?(rdoc_path)
end

def rdoc_path
File.join(installation_path, 'doc', full_name, 'rdoc')
end
end
end
19 changes: 17 additions & 2 deletions lib/gembox/gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ class << self
attr_accessor :source_index

def load
@source_index ||= ::Gem.source_index
if !@source_index || reload?
@source_index = ::Gem.source_index
end
local_gems
end

def local_gems
@local_gems ||= group_gems(source_index.gems)
if !@local_gems || reload?
@local_gems = group_gems(source_index.gems)
end
@local_gems
end

def search(search_term, version = nil, strict = false)
Expand Down Expand Up @@ -38,6 +43,16 @@ def group_gems(gem_collection)
end
gem_hash.sort {|a, b| a[0].downcase <=> b[0].downcase }
end

def reload?
@now_mtime = File.mtime(File.join(::Gem.dir, 'gems'))
if @old_mtime != @now_mtime
@old_mtime = @now_mtime
true
else
false
end
end
end

end
Expand Down

0 comments on commit 44673f9

Please sign in to comment.