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



149
150
151
# File 'lib/ihelp.rb', line 149

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

#html(info) ⇒ Object



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/ihelp.rb', line 153

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.



114
115
116
# File 'lib/ihelp.rb', line 114

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.



121
122
123
124
125
126
# File 'lib/ihelp.rb', line 121

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



134
135
136
137
138
139
140
141
# File 'lib/ihelp.rb', line 134

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