mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 00:41:16 +08:00
FIX: Do not include theme variables in plugin SCSS, and fix register_css
This commit is contained in:
@ -15,6 +15,41 @@ describe Stylesheet::Compiler do
|
||||
end
|
||||
end
|
||||
|
||||
context "with a theme" do
|
||||
let!(:theme) { Fabricate(:theme) }
|
||||
let!(:upload) { Fabricate(:upload) }
|
||||
let!(:upload_theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: "primary", upload: upload, value: "", type_id: ThemeField.types[:theme_upload_var]) }
|
||||
let!(:stylesheet_theme_field) { ThemeField.create!(theme: theme, target_id: 0, name: "scss", value: "body { background: $primary }", type_id: ThemeField.types[:scss]) }
|
||||
before { stylesheet_theme_field.save! }
|
||||
|
||||
it "theme stylesheet should be able to access theme asset variables" do
|
||||
css, _map = Stylesheet::Compiler.compile_asset("desktop_theme", theme_id: theme.id)
|
||||
expect(css).to include(upload.url)
|
||||
end
|
||||
|
||||
context "with a plugin" do
|
||||
before do
|
||||
plugin = Plugin::Instance.new
|
||||
plugin.path = "#{Rails.root}/spec/fixtures/plugins/my_plugin/plugin.rb"
|
||||
plugin.register_css "body { background: $primary }"
|
||||
Discourse.plugins << plugin
|
||||
plugin.activate!
|
||||
Stylesheet::Importer.register_imports!
|
||||
end
|
||||
|
||||
after do
|
||||
Discourse.plugins.pop
|
||||
Stylesheet::Importer.register_imports!
|
||||
end
|
||||
|
||||
it "does not include theme variables in plugins" do
|
||||
css, _map = Stylesheet::Compiler.compile_asset("my_plugin", theme_id: theme.id)
|
||||
expect(css).not_to include(upload.url)
|
||||
expect(css).to include("background:")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "supports asset-url" do
|
||||
css, _map = Stylesheet::Compiler.compile(".body{background-image: asset-url('/images/favicons/github.png');}", "test.scss")
|
||||
|
||||
|
Reference in New Issue
Block a user