static_server 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
File without changes
Binary file
Binary file
@@ -0,0 +1,2 @@
1
+ require 'static_server/static_config'
2
+ require 'static_server/static_server'
@@ -0,0 +1,27 @@
1
+ class StaticConfig
2
+ def initialize
3
+ @redirect = {}
4
+ @forward = {}
5
+ end
6
+
7
+ def redirect(opt)
8
+ validate_params(opt)
9
+ @redirect.merge! opt
10
+ end
11
+ def forward(opt)
12
+ validate_params(opt)
13
+ @forward.merge! opt
14
+ end
15
+
16
+ def forwards
17
+ @forward
18
+ end
19
+
20
+ def redirects
21
+ @redirect
22
+ end
23
+ private
24
+ def validate_params(opt)
25
+ raise "Invalid param" if opt.size != 1
26
+ end
27
+ end
@@ -0,0 +1,26 @@
1
+ class StaticServer
2
+ def self.configure(params = {})
3
+ options = {:root => 'index.html', :base_dir => 'public'}
4
+ options.merge!(params)
5
+ config = StaticConfig.new
6
+
7
+ yield config if block_given?
8
+
9
+ return Proc.new{ |env|
10
+ if config.redirects.keys.include? env["PATH_INFO"]
11
+ [302, {"Location" => config.redirects[env["PATH_INFO"]], "Content-Type" => "text/html"}, []]
12
+ else
13
+ if config.forwards.keys.include? env["PATH_INFO"]
14
+ env["PATH_INFO"] = config.forwards[env["PATH_INFO"]]
15
+ end
16
+
17
+ if env["PATH_INFO"] == '/'
18
+ env["PATH_INFO"] = options[:root]
19
+ end
20
+
21
+ Rack::File.new("./#{options[:base_dir]}").call(env)
22
+ end
23
+ }
24
+
25
+ end
26
+ end
@@ -0,0 +1,18 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'static_server'
3
+ s.version = '0.0.1'
4
+ s.date = '2011-05-26'
5
+ s.summary = "A simple way to provide static files using rack"
6
+ s.description = "A simple way to provide static files using rack"
7
+ s.authors = ["David Paniz"]
8
+ s.email = 'contato@davidpaniz.com'
9
+
10
+ s.files = `git ls-files`.split("\n")
11
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
13
+ s.require_paths = ["lib"]
14
+
15
+ s.homepage =
16
+ 'http://github.com/davidpaniz/StaticServer'
17
+ end
18
+
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: static_server
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - David Paniz
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-26 00:00:00 -03:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: A simple way to provide static files using rack
18
+ email: contato@davidpaniz.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - .static_server.gemspec.swp
27
+ - README
28
+ - lib/.static_config.rb.swp
29
+ - lib/.static_s.swp
30
+ - lib/.static_server.gemspec.swp
31
+ - lib/static_server.rb
32
+ - lib/static_server/static_config.rb
33
+ - lib/static_server/static_server.rb
34
+ - static_server-0.0.1.gem
35
+ - static_server.gemspec
36
+ has_rdoc: true
37
+ homepage: http://github.com/davidpaniz/StaticServer
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.5.2
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: A simple way to provide static files using rack
64
+ test_files: []
65
+