WebRI  WebRI::Server

[Validate]
Generated with WebRI Redfish 1.2

Server

Server class and base class for Generator.

Attributes

service[R]

Reference to RI Service

title[R]

Title of docs to add to webpage header.

Public Class Methods

esc(text) click to toggle source
# File lib/webri/server/server.rb, line 345
    def self.esc(text)
      OpEsc.escape(text.to_s)
      #CGI.escape(text.to_s).gsub('-','%2D')
    end
new(service, options={}) click to toggle source
# File lib/webri/server/server.rb, line 26
    def initialize(service, options={})
      #@cgi = {} #CGI.new('html4')
      @service = service
      @templates = {}

      @title = options[:title]
    end

Public Instance Methods

current_content() click to toggle source
# File lib/webri/server/server.rb, line 334
    def current_content
      @current_content
    end
directory() click to toggle source
# File lib/webri/server/server.rb, line 41
    def directory
      @directory ||= File.dirname(__FILE__)
    end
esc(text) click to toggle source
# File lib/webri/server/server.rb, line 339
    def esc(text)
      OpEsc.escape(text.to_s)
      #CGI.escape(text.to_s).gsub('-','%2D')
    end
generate_tree(entry) click to toggle source

generate html tree

# File lib/webri/server/server.rb, line 91
    def generate_tree(entry)
      markup = []
      if entry.root?
        markup << %[<div class="root">]
      else
        path = WebRI.entry_to_path(entry.full_name)
        markup << %[
         <li class="trigger">
           <img src="assets/img/class.png" onClick="showBranch(this);"/>
           <span class="link" onClick="lookup_static(this, '#{path}');">#{entry.name}</span>
        ]
        markup << %[<div class="branch">]
      end

      markup << %[<ul>]

      cmethods = entry.class_methods.map{ |x| x.to_s }.sort
      cmethods.each do |method|
        path = WebRI.entry_to_path(entry.full_name + ".#{method}")
        markup << %[
          <li class="meta_leaf">
            <span class="link" onClick="lookup_static(this, '#{path}');">#{method}</span>
          </li>
        ]
      end

      imethods = entry.instance_methods.map{ |x| x.to_s }.sort
      imethods.each do |method|
        path = WebRI.entry_to_path(entry.full_name + "##{method}")
        markup << %[
          <li class="leaf">
            <span class="link" onClick="lookup_static(this, '#{path}');">#{method}</span>
          </li>
        ]
      end

      entry.subspaces.to_a.sort{ |a,b| a[0].to_s <=> b[0].to_s }.each do |(name, subspace)|
      #subspaces.each do |name, subspace|
        markup << generate_tree(subspace) #subspace.to_html
      end
      markup << %[</ul>]

      if entry.root?
        markup << %[</div>]
      else
        markup << %[</div>]
        markup << %[</li>]
      end

      return markup.join("\n")
    end
heirarchy() click to toggle source
# File lib/webri/server/server.rb, line 46
    def heirarchy
      @heirarchy ||=(
        ns = Heirarchy.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
            spaces = m.split('::').collect{|s| s.to_sym }
            if spaces.last.to_s =~ /^[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] ||= Heirarchy.new(space, memo)
            memo = memo[space]
          end

          if type == :class
            memo.class_methods << method
          else
            memo.instance_methods << method
          end
        end
        ns
      )
    end
index() click to toggle source
# File lib/webri/server/server.rb, line 226
    def index
      render(template('index'))
    end
lookup(path) click to toggle source
# File lib/webri/server/server.rb, line 144
    def lookup(path)
      entry = WebRI.path_to_entry(path)
      if entry
        html = service.info(entry)
        html = autolink(html, entry)

        #term = AnsiSys::Terminal.new.echo(ansi)
        #html = term.render(:html) #=> HTML fragment
        #html = ERB::Util.html_escape(html)

        html = "#{html}<br/><br/>"
      else
        html = "<h1>ERROR</h1>"
      end
      return html
    end
render(source) click to toggle source
# File lib/webri/server/server.rb, line 210
    def render(source)
      template = ERB.new(source)
      template.result(binding)
    end
template(name) click to toggle source
# File lib/webri/server/server.rb, line 197
    def template(name)
      @templates[name] ||= File.read(File.join(directory, 'templates', name + '.html'))
    end
title() click to toggle source

Tile of documentation as given by commandline option or a the namespace of the root entry of the heirarchy.

# File lib/webri/server/server.rb, line 36
    def title
      @title ||= heirarchy.full_name
    end
tree() click to toggle source
# File lib/webri/server/server.rb, line 84
    def tree
      #%[<iframe src="tree.html"></iframe>]
      @tree ||= generate_tree(heirarchy) #heirarchy.to_html
    end

Disabled; run with --debug to generate this.