Class: GG::DemoApp

Inherits:
Object show all
Defined in:
lib/gg/demo_app.rb

Defined Under Namespace

Classes: Custom, CustomWithError

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



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
# File 'lib/gg/demo_app.rb', line 21

def call(env)
  case env[ 'PATH_INFO' ]
  when '/'
    response = Rack::Response.new
    response.write GG.render( 'slim/index.slim' )
    response
  when '/demo'
    log_stuff
    [ 200, { 'Content-Type' => 'text/html' }, [ "<h1>GG</h1><p>This is a demo of GG</p>"] ]
  when '/inline_demo'
    log_stuff
    [ 200, { 'Content-Type' => 'text/html' }, [ %q{
      <head>
      </head>
      <body>
        <h1>GG</h1>
        <p>This is a demo of GG</p>
        <div style="border:1px dotted silver;padding: 10px;background-color:#F0F0F0;">
          <!--gg-->
        </div>
        <p>This is a footer</p>
      </body>
    } ] ]
  when '/demo.txt'
    log_stuff
    [ 200, { 'Content-Type' => 'text/plain' }, [ "This is a demo of GG (output goes to console using awesome_print gem)"] ]
  when '/env'
    gg env
    [ 200, { 'Content-Type' => 'text/html' }, [ "<h1>GG</h1><p>This is a dump of request.env and should contain some recursion</p><!--gg-->"] ]
  when '/limit'
    hash = (1..10).inject({}) do |memo, value|
      memo[value] = (1..20).inject({}) do |memo, value|
        memo[value] = rand(1..10)
        memo
      end
      memo
    end
    gg hash
    [ 200, { 'Content-Type' => 'text/html' }, [ "<h1>GG</h1><p>This is a dump of request.env and should contain some recursion</p><!--gg-->"] ]
  else
    [ 404, { 'Content-Type' => 'text/html' }, [ "<h1>Page Not Found</h1>" ] ]
  end
end

#log_stuffObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/gg/demo_app.rb', line 65

def log_stuff
  gg Object.new
  gg 123
  gg 12.5
  gg Object.new, true, :symbol, 'String'
  gg true
  gg false
  gg nil
  gg /^http[:]/
  gg "Hello World <Escaped>"
  gg [ 1, "two", :three, [ 4, 5, 6 ] ]
  hash = {
    make: 'Lamborghini', 
    model: 'Aventador', 
    color: 'yellow', 
    tags: [ 'car', 'exotic' ],
    wheels: {
      front: 22,
      rear: 24
    }
  }
  gg hash
  
  custom = Custom.new( 'cube', [ 5, 3 ], 'yellow' )
  gg custom
  
  custom_with_error = CustomWithError.new
  gg custom_with_error
  
  hash_with_error = {
    'a' => 'alpha',
    'custom' => CustomWithError.new
  }
  gg hash_with_error
  
  recursive_hash = { a: 'alpha', b: 'bravo' }
  recursive_array = [ :a, :b, recursive_hash ] 
  recursive_hash[ :array ] = recursive_array
  recursive_object = Object.new
  recursive_object.instance_variable_set :@hash, recursive_hash
  recursive_object.instance_variable_set :@array, recursive_array
  gg recursive_hash
  gg recursive_array
  gg recursive_object
  
  non_recursive_hash = {
    'a' => {1 => true, 2 => true},
    'b' => {1 => true, 2 => true}
  }
  gg non_recursive_hash
end