Allow sorting of rewriters. Fixes #1752
This commit is contained in:
parent
d82ac590db
commit
ff9c34bca9
|
@ -107,7 +107,45 @@ Feature: Assets get file hashes appended to them and references to them are upda
|
|||
And I should see 'src="images/100px-5fd6fb90.jpg"'
|
||||
And I should see 'srcset="images/100px-5fd6fb90.jpg 1x, images/200px-c11eb203.jpg 2x, images/300px-59adce76.jpg 3x"'
|
||||
|
||||
Scenario: Enabling an asset host still produces hashed files and references
|
||||
Scenario: Enabling an asset host still produces hashed files and references (hash first)
|
||||
Given a fixture app "asset-hash-host-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :asset_hash
|
||||
activate :directory_indexes
|
||||
activate :asset_host, host: 'http://middlemanapp.com'
|
||||
"""
|
||||
Given the Server is running at "asset-hash-host-app"
|
||||
When I go to "/"
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"'
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/fragment-a772891f.css"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?test"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?#test"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg#test"'
|
||||
When I go to "/subdir/"
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"'
|
||||
When I go to "/other/"
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?test"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg?#test"'
|
||||
And I should see 'src="http://middlemanapp.com/images/100px-5fd6fb90.jpg#test"'
|
||||
When I go to "/stylesheets/fragment-a772891f.css"
|
||||
And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg")'
|
||||
And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg?test")'
|
||||
And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg?#test")'
|
||||
And I should see 'url("http://middlemanapp.com/images/100px-5fd6fb90.jpg#test")'
|
||||
|
||||
Scenario: Enabling an asset host still produces hashed files and references (host first)
|
||||
Given a fixture app "asset-hash-host-app"
|
||||
And a file named "config.rb" with:
|
||||
"""
|
||||
activate :asset_host, host: 'http://middlemanapp.com'
|
||||
activate :directory_indexes
|
||||
activate :asset_hash
|
||||
"""
|
||||
Given the Server is running at "asset-hash-host-app"
|
||||
When I go to "/"
|
||||
Then I should see 'href="http://middlemanapp.com/stylesheets/site-4b64a653.css"'
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
|
||||
activate :asset_hash
|
||||
activate :directory_indexes
|
||||
activate :asset_host, host: 'http://middlemanapp.com'
|
|
@ -3,7 +3,7 @@
|
|||
<% end %>
|
||||
|
||||
<h2>Image url:</h2>
|
||||
<%= image_tag('100px.jpg') %>
|
||||
<img src="/images/100px.jpg">
|
||||
<%= image_tag('100px.jpg?test') %>
|
||||
<%= image_tag('100px.jpg?#test') %>
|
||||
<%= image_tag('100px.jpg#test') %>
|
||||
|
|
|
@ -17,7 +17,8 @@ module Middleman
|
|||
proc: Or[Proc, Method],
|
||||
url_extensions: ArrayOf[String],
|
||||
source_extensions: ArrayOf[String],
|
||||
ignore: ArrayOf[IGNORE_DESCRIPTOR]
|
||||
ignore: ArrayOf[IGNORE_DESCRIPTOR],
|
||||
after: Maybe[Symbol]
|
||||
}.freeze
|
||||
|
||||
def initialize(app, options_hash={}, &block)
|
||||
|
@ -32,8 +33,15 @@ module Middleman
|
|||
end
|
||||
|
||||
def after_configuration
|
||||
app.use Rack, rewriters: @rewriters.values,
|
||||
middleman_app: @app
|
||||
rewriters = @rewriters.values.sort do |a, b|
|
||||
if b[:after] && b[:after] == a[:id]
|
||||
1
|
||||
else
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
app.use Rack, rewriters: rewriters, middleman_app: @app
|
||||
end
|
||||
|
||||
class Rack
|
||||
|
|
|
@ -22,7 +22,8 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension
|
|||
source_extensions: options.sources,
|
||||
ignore: @ignore,
|
||||
rewrite_ignore: options.rewrite_ignore,
|
||||
proc: method(:rewrite_url)
|
||||
proc: method(:rewrite_url),
|
||||
after: :asset_host
|
||||
end
|
||||
|
||||
Contract String, Or[String, Pathname], Any => Maybe[String]
|
||||
|
|
Loading…
Reference in a new issue