Class: GRI::Grapher

Inherits:
Object show all
Defined in:
lib/gri/grapher.rb,
lib/gri/plugin/bootstrap.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGrapher

Returns a new instance of Grapher.



14
15
16
17
18
19
20
# File 'lib/gri/grapher.rb', line 14

def initialize
  root_dir = Config['root-dir'] ||= Config::ROOT_PATH
  log_dir = Config['log-dir'] || Config['root-dir'] + '/log'
  Log.init "#{log_dir}/#{File.basename $0}.log", :no_dash=>true
rescue SystemCallError
  Log.init '/tmp/grapher.log', :no_dash=>true
end

Class Method Details

.layoutObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gri/grapher.rb', line 48

def self.layout
  <<EOS
<html>
<head>
<title><%= @title %></title>
<style>
td.text-right {text-align:right;}
span.large {font-size: x-large;}
table.ds td {padding:0;background:#f9f9f9;}
table.ds th {background:#ffd0d0;
background:linear-gradient(to bottom, #ffd8d8 0%,#ffcccc 45%,#ffc0c0 100%);
text-align:left;}
hr {border:none;border-top:1px #cccccc solid;}
</style>
</head>
<body>
<%= yield %>
</body>
</html>
EOS
end

Instance Method Details

#call(env) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/gri/grapher.rb', line 22

def call env
  req = GRI::Request.new env
  params = req.params

  gra_dirs = Config.getvar('gra-dir') || [Config::ROOT_PATH + '/gra']
  if (req.query_string =~ /\A(\d+),(\d+)\z/)
    app = Page.new :dirs=>gra_dirs, :clicked=>true, :imgx=>$1, :imgy=>$2
  elsif params['r'] or params['tag']
    if params['stime']
      app = Graph.new :dirs=>gra_dirs
    else
      app = Page.new :dirs=>gra_dirs
    end
  elsif req.path_info =~ %r{^/([-\w][-#\.\w]*)}
    app = DSList.new :dirs=>gra_dirs
  else
    app = List.new :dirs=>gra_dirs, :list_format=>Config['list-format'],
      :use_regexp_search=>Config['use-regexp-search']
  end
  app.call env
end

#public_dirObject



44
45
46
# File 'lib/gri/grapher.rb', line 44

def public_dir
  File.dirname(__FILE__) + '/../../public'
end