Module: Bdoc

Defined in:
lib/bdoc.rb

Constant Summary collapse

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

def gems_with_doc_index
  gems = Gem::Specification.list.map { |g|
    rdoc_index = rdoc_file(g.full_name)
    if File.exist?(rdoc_index)
      g.name if g.has_rdoc?
    end
  }.compact.uniq.sort{|x,y| x.downcase <=> y.downcase}
  gems = gems.map do |g|
    gem = Gem::Specification.list.find_all{|gem| gem.name == g}.last
    { :name => g,
      :description => gem.description,
      :homepage => gem.homepage,
      :versions => Gem::Specification.list.find_all{|gem| 
        gem.name == g && File.exist?(rdoc_file(gem.full_name))
      }.map{|gem|
        rdoc_index = File.join(Gem.dir, "doc", gem.full_name, "rdoc", "index.html")
        { :version => gem.version.version,
          :rdoc_index => rdoc_index
        }
      #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



49
50
51
52
53
54
55
56
# File 'lib/bdoc.rb', line 49

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_r Dir.glob('templates/*.js'), output_dir
  FileUtils.cp_r Dir.glob('templates/*.css'), output_dir
end

.openObject



58
59
60
61
# File 'lib/bdoc.rb', line 58

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