Browse code

Merge branch 'sinatra_static_server' of https://github.com/scottwater/octopress into scottwater-sinatra_static_server

Conflicts:
Gemfile
Gemfile.lock

Brandon Mathis authored on 08/09/2011 at 15:31:36
Showing 3 changed files
... ...
@@ -1,13 +1,17 @@
1 1
 source "http://rubygems.org"
2 2
 
3
-gem 'rake'
4
-gem 'rack'
5
-gem 'jekyll'
6
-gem 'rdiscount'
7
-gem 'pygments.rb'
8
-gem 'RedCloth'
9
-gem 'haml', '>= 3.1'
10
-gem 'compass', '>= 0.11'
11
-gem 'rubypants'
12
-gem 'rb-fsevent'
13
-gem 'stringex'
3
+group :development do
4
+  gem 'rake'
5
+  gem 'rack'
6
+  gem 'jekyll'
7
+  gem 'rdiscount'
8
+  gem 'pygments.rb'
9
+  gem 'RedCloth'
10
+  gem 'haml', '>= 3.1'
11
+  gem 'compass', '>= 0.11'
12
+  gem 'rubypants'
13
+  gem 'rb-fsevent'
14
+  gem 'stringex'
15
+end
16
+
17
+gem 'sinatra', '1.2.6'
... ...
@@ -39,9 +39,17 @@ GEM
39 39
     rubypython (0.5.1)
40 40
       blankslate (>= 2.1.2.3)
41 41
       ffi (~> 1.0.7)
42
+<<<<<<< HEAD
42 43
     sass (3.1.7)
44
+=======
45
+    sass (3.1.5)
46
+    sinatra (1.2.6)
47
+      rack (~> 1.1)
48
+      tilt (>= 1.2.2, < 2.0)
49
+>>>>>>> 423e8ecbda0394d4c77e2ea659768a8f30c35018
43 50
     stringex (1.3.0)
44 51
     syntax (1.0.0)
52
+    tilt (1.3.2)
45 53
 
46 54
 PLATFORMS
47 55
   ruby
... ...
@@ -57,4 +65,5 @@ DEPENDENCIES
57 57
   rb-fsevent
58 58
   rdiscount
59 59
   rubypants
60
+  sinatra (= 1.2.6)
60 61
   stringex
... ...
@@ -1,35 +1,25 @@
1
-require 'rubygems'
2 1
 require 'bundler/setup'
3
-require 'rack'
2
+require 'sinatra/base'
4 3
 
5 4
 # The project root directory
6 5
 $root = ::File.dirname(__FILE__)
7 6
 
8
-# Common Rack Middleware
9
-use Rack::ShowStatus      # Nice looking 404s and other messages
10
-use Rack::ShowExceptions  # Nice looking errors
7
+class SinatraStaticServer < Sinatra::Base  
11 8
 
12
-#
13
-# From Rack::DirectoryIndex:
14
-# https://github.com/craigmarksmith/rack-directory-index/
15
-#
16
-module Rack
17
-  class DirectoryIndex
18
-    def initialize(app)
19
-      @app = app
20
-    end
21
-    def call(env)
22
-      index_path = ::File.join($root, 'public', Rack::Request.new(env).path.split('/'), 'index.html')
23
-      if ::File.exists?(index_path)
24
-        return [200, {"Content-Type" => "text/html"}, [::File.read(index_path)]]
25
-      else
26
-        @app.call(env)
27
-      end
28
-    end
9
+  get(/.+/) do
10
+    send_sinatra_file(request.path) {404}
29 11
   end
30
-end
31 12
 
32
-use Rack::DirectoryIndex
13
+  not_found do
14
+    send_sinatra_file('404.html') {"Sorry, I cannot find #{request.path}"}
15
+  end
33 16
 
34
-run Rack::Directory.new($root + '/public')
17
+  def send_sinatra_file(path, &missing_file_block)
18
+    file_path = File.join(File.dirname(__FILE__), 'public',  path)
19
+    file_path = File.join(file_path, 'index.html') unless file_path =~ /\.[a-z]+$/i  
20
+    File.exist?(file_path) ? send_file(file_path) : missing_file_block.call
21
+  end
22
+
23
+end
35 24
 
25
+run SinatraStaticServer
36 26
\ No newline at end of file