sprockets-redirect 0.3.0 → 1.0.0
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.
- checksums.yaml +4 -4
- data/README.md +13 -5
- data/lib/sprockets-redirect.rb +4 -1
- data/lib/sprockets/redirect.rb +21 -2
- metadata +24 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7b0d9246f5bf9ef46cce7509f22943034ab6448
|
4
|
+
data.tar.gz: f6ba49fa0ee6e9e06962b9f6084ac1efe3cac0f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c018a1bd6ea7d5cffad27e224a484170d9ac9706ae4f3a04c31ab3d6be1a6c21807fbf0af254263ff083e68a6a17b69769b8623b815607e022566f534c18364f
|
7
|
+
data.tar.gz: 20ff5c2a6b9a2547cbab31dcf83178034d17edefce2f249ec36106ff699490647eb558ed2d10030b1a34828250064474d4ea5e4b11d0def6e0dc505de6bcd2b3
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
Sprockets::Redirect [](http://travis-ci.org/sikachu/sprockets-redirect)
|
2
2
|
===================
|
3
3
|
|
4
|
-
A Rack middleware for [Rails](https://github.com/rails/rails) >= 3.1.0 with asset pipeline and asset digest enabled. This middleware is used to redirect any request to static asset without a digest to the version with digest in its filename by reading the
|
4
|
+
A Rack middleware for [Rails](https://github.com/rails/rails) >= 3.1.0 with asset pipeline and asset digest enabled. This middleware is used to redirect any request to static asset without a digest to the version with digest in its filename by reading the manifest file generated after you run `rake assets:precompile`
|
5
5
|
|
6
6
|
For example, if a browser is requesting this URL:
|
7
7
|
|
@@ -28,7 +28,7 @@ Installation
|
|
28
28
|
Insert this line into your Gemfile:
|
29
29
|
|
30
30
|
group :production, :staging do
|
31
|
-
gem
|
31
|
+
gem "sprockets-redirect"
|
32
32
|
end
|
33
33
|
|
34
34
|
|
@@ -64,7 +64,15 @@ These configurations are configured via an option hash:
|
|
64
64
|
* `:digests` - Set a hash used for file name lookup. This will be default to Rails' manifest at `Rails.configuration.assets.digests`.
|
65
65
|
* `:prefix` - Set a path prefix of your assets file. This will be default to `Rails.configuration.assets.prefix` (usually at `/assets`.)
|
66
66
|
* `:manifest` - Set a path to your own manifest file to use for lookup. This will override both `:digest` hash and `Sprockets::Redirect.manifest` setting.
|
67
|
-
* `:asset_host` - Set the name of the host to use when serving assets. This is useful if you want your server to redirect to assets that are hosted on a CDN.
|
67
|
+
* `:asset_host` - Set the name of the host to use when serving assets. This is useful if you want your server to redirect to assets that are hosted on a CDN. You can also passing a `Proc` object which will be called on every asset requests to determine the host for that request:
|
68
|
+
|
69
|
+
config.middleware.swap Sprockets::Redirect,
|
70
|
+
Sprockets::Redirect,
|
71
|
+
:asset_host => Proc.new do |request|
|
72
|
+
if request.path =~ /\.min\.(js|css)\z/
|
73
|
+
"cdn.example.com"
|
74
|
+
end
|
75
|
+
end
|
68
76
|
|
69
77
|
You can swap out the middleware inserted automatically by the gem by using `config.middleware.swap` in your configuration file:
|
70
78
|
|
@@ -76,7 +84,7 @@ Contributing
|
|
76
84
|
|
77
85
|
If you found any bug or would like to request a feature, please use Github's [issue tracker](https://github.com/sikachu/sprockets-redirect/issues) to report them. [Pull requests](https://github.com/sikachu/sprockets-redirect/pulls) are always welcomed if you also want to help me fix it. Please make sure to include a test to make sure that I don't break it in the future.
|
78
86
|
|
79
|
-
Also, you should run `rake
|
87
|
+
Also, you should run `appraisal rake` to run the test against multiple versions of Ruby. We're currently testing against latest patch version of Rails 3.1, 3.2, 4.0, 4.1, 4.2, and 5.0.0 beta.
|
80
88
|
|
81
89
|
|
82
90
|
License
|
data/lib/sprockets-redirect.rb
CHANGED
@@ -4,7 +4,10 @@ module Sprockets
|
|
4
4
|
class RedirectRailtie < ::Rails::Railtie
|
5
5
|
initializer "insert_sprockets_redirect_middleware" do |app|
|
6
6
|
if !::Rails.configuration.assets.compile && ::Rails.configuration.assets.digest
|
7
|
-
app.middleware.insert 0,
|
7
|
+
app.middleware.insert 0,
|
8
|
+
Sprockets::Redirect,
|
9
|
+
::Rails.application.assets ||
|
10
|
+
Sprockets::Railtie.build_manifest(::Rails.application).assets,
|
8
11
|
:prefix => ::Rails.configuration.assets.prefix,
|
9
12
|
:asset_host => ::Rails.configuration.action_controller.asset_host
|
10
13
|
end
|
data/lib/sprockets/redirect.rb
CHANGED
@@ -69,21 +69,40 @@ module Sprockets
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def digest_path
|
72
|
-
@environment[logical_path].digest_path
|
72
|
+
if @environment[logical_path].respond_to?(:digest_path)
|
73
|
+
@environment[logical_path].digest_path
|
74
|
+
else
|
75
|
+
@environment[logical_path]
|
76
|
+
end
|
73
77
|
end
|
74
78
|
|
75
79
|
# Sends a redirect header back to browser
|
76
80
|
def redirect_to_digest_version(env)
|
77
|
-
url = URI(
|
81
|
+
url = URI(computed_asset_host || @request.url)
|
78
82
|
url.path = "#{@prefix}/#{digest_path}"
|
79
83
|
|
80
84
|
headers = { 'Location' => url.to_s,
|
81
85
|
'Content-Type' => Rack::Mime.mime_type(::File.extname(digest_path)),
|
82
86
|
'Pragma' => 'no-cache',
|
83
87
|
'Cache-Control' => 'no-cache; max-age=0' }
|
88
|
+
|
84
89
|
[self.class.redirect_status, headers, [redirect_message(url.to_s)]]
|
85
90
|
end
|
86
91
|
|
92
|
+
def computed_asset_host
|
93
|
+
if @asset_host.respond_to?(:call)
|
94
|
+
host = @asset_host.call(@request)
|
95
|
+
else
|
96
|
+
host = @asset_host
|
97
|
+
end
|
98
|
+
|
99
|
+
if host.nil? || host =~ %r(^https?://)
|
100
|
+
host
|
101
|
+
else
|
102
|
+
"#{@request.scheme}://#{host}"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
87
106
|
# Create a default redirect message
|
88
107
|
def redirect_message(location)
|
89
108
|
%Q(Redirecting to <a href="#{location}">#{location}</a>)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sprockets-redirect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prem Sichanugrist
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,10 +122,24 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: test-unit
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: |2
|
126
|
-
Rack middleware which will look up your
|
127
|
-
|
128
|
-
|
140
|
+
Rack middleware which will look up your assets manifest file and redirect a
|
141
|
+
request with no digest in the file name to the version with digest in the
|
142
|
+
file name.
|
129
143
|
email: s@sikac.hu
|
130
144
|
executables: []
|
131
145
|
extensions: []
|
@@ -137,7 +151,8 @@ files:
|
|
137
151
|
- lib/sprockets-redirect.rb
|
138
152
|
- lib/sprockets/redirect.rb
|
139
153
|
homepage: https://github.com/sikachu/sprockets-redirect
|
140
|
-
licenses:
|
154
|
+
licenses:
|
155
|
+
- MIT
|
141
156
|
metadata: {}
|
142
157
|
post_install_message:
|
143
158
|
rdoc_options: []
|
@@ -155,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
155
170
|
version: '0'
|
156
171
|
requirements: []
|
157
172
|
rubyforge_project:
|
158
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.5.1
|
159
174
|
signing_key:
|
160
175
|
specification_version: 4
|
161
176
|
summary: Redirect assets with no digest request to a filename with digest version.
|