utopia 0.9.54 → 0.9.55
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/utopia/link.rb +1 -1
- data/lib/utopia/middleware/controller.rb +5 -2
- data/lib/utopia/middleware/static.rb +3 -23
- data/lib/utopia/path.rb +15 -0
- data/lib/utopia/version.rb +1 -1
- metadata +4 -4
data/lib/utopia/link.rb
CHANGED
@@ -168,9 +168,11 @@ module Utopia
|
|
168
168
|
|
169
169
|
def load_file(path)
|
170
170
|
if path.directory?
|
171
|
-
|
171
|
+
uri_path = path
|
172
|
+
base_path = File.join(@root, uri_path.components)
|
172
173
|
else
|
173
|
-
|
174
|
+
uri_path = path.dirname
|
175
|
+
base_path = File.join(@root, uri_path.components)
|
174
176
|
end
|
175
177
|
|
176
178
|
controller_path = File.join(base_path, CONTROLLER_RB)
|
@@ -178,6 +180,7 @@ module Utopia
|
|
178
180
|
if File.exist?(controller_path)
|
179
181
|
klass = Class.new(Base)
|
180
182
|
klass.const_set('BASE_PATH', base_path)
|
183
|
+
klass.const_set('URI_PATH', uri_path)
|
181
184
|
|
182
185
|
$LOAD_PATH.unshift(base_path)
|
183
186
|
|
@@ -56,6 +56,7 @@ module Utopia
|
|
56
56
|
attr :path
|
57
57
|
attr :etag
|
58
58
|
|
59
|
+
# Fit in with Rack::Sendfile
|
59
60
|
def to_path
|
60
61
|
full_path
|
61
62
|
end
|
@@ -136,32 +137,11 @@ module Utopia
|
|
136
137
|
return result
|
137
138
|
end
|
138
139
|
|
139
|
-
# Accelerate the response if sendfile is configured.
|
140
|
-
def sendfile(request, response)
|
141
|
-
if @sendfile.respond_to?(:call)
|
142
|
-
response = @sendfile.call(request.env, response)
|
143
|
-
elsif @sendfile && request.env['UTOPIA_SENDFILE'] == "X-Sendfile"
|
144
|
-
response[1]["X-Sendfile"] = response[2].full_path
|
145
|
-
response[2] = []
|
146
|
-
elsif @sendfile && request.env['UTOPIA_SENDFILE'] == "X-Accel-Redirect"
|
147
|
-
response[1]["X-Accel-Redirect"] = response[2].path.to_s
|
148
|
-
response[2] = []
|
149
|
-
end
|
150
|
-
|
151
|
-
return response
|
152
|
-
end
|
153
|
-
|
154
140
|
public
|
155
141
|
def initialize(app, options = {})
|
156
142
|
@app = app
|
157
143
|
@root = options[:root] || Utopia::Middleware::default_root
|
158
|
-
|
159
|
-
if options.key? :sendfile
|
160
|
-
@sendfile = options[:sendfile]
|
161
|
-
else
|
162
|
-
@sendfile = (UTOPIA_ENV == :production)
|
163
|
-
end
|
164
|
-
|
144
|
+
|
165
145
|
if options[:types]
|
166
146
|
@extensions = load_mime_types(options[:types])
|
167
147
|
else
|
@@ -236,7 +216,7 @@ module Utopia
|
|
236
216
|
if file.modified?(env)
|
237
217
|
response_headers["Content-Length"] = file.size.to_s
|
238
218
|
|
239
|
-
return
|
219
|
+
return [200, response_headers, file]
|
240
220
|
else
|
241
221
|
return [304, response_headers, []]
|
242
222
|
end
|
data/lib/utopia/path.rb
CHANGED
@@ -88,6 +88,21 @@ module Utopia
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
+
# Computes the difference of the path.
|
92
|
+
# /a/b/c - /a/b -> c
|
93
|
+
# a/b/c - a/b -> c
|
94
|
+
def -(other)
|
95
|
+
i = 0
|
96
|
+
|
97
|
+
while i < other.components.size
|
98
|
+
break if @components[i] != other.components[i]
|
99
|
+
|
100
|
+
i += 1
|
101
|
+
end
|
102
|
+
|
103
|
+
return Path.create(@components[i,@components.size])
|
104
|
+
end
|
105
|
+
|
91
106
|
def simplify
|
92
107
|
result = absolute? ? [""] : []
|
93
108
|
|
data/lib/utopia/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utopia
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 85
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 55
|
10
|
+
version: 0.9.55
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Samuel Williams
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-30 00:00:00 +12:00
|
19
19
|
default_executable: utopia
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|