Class: Tau::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/tau/server.rb

Class Method Summary collapse

Class Method Details

.startObject



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
# File 'lib/tau/server.rb', line 8

def self.start
  set :port, 15000 # TODO: it should be changeable

  # TODO: / route should return list of all files
  get '/' do
    "There should be list of all files."
  end

  # html
  get /([\/\.\w-]+)\.html/ do |filename|
    filename = "code/#{filename}"
    return haml File.read("#{filename}.haml") if File.exist?("#{filename}.haml")
    send_file "#{filename}.html" if File.exist?("#{filename}.html")
    raise Sinatra::NotFound
  end

  # javascript
  get /js\/([\/\.\w-]+)\.js/ do |filename|
    filename = "code/js/#{filename}"
    return coffee File.read("#{filename}.coffee") if File.exist?("#{filename}.coffee")
    send_file "#{filename}.js" if File.exist?("#{filename}.js")
    raise Sinatra::NotFound
  end

  # css
  get /css\/([\/\.\w-]+)\.css/ do |filename|
    filename = "code/css/#{filename}"
    return sass File.read("#{filename}.sass") if File.exist?("#{filename}.sass")
    return scss File.read("#{filename}.scss") if File.exist?("#{filename}.scss")
    send_file "#{filename}.css" if File.exist?("#{filename}.css")
    raise Sinatra::NotFound
  end

  # images
  get /img\/([\/\.\w-]+)/ do |filename|
    filename = "code/img/#{filename}"
    send_file filename if File.exist?(filename)
    raise Sinatra::NotFound
  end

  not_found do
    "No such file or directory"
  end

  run!
end