Class: WRI::Server
- Inherits:
-
Object
- Object
- WRI::Server
- Defined in:
- lib/wri/server.rb
Defined Under Namespace
Classes: NS
Instance Attribute Summary collapse
-
#cgi ⇒ Object
readonly
Reference to CGI Service.
-
#service ⇒ Object
readonly
Reference to RI Service.
Instance Method Summary collapse
- #directory ⇒ Object
- #heirarchy ⇒ Object
-
#initialize(service) ⇒ Server
constructor
A new instance of Server.
- #lookup(req) ⇒ Object
- #to_html ⇒ Object
- #tree ⇒ Object
Constructor Details
#initialize(service) ⇒ Server
Returns a new instance of Server.
14 15 16 17 |
# File 'lib/wri/server.rb', line 14 def initialize(service) @cgi = {} #CGI.new('html4') @service = service end |
Instance Attribute Details
#cgi ⇒ Object (readonly)
Reference to CGI Service
9 10 11 |
# File 'lib/wri/server.rb', line 9 def cgi @cgi end |
#service ⇒ Object (readonly)
Reference to RI Service
12 13 14 |
# File 'lib/wri/server.rb', line 12 def service @service end |
Instance Method Details
#directory ⇒ Object
19 20 21 |
# File 'lib/wri/server.rb', line 19 def directory File.dirname(__FILE__) end |
#heirarchy ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/wri/server.rb', line 23 def heirarchy ns = NS.new(nil) service.names.each do |m| if m.index('#') type = :instance space, method = m.split('#') spaces = space.split('::').collect{|s| s.to_sym } method = method.to_sym elsif m.index('::') type = :class space, method = m.split('::') spaces = space.split('::').collect{|s| s.to_sym } if spaces.last =~ /^[a-z]/ method = spaces.pop else next # what to do about class/module ? end else next # what to do abot class/module ? end memo = ns spaces.each do |space| memo[space] ||= NS.new(space, memo) memo = memo[space] end if type == :class memo.class_methods << method else memo.instance_methods << method end end return ns end |
#lookup(req) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/wri/server.rb', line 63 def lookup(req) keyw = File.basename(req.path_info) if keyw keyw.sub!('-','#') html = service.info(keyw) puts html #term = AnsiSys::Terminal.new.echo(ansi) #html = term.render(:html) #=> HTML fragment #html = ERB::Util.html_escape(html) html = "#{html}" else html = "<h1>ERROR</h1>" end return html end |
#to_html ⇒ Object
79 80 81 82 83 84 |
# File 'lib/wri/server.rb', line 79 def to_html filetext = File.read(File.join(File.dirname(__FILE__), 'template.rhtml')) template = ERB.new(filetext) template.result(binding) #heirarchy.to_html end |
#tree ⇒ Object
59 60 61 |
# File 'lib/wri/server.rb', line 59 def tree @tree ||= heirarchy.to_html end |