Changeset 6

Show
Ignore:
Timestamp:
01/08/08 18:34:34 (6 months ago)
Author:
jeremymcanal..@gmail.com
Message:

DRY'ing up the ErrorReporter?
Small fixes/tweaks to hoe config
Added rescue for Mongrel::StopServer?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • config/hoe.rb

    r5 r6  
    6060  # == Optional 
    6161  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n") 
    62   #p.extra_deps = []     # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ] 
     62  p.extra_deps = [['rubigen', '>= 0.0.0']]     # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ] 
    6363   
    6464  #p.spec_extras = {}    # A hash of extra values to set in the gemspec. 
  • lib/vintage/errors.rb

    r1 r6  
    33  # not render if error pages are specified in the configuration. 
    44  class ErrorReporter 
     5    # CSS shared among error templates 
     6    CSS = """ 
     7      body { margin: 0px; padding: 0px; font-family: sans-serif; } 
     8      h1 { background: #3E2B09; padding: 45px 10px 10px 10px; color: #6F5E3C;  border: 0px; border-bottom: 2px solid #1C0907; margin: 0px; } 
     9      h1 span.error { text-shadow: 0.1em 0.1em #333; color: white; } 
     10      h2 { margin: 0px; padding: 5px 5px 10px 10px; font-size: 14pt !important; } 
     11      h2 span.where { color: #999; } 
     12      h3 { margin: 0px; padding: 10px 10px; color: #999;} 
     13      ul { margin: 0px; } 
     14      li { margin: 0px; padding: 0px 30px; } 
     15      pre { padding: 0 30px; margin: 0px; } 
     16    """ 
     17     
    518    # Standard template to render for a <tt>500 Internal Server Error</tt> 
    619    def self.internal_error(error, params) 
     20      error_page("500 Internal Server Error", error.class.to_s, "500 Internal Server Error", error.message.to_s, "at #{error.backtrace[0]}", "<h3>Backtrace</h3>\n\t<pre>#{error.backtrace.join('\n')}</pre>") 
     21    end 
     22     
     23    # Standard template to render for a <tt>404 Page Not Found</tt> error 
     24    def self.not_found(url, remote_ip, params) 
     25      error_page("404 Not Found", "Page Not Found", "404 Not Found", "Request for #{url}", "from #{remote_ip}") 
     26    end 
     27     
     28    private 
     29    # Standard template to render for a <tt>404 Page Not Found</tt> error 
     30    def self.error_page(title, h1_primary, h1_secondary, h2_primary, h2_secondary, extra_content = "") 
    731      """ 
    832      <html> 
    933        <head> 
    10           <title>Vintage Error: 500 Internal Server Error</title> 
     34          <title>Vintage Error: #{title}</title> 
    1135          <style> 
    12             body { margin: 0px; padding: 0px; font-family: sans-serif; } 
    13             h1 { background: #3E2B09; padding: 45px 10px 10px 10px; color: #6F5E3C;  border: 0px; border-bottom: 2px solid #1C0907; margin: 0px; } 
    14             h1 span.error { text-shadow: 0.1em 0.1em #333; color: white; } 
    15             h2 { margin: 0px; padding: 5px 5px 10px 10px; font-size: 14pt !important; } 
    16             h2 span.where { color: #999; } 
    17             h3 { margin: 0px; padding: 10px 10px; color: #999;} 
    18             ul { margin: 0px; } 
    19             li { margin: 0px; padding: 0px 30px; } 
    20             pre { padding: 0 30px; margin: 0px; } 
     36            #{CSS} 
    2137          </style> 
    2238        </head> 
    2339 
    2440        <body> 
    25           <h1><span class='error'>#{error.class}</span> 500 Internal Server Error</h1> 
    26           <h2>#{error.message} <span class='where'>at #{error.backtrace[0]}</span></h2> 
     41          <h1><span class='error'>#{h1_primary}</span> #{h1_secondary}</h1> 
     42          <h2>#{h2_primary} <span class='where'>#{h2_secondary}</span></h2> 
    2743          <div> 
    2844            <h3>Parameters</h3> 
     
    3147            </ul> 
    3248            <br /> 
    33             <h3>Backtrace</h3> 
    34             <pre>#{error.backtrace.join("\n")}</pre> 
     49            #{extra_content} 
    3550          </div> 
    3651        </body> 
    3752      </html> 
    38        
    39       """ 
    40     end 
    41      
    42     # Standard template to render for a <tt>404 Page Not Found</tt> error 
    43     def self.not_found(url, remote_ip, params) 
    44       """ 
    45       <html> 
    46         <head> 
    47           <title>Vintage Error: 404 Page Not Found</title> 
    48           <style> 
    49             body { margin: 0px; padding: 0px; font-family: sans-serif; } 
    50             h1 { background: #3E2B09; padding: 45px 10px 10px 10px; color: #6F5E3C;  border: 0px; border-bottom: 2px solid #1C0907; margin: 0px; } 
    51             h1 span.error { text-shadow: 0.1em 0.1em #333; color: white; } 
    52             h2 { margin: 0px; padding: 5px 5px 10px 10px; font-size: 14pt !important; } 
    53             h2 span.where { color: #999; } 
    54             h3 { margin: 0px; padding: 10px 10px; color: #999;} 
    55             ul { margin: 0px; } 
    56             li { margin: 0px; padding: 0px 30px; } 
    57             pre { padding: 0 30px; margin: 0px; } 
    58           </style> 
    59         </head> 
    60  
    61         <body> 
    62           <h1><span class='error'>Page Not Found</span> 404 Not Found</h1> 
    63           <h2>Request for #{url} <span class='where'>from #{remote_ip}</span></h2> 
    64           <div> 
    65             <h3>Parameters</h3> 
    66             <ul> 
    67               #{params == {} ? "None" : params.to_a.map{|key, val| "<li><b>" + key.to_s + "<b> = " + val.to_s + "</li>"}.join("\n") } 
    68             </ul> 
    69           </div> 
    70         </body> 
    71       </html> 
    72        
    7353      """ 
    7454    end 
  • lib/vintage/server.rb

    r4 r6  
    5656 
    5757      server.run application, {:Port => options[:port], :Host => "0.0.0.0", :AccessLog => []} 
    58     rescue Interrupt 
     58    rescue Interrupt, Mongrel::StopServer 
    5959      Log.enter 
    6060      Log.enter "- interrupt signal caught"