DEV: Add SCSS helper to replace `asset-uri` and `image-uri` (#12664)

DEV: Add SCSS helper to replace asset-uri and image-uri (#12664)

diff --git a/app/assets/images/favicons/discourse.png b/app/assets/images/favicons/discourse.png
deleted file mode 100644
index b0441a3..0000000
Binary files a/app/assets/images/favicons/discourse.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_branding/logo_calendar_128px.png b/app/assets/images/favicons/google_branding/logo_calendar_128px.png
deleted file mode 100644
index a013a3f..0000000
Binary files a/app/assets/images/favicons/google_branding/logo_calendar_128px.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_branding/logo_calendar_48px.png b/app/assets/images/favicons/google_branding/logo_calendar_48px.png
deleted file mode 100644
index 549641d..0000000
Binary files a/app/assets/images/favicons/google_branding/logo_calendar_48px.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_branding/logo_docs_48px.png b/app/assets/images/favicons/google_branding/logo_docs_48px.png
deleted file mode 100644
index 6ffbc98..0000000
Binary files a/app/assets/images/favicons/google_branding/logo_docs_48px.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_branding/logo_drive_48px.png b/app/assets/images/favicons/google_branding/logo_drive_48px.png
deleted file mode 100644
index 6c45b46..0000000
Binary files a/app/assets/images/favicons/google_branding/logo_drive_48px.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_branding/logo_forms_48px.png b/app/assets/images/favicons/google_branding/logo_forms_48px.png
deleted file mode 100644
index 331b9aa..0000000
Binary files a/app/assets/images/favicons/google_branding/logo_forms_48px.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_branding/logo_sheets_48px.png b/app/assets/images/favicons/google_branding/logo_sheets_48px.png
deleted file mode 100644
index f507c28..0000000
Binary files a/app/assets/images/favicons/google_branding/logo_sheets_48px.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_branding/logo_slides_48px.png b/app/assets/images/favicons/google_branding/logo_slides_48px.png
deleted file mode 100644
index 2e65c6f..0000000
Binary files a/app/assets/images/favicons/google_branding/logo_slides_48px.png and /dev/null differ
diff --git a/app/assets/images/favicons/google_play.png b/app/assets/images/favicons/google_play.png
deleted file mode 100644
index cdd201c..0000000
Binary files a/app/assets/images/favicons/google_play.png and /dev/null differ
diff --git a/app/assets/images/favicons/instagram.png b/app/assets/images/favicons/instagram.png
deleted file mode 100644
index 5d3ec88..0000000
Binary files a/app/assets/images/favicons/instagram.png and /dev/null differ
diff --git a/app/assets/images/favicons/pdf_48px.png b/app/assets/images/favicons/pdf_48px.png
deleted file mode 100644
index a16e41a..0000000
Binary files a/app/assets/images/favicons/pdf_48px.png and /dev/null differ
diff --git a/app/assets/images/favicons/pdf_64px.png b/app/assets/images/favicons/pdf_64px.png
deleted file mode 100644
index 44ad3ce..0000000
Binary files a/app/assets/images/favicons/pdf_64px.png and /dev/null differ
diff --git a/app/assets/images/favicons/stackexchange.png b/app/assets/images/favicons/stackexchange.png
deleted file mode 100644
index 23029c5..0000000
Binary files a/app/assets/images/favicons/stackexchange.png and /dev/null differ
diff --git a/app/assets/images/select2-spinner.gif b/app/assets/images/select2-spinner.gif
deleted file mode 100644
index 7033910..0000000
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 32c2fc3..0000000
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 e0a6265..0000000
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 0fe3321..0000000
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 29eb1a0..a5716c7 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 d6bd2ed..28c6b80 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 fa1c333..4abc98a 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 01ca468..8b02e80 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/public/images/favicons/discourse.png b/public/images/favicons/discourse.png
new file mode 100644
index 0000000..b0441a3

[... diff too long, it was truncated ...]

GitHub sha: abb0a4ba

This commit appears in #12664 which was approved by CvX and eviltrout. It was merged by SamSaffron.