Class: Luneta::Park

Inherits:
Object
  • Object
show all
Defined in:
lib/luneta/park.rb

Constant Summary collapse

@@routes =
[]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routes) ⇒ Park

Returns a new instance of Park.



32
33
34
# File 'lib/luneta/park.rb', line 32

def initialize(routes) 
  @routes = routes
end

Class Method Details

.path {|block| ... } ⇒ Object

Yields:

  • (block)


26
27
28
# File 'lib/luneta/park.rb', line 26

def path(&block)
  yield block
end

.start(routes = []) {|block| ... } ⇒ Object

Yields:

  • (block)


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/luneta/park.rb', line 14

def start(routes = [], &block)

  builder = Luneta::Builder.new do |builder| 
    builder.run Luneta::Park.new(routes)
  end
  
  yield block

  return builder

end

Instance Method Details

#call(env) ⇒ Object



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
66
67
68
69
70
# File 'lib/luneta/park.rb', line 36

def call(env)

  @output = ""

  @routes.each do |route|
   match = env['PATH_INFO'].match(route[:path])
   if match
      req = Rack::Request.new(env)
      template = route[:template]
      template = Dir.pwd + "/" + template
      layout_template = route[:layout]
      layout_template = Dir.pwd + "/" + layout_template

      res = Rack::Response.new

      if layout_template

        layout = Luneta::Template.new(layout_template)

        @output = layout.render(route[:title], route[:locals]) do
          Luneta::Template.new(template).render(route[:title], route[:locals])
        end

      else
        @output = Luneta::Template.new(template).render(route[:title], route[:locals])
      end

      res.write @output
      res.finish

      return res
   end
 end

end