Skip to content

Commit

Permalink
Use a static file middleware that will pass through to the applicatio…
Browse files Browse the repository at this point in the history
…n if the file does not exist. This is based on the Rails::Rack::Static middleware from Rails 3. Making this change will enable serving files from any path (not just under 'public', and allow creation of files such as robots.txt.
  • Loading branch information
lazyatom committed Jan 4, 2010
1 parent 2dce9d7 commit 89b2743
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -25,7 +25,7 @@ if Object.const_defined?(:Gem)

# Change these as appropriate
s.name = "vanilla"
s.version = "1.9.16"
s.version = "1.9.17"
s.summary = "A bliki-type web content thing."
s.author = "James Adam"
s.email = "james@lazyatom.com.com"
Expand Down
3 changes: 2 additions & 1 deletion config.ru
@@ -1,5 +1,6 @@
$:.unshift File.join(File.dirname(__FILE__), *%w[lib])
require 'vanilla'
require 'vanilla/static'

app = Vanilla::App.new(ENV['VANILLA_CONFIG'])

Expand All @@ -15,6 +16,6 @@ use Warden::Manager do |manager|
manager.failure_app = Vanilla::Authentication::Warden::FailApp.new
end

use Rack::Static, :urls => ["/public"], :root => File.join(File.dirname(__FILE__))
use Vanilla::Static, File.join(File.dirname(__FILE__), 'public')

run app
10 changes: 5 additions & 5 deletions lib/vanilla/snips/system.rb
Expand Up @@ -8,9 +8,9 @@
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>{current_snip name}</title>
<script language="javascript" src="/public/javascripts/jquery.js"></script>
<script language="javascript" src="/public/javascripts/jquery.autogrow-textarea.js"></script>
<script language="javascript" src="/public/javascripts/vanilla.js"></script>
<script language="javascript" src="/javascripts/jquery.js"></script>
<script language="javascript" src="/javascripts/jquery.autogrow-textarea.js"></script>
<script language="javascript" src="/javascripts/vanilla.js"></script>
<link rel="stylesheet" type="text/css" media="screen" href="<%= url_to("system", "css.css") %>" />
</head>
<body>
Expand All @@ -33,8 +33,8 @@
<body id="login">
<form action='' method='post'>
<h1>Login</h1><p class="message">MESSAGE</p>
<label>Name: <input type="text" name="name"></input></label>
<label>Password: <input type="password" name="password"></input></label>
<label>Name: <input type="text" name="login[username]"></input></label>
<label>Password: <input type="password" name="login[password]"></input></label>
<button>login</button>
</form>
</body>
Expand Down
28 changes: 28 additions & 0 deletions lib/vanilla/static.rb
@@ -0,0 +1,28 @@
require 'rack/utils'

# Heavily based on ActionDispatch::Static
module Vanilla
class Static
def initialize(app, root)
@app = app
@file_server = ::Rack::File.new(root)
end

def call(env)
path = env['PATH_INFO'].chomp('/')
method = env['REQUEST_METHOD']

if %w(GET HEAD).include?(method) && file_exist?(path)
@file_server.call(env)
else
@app.call(env)
end
end

private
def file_exist?(path)
full_path = File.join(@file_server.root, ::Rack::Utils.unescape(path))
File.file?(full_path) && File.readable?(full_path)
end
end
end
6 changes: 3 additions & 3 deletions vanilla.gemspec
Expand Up @@ -2,16 +2,16 @@

Gem::Specification.new do |s|
s.name = %q{vanilla}
s.version = "1.9.16"
s.version = "1.9.17"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["James Adam"]
s.date = %q{2009-12-16}
s.date = %q{2010-01-04}
s.default_executable = %q{vanilla}
s.email = %q{james@lazyatom.com.com}
s.executables = ["vanilla"]
s.extra_rdoc_files = ["README"]
s.files = ["config.example.yml", "config.ru", "Rakefile", "README", "README_FOR_APP", "test/base_renderer_test.rb", "test/dynasnip_test.rb", "test/erb_renderer_test.rb", "test/markdown_renderer_test.rb", "test/raw_renderer_test.rb", "test/ruby_renderer_test.rb", "test/snip_reference_parser_test.rb", "test/snip_reference_test.rb", "test/test_helper.rb", "test/tmp", "test/tmp/config.yml", "test/tmp/soup", "test/tmp/soup/current_snip.yml", "test/tmp/soup/system.yml", "test/vanilla_app_test.rb", "test/vanilla_presenting_test.rb", "test/vanilla_request_test.rb", "test/vanilla_soup_test.rb", "lib/defensio.rb", "lib/tasks", "lib/tasks/vanilla.rake", "lib/vanilla", "lib/vanilla/app.rb", "lib/vanilla/authentication", "lib/vanilla/authentication/warden.rb", "lib/vanilla/authentication.rb", "lib/vanilla/console.rb", "lib/vanilla/dynasnip.rb", "lib/vanilla/dynasnips", "lib/vanilla/dynasnips/comments.rb", "lib/vanilla/dynasnips/current_snip.rb", "lib/vanilla/dynasnips/debug.rb", "lib/vanilla/dynasnips/edit.rb", "lib/vanilla/dynasnips/edit_link.rb", "lib/vanilla/dynasnips/index.rb", "lib/vanilla/dynasnips/kind.rb", "lib/vanilla/dynasnips/link_to.rb", "lib/vanilla/dynasnips/link_to_current_snip.rb", "lib/vanilla/dynasnips/logout.rb", "lib/vanilla/dynasnips/new.rb", "lib/vanilla/dynasnips/notes.rb", "lib/vanilla/dynasnips/pre.rb", "lib/vanilla/dynasnips/rand.rb", "lib/vanilla/dynasnips/raw.rb", "lib/vanilla/dynasnips/url_to.rb", "lib/vanilla/renderers", "lib/vanilla/renderers/base.rb", "lib/vanilla/renderers/bold.rb", "lib/vanilla/renderers/erb.rb", "lib/vanilla/renderers/markdown.rb", "lib/vanilla/renderers/raw.rb", "lib/vanilla/renderers/ruby.rb", "lib/vanilla/renderers/textile.rb", "lib/vanilla/request.rb", "lib/vanilla/routes.rb", "lib/vanilla/snip_reference.rb", "lib/vanilla/snip_reference.treetop", "lib/vanilla/snip_reference_parser.rb", "lib/vanilla/snips", "lib/vanilla/snips/start.rb", "lib/vanilla/snips/system.rb", "lib/vanilla/snips/tutorial.rb", "lib/vanilla/soup_with_timestamps.rb", "lib/vanilla.rb", "bin/vanilla", "public/hatch.png", "public/javascripts", "public/javascripts/jquery.autogrow-textarea.js", "public/javascripts/jquery.js", "public/javascripts/vanilla.js"]
s.files = ["config.example.yml", "config.ru", "Rakefile", "README", "README_FOR_APP", "test/base_renderer_test.rb", "test/dynasnip_test.rb", "test/erb_renderer_test.rb", "test/markdown_renderer_test.rb", "test/raw_renderer_test.rb", "test/ruby_renderer_test.rb", "test/snip_reference_parser_test.rb", "test/snip_reference_test.rb", "test/test_helper.rb", "test/tmp", "test/tmp/config.yml", "test/tmp/soup", "test/tmp/soup/current_snip.yml", "test/tmp/soup/system.yml", "test/vanilla_app_test.rb", "test/vanilla_presenting_test.rb", "test/vanilla_request_test.rb", "test/vanilla_soup_test.rb", "lib/defensio.rb", "lib/tasks", "lib/tasks/vanilla.rake", "lib/vanilla", "lib/vanilla/app.rb", "lib/vanilla/authentication", "lib/vanilla/authentication/warden.rb", "lib/vanilla/authentication.rb", "lib/vanilla/console.rb", "lib/vanilla/dynasnip.rb", "lib/vanilla/dynasnips", "lib/vanilla/dynasnips/comments.rb", "lib/vanilla/dynasnips/current_snip.rb", "lib/vanilla/dynasnips/debug.rb", "lib/vanilla/dynasnips/edit.rb", "lib/vanilla/dynasnips/edit_link.rb", "lib/vanilla/dynasnips/index.rb", "lib/vanilla/dynasnips/kind.rb", "lib/vanilla/dynasnips/link_to.rb", "lib/vanilla/dynasnips/link_to_current_snip.rb", "lib/vanilla/dynasnips/logout.rb", "lib/vanilla/dynasnips/new.rb", "lib/vanilla/dynasnips/notes.rb", "lib/vanilla/dynasnips/pre.rb", "lib/vanilla/dynasnips/rand.rb", "lib/vanilla/dynasnips/raw.rb", "lib/vanilla/dynasnips/url_to.rb", "lib/vanilla/renderers", "lib/vanilla/renderers/base.rb", "lib/vanilla/renderers/bold.rb", "lib/vanilla/renderers/erb.rb", "lib/vanilla/renderers/markdown.rb", "lib/vanilla/renderers/raw.rb", "lib/vanilla/renderers/ruby.rb", "lib/vanilla/renderers/textile.rb", "lib/vanilla/request.rb", "lib/vanilla/routes.rb", "lib/vanilla/snip_reference.rb", "lib/vanilla/snip_reference.treetop", "lib/vanilla/snip_reference_parser.rb", "lib/vanilla/snips", "lib/vanilla/snips/start.rb", "lib/vanilla/snips/system.rb", "lib/vanilla/snips/tutorial.rb", "lib/vanilla/soup_with_timestamps.rb", "lib/vanilla/static.rb", "lib/vanilla.rb", "bin/vanilla", "public/hatch.png", "public/javascripts", "public/javascripts/jquery.autogrow-textarea.js", "public/javascripts/jquery.js", "public/javascripts/vanilla.js"]
s.homepage = %q{http://github.com/lazyatom/vanilla-rb}
s.rdoc_options = ["--main", "README"]
s.require_paths = ["lib"]
Expand Down

0 comments on commit 89b2743

Please sign in to comment.