Class: Sinatra::ShowExceptions

Inherits:
Rack::ShowExceptions
  • Object
show all
Defined in:
lib/sinatra/showexceptions.rb

Constant Summary collapse

TEMPLATE =
"<!DOCTYPE html>\n<html>\n<head>\n  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>\n  <title><%=h exception.class %> at <%=h path %></title>\n\n  <script type=\"text/javascript\">\n  //<!--\n  function toggle(id) {\n    var pre  = document.getElementById(\"pre-\" + id);\n    var post = document.getElementById(\"post-\" + id);\n    var context = document.getElementById(\"context-\" + id);\n\n    if (pre.style.display == 'block') {\n      pre.style.display = 'none';\n      post.style.display = 'none';\n      context.style.background = \"none\";\n    } else {\n      pre.style.display = 'block';\n      post.style.display = 'block';\n      context.style.background = \"#fffed9\";\n    }\n  }\n\n  function toggleBacktrace(){\n    var bt = document.getElementById(\"backtrace\");\n    var toggler = document.getElementById(\"expando\");\n\n    if (bt.className == 'condensed') {\n      bt.className = 'expanded';\n      toggler.innerHTML = \"(condense)\";\n    } else {\n      bt.className = 'condensed';\n      toggler.innerHTML = \"(expand)\";\n    }\n  }\n  //-->\n  </script>\n\n<style type=\"text/css\" media=\"screen\">\n  *                   {margin: 0; padding: 0; border: 0; outline: 0;}\n  div.clear           {clear: both;}\n  body                {background: #EEEEEE; margin: 0; padding: 0;\n                       font-family: 'Lucida Grande', 'Lucida Sans Unicode',\n                       'Garuda';}\n  code                {font-family: 'Lucida Console', monospace;\n                       font-size: 12px;}\n  li                  {height: 18px;}\n  ul                  {list-style: none; margin: 0; padding: 0;}\n  ol:hover            {cursor: pointer;}\n  ol li               {white-space: pre;}\n  #explanation        {font-size: 12px; color: #666666;\n                       margin: 20px 0 0 100px;}\n/* WRAP */\n  #wrap               {width: 860px; background: #FFFFFF; margin: 0 auto;\n                       padding: 30px 50px 20px 50px;\n                       border-left: 1px solid #DDDDDD;\n                       border-right: 1px solid #DDDDDD;}\n/* HEADER */\n  #header             {margin: 0 auto 25px auto;}\n  #header img         {float: left;}\n  #header #summary    {float: left; margin: 12px 0 0 20px; width:520px;\n                       font-family: 'Lucida Grande', 'Lucida Sans Unicode';}\n  h1                  {margin: 0; font-size: 36px; color: #981919;}\n  h2                  {margin: 0; font-size: 22px; color: #333333;}\n  #header ul          {margin: 0; font-size: 12px; color: #666666;}\n  #header ul li strong{color: #444444;}\n  #header ul li       {display: inline; padding: 0 10px;}\n  #header ul li.first {padding-left: 0;}\n  #header ul li.last  {border: 0; padding-right: 0;}\n/* BODY */\n  #backtrace,\n  #get,\n  #post,\n  #cookies,\n  #rack               {width: 860px; margin: 0 auto 10px auto;}\n  p#nav               {float: right; font-size: 14px;}\n/* BACKTRACE */\n  a#expando           {float: left; padding-left: 5px; color: #666666;\n                      font-size: 14px; text-decoration: none; cursor: pointer;}\n  a#expando:hover     {text-decoration: underline;}\n  h3                  {float: left; width: 100px; margin-bottom: 10px;\n                       color: #981919; font-size: 14px; font-weight: bold;}\n  #nav a              {color: #666666; text-decoration: none; padding: 0 5px;}\n  #backtrace li.frame-info {background: #f7f7f7; padding-left: 10px;\n                           font-size: 12px; color: #333333;}\n  #backtrace ul       {list-style-position: outside; border: 1px solid #E9E9E9;\n                       border-bottom: 0;}\n  #backtrace ol       {width: 808px; margin-left: 50px;\n                       font: 10px 'Lucida Console', monospace; color: #666666;}\n  #backtrace ol li    {border: 0; border-left: 1px solid #E9E9E9;\n                       padding: 2px 0;}\n  #backtrace ol code  {font-size: 10px; color: #555555; padding-left: 5px;}\n  #backtrace-ul li    {border-bottom: 1px solid #E9E9E9; height: auto;\n                       padding: 3px 0;}\n  #backtrace-ul .code {padding: 6px 0 4px 0;}\n  #backtrace.condensed .system,\n  #backtrace.condensed .framework {display:none;}\n/* REQUEST DATA */\n  p.no-data           {padding-top: 2px; font-size: 12px; color: #666666;}\n  table.req           {width: 760px; text-align: left; font-size: 12px;\n                       color: #666666; padding: 0; border-spacing: 0;\n                       border: 1px solid #EEEEEE; border-bottom: 0;\n                       border-left: 0;}\n  table.req tr th     {padding: 2px 10px; font-weight: bold;\n                       background: #F7F7F7; border-bottom: 1px solid #EEEEEE;\n                       border-left: 1px solid #EEEEEE;}\n  table.req tr td     {padding: 2px 20px 2px 10px;\n                       border-bottom: 1px solid #EEEEEE;\n                       border-left: 1px solid #EEEEEE;}\n/* HIDE PRE/POST CODE AT START */\n  .pre-context,\n  .post-context       {display: none;}\n</style>\n</head>\n<body>\n  <div id=\"wrap\">\n    <div id=\"header\">\n      <img src=\"/__sinatra__/500.png\" alt=\"application error\" />\n      <div id=\"summary\">\n        <h1><strong><%=h exception.class %></strong> at <strong><%=h path %>\n          </strong></h1>\n        <h2><%=h exception.message %></h2>\n        <ul>\n          <li class=\"first\"><strong>file:</strong> <code>\n            <%=h frames.first.filename.split(\"/\").last %></code></li>\n          <li><strong>location:</strong> <code><%=h frames.first.function %>\n            </code></li>\n          <li class=\"last\"><strong>line:\n            </strong> <%=h frames.first.lineno %></li>\n        </ul>\n      </div>\n      <div class=\"clear\"></div>\n    </div>\n\n    <div id=\"backtrace\" class='condensed'>\n      <h3>BACKTRACE</h3>\n      <p><a href=\"#\" id=\"expando\"\n            onclick=\"toggleBacktrace(); return false\">(expand)</a></p>\n      <p id=\"nav\"><strong>JUMP TO:</strong>\n         <a href=\"#get-info\">GET</a>\n         <a href=\"#post-info\">POST</a>\n         <a href=\"#cookie-info\">COOKIES</a>\n         <a href=\"#env-info\">ENV</a>\n      </p>\n      <div class=\"clear\"></div>\n\n      <ul id=\"backtrace-ul\">\n\n      <% id = 1 %>\n      <% frames.each do |frame| %>\n          <% if frame.context_line && frame.context_line != \"#\" %>\n\n            <li class=\"frame-info <%= frame_class(frame) %>\">\n              <code><%=h frame.filename %></code> in\n                <code><strong><%=h frame.function %></strong></code>\n            </li>\n\n            <li class=\"code <%= frame_class(frame) %>\">\n              <% if frame.pre_context %>\n              <ol start=\"<%=h frame.pre_context_lineno + 1 %>\"\n                  class=\"pre-context\" id=\"pre-<%= id %>\"\n                  onclick=\"toggle(<%= id %>);\">\n                <% frame.pre_context.each do |line| %>\n                <li class=\"pre-context-line\"><code><%=h line %></code></li>\n                <% end %>\n              </ol>\n              <% end %>\n\n              <ol start=\"<%= frame.lineno %>\" class=\"context\" id=\"<%= id %>\"\n                  onclick=\"toggle(<%= id %>);\">\n                <li class=\"context-line\" id=\"context-<%= id %>\"><code><%=\n                  h frame.context_line %></code></li>\n              </ol>\n\n              <% if frame.post_context %>\n              <ol start=\"<%=h frame.lineno + 1 %>\" class=\"post-context\"\n                  id=\"post-<%= id %>\" onclick=\"toggle(<%= id %>);\">\n                <% frame.post_context.each do |line| %>\n                <li class=\"post-context-line\"><code><%=h line %></code></li>\n                <% end %>\n              </ol>\n              <% end %>\n              <div class=\"clear\"></div>\n            </li>\n\n          <% end %>\n\n        <% id += 1 %>\n      <% end %>\n\n      </ul>\n    </div> <!-- /BACKTRACE -->\n\n    <div id=\"get\">\n      <h3 id=\"get-info\">GET</h3>\n      <% unless req.GET.empty? %>\n        <table class=\"req\">\n          <tr>\n            <th>Variable</th>\n            <th>Value</th>\n          </tr>\n           <% req.GET.sort_by { |k, v| k.to_s }.each { |key, val| %>\n          <tr>\n            <td><%=h key %></td>\n            <td class=\"code\"><div><%=h val.inspect %></div></td>\n          </tr>\n          <% } %>\n        </table>\n      <% else %>\n        <p class=\"no-data\">No GET data.</p>\n      <% end %>\n      <div class=\"clear\"></div>\n    </div> <!-- /GET -->\n\n    <div id=\"post\">\n      <h3 id=\"post-info\">POST</h3>\n      <% unless req.POST.empty? %>\n        <table class=\"req\">\n          <tr>\n            <th>Variable</th>\n            <th>Value</th>\n          </tr>\n          <% req.POST.sort_by { |k, v| k.to_s }.each { |key, val| %>\n          <tr>\n            <td><%=h key %></td>\n            <td class=\"code\"><div><%=h val.inspect %></div></td>\n          </tr>\n          <% } %>\n        </table>\n      <% else %>\n        <p class=\"no-data\">No POST data.</p>\n      <% end %>\n      <div class=\"clear\"></div>\n    </div> <!-- /POST -->\n\n    <div id=\"cookies\">\n      <h3 id=\"cookie-info\">COOKIES</h3>\n      <% unless req.cookies.empty? %>\n        <table class=\"req\">\n          <tr>\n            <th>Variable</th>\n            <th>Value</th>\n          </tr>\n          <% req.cookies.each { |key, val| %>\n            <tr>\n              <td><%=h key %></td>\n              <td class=\"code\"><div><%=h val.inspect %></div></td>\n            </tr>\n          <% } %>\n        </table>\n      <% else %>\n        <p class=\"no-data\">No cookie data.</p>\n      <% end %>\n      <div class=\"clear\"></div>\n    </div> <!-- /COOKIES -->\n\n    <div id=\"rack\">\n      <h3 id=\"env-info\">Rack ENV</h3>\n      <table class=\"req\">\n        <tr>\n          <th>Variable</th>\n          <th>Value</th>\n        </tr>\n         <% env.sort_by { |k, v| k.to_s }.each { |key, val| %>\n         <tr>\n           <td><%=h key %></td>\n           <td class=\"code\"><div><%=h val %></div></td>\n         </tr>\n         <% } %>\n      </table>\n      <div class=\"clear\"></div>\n    </div> <!-- /RACK ENV -->\n\n    <p id=\"explanation\">You're seeing this error because you have\nenabled the <code>show_exceptions</code> setting.</p>\n  </div> <!-- /WRAP -->\n  </body>\n</html>\n"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ShowExceptions

Returns a new instance of ShowExceptions.



5
6
7
8
# File 'lib/sinatra/showexceptions.rb', line 5

def initialize(app)
  @app      = app
  @template = ERB.new(TEMPLATE)
end

Instance Method Details

#frame_class(frame) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/sinatra/showexceptions.rb', line 10

def frame_class(frame)
  if frame.filename =~ /lib\/sinatra.*\.rb/
    "framework"
  elsif (defined?(Gem) && frame.filename.include?(Gem.dir)) ||
        frame.filename =~ /\/bin\/(\w+)$/
    "system"
  else
    "app"
  end
end