Class: Shutterbug::Handlers::FileHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/shutterbug/handlers/file_handler.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.path_prefixObject

relative url



6
7
8
# File 'lib/shutterbug/handlers/file_handler.rb', line 6

def self.path_prefix
  "#{Configuration.instance.path_prefix}/get_file"
end

.regexObject



15
16
17
18
# File 'lib/shutterbug/handlers/file_handler.rb', line 15

def self.regex
  filename_matcher = "(([^\/|\.]+)\.?([^\/]+))?"
  /#{self.path_prefix}\/#{filename_matcher}/
end

.uri_prefixObject

absolute url



11
12
13
# File 'lib/shutterbug/handlers/file_handler.rb', line 11

def self.uri_prefix
  "#{Configuration.instance.uri_prefix}#{self.path_prefix}"
end

Instance Method Details

#handle(helper, req, env) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/shutterbug/handlers/file_handler.rb', line 20

def handle(helper, req, env)
  filename = self.class.regex.match(req.path)[1]
  if File.extname(filename) == ''
    filename += '.html'
  end
  file = Configuration.instance.storage.new(filename)
  helper.response(file.get_content, file.mime_type)
end