| Class | IHelp::Renderer |
| In: |
lib/ihelp.rb
|
| Parent: | Object |
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.
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
# File lib/ihelp.rb, line 173
173: def emacs(info)
174: system "gnudoit", %Q[(progn (ri "#{info.full_name}") "#{info.full_name}")]
175: end
# File lib/ihelp.rb, line 177
177: def html(info)
178: puts "Opening help for: #{info.full_name}"
179: doc = REXML::Document.new
180: root = doc.add_element("html")
181: head = root.add_element("head")
182: title = head.add_element("title")
183: title.add_text("#{info.full_name} - RI Documentation")
184: body = root.add_element("body")
185: body.add_element(info.to_html.root)
186: tmp = Tempfile.new("#{info.full_name.gsub(/\W/,"_")}_doc.html")
187: tmp.write( doc.to_s(2) )
188: tmp.flush
189: pid = fork{
190: system(IHelp.web_browser, "file://#{tmp.path}")
191: tmp.close!
192: }
193: Process.detach(pid)
194: pid
195: end
Default renderer method, opens the help using the IHelpDriver gotten from IHelp.ri_driver.
# File lib/ihelp.rb, line 138
138: def ri(info)
139: IHelp.ri_driver.display_info(info)
140: end
Opens the class documentation page on www.ruby-doc.org using the program defined in IHelp::Renderer.web_browser.
# File lib/ihelp.rb, line 145
145: def rubydoc(info)
146: require 'uri'
147: class_name = parse_ruby_doc_url(info.full_name)
148: puts "Opening help for: #{class_name.gsub(/\//,"::")}"
149: system(IHelp.web_browser, "http://www.ruby-doc.org/core/classes/#{class_name}.html")
150: end
Show sources -renderer using RubyToRuby.
sudo gem install ruby2ruby
# File lib/ihelp.rb, line 158
158: def source(info)
159: require 'ruby2ruby'
160: class_name = info.full_name.split(/[#\.]/).first
161: klass = class_name.split("::").inject(Object){|o,i| o.const_get(i)}
162: args = [klass]
163: args << info.name if info.is_a? RI::MethodDescription
164: puts RubyToRuby.translate(*args)
165: end