rack_image_assets_cache_control 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/README.markdown ADDED
@@ -0,0 +1,16 @@
1
+ Cache Control Image Assets in rails development
2
+ ===================
3
+ 原理见 http://code.eoe.cn/6/title/Unicorn和Nginx部署Rails应用的css__js__img等静态资源缓存使用总结
4
+
5
+
6
+ ## Usage
7
+ * Add it to Gemfile
8
+
9
+ ```ruby
10
+ gem 'rack_image_assets_cache_control'
11
+ ```
12
+ * setup in config/environments/development.rb
13
+
14
+ ```ruby
15
+ config.middleware.use(Rack::ImageAssetsCacheControl)
16
+ ```
@@ -0,0 +1,26 @@
1
+ module Rack
2
+ class ImageAssetsCacheControl
3
+ ImagePostfixRegexp = Regexp.new(
4
+ MIME::Types.to_a.select {|t| t.media_type == 'image' }.map {|i| i.raw_sub_type }.reject {|i| i.match(/\.|\-|\+/) }.map {|i| "\.#{i}" }.join("|"),
5
+ 'i'
6
+ )
7
+
8
+ def initialize(app, options={})
9
+ @app = app
10
+ @max_age = options["max-age"] || 300
11
+ end
12
+
13
+ def call(env)
14
+ @status, @headers, @response = @app.call(env)
15
+
16
+ # if @status is 304, then @headers and @response will be blank,
17
+ # so @headers['Content-Type'].to_s.start_with?("image") will not work
18
+ if env['REQUEST_PATH'].match(ImagePostfixRegexp)
19
+ @headers.merge!("Cache-Control" => "public, max-age=#{@max_age}")
20
+ end
21
+
22
+ [@status, @headers, @response]
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,14 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'rack_image_assets_cache_control'
3
+ s.version = '0.1'
4
+ s.date = '2013-05-06'
5
+ s.summary = "Cache Control Image Assets in rails development"
6
+ s.description = s.summary
7
+ s.authors = ["mvj3"]
8
+ s.email = 'mvjome@gmail.com'
9
+ s.homepage = 'https://github.com/eoecn/image_assets_cache_control'
10
+ s.require_paths = ["lib"]
11
+ s.add_dependency "rack"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack_image_assets_cache_control
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - mvj3
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rack
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: Cache Control Image Assets in rails development
31
+ email: mvjome@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - README.markdown
38
+ - lib/rack_image_assets_cache_control.rb
39
+ - rack_image_assets_cache_control.gemspec
40
+ homepage: https://github.com/eoecn/image_assets_cache_control
41
+ licenses: []
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ! '>='
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubyforge_project:
60
+ rubygems_version: 1.8.25
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Cache Control Image Assets in rails development
64
+ test_files: []