Class: Mosaic::Modules::Static
- Inherits:
-
Mosaic::Module
- Object
- Mosaic::Module
- Mosaic::Modules::Static
- 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
Instance Method Summary collapse
-
#file ⇒ Object
Work out what view to serve.
-
#handle ⇒ Object
Set the response file to the requested view.
-
#response_code ⇒ Object
Work out the response code.
-
#set_layout ⇒ Object
Use no layout for 404.
-
#view ⇒ Object
Return the 404 view if needed.
Methods inherited from Mosaic::Module
#initialize, provide_middleware, respond_to
Constructor Details
This class inherits a constructor from Mosaic::Module
Instance Method Details
#file ⇒ Object
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 |
#handle ⇒ Object
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_code ⇒ Object
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_layout ⇒ Object
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 |