module Pakyow::Application::Behavior::Presenter::ErrorRendering

Public Class Methods

render_error(error, context) click to toggle source

@api private

# File lib/pakyow/application/behavior/presenter/error_rendering.rb, line 20
def self.render_error(error, context)
  context.respond_to :html do
    if Pakyow.env?(:production)
      context.render "/500"
    else
      unless error.is_a?(Pakyow::Error)
        error = Pakyow::Error.build(error)
      end

      error.extend Support::Bindable
      context.expose :pw_error, error
      context.render "/development/500"
    end
  end
end

Public Instance Methods

backtrace() click to toggle source
# File lib/pakyow/application/behavior/presenter/error_rendering.rb, line 80
def backtrace
  html_safe(object.condensed_backtrace.to_a.map { |line|
    CGI.escape_html(line)
  }.join("<br>"))
end
contextual_message() click to toggle source
# File lib/pakyow/application/behavior/presenter/error_rendering.rb, line 68
def contextual_message
  if object.respond_to?(:contextual_message)
    html_safe(markdown.render(format(object.contextual_message)))
  else
    nil
  end
end
details() click to toggle source
# File lib/pakyow/application/behavior/presenter/error_rendering.rb, line 76
def details
  html_safe(markdown.render(format(object.details)))
end
format(string) click to toggle source
# File lib/pakyow/application/behavior/presenter/error_rendering.rb, line 104
def format(string)
  string = string.dup

  # Replace `foo' with `foo` to render as inline code.
  #
  string.dup.scan(/`([^']*)'/).each do |match|
    string.gsub!("`#{match[0]}'", "`#{match[0]}`")
  end

  # Format object references as inline code.
  #
  string.dup.scan(/#<(.*)>/).each do |match|
    string.gsub!("#<#{match[0]}>", "`#<#{match[0]}>`")
  end

  string
end
markdown() click to toggle source
# File lib/pakyow/application/behavior/presenter/error_rendering.rb, line 98
def markdown
  @markdown ||= Redcarpet::Markdown.new(
    Redcarpet::Render::HTML.new({})
  )
end
message() click to toggle source
# File lib/pakyow/application/behavior/presenter/error_rendering.rb, line 64
def message
  html_safe(markdown.render(format(object.message)))
end