Skip to content

Commit

Permalink
refactor(asset_path#http_prefix): rework to use File.join & array.com…
Browse files Browse the repository at this point in the history
…pact

this implementation contains less code paths & benchmarks a bit faster: https://gist.github.com/stevenosloan/d9b0032500ed4801f0cdd1eb36b9d7b3
  • Loading branch information
stevenosloan committed Oct 25, 2016
1 parent 24cb47c commit 299abd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ group :test do
gem 'simplecov', '~> 0.9', require: false
gem 'coveralls', '~> 0.8', require: false
gem 'codeclimate-test-reporter', '~> 0.3', require: false
gem 'benchmark-ips'
end
6 changes: 4 additions & 2 deletions lib/middleman-sprockets/extension/context_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ def asset_path path, options={}

if app.extensions[:sprockets].check_asset(path)
link_asset(path)
prefix = app.config[:http_prefix].nil? ? '/' : app.config[:http_prefix].sub(/\/?$/, '/')
app.extensions[:sprockets].sprockets_asset_path(env[path]).sub(/^\/?/, prefix)

File.join *[app.config[:http_prefix],
app.extensions[:sprockets].sprockets_asset_path(env[path])].compact
else
app.asset_path(kind, path)
end

end
end
end
Expand Down

0 comments on commit 299abd4

Please sign in to comment.