bunch 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/lib/bunch.rb CHANGED
@@ -13,6 +13,7 @@ end
13
13
 
14
14
  require 'bunch/version'
15
15
  require 'bunch/rack'
16
+ require 'bunch/middleware'
16
17
  require 'bunch/caching'
17
18
  require 'bunch/directory_node'
18
19
  require 'bunch/file_node'
@@ -0,0 +1,41 @@
1
+ # heavily inspired by Rack::URLMap
2
+
3
+ module Bunch
4
+ class Middleware
5
+ attr_accessor :app
6
+
7
+ def initialize(app, options={})
8
+ unless options[:root_url] && options[:path]
9
+ raise "Must provide :root_url and :path"
10
+ end
11
+
12
+ @app = app
13
+ @root_url = options.delete(:root_url)
14
+ @endpoint = Bunch::Rack.new(options.delete(:path), options)
15
+ end
16
+
17
+ def call(env)
18
+ path = env['PATH_INFO'].to_s
19
+ script_name = env['SCRIPT_NAME']
20
+
21
+ if path =~ root_regexp &&
22
+ (rest = $1) &&
23
+ (rest.empty? || rest[0] == ?/)
24
+
25
+ @endpoint.call(
26
+ env.merge(
27
+ 'SCRIPT_NAME' => (script_name + @root_url),
28
+ 'PATH_INFO' => rest
29
+ )
30
+ )
31
+ else
32
+ @app.call(env)
33
+ end
34
+ end
35
+
36
+ private
37
+ def root_regexp
38
+ Regexp.new("^#{Regexp.quote(@root_url).gsub('/', '/+')}(.*)")
39
+ end
40
+ end
41
+ end
data/lib/bunch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Bunch
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bunch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-01-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mime-types
16
- requirement: &70263668761740 !ruby/object:Gem::Requirement
16
+ requirement: &70177706384580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70263668761740
24
+ version_requirements: *70177706384580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: slop
27
- requirement: &70263668761320 !ruby/object:Gem::Requirement
27
+ requirement: &70177706384160 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70263668761320
35
+ version_requirements: *70177706384160
36
36
  description: Directory-structure-based asset bundling.
37
37
  email:
38
38
  - rfitz@academia.edu
@@ -70,6 +70,7 @@ files:
70
70
  - lib/bunch/coffee_node.rb
71
71
  - lib/bunch/directory_node.rb
72
72
  - lib/bunch/file_node.rb
73
+ - lib/bunch/middleware.rb
73
74
  - lib/bunch/rack.rb
74
75
  - lib/bunch/sass_node.rb
75
76
  - lib/bunch/version.rb