* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / lib / rdoc / generator / texinfo.rb
blob0b79820228ade6260d27d7a92ab49e813ed3cd1e
1 require 'rdoc/rdoc'
2 require 'rdoc/generator'
3 require 'rdoc/markup/to_texinfo'
5 module RDoc
6   RDoc::GENERATORS['texinfo'] = RDoc::Generator.new("rdoc/generator/texinfo",
7                                                     :Texinfo,
8                                                     'texinfo')
9   module Generator
10     # This generates Texinfo files for viewing with GNU Info or Emacs
11     # from RDoc extracted from Ruby source files.
12     class Texinfo
13       # What should the .info file be named by default?
14       DEFAULT_INFO_FILENAME = 'rdoc.info'
16       include Generator::MarkUp
18       # Accept some options
19       def initialize(options)
20         @options = options
21         @options.inline_source = true
22         @options.op_name ||= 'rdoc.texinfo'
23         @options.formatter = ::RDoc::Markup::ToTexInfo.new
24       end
26       # Generate the +texinfo+ files
27       def generate(toplevels)
28         @toplevels = toplevels
29         @files, @classes = ::RDoc::Generator::Context.build_indicies(@toplevels,
30                                                                      @options)
32         (@files + @classes).each { |x| x.value_hash }
34         open(@options.op_name, 'w') do |f|
35           f.puts TexinfoTemplate.new('files' => @files,
36                                      'classes' => @classes,
37                                      'filename' => @options.op_name.gsub(/texinfo/, 'info'),
38                                      'title' => @options.title).render
39         end
40         # TODO: create info files and install?
41       end
43       class << self
44         # Factory? We don't need no stinkin' factory!
45         alias_method :for, :new
46       end
47     end
49     # Basically just a wrapper around ERB.
50     # Should probably use RDoc::TemplatePage instead
51     class TexinfoTemplate
52       BASE_DIR = ::File.expand_path(::File.dirname(__FILE__)) # have to calculate this when the file's loaded.
54       def initialize(values, file = 'texinfo.erb')
55         @v, @file = [values, file]
56       end
57      
58       def template
59         ::File.read(::File.join(BASE_DIR, 'texinfo', @file))
60       end
62       # Go!
63       def render
64         ERB.new(template).result binding
65       end
67       def href(location, text)
68         text # TODO: how does texinfo do hyperlinks?
69       end
71       def target(name, text)
72         text # TODO: how do hyperlink targets work?
73       end
75       # TODO: this is probably implemented elsewhere?
76       def method_prefix(section)
77         { 'Class' => '.',
78           'Module' => '::',
79           'Instance' => '#',
80         }[section['category']]
81       end
82     end
83   end
84 end