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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05d5cb9d08ef29f06faf57b18deb3260adad7c69
4
- data.tar.gz: a3ce3c2cc136c764d5b8e20e653d51075554f3a7
3
+ metadata.gz: f41dc0384cfa7bc014de1d10b94866bee6631d13
4
+ data.tar.gz: d1c18264ecf5b6f332c5f9a33a7313c8b948ae30
5
5
  SHA512:
6
- metadata.gz: dcd791c45fdb487e7f3be2a414c6c4efd1ef1748f0c56034b1bd1adddbbd418db88279058a1a12cb3ccb391bb86759b980546212ac72820901f47edb4303f74b
7
- data.tar.gz: ed4b47f3c13be3d89cc5b16a60882cc8d1188c9e89405c96351d3510e1b4601723ed06998a3995ac1360c86b2a545e07262018d8031f949605ff23dfb0994ff7
6
+ metadata.gz: 4e3a91ce022115c917b2244c1123b81bc5ee5ed5be7b0ad815d1481bf3600fc8006ced9ed326157f9e8742d14bd23a615c7bfc24bb4cf16f80e05acf8543312f
7
+ data.tar.gz: 85830efbb1d57c4b361d9d84adbbe54cab72d60eca59e7da900d33e0ce83e97d2d0d0fffe1d55bb5bc389baf72908f70238e6b19f9cc58fff2a422f3e491ae17
@@ -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
@@ -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
- mime_type = Rack::Mime.mime_type(File.extname(file))
21
- response.headers.merge!(
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flame
4
- VERSION = '4.0.12'.freeze
4
+ VERSION = '4.0.13'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flame
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.12
4
+ version: 4.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov