Class: IHelp::Renderer

Inherits:
Object show all
Defined in:
lib/ihelp.rb

Overview

Contains the help renderer methods to be used by IHelp#help. The help-method creates a new instance of Renderer and calls the method defined by IHelp.renderer with the RI info object.

Instance Method Summary collapse

Instance Method Details

#emacs(info) ⇒ Object

XEmacs renderer. Uses ri-emacs to show the ri output in Emacs.

rubyforge.org/projects/ri-emacs/ www.rubyist.net/~rubikitch/computer/irbsh/index.en.html



168
169
170
# File 'lib/ihelp.rb', line 168

def emacs(info)
  system "gnudoit", %Q[(progn (ri "#{info.full_name}") "#{info.full_name}")]
end

#html(info) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/ihelp.rb', line 172

def html(info)
  puts "Opening help for: #{info.full_name}"
  doc = REXML::Document.new
  root = doc.add_element("html")
  head = root.add_element("head")
  title = head.add_element("title")
  title.add_text("#{info.full_name} - RI Documentation")
  body = root.add_element("body")
  body.add_element(info.to_html.root)
  tmp = Tempfile.new("#{info.full_name.gsub(/\W/,"_")}_doc.html")
  tmp.write( doc.to_s(2) )
  tmp.flush
  pid = fork{
    system(IHelp.web_browser, "file://#{tmp.path}")
    tmp.close!
  }
  Process.detach(pid)
  pid
end

#ri(info) ⇒ Object

Default renderer method, opens the help using the IHelpDriver gotten from IHelp.ri_driver.



133
134
135
# File 'lib/ihelp.rb', line 133

def ri(info)
  IHelp.ri_driver.display_info(info)
end

#rubydoc(info) ⇒ Object

Opens the class documentation page on www.ruby-doc.org using the program defined in IHelp::Renderer.web_browser.



140
141
142
143
144
145
# File 'lib/ihelp.rb', line 140

def rubydoc(info)
  require 'uri'
  class_name = parse_ruby_doc_url(info.full_name)
  puts "Opening help for: #{class_name.gsub(/\//,"::")}"
  system(IHelp.web_browser, "http://www.ruby-doc.org/core/classes/#{class_name}.html")
end

#source(info) ⇒ Object

Show sources -renderer using RubyToRuby.

seattlerb.rubyforge.org/

sudo gem install ruby2ruby



153
154
155
156
157
158
159
160
# File 'lib/ihelp.rb', line 153

def source(info)
  require 'ruby2ruby'
  class_name = info.full_name.split(/[#\.]/).first
  klass = class_name.split("::").inject(Object){|o,i| o.const_get(i)}
  args = [klass]
  args << info.name if info.is_a? RI::MethodDescription
  puts RubyToRuby.translate(*args)
end