Module: Bdoc

Defined in:
lib/bdoc.rb

Constant Summary collapse

VERSION =
'0.2.2'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.output_dirObject

Returns the value of attribute output_dir.



14
15
16
# File 'lib/bdoc.rb', line 14

def output_dir
  @output_dir
end

.output_indexObject

Returns the value of attribute output_index.



15
16
17
# File 'lib/bdoc.rb', line 15

def output_index
  @output_index
end

Class Method Details

.gems_with_doc_indexObject



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
# File 'lib/bdoc.rb', line 21

def gems_with_doc_index
  installed_gems = Gem::SourceIndex.from_installed_gems.gems.map{|k,v|v}
  gems = installed_gems.map { |g|
    g.name if g.has_rdoc?
  }.compact.uniq.sort{|x,y| x.downcase <=> y.downcase}
  gems = gems.map do |g|

    gem = installed_gems.find_all{|gem| gem.name == g}.last
    # calculate homepage if exists
    homepage = gem.homepage 
    homepage ||= "http://" + gem.rubyforge_project + ".rubyforge.org" if gem.rubyforge_project
    homepage = nil if homepage == '' # disallow blank url (a la fastthread)


    { :name => g,
      :description => gem.description,
      :summary => gem.summary,
      :homepage => homepage,
      :versions => installed_gems.find_all{|gem| 
        gem.name == g
        }.map{|gem|
          rdoc_index = File.join(gem.full_gem_path,"..","..","doc",gem.full_name, "rdoc","index.html")
          { :version => gem.version.version,
            :rdoc_index => (File.exist?(rdoc_index) ? rdoc_index : nil)
          }
        #removes dups since uniq doesn't work on array of hashes
        }.compact.sort_by{|g|g[:version]}.inject([]){|result,h| 
          result << h unless result.include?(h)
          result
        }
    }
  end
end

.generate_indexObject



55
56
57
58
59
60
61
62
# File 'lib/bdoc.rb', line 55

def generate_index
  @gems = gems_with_doc_index
  index = ERB.new(File.read(File.join(File.dirname(__FILE__), '..', "templates","index.html"))).result(binding) 
  Dir.mkdir(output_dir) unless File.exists?(output_dir)
  File.open(output_index,"w") {|f| f.write(index)}
  FileUtils.cp File.join(File.dirname(__FILE__), '..', "templates","jquery.js"), output_dir
  FileUtils.cp File.join(File.dirname(__FILE__), '..', "templates","screen.css"), output_dir
end

.openObject



64
65
66
67
# File 'lib/bdoc.rb', line 64

def open
  generate_index
  Launchy::Browser.run(output_index)
end

.rdoc_file(gem_name) ⇒ Object



17
18
19
# File 'lib/bdoc.rb', line 17

def rdoc_file(gem_name)
  File.join(Gem.dir, "doc", gem_name, "rdoc", "index.html")
end