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.
# File lib/ihelp.rb, line 117 117: def html(info) 118: puts "Opening help for: #{info.full_name}" 119: doc = REXML::Document.new 120: root = doc.add_element("html") 121: head = root.add_element("head") 122: title = head.add_element("title") 123: title.add_text("#{info.full_name} - RI Documentation") 124: body = root.add_element("body") 125: body.add_element(info.to_html.root) 126: tmp = Tempfile.new("#{info.full_name.gsub(/\W/,"_")}_doc.html") 127: tmp.write( doc.to_s(2) ) 128: tmp.flush 129: pid = fork{ 130: system("#{IHelp::WWW_BROWSER} 'file://#{tmp.path}'") 131: tmp.close! 132: } 133: Process.detach(pid) 134: pid 135: end
Default renderer method, opens the help using the IHelpDriver gotten from IHelp.ri_driver.
# File lib/ihelp.rb, line 89 89: def ri(info) 90: IHelp.ri_driver.display_info(info) 91: end
Opens the class documentation page on www.ruby-doc.org using the program defined in IHelp::WWW_BROWSER.
# File lib/ihelp.rb, line 96 96: def rubydoc_org(info) 97: require 'uri' 98: class_name = parse_ruby_doc_url(info.full_name) 99: puts "Opening help for: #{class_name.gsub(/\//,"::")}" 100: system("#{IHelp::WWW_BROWSER} 'http://www.ruby-doc.org/core/classes/#{class_name}.html'") 101: end
Experimental show sources -renderer using RubyToRuby. Prints the generated source with puts. See blog.zenspider.com/archives/2005/02/rubytoruby.html for more info about RubyToRuby
# File lib/ihelp.rb, line 108 108: def rubytoruby_src(info) 109: require 'rubytoruby' 110: class_name = info.full_name.split(/[#\.]/).first 111: klass = class_name.split("::").inject(Object){|o,i| o.const_get(i)} 112: args = [klass] 113: args << info.name if info.is_a? RI::MethodDescription 114: puts RubyToRuby.translate(*args) 115: end