mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 15:33:44 +08:00
882b0aac19
Themes can now declare custom colors that get compiled in core's color definitions stylesheet, thus allowing themes to better support dark/light color schemes. For example, if you need your theme to use tertiary for an element in a light color scheme and quaternary in a dark scheme, you can add the following SCSS to your theme's `color_definitions.scss` file: ``` :root { --mytheme-tertiary-or-quaternary: #{dark-light-choose($tertiary, $quaternary)}; } ``` And then use the `--mytheme-tertiary-or-quaternary` variable as the color property of that element. You can also use this file to add color variables that use SCSS color transformation functions (lighten, darken, saturate, etc.) without compromising your theme's compatibility with different color schemes.
61 lines
1.9 KiB
Ruby
61 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'stylesheet/common'
|
|
require 'stylesheet/importer'
|
|
require 'stylesheet/functions'
|
|
|
|
module Stylesheet
|
|
|
|
class Compiler
|
|
|
|
def self.compile_asset(asset, options = {})
|
|
|
|
if Importer.special_imports[asset.to_s]
|
|
filename = "theme_#{options[:theme_id]}.scss"
|
|
file = "@import \"common/foundation/variables\"; @import \"common/foundation/mixins\";"
|
|
file += " @import \"theme_variables\";" if Importer::THEME_TARGETS.include?(asset.to_s)
|
|
file += " @import \"#{asset}\";"
|
|
else
|
|
filename = "#{asset}.scss"
|
|
path = "#{Stylesheet::Common::ASSET_ROOT}/#{filename}"
|
|
file = File.read path
|
|
|
|
if asset.to_s == Stylesheet::Manager::COLOR_SCHEME_STYLESHEET
|
|
file += Stylesheet::Importer.import_color_definitions(options[:theme_id])
|
|
end
|
|
end
|
|
|
|
compile(file, filename, options)
|
|
|
|
end
|
|
|
|
def self.compile(stylesheet, filename, options = {})
|
|
source_map_file = options[:source_map_file] || "#{filename.sub(".scss", "")}.css.map"
|
|
|
|
engine = SassC::Engine.new(stylesheet,
|
|
importer: Importer,
|
|
filename: filename,
|
|
style: :compressed,
|
|
source_map_file: source_map_file,
|
|
source_map_contents: true,
|
|
theme_id: options[:theme_id],
|
|
theme: options[:theme],
|
|
theme_field: options[:theme_field],
|
|
color_scheme_id: options[:color_scheme_id],
|
|
load_paths: [Stylesheet::Common::ASSET_ROOT])
|
|
|
|
result = engine.render
|
|
|
|
if options[:rtl]
|
|
require 'r2'
|
|
[R2.r2(result), nil]
|
|
else
|
|
source_map = engine.source_map
|
|
source_map.force_encoding("UTF-8")
|
|
|
|
[result, source_map]
|
|
end
|
|
end
|
|
end
|
|
end
|