DEV: Support referencing public images in plugins in SCSS (#12930)

This commit is contained in:
Penar Musaraj 2021-05-03 14:40:02 -04:00 committed by GitHub
parent 8ca6202d81
commit 9bc126949e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -200,7 +200,12 @@ $breakpoints: (
// 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}");
@if (str-index("#{$path}", "/plugins") == 1) {
$plugin_asset_path: str-replace($public_image_path, "/images", "");
@return url("#{$plugin_asset_path}#{$path}");
} @else {
@return url("#{$public_image_path}#{$path}");
}
} @else {
@return url("#{$path}");
}

View File

@ -118,6 +118,16 @@ describe Stylesheet::Compiler do
expect(css).not_to include('absolute-image-url')
end
it "supports absolute-image-url in plugins" do
set_cdn_url "https://awesome.com"
scss = Stylesheet::Importer.new({}).prepended_scss
scss += ".body{background-image: absolute-image-url('/plugins/discourse-special/images/somefile.png');}"
css, _map = Stylesheet::Compiler.compile(scss, "discourse-special.scss")
expect(css).to include('url("https://awesome.com/plugins/discourse-special/images/somefile.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")