mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-06-17 18:03:07 +08:00
This reduces chances of errors where consumers of strings mutate inputs and reduces memory usage of the app. Test suite passes now, but there may be some stuff left, so we will run a few sites on a branch prior to merging
53 lines
1.6 KiB
Ruby
Vendored
53 lines
1.6 KiB
Ruby
Vendored
# frozen_string_literal: true
|
|
|
|
require_dependency 'stylesheet/common'
|
|
require_dependency 'stylesheet/importer'
|
|
require_dependency '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 \"theme_variables\"; @import \"#{asset}\";"
|
|
else
|
|
filename = "#{asset}.scss"
|
|
path = "#{ASSET_ROOT}/#{filename}"
|
|
file = File.read path
|
|
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],
|
|
load_paths: [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
|