Fancy/useful error output for Strelka appliation development. This plugin uses the Strelka default :errors and :templating plugins.
Configurability configuration defaults
The data directory in the project if that exists, otherwise the gem datadir
Version-control revision constant
Library version constant
Configurability API – Configure the plugin
# File lib/strelka/app/fancyerrors.rb, line 66
def self::configure( config=nil )
if config
self.log.debug "Configuring fancy error templates: %p" % [ config ]
self.templates_dir = Pathname( config[:templates_dir] ) if config[:templates_dir]
end
end
Inclusion callback – add the plugin’s templates directory right before activation so loading the config doesn’t clobber it.
# File lib/strelka/app/fancyerrors.rb, line 76
def self::included( mod )
# Add the plugin's template directory to Inversion's template path
Inversion::Template.template_paths.push( self.templates_dir )
super
end
Load the template that corresponds to key and populate it with
the given status_info. If the application has a layout
template, wrap it in that. Otherwise, use a simple default layout template.
# File lib/strelka/app/fancyerrors.rb, line 114
def fancy_error_template( key, response, status_info )
self.log.info "[:fancyerrors] Handling %d status response." % [ status_info[:status] ]
content = self.template( key )
content.status_info = status_info
self.log.debug " error content template loaded from %s" % [ content.source_file || 'memory' ]
# If there's a layout template, just return the template as-is so
# templating will wrap it correctly
return content if self.layout
self.log.debug " using the fancyerrors layout template."
# Otherwise, wrap it in a simple layout of our own
layout = self.template( :fancy_error_layout )
layout.body = content
layout.status_info = status_info
self.log.debug " error layout template loaded from %s" % [ layout.source_file || 'memory' ]
# :templating method
self.set_common_attributes( layout, response.request )
return layout
end
The path to the error templates
# File lib/strelka/app/fancyerrors.rb, line 61
singleton_attr_accessor :templates_dir