Presentation layer plugin for Strelka
service apps.
The configured Yaks presenter object
Set a block passed to plugin
to the presenter library when it's configured.
# File lib/strelka/app/presenters.rb, line 41
def self::configure_block( app, &block )
app.plugin( :negotiation )
app.presenter_config_block = block
end
Extension callback – extend the HTTPResponse
classes with presenter logic when the plugin is loaded.
# File lib/strelka/app/presenters.rb, line 33
def self::included( object )
Strelka::HTTPResponse.include( Strelka::HTTPResponse::Presenters )
super
end
Set up the presenters when the app is created.
# File lib/strelka/app/presenters.rb, line 48
def initialize( * )
super
@presenter = self.setup_presentation_layer
end
Set up the presenter when the response has returned.
# File lib/strelka/app/presenters.rb, line 64
def handle_request( req )
self.log.debug "[:negotiation] Wrapping response with hypermedia presentation."
response = super
response.presenter = self.presenter
return response
end
Configure and return the presenter.
# File lib/strelka/app/presenters.rb, line 75
def setup_presentation_layer
self.log.debug "Setting up presenters using %s" %
[ self.class.presenter_config_block&.inspect || 'defaults' ]
config_block = self.class.presenter_config_block || Proc.new {}
return Yaks.new( &config_block )
end