From 9e5b137ed8f6299fec6479b14bf58a4716d39d2e Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Tue, 15 Dec 2015 09:58:22 -0800 Subject: [PATCH] Really fix #1689 --- middleman-cli/lib/middleman-cli/build.rb | 2 +- middleman-core/features/relative_assets.feature | 5 +++++ .../source/stylesheets/fonts2.css.scss | 10 ++++++++++ middleman-core/lib/middleman-core/util.rb | 9 ++++++++- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts2.css.scss diff --git a/middleman-cli/lib/middleman-cli/build.rb b/middleman-cli/lib/middleman-cli/build.rb index cf2d58a8..1ef884b2 100644 --- a/middleman-cli/lib/middleman-cli/build.rb +++ b/middleman-cli/lib/middleman-cli/build.rb @@ -64,7 +64,7 @@ module Middleman::Cli if builder.run! clean_directories! if options['clean'] - shell.say "Project built successfully." + shell.say 'Project built successfully.' else msg = 'There were errors during this build' unless options['verbose'] diff --git a/middleman-core/features/relative_assets.feature b/middleman-core/features/relative_assets.feature index 0f782761..a4b6fc68 100644 --- a/middleman-core/features/relative_assets.feature +++ b/middleman-core/features/relative_assets.feature @@ -41,6 +41,11 @@ Feature: Relative Assets And I should see 'url(../fonts/roboto/roboto-regular-webfont.woff' And I should see 'url(../fonts/roboto/roboto-regular-webfont.ttf' And I should see 'url(../fonts/roboto/roboto-regular-webfont.svg' + When I go to "/stylesheets/fonts2.css" + Then I should see 'url(../fonts/roboto/roboto-regular-webfont.eot' + And I should see 'url(../fonts/roboto/roboto-regular-webfont.woff' + And I should see 'url(../fonts/roboto/roboto-regular-webfont.ttf' + And I should see 'url(../fonts/roboto/roboto-regular-webfont.svg' Scenario: Building css with the feature enabled Given a fixture app "relative-assets-app" diff --git a/middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts2.css.scss b/middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts2.css.scss new file mode 100644 index 00000000..ef6c7dfe --- /dev/null +++ b/middleman-core/fixtures/relative-assets-app/source/stylesheets/fonts2.css.scss @@ -0,0 +1,10 @@ +@font-face { + font-family: 'Roboto'; + src: url(/fonts/roboto/roboto-regular-webfont.eot); + src: url(/fonts/roboto/roboto-regular-webfont.eot?#iefix) format('embedded-opentype'), + url(/fonts/roboto/roboto-regular-webfont.woff) format('woff'), + url(/fonts/roboto/roboto-regular-webfont.ttf) format('truetype'), + url(/fonts/roboto/roboto-regular-webfont.svg#robotoregular) format('svg'); + font-weight: normal; + font-style: normal; +} diff --git a/middleman-core/lib/middleman-core/util.rb b/middleman-core/lib/middleman-core/util.rb index 4d700e0e..db29cf92 100644 --- a/middleman-core/lib/middleman-core/util.rb +++ b/middleman-core/lib/middleman-core/util.rb @@ -332,12 +332,19 @@ module Middleman Contract String, String, ArrayOf[String], Proc => String def rewrite_paths(body, _path, exts, &_block) - matcher = /([=\'\"\(,] *)([^\s\'\"\)>]+(#{Regexp.union(exts)}))/ + matcher = /([=\'\"\(,]\s*)([^\s\'\"\)>]+(#{Regexp.union(exts)}))/ + + url_fn_prefix = 'url(' body.dup.gsub(matcher) do |match| opening_character = $1 asset_path = $2 + if asset_path.start_with?(url_fn_prefix) + opening_character << url_fn_prefix + asset_path = asset_path[url_fn_prefix.length..-1] + end + begin uri = ::Addressable::URI.parse(asset_path)