Class: Slideshift::Tool::Server::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/slideshift/tool/server/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(presentation) ⇒ Server

Returns a new instance of Server.



9
10
11
# File 'lib/slideshift/tool/server/server.rb', line 9

def initialize(presentation)
  @presentation = presentation
end

Instance Method Details

#startObject



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
# File 'lib/slideshift/tool/server/server.rb', line 13

def start

  @server = WEBrick::HTTPServer.new(:Port => Slideshift::Tool.config['server']['port'])

  @server.mount_proc('/') do |req, res|
    file = nil

    local_file = File.join(Dir.getwd, req.path)
    file = local_file if File.exists?(local_file) && File.file?(local_file)

    static_file = File.join(Slideshift::Static.path, '..', req.path)
    puts static_file
    file = static_file if File.exists?(static_file) && File.file?(static_file)

    if file
      res.body = File.read(file)
    else
      @presentation.load
      res.body = @presentation.render
    end
  end

  trap('INT') { @server.shutdown }

  @server.start

end