Skip to content

Commit

Permalink
Merge pull request #13 from AndrewKvalheim/content-type
Browse files Browse the repository at this point in the history
Prefixing fails when a proxy has removed the file extension.
  • Loading branch information
tdreyno committed Jan 30, 2015
2 parents 14ec7ab + 570acd4 commit 0259f48
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
9 changes: 9 additions & 0 deletions features/autoprefixer.feature
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,12 @@ Feature: Postprocessing stylesheets with Autoprefixer in different configuration
When I go to "/stylesheets/nope.css"
Then I should not see "-ms-border-radius"
And I should see "border-radius"

Scenario: With arbitrary proxy paths
Given the Server is running at "proxy-app"
When I go to "/proxy"
Then I should not see "-ms-border-radius"
And I should see "border-radius"
When I go to "/proxy-inline"
Then I should not see "-ms-border-radius"
And I should see "border-radius"
4 changes: 4 additions & 0 deletions fixtures/proxy-app/config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
activate :autoprefixer, inline: true

proxy '/proxy', '/stylesheets/page.css', ignore: true
proxy '/proxy-inline', '/index.html', ignore: true
12 changes: 12 additions & 0 deletions fixtures/proxy-app/source/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<html>
<head>
</head>
<body>
<style>
input {
-ms-border-radius: 5px;
border-radius: 5px;
}
</style>
</body>
</html>
4 changes: 4 additions & 0 deletions fixtures/proxy-app/source/stylesheets/page.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
input {
-ms-border-radius: 5px;
border-radius: 5px;
}
20 changes: 12 additions & 8 deletions lib/middleman-autoprefixer/extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ def initialize(app, options = {})
# @return [Array]
def call(env)
status, headers, response = @app.call(env)
prefixed = process(response, env['PATH_INFO'])

type = headers['Content-Type'].split(';').first
path = env['PATH_INFO']

prefixed = process(response, type, path)

if prefixed.is_a?(String)
headers['Content-Length'] = ::Rack::Utils.bytesize(prefixed).to_s
Expand All @@ -53,10 +57,10 @@ def call(env)

private

def process(response, path)
if standalone_css_content?(path)
def process(response, type, path)
if standalone_css_content?(type, path)
prefix(extract_styles(response))
elsif inline_html_content?(path)
elsif inline_html_content?(type, path)
prefix_inline_styles(extract_styles(response))
else
nil
Expand All @@ -81,12 +85,12 @@ def extract_styles(response)
::Middleman::Util.extract_response_text(response)
end

def inline_html_content?(path)
(path.end_with?('.html') || path.end_with?('.php')) && @inline
def inline_html_content?(type, path)
(type == 'text/html' || path.end_with?('.php')) && @inline
end

def standalone_css_content?(path)
path.end_with?('.css') && @ignore.none? { |ignore| ::Middleman::Util.path_match(ignore, path) }
def standalone_css_content?(type, path)
type == 'text/css' && @ignore.none? { |ignore| ::Middleman::Util.path_match(ignore, path) }
end
end
end
Expand Down

0 comments on commit 0259f48

Please sign in to comment.