Class: Susanoo::Application::Static

Inherits:
Controller show all
Defined in:
lib/susanoo/controllers/static.rb

Overview

This controller is responsible for serving/building static files. It does not supports regex at this time.

Instance Attribute Summary

Attributes inherited from Controller

#debug, #environment, #project_root

Instance Method Summary collapse

Methods inherited from Controller

#initialize, #static_compile?

Constructor Details

This class inherits a constructor from Susanoo::Controller

Instance Method Details

#build(generator, options) ⇒ Object



23
24
25
26
27
# File 'lib/susanoo/controllers/static.rb', line 23

def build(generator, options)
  route = options[:route]
  file = route.path_for_generation[1..-1]
  generator.copy_file file, "www/#{route.path_for_generation}"
end

#call(env) ⇒ Object

TODO: Add regext support to this controller



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/susanoo/controllers/static.rb', line 9

def call(env)
  path = env['REQUEST_PATH']
  file = ::File.join(project_root, 'src', path)
  if ::File.exist? file
    [200,
     {'Content-Type' => 'text/plain'},
     [::File.new(file).read]]
  else
    [404,
     {},
     ['Can not find the file']]
  end
end