Wouter Views
Adds view template support to the Wouter web framework.
wouter-views uses Tilt to load Ruby template engines.
Usage
Require the gem after your wouter require.
require 'wouter'
require 'wouter/views'
Render a view directly in your route definition:
class Routes < Wouter
get '/', render_view(:index)
end
Render a view in your endpoint:
class Index < Wouter::Endpoint
def respond
render_view :index
end
end
Configuration
View Directory
By default, the view folder is set to ./views. You can set the view directory using view_dir:
class Routes < Wouter
view_dir './template/views'
get '/', render_view(:index)
end
Template Engine
By default, wouter-views will look for .html files. You can specify which templating engine to use and it will try to find the file:
get '/', render_view(:index, engine: :slim)
You can also change the engine globally:
class Routes < Wouter
view_engine :slim
get '/', render_view(:index)
end
If you provide a string with a file extension, wouter-views will first try to find the file with the given engine extension. If it does not find it, it will try to find the file given the literal string value. This allows you to load any file:
class Routes < Wouter
get '/', render_view('randomfile.extension')
end
Tilt will try to auto-load the appropriate templating engine. It is recommended you load the template engine library yourself. Example:
require 'wouter'
require 'wouter/views'
require 'slim'
class Routes < Wouter
get '/', render_view(:index, engine: :slim)
end