diff --git a/app/assets/images/select2-spinner.gif b/app/assets/images/select2-spinner.gif deleted file mode 100644 index 703391003b2..00000000000 Binary files a/app/assets/images/select2-spinner.gif and /dev/null differ diff --git a/app/assets/images/select2.png b/app/assets/images/select2.png deleted file mode 100644 index 32c2fc3a22b..00000000000 Binary files a/app/assets/images/select2.png and /dev/null differ diff --git a/app/assets/images/select2x2.png b/app/assets/images/select2x2.png deleted file mode 100644 index e0a62658dae..00000000000 Binary files a/app/assets/images/select2x2.png and /dev/null differ diff --git a/app/assets/images/spinner_96.gif b/app/assets/images/spinner_96.gif deleted file mode 100644 index 0fe33214395..00000000000 Binary files a/app/assets/images/spinner_96.gif and /dev/null differ diff --git a/app/assets/stylesheets/common/base/onebox.scss b/app/assets/stylesheets/common/base/onebox.scss index 29eb1a03e0c..a5716c7e662 100644 --- a/app/assets/stylesheets/common/base/onebox.scss +++ b/app/assets/stylesheets/common/base/onebox.scss @@ -87,7 +87,7 @@ a.loading-onebox { @mixin onebox-favicon($class, $image) { &.#{$class} .source { - background: image-url("favicons/#{$image}.png") no-repeat 0% 50%; + background: absolute-image-url("/favicons/#{$image}.png") no-repeat 0% 50%; background-size: 16px 16px; padding-left: 20px; } @@ -289,7 +289,9 @@ aside.onebox { @mixin gdocs-logo($type) { &.g-#{$type}-logo { - background: image-url("favicons/google_branding/logo_#{$type}_48px.png") + background: absolute-image-url( + "/favicons/google_branding/logo_#{$type}_48px.png" + ) no-repeat; } } @@ -316,7 +318,9 @@ aside.onebox { width: 128px; height: 128px; &.g-calendar-logo { - background: image-url("favicons/google_branding/logo_calendar_128px.png") + background: absolute-image-url( + "/favicons/google_branding/logo_calendar_128px.png" + ) no-repeat; } } @@ -635,7 +639,7 @@ aside.onebox.stackexchange .onebox-body { width: 60px; height: 50px; float: left; - background: image-url("favicons/pdf_64px.png") no-repeat; + background: absolute-image-url("/favicons/pdf_64px.png") no-repeat; background-size: 48px 48px; display: inline-block; } diff --git a/app/assets/stylesheets/common/foundation/mixins.scss b/app/assets/stylesheets/common/foundation/mixins.scss index d6bd2eddce7..28c6b807c49 100644 --- a/app/assets/stylesheets/common/foundation/mixins.scss +++ b/app/assets/stylesheets/common/foundation/mixins.scss @@ -194,3 +194,14 @@ $breakpoints: ( @return "dark"; } } + +@function absolute-image-url($path) { + // public_image_path is added by the stylesheet importer + // it returns a CDN or subfolder path (if applicable). + // SCSS will compile (and return the relative path) if public_image_path is missing. + @if variable-exists(public_image_path) { + @return url("#{$public_image_path}#{$path}"); + } @else { + @return url("#{$path}"); + } +} diff --git a/lib/stylesheet/functions.rb b/lib/stylesheet/functions.rb index fa1c3330d33..4abc98a51a4 100644 --- a/lib/stylesheet/functions.rb +++ b/lib/stylesheet/functions.rb @@ -3,9 +3,11 @@ module Stylesheet module ScssFunctions def asset_url(path) + Discourse.deprecate("The `asset-url` SCSS function is deprecated. Use `absolute-image-url` instead.") SassC::Script::Value::String.new("url('#{ActionController::Base.helpers.asset_url(path.value)}')") end def image_url(path) + Discourse.deprecate("The `image-url` SCSS function is deprecated. Use `absolute-image-url` instead.") SassC::Script::Value::String.new("url('#{ActionController::Base.helpers.image_url(path.value)}')") end end diff --git a/lib/stylesheet/importer.rb b/lib/stylesheet/importer.rb index 01ca4686db6..8b02e809c97 100644 --- a/lib/stylesheet/importer.rb +++ b/lib/stylesheet/importer.rb @@ -152,8 +152,13 @@ module Stylesheet contents end + def public_image_path + image_path = UrlHelper.absolute("#{Discourse.base_path}/images") + "$public_image_path: \"#{image_path}\"; " + end + def prepended_scss - "#{color_variables} @import \"common/foundation/variables\"; @import \"common/foundation/mixins\"; " + "#{color_variables} #{public_image_path} @import \"common/foundation/variables\"; @import \"common/foundation/mixins\"; " end def initialize(options) diff --git a/app/assets/images/favicons/discourse.png b/public/images/favicons/discourse.png similarity index 100% rename from app/assets/images/favicons/discourse.png rename to public/images/favicons/discourse.png diff --git a/app/assets/images/favicons/google_branding/logo_calendar_128px.png b/public/images/favicons/google_branding/logo_calendar_128px.png similarity index 100% rename from app/assets/images/favicons/google_branding/logo_calendar_128px.png rename to public/images/favicons/google_branding/logo_calendar_128px.png diff --git a/app/assets/images/favicons/google_branding/logo_calendar_48px.png b/public/images/favicons/google_branding/logo_calendar_48px.png similarity index 100% rename from app/assets/images/favicons/google_branding/logo_calendar_48px.png rename to public/images/favicons/google_branding/logo_calendar_48px.png diff --git a/app/assets/images/favicons/google_branding/logo_docs_48px.png b/public/images/favicons/google_branding/logo_docs_48px.png similarity index 100% rename from app/assets/images/favicons/google_branding/logo_docs_48px.png rename to public/images/favicons/google_branding/logo_docs_48px.png diff --git a/app/assets/images/favicons/google_branding/logo_drive_48px.png b/public/images/favicons/google_branding/logo_drive_48px.png similarity index 100% rename from app/assets/images/favicons/google_branding/logo_drive_48px.png rename to public/images/favicons/google_branding/logo_drive_48px.png diff --git a/app/assets/images/favicons/google_branding/logo_forms_48px.png b/public/images/favicons/google_branding/logo_forms_48px.png similarity index 100% rename from app/assets/images/favicons/google_branding/logo_forms_48px.png rename to public/images/favicons/google_branding/logo_forms_48px.png diff --git a/app/assets/images/favicons/google_branding/logo_sheets_48px.png b/public/images/favicons/google_branding/logo_sheets_48px.png similarity index 100% rename from app/assets/images/favicons/google_branding/logo_sheets_48px.png rename to public/images/favicons/google_branding/logo_sheets_48px.png diff --git a/app/assets/images/favicons/google_branding/logo_slides_48px.png b/public/images/favicons/google_branding/logo_slides_48px.png similarity index 100% rename from app/assets/images/favicons/google_branding/logo_slides_48px.png rename to public/images/favicons/google_branding/logo_slides_48px.png diff --git a/app/assets/images/favicons/google_play.png b/public/images/favicons/google_play.png similarity index 100% rename from app/assets/images/favicons/google_play.png rename to public/images/favicons/google_play.png diff --git a/app/assets/images/favicons/instagram.png b/public/images/favicons/instagram.png similarity index 100% rename from app/assets/images/favicons/instagram.png rename to public/images/favicons/instagram.png diff --git a/app/assets/images/favicons/pdf_48px.png b/public/images/favicons/pdf_48px.png similarity index 100% rename from app/assets/images/favicons/pdf_48px.png rename to public/images/favicons/pdf_48px.png diff --git a/app/assets/images/favicons/pdf_64px.png b/public/images/favicons/pdf_64px.png similarity index 100% rename from app/assets/images/favicons/pdf_64px.png rename to public/images/favicons/pdf_64px.png diff --git a/app/assets/images/favicons/stackexchange.png b/public/images/favicons/stackexchange.png similarity index 100% rename from app/assets/images/favicons/stackexchange.png rename to public/images/favicons/stackexchange.png diff --git a/spec/components/stylesheet/compiler_spec.rb b/spec/components/stylesheet/compiler_spec.rb index 6de836e425a..b71b2d6cce3 100644 --- a/spec/components/stylesheet/compiler_spec.rb +++ b/spec/components/stylesheet/compiler_spec.rb @@ -87,6 +87,35 @@ describe Stylesheet::Compiler do expect(css).not_to include('image-url') end + it "supports absolute-image-url" do + scss = Stylesheet::Importer.new({}).prepended_scss + scss += ".body{background-image: absolute-image-url('/favicons/github.png');}" + css, _map = Stylesheet::Compiler.compile(scss, "test.scss") + + expect(css).to include('url("http://test.localhost/images/favicons/github.png")') + expect(css).not_to include('absolute-image-url') + end + + it "supports absolute-image-url in subfolder" do + set_subfolder "/subfo" + scss = Stylesheet::Importer.new({}).prepended_scss + scss += ".body{background-image: absolute-image-url('/favicons/github.png');}" + css, _map = Stylesheet::Compiler.compile(scss, "test2.scss") + + expect(css).to include('url("http://test.localhost/subfo/images/favicons/github.png")') + expect(css).not_to include('absolute-image-url') + end + + it "supports absolute-image-url with CDNs" do + set_cdn_url "https://awesome.com" + scss = Stylesheet::Importer.new({}).prepended_scss + scss += ".body{background-image: absolute-image-url('/favicons/github.png');}" + css, _map = Stylesheet::Compiler.compile(scss, "test2.scss") + + expect(css).to include('url("https://awesome.com/images/favicons/github.png")') + expect(css).not_to include('absolute-image-url') + end + context "with a color scheme" do it "returns the default color definitions when no color scheme is specified" do css, _map = Stylesheet::Compiler.compile_asset("color_definitions") diff --git a/spec/models/post_analyzer_spec.rb b/spec/models/post_analyzer_spec.rb index dccd31597ca..f7de1074ee5 100644 --- a/spec/models/post_analyzer_spec.rb +++ b/spec/models/post_analyzer_spec.rb @@ -119,7 +119,7 @@ describe PostAnalyzer do let(:raw_post_one_image_md) { "![sherlock](http://bbc.co.uk/sherlock.jpg)" } let(:raw_post_two_images_html) { " " } let(:raw_post_with_avatars) { 'smiley wink' } - let(:raw_post_with_favicon) { '' } + let(:raw_post_with_favicon) { '' } let(:raw_post_with_thumbnail) { '' } let(:raw_post_with_two_classy_images) { " " } let(:raw_post_with_two_embedded_media) { '' } diff --git a/spec/models/post_spec.rb b/spec/models/post_spec.rb index 5db5dab72cf..4108857b481 100644 --- a/spec/models/post_spec.rb +++ b/spec/models/post_spec.rb @@ -241,7 +241,7 @@ describe Post do let(:post_one_image) { post_with_body("![sherlock](http://bbc.co.uk/sherlock.jpg)", newuser) } let(:post_two_images) { post_with_body(" ", newuser) } let(:post_with_avatars) { post_with_body('smiley wink', newuser) } - let(:post_with_favicon) { post_with_body('', newuser) } + let(:post_with_favicon) { post_with_body('', newuser) } let(:post_image_within_quote) { post_with_body('[quote][/quote]', newuser) } let(:post_image_within_code) { post_with_body('', newuser) } let(:post_image_within_pre) { post_with_body('
', newuser) }