Class: SassC::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/sassc/embedded.rb

Instance Method Summary collapse

Instance Method Details

#renderObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sassc/embedded.rb', line 15

def render
  return @template.dup if @template.empty?

  result = ::Sass.compile_string(
    @template,
    importer: nil,
    load_paths: load_paths,
    syntax: syntax,
    url: file_url,

    source_map: source_map_embed? || !source_map_file.nil?,
    source_map_include_sources: source_map_contents?,
    style: output_style,

    functions: FunctionsHandler.new(@options).setup(nil, functions: @functions),
    importers: ImportHandler.new(@options).setup(nil),

    alert_ascii: @options.fetch(:alert_ascii, false),
    alert_color: @options.fetch(:alert_color, nil),
    logger: @options.fetch(:logger, nil),
    quiet_deps: @options.fetch(:quiet_deps, false),
    verbose: @options.fetch(:verbose, false)
  )

  @dependencies = result.loaded_urls
                        .filter { |url| url.start_with?('file:') && url != file_url }
                        .map { |url| Util.file_url_to_path(url) }
  @source_map   = post_process_source_map(result.source_map)

  return post_process_css(result.css) unless quiet?
rescue ::Sass::CompileError => e
  line = e.span&.start&.line
  line += 1 unless line.nil?
  path = Util.file_url_to_path(e.span&.url)
  path = relative_path(Dir.pwd, path)
  raise SyntaxError.new(e.message, filename: path, line: line)
end