Class: Mosaic::Modules::Static

Inherits:
Mosaic::Module show all
Defined in:
lib/mosaic/modules/static.rb

Overview

Static view system. Allows requests to be made for files in the views folder Will always be at the bottom of the response list

Instance Attribute Summary

Attributes inherited from Mosaic::Module

#params, #request, #response

Instance Method Summary collapse

Methods inherited from Mosaic::Module

#initialize, provide_middleware, respond_to

Constructor Details

This class inherits a constructor from Mosaic::Module

Instance Method Details

#fileObject

Work out what view to serve



23
24
25
# File 'lib/mosaic/modules/static.rb', line 23

def file
  "#{@request.path_info}.html".gsub(/\/\./, 'index.')
end

#handleObject

Set the response file to the requested view



15
16
17
18
19
20
# File 'lib/mosaic/modules/static.rb', line 15

def handle
  @response.response_code = response_code
  @response.content = view
  @response.layout = set_layout
  @response.output_format = @request.path_info.split(".").last
end

#response_codeObject

Work out the response code



38
39
40
# File 'lib/mosaic/modules/static.rb', line 38

def response_code
  File.exists?("views/#{file}.erb") ? 200 : 404
end

#set_layoutObject

Use no layout for 404



33
34
35
# File 'lib/mosaic/modules/static.rb', line 33

def set_layout
  response_code == 200 ? :"layouts/application.#{@response.output_format}" : nil
end

#viewObject

Return the 404 view if needed



28
29
30
# File 'lib/mosaic/modules/static.rb', line 28

def view
  response_code == 200 ? file.to_sym : Mosaic.error404
end