Module: Porthole::Sinatra
- Defined in:
- lib/porthole/sinatra.rb
Overview
Support for Porthole in your Sinatra app.
require 'porthole/sinatra'
class Hurl < Sinatra::Base
register Porthole::Sinatra
set :porthole, {
# Should be the path to your .porthole template files.
:templates => "path/to/porthole/templates",
# Should be the path to your .rb Porthole view files.
:views => "path/to/porthole/views",
# This tells Porthole where to look for the Views module,
# under which your View classes should live. By default it's
# the class of your app - in this case `Hurl`. That is, for an :index
# view Porthole will expect Hurl::Views::Index by default.
# If our Sinatra::Base subclass was instead Hurl::App,
# we'd want to do `set :namespace, Hurl::App`
:namespace => Hurl
}
get '/stats' do
porthole :stats
end
end
As noted above, Porthole will look for ‘Hurl::Views::Index` when `porthole :index` is called.
If no ‘Views::Stats` class exists Porthole will render the template file directly.
You can indeed use layouts with this library. Where you’d normally <%= yield %> you instead {{yield}} - the body of the subview is set to the ‘yield` variable and made available to you.
If you don’t want the Sinatra extension to look up your view class, maybe because you’ve already loaded it or you’re pulling it in from a gem, you can hand the ‘porthole` helper a Porthole subclass directly:
# Assuming `class Omnigollum::Login < Porthole`
get '/login' do
@title = "Log In"
require 'lib/omnigollum/views/login'
porthole Omnigollum::Login
end
Defined Under Namespace
Modules: Helpers
Class Method Summary collapse
-
.registered(app) ⇒ Object
Called when you ‘register Porthole::Sinatra` in your Sinatra app.
Class Method Details
.registered(app) ⇒ Object
Called when you ‘register Porthole::Sinatra` in your Sinatra app.
199 200 201 |
# File 'lib/porthole/sinatra.rb', line 199 def self.registered(app) app.helpers Porthole::Sinatra::Helpers end |