Module: Strelka::App::FancyErrors
- Extended by:
- Configurability, Loggability, MethodUtilities, Plugin
- Defined in:
- lib/strelka/app/fancyerrors.rb
Overview
Fancy/useful error output for Strelka appliation development. This plugin uses the Strelka default :errors and :templating plugins.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- VERSION =
Library version constant
'0.1.0'
- REVISION =
Version-control revision constant
%q$Revision: a8125dbd7d06 $
- DEFAULT_DATADIR =
The data directory in the project if that exists, otherwise the gem datadir
if ENV['FANCYERRORS_DATADIR'] Pathname( ENV['FANCYERRORS_DATADIR'] ) elsif File.directory?( 'data/strelka-fancyerrors' ) Pathname( 'data/strelka-fancyerrors' ) elsif path = Gem.datadir('strelka-fancyerrors') Pathname( path ) else raise ScriptError, "can't find the data directory!" end
- CONFIG_DEFAULTS =
Configurability configuration defaults
{ templates_dir: DEFAULT_DATADIR + 'templates', }
Class Method Summary collapse
-
.configure(config = nil) ⇒ Object
Configurability API – Configure the plugin.
-
.included(mod) ⇒ Object
Inclusion callback – add the plugin’s templates directory right before activation so loading the config doesn’t clobber it.
Instance Method Summary collapse
-
#fancy_error_template(key, response, status_info) ⇒ Object
Load the template that corresponds to
key
and populate it with the givenstatus_info
. -
#templates_dir ⇒ Object
The path to the error templates.
Class Method Details
.configure(config = nil) ⇒ Object
Configurability API – Configure the plugin
66 67 68 69 70 71 |
# 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 |
.included(mod) ⇒ Object
Inclusion callback – add the plugin’s templates directory right before activation so loading the config doesn’t clobber it.
76 77 78 79 80 81 |
# 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 |
Instance Method Details
#fancy_error_template(key, response, status_info) ⇒ Object
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.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# 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 |
#templates_dir ⇒ Object
The path to the error templates
61 |
# File 'lib/strelka/app/fancyerrors.rb', line 61 singleton_attr_accessor :templates_dir |