flame 4.0.12 → 4.0.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/flame/controller.rb +13 -0
- data/lib/flame/dispatcher.rb +6 -0
- data/lib/flame/static.rb +2 -5
- data/lib/flame/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f41dc0384cfa7bc014de1d10b94866bee6631d13
|
4
|
+
data.tar.gz: d1c18264ecf5b6f332c5f9a33a7313c8b948ae30
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e3a91ce022115c917b2244c1123b81bc5ee5ed5be7b0ad815d1481bf3600fc8006ced9ed326157f9e8742d14bd23a615c7bfc24bb4cf16f80e05acf8543312f
|
7
|
+
data.tar.gz: 85830efbb1d57c4b361d9d84adbbe54cab72d60eca59e7da900d33e0ce83e97d2d0d0fffe1d55bb5bc389baf72908f70238e6b19f9cc58fff2a422f3e491ae17
|
data/lib/flame/controller.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative 'render'
|
2
4
|
|
3
5
|
module Flame
|
@@ -33,6 +35,17 @@ module Flame
|
|
33
35
|
)
|
34
36
|
end
|
35
37
|
|
38
|
+
# Set the Content-Disposition to "attachment" with the specified filename,
|
39
|
+
# instructing the user agents to prompt to save.
|
40
|
+
def attachment(filename = nil, disposition = :attachment)
|
41
|
+
content_dis = 'Content-Disposition'.freeze
|
42
|
+
response[content_dis] = disposition.to_s
|
43
|
+
return unless filename
|
44
|
+
response[content_dis] << "; filename=\"#{File.basename(filename)}\""
|
45
|
+
ext = File.extname(filename)
|
46
|
+
content_type(ext) unless response[Rack::CONTENT_TYPE] || ext.empty?
|
47
|
+
end
|
48
|
+
|
36
49
|
## Render a template with `Flame::Render` (based on Tilt-engine)
|
37
50
|
## @param path [Symbol, nil] path to the template file
|
38
51
|
## @param options [Hash] options for the `Flame::Render` rendering
|
data/lib/flame/dispatcher.rb
CHANGED
@@ -76,6 +76,12 @@ module Flame
|
|
76
76
|
@app.config
|
77
77
|
end
|
78
78
|
|
79
|
+
## Access to Content-Type header of response
|
80
|
+
def content_type(ext = nil)
|
81
|
+
return response[Rack::CONTENT_TYPE] unless ext
|
82
|
+
response[Rack::CONTENT_TYPE] = Rack::Mime.mime_type(ext)
|
83
|
+
end
|
84
|
+
|
79
85
|
## Get path for controller and action.
|
80
86
|
##
|
81
87
|
## @param ctrl [Flame::Controller] class of controller
|
data/lib/flame/static.rb
CHANGED
@@ -17,14 +17,11 @@ module Flame
|
|
17
17
|
def return_static(file)
|
18
18
|
file_time = File.mtime(file)
|
19
19
|
halt 304 if static_cached?(file_time)
|
20
|
-
|
21
|
-
response.
|
22
|
-
'Content-Type' => mime_type,
|
23
|
-
'Last-Modified' => file_time.httpdate
|
20
|
+
content_type File.extname(file)
|
21
|
+
response['Last-Modified'] = file_time.httpdate
|
24
22
|
# 'Content-Disposition' => 'attachment;' \
|
25
23
|
# "filename=\"#{File.basename(static_file)}\"",
|
26
24
|
# 'Content-Length' => File.size?(static_file).to_s
|
27
|
-
)
|
28
25
|
halt 200, File.read(file)
|
29
26
|
end
|
30
27
|
end
|
data/lib/flame/version.rb
CHANGED