sinatra-index 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sinatra-index.gemspec
4
+ gemspec
@@ -0,0 +1,15 @@
1
+ # Sinatra Indices
2
+
3
+ The problem: you want the path `/` to give the contents of `public/index.html` and `/foo`, to go to `public/foo/index.html`.
4
+
5
+ The solution:
6
+
7
+ require 'rubygems'
8
+ require 'sinatra-index'
9
+
10
+ class MyApp < Sinatra::Base
11
+ register Sinatra::Index
12
+ use_static_index 'index.html'
13
+
14
+ ... Sinatra routes ...
15
+ end
@@ -0,0 +1,14 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+
7
+ task :default => [:test_units]
8
+
9
+ desc "Run basic tests"
10
+ Rake::TestTask.new("test_units") { |t|
11
+ t.pattern = 'test/*_test.rb'
12
+ t.verbose = true
13
+ t.warning = true
14
+ }
@@ -0,0 +1,33 @@
1
+ require 'rubygems'
2
+ require 'sinatra/base'
3
+
4
+ module Sinatra
5
+ module Index
6
+
7
+ def self.registered(app)
8
+ app.set :static_indices, []
9
+ app.before do
10
+ if app.static? && (request.get? || request.head?)
11
+ orig_path = request.path_info
12
+ path = unescape orig_path
13
+ path = path << '/' unless path.end_with? '/'
14
+
15
+ app.static_indices.each do |idx|
16
+ request.path_info = path + idx
17
+ static!
18
+ end
19
+
20
+ request.path_info = orig_path
21
+ end
22
+ end
23
+ end
24
+
25
+ def use_static_indices(*args)
26
+ static_indices.concat(args.flatten)
27
+ end
28
+
29
+ alias_method :use_static_index, :use_static_indices
30
+ end
31
+
32
+ register Index
33
+ end
@@ -0,0 +1,5 @@
1
+ module Sinatra
2
+ module Index
3
+ VERSION = "0.0.2"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sinatra-index/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sinatra-index"
7
+ s.version = Sinatra::Index::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ['Eli Fox-Epstein']
10
+ s.email = ['eli@redhyphen.com']
11
+ s.homepage = "http://github.com/elitheeli/sinatra-index"
12
+ s.summary = %q{Provides indices for public}
13
+ s.description = %q{Provides indices for public}
14
+
15
+ s.rubyforge_project = "sinatra-index"
16
+
17
+ s.add_dependency 'sinatra'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'rack/test'
4
+ require 'sinatra/base'
5
+ require "./#{File.dirname(__FILE__)}/../lib/sinatra-index"
6
+
7
+ class TestIndices < Test::Unit::TestCase
8
+ include Rack::Test::Methods
9
+
10
+ def app
11
+ TestApp
12
+ end
13
+
14
+ def test_serves_first_asset
15
+ get 'foo'
16
+ assert_equal 'foo', last_response.body
17
+ end
18
+
19
+ def test_serves_first_index
20
+ get '/'
21
+ assert_equal 'foo.html', last_response.body
22
+ end
23
+
24
+ def test_subfolders
25
+ get '/qux'
26
+ assert_equal 'qux/foo.html', last_response.body
27
+ end
28
+
29
+ end
30
+
31
+ class TestApp < Sinatra::Base
32
+
33
+ register Sinatra::Index
34
+ use_static_indices 'foo.html', 'bar.html'
35
+
36
+ set :app_file, __FILE__
37
+
38
+ end
@@ -0,0 +1 @@
1
+ bar.html
@@ -0,0 +1 @@
1
+ foo
@@ -0,0 +1 @@
1
+ foo.html
@@ -0,0 +1 @@
1
+ qux/foo.html
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sinatra-index
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 2
9
+ version: 0.0.2
10
+ platform: ruby
11
+ authors:
12
+ - Eli Fox-Epstein
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-12 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: sinatra
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: Provides indices for public
34
+ email:
35
+ - eli@redhyphen.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - Gemfile
44
+ - README.md
45
+ - Rakefile
46
+ - lib/sinatra-index.rb
47
+ - lib/sinatra-index/version.rb
48
+ - sinatra-index.gemspec
49
+ - test/indices_test.rb
50
+ - test/public/bar.html
51
+ - test/public/foo
52
+ - test/public/foo.html
53
+ - test/public/qux/foo.html
54
+ has_rdoc: true
55
+ homepage: http://github.com/elitheeli/sinatra-index
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project: sinatra-index
82
+ rubygems_version: 1.3.7
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Provides indices for public
86
+ test_files:
87
+ - test/indices_test.rb
88
+ - test/public/bar.html
89
+ - test/public/foo
90
+ - test/public/foo.html
91
+ - test/public/qux/foo.html