File: env_debug.rb

package info (click to toggle)
camping 3.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,312 kB
  • sloc: ruby: 5,032; javascript: 2,362; makefile: 29
file content (65 lines) | stat: -rw-r--r-- 1,238 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby

begin require "rubygems" rescue LoadError end
require "camping"

Camping.goes :EnvDebug

module EnvDebug
  module Controllers
    class ShowEnv < R '/', '/(.*)'
      def get(extra = nil)
        @extra = extra
        render :show_env
      end
      alias post get
    end
  end

  module Views
    def layout
      html do
        head{ title C }
        body do
          ul do
            li{ a "show env", :href=>R(ShowEnv)}
          end
          p { yield }
        end
      end
    end

    def _print_hash(hash)
      hash.keys.sort.each do |key|
        value = hash[key]
        pre "%30s: %s" % [key.inspect, value.inspect]
      end
    end

    def show_env
      b "extra: #{@extra.inspect}"
      h2 "@status : #{@status.inspect}"
      h2 "@method : #{@method.inspect}"
      h2 "@root : #{@root.inspect}"
      h2 "@env :"
      _print_hash @env
      h2 "@input : "
      _print_hash @input
      h2 "@headers :"
      _print_hash @headers
   end

  end
end

# For CGI
if $0 == __FILE__
  EnvDebug.create if EnvDebug.respond_to? :create
  if ARGV.any?
    require 'camping/fastcgi'
    #Dir.chdir('/var/camping/blog/')
    Camping::FastCGI.start(EnvDebug)
  else
    puts EnvDebug.run
  end
end