2017-04-12 10:52:52 -04:00
|
|
|
require_dependency 'stylesheet/common'
|
|
|
|
require_dependency 'stylesheet/importer'
|
|
|
|
require_dependency 'stylesheet/functions'
|
|
|
|
|
|
|
|
module Stylesheet
|
|
|
|
|
|
|
|
class Compiler
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
def self.compile_asset(asset, options = {})
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
if Importer.special_imports[asset.to_s]
|
2019-04-12 06:36:08 -04:00
|
|
|
filename = "theme_#{options[:theme_id]}.scss"
|
2019-02-19 10:55:59 -05:00
|
|
|
file = "@import \"common/foundation/variables\"; @import \"theme_variables\"; @import \"#{asset}\";"
|
2017-04-12 10:52:52 -04:00
|
|
|
else
|
|
|
|
filename = "#{asset}.scss"
|
|
|
|
path = "#{ASSET_ROOT}/#{filename}"
|
|
|
|
file = File.read path
|
|
|
|
end
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
compile(file, filename, options)
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
def self.compile(stylesheet, filename, options = {})
|
2018-12-03 22:48:13 -05:00
|
|
|
source_map_file = options[:source_map_file] || "#{filename.sub(".scss", "")}.css.map"
|
2017-04-19 16:46:28 -04:00
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
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],
|
2017-05-09 17:20:28 -04:00
|
|
|
theme: options[:theme],
|
2017-04-19 16:46:28 -04:00
|
|
|
theme_field: options[:theme_field],
|
2017-04-12 10:52:52 -04:00
|
|
|
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
|