Module: Sinatra::Environment

Extended by:
Environment
Included in:
Environment
Defined in:
lib/codebutler/sinatra.rb

Instance Method Summary collapse

Instance Method Details

#setup!Object



766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
# File 'lib/codebutler/sinatra.rb', line 766

def setup!
  configure do
    error do
      raise request.env['sinatra.error'] if Sinatra.options.raise_errors
      '<h1>Internal Server Error</h1>'
    end
    not_found { '<h1>Not Found</h1>'}
  end
  
  configures :development do

    get '/sinatra_custom_images/:image.png' do
      File.read(File.dirname(__FILE__) + "/../images/#{params[:image]}.png")
    end

    not_found do
      %Q(
      <style>
      body {
        text-align: center; 
        color: #888;
        font-family: Arial; 
        font-size: 22px; 
        margin: 20px;
      }
      #content {
        margin: 0 auto;
        width: 500px;
        text-align: left;
      }
      </style>
      <html>
        <body>
          <h2>Sinatra doesn't know this diddy.</h2>
          <img src='/sinatra_custom_images/404.png'></img>
          <div id="content">
            Try this:
<pre>#{request.request_method.downcase} "#{request.path_info}" do
  .. do something ..
end<pre>
          </div>
        </body>
      </html>
      )
    end

    error do
      @error = request.env['sinatra.error']
      %Q(
      <html>
      	<body>
      		<style type="text/css" media="screen">
      			body {
      				font-family: Verdana;
      				color: #333;
      			}

      			#content {
      				width: 700px;
      				margin-left: 20px;
      			}

      			#content h1 {
      				width: 99%;
      				color: #1D6B8D;
      				font-weight: bold;
      			}

      			#stacktrace {
      			  margin-top: -20px;
      			}

      			#stacktrace pre {
      				font-size: 12px;
      				border-left: 2px solid #ddd;
      				padding-left: 10px;
      			}

      			#stacktrace img {
      				margin-top: 10px;
      			}
      		</style>
      		<div id="content">
        		<img src="/sinatra_custom_images/500.png" />
        		<div class="info">
              Params: <pre>#{params.inspect}
        		</div>
      			<div id="stacktrace">
      				<h1>#{Rack::Utils.escape_html(@error.class.name + ' - ' + @error.message)}</h1>
      				<pre><code>#{Rack::Utils.escape_html(@error.backtrace.join("\n"))}</code></pre>
      		</div>
      	</body>
      </html>
      )
    end
  end
end