sass-embedded 1.69.1 → 1.69.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/exe/sass +2 -2
  4. data/ext/sass/Rakefile +8 -24
  5. data/ext/sass/embedded_sass_pb.rb +1 -1
  6. data/ext/sass/package.json +1 -1
  7. data/lib/sass/calculation_value/calculation_operation.rb +2 -5
  8. data/lib/sass/calculation_value.rb +10 -4
  9. data/lib/sass/compiler/connection.rb +92 -0
  10. data/lib/sass/{embedded → compiler}/dispatcher.rb +54 -38
  11. data/lib/sass/compiler/dispatcher_manager.rb +44 -0
  12. data/lib/sass/{embedded → compiler}/host/function_registry.rb +3 -3
  13. data/lib/sass/{embedded → compiler}/host/importer_registry.rb +4 -4
  14. data/lib/sass/{embedded → compiler}/host/logger_registry.rb +1 -1
  15. data/lib/sass/compiler/host/protofier.rb +88 -0
  16. data/lib/sass/compiler/host/structifier.rb +37 -0
  17. data/lib/sass/{embedded → compiler}/host/value_protofier.rb +3 -3
  18. data/lib/sass/{embedded → compiler}/host.rb +26 -15
  19. data/lib/sass/{embedded → compiler}/varint.rb +3 -5
  20. data/lib/sass/compiler.rb +191 -0
  21. data/lib/sass/elf.rb +2 -2
  22. data/lib/sass/embedded/version.rb +2 -2
  23. data/lib/sass/embedded.rb +65 -208
  24. data/lib/sass/exception.rb +65 -0
  25. data/lib/sass/fork_tracker.rb +51 -0
  26. data/lib/sass/serializer.rb +41 -0
  27. data/lib/sass/value/argument_list.rb +2 -2
  28. data/lib/sass/value/calculation.rb +3 -1
  29. data/lib/sass/value/color.rb +6 -6
  30. data/lib/sass/value/function.rb +6 -4
  31. data/lib/sass/value/map.rb +1 -1
  32. data/lib/sass/value/number.rb +11 -11
  33. data/lib/sass/value/string.rb +5 -8
  34. data/lib/sass/value.rb +1 -9
  35. metadata +25 -23
  36. data/ext/sass/win32_api.rb +0 -133
  37. data/lib/sass/compile_error.rb +0 -31
  38. data/lib/sass/embedded/connection.rb +0 -71
  39. data/lib/sass/embedded/protofier.rb +0 -86
  40. data/lib/sass/embedded/resilient_dispatcher.rb +0 -44
  41. data/lib/sass/embedded/structifier.rb +0 -35
  42. data/lib/sass/script_error.rb +0 -10
@@ -3,10 +3,12 @@
3
3
  require_relative 'host/function_registry'
4
4
  require_relative 'host/importer_registry'
5
5
  require_relative 'host/logger_registry'
6
+ require_relative 'host/protofier'
7
+ require_relative 'host/structifier'
6
8
  require_relative 'host/value_protofier'
7
9
 
8
10
  module Sass
9
- class Embedded
11
+ class Compiler
10
12
  # The {Host} class.
11
13
  #
12
14
  # It communicates with {Dispatcher} and handles the host logic.
@@ -33,16 +35,16 @@ module Sass
33
35
  quiet_deps:,
34
36
  verbose:)
35
37
  compile_response = await do
36
- alert_color = $stderr.tty? if alert_color.nil?
38
+ alert_color = Exception.respond_to?(:to_tty?) && Exception.to_tty? if alert_color.nil?
37
39
 
38
- @function_registry = FunctionRegistry.new(functions, alert_color: alert_color)
39
- @importer_registry = ImporterRegistry.new(importers, load_paths, alert_color: alert_color)
40
+ @function_registry = FunctionRegistry.new(functions, alert_color:)
41
+ @importer_registry = ImporterRegistry.new(importers, load_paths, alert_color:)
40
42
  @logger_registry = LoggerRegistry.new(logger)
41
43
 
42
44
  send_message(compile_request: EmbeddedProtocol::InboundMessage::CompileRequest.new(
43
45
  string: unless source.nil?
44
46
  EmbeddedProtocol::InboundMessage::CompileRequest::StringInput.new(
45
- source: source,
47
+ source: source.to_str,
46
48
  url: url&.to_s,
47
49
  syntax: Protofier.to_proto_syntax(syntax),
48
50
  importer: (@importer_registry.register(importer) unless importer.nil?)
@@ -50,15 +52,15 @@ module Sass
50
52
  end,
51
53
  path: (File.absolute_path(path) unless path.nil?),
52
54
  style: Protofier.to_proto_output_style(style),
53
- charset: charset,
54
- source_map: source_map,
55
- source_map_include_sources: source_map_include_sources,
55
+ charset:,
56
+ source_map:,
57
+ source_map_include_sources:,
56
58
  importers: @importer_registry.importers,
57
59
  global_functions: @function_registry.global_functions,
58
- alert_ascii: alert_ascii,
59
- alert_color: alert_color,
60
- quiet_deps: quiet_deps,
61
- verbose: verbose
60
+ alert_ascii:,
61
+ alert_color:,
62
+ quiet_deps:,
63
+ verbose:
62
64
  ))
63
65
  end
64
66
 
@@ -68,11 +70,18 @@ module Sass
68
70
  def version_request
69
71
  version_response = await0 do
70
72
  send_message0(version_request: EmbeddedProtocol::InboundMessage::VersionRequest.new(
71
- id: id
73
+ id:
72
74
  ))
73
75
  end
74
76
 
75
- "sass-embedded\t#{version_response.implementation_version}"
77
+ lang = case version_response.implementation_name
78
+ when /\bdart\b/i
79
+ '[Dart]'
80
+ else
81
+ '[?]'
82
+ end
83
+
84
+ "#{version_response.implementation_name}\t#{version_response.implementation_version}\t(Sass Compiler)\t#{lang}"
76
85
  end
77
86
 
78
87
  def compile_response(message)
@@ -88,8 +97,8 @@ module Sass
88
97
  def error(message)
89
98
  case message
90
99
  when EmbeddedProtocol::ProtocolError
91
- @dispatcher.error
92
100
  @error = Errno::EPROTO.new(message.message)
101
+ @channel.error(@error)
93
102
  else
94
103
  @error ||= message
95
104
  end
@@ -98,6 +107,8 @@ module Sass
98
107
 
99
108
  def log_event(message)
100
109
  @logger_registry.log(message)
110
+ rescue StandardError => e
111
+ @channel.error(e)
101
112
  end
102
113
 
103
114
  def canonicalize_request(message)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sass
4
- class Embedded
4
+ class Compiler
5
5
  # The {Varint} module.
6
6
  #
7
7
  # It reads and writes varints.
@@ -26,13 +26,11 @@ module Sass
26
26
  end
27
27
 
28
28
  def write(writeable, value)
29
- bytes = []
30
29
  until value < 0x80
31
- bytes << ((value & 0x7f) | 0x80)
30
+ writeable << ((value & 0x7f) | 0x80)
32
31
  value >>= 7
33
32
  end
34
- bytes << value
35
- writeable.write bytes.pack('C*')
33
+ writeable << value
36
34
  end
37
35
  end
38
36
 
@@ -0,0 +1,191 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'canonicalize_context'
4
+ require_relative 'compile_result'
5
+ require_relative 'compiler/connection'
6
+ require_relative 'compiler/dispatcher'
7
+ require_relative 'compiler/dispatcher_manager'
8
+ require_relative 'compiler/host'
9
+ require_relative 'compiler/varint'
10
+ require_relative 'embedded_protocol'
11
+ require_relative 'exception'
12
+ require_relative 'fork_tracker'
13
+ require_relative 'logger/silent'
14
+ require_relative 'logger/source_location'
15
+ require_relative 'logger/source_span'
16
+ require_relative 'serializer'
17
+ require_relative 'value'
18
+
19
+ module Sass
20
+ # The {Compiler} for using dart-sass. Each instance creates its own
21
+ # communication {Dispatcher} with a dedicated compiler process.
22
+ #
23
+ # @example
24
+ # sass = Sass::Compiler.new
25
+ # result = sass.compile_string('h1 { font-size: 40px; }')
26
+ # result = sass.compile('style.scss')
27
+ # sass.close
28
+ class Compiler
29
+ def initialize
30
+ @dispatcher = DispatcherManager.new(Dispatcher)
31
+ end
32
+
33
+ # Compiles the Sass file at +path+ to CSS.
34
+ # @param path [String]
35
+ # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
36
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
37
+ # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
38
+ # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
39
+ # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
40
+ # @param source_map [Boolean] Whether or not Sass should generate a source map.
41
+ # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
42
+ # @param style [String, Symbol] The OutputStyle of the compiled CSS.
43
+ # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
44
+ # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
45
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
46
+ # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
47
+ # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
48
+ # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
49
+ # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
50
+ # not to use colors depending on whether the user is using an interactive terminal.
51
+ # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
52
+ # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
53
+ # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
54
+ # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
55
+ # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
56
+ # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
57
+ # deprecation warning it encounters.
58
+ # @return [CompileResult]
59
+ # @raise [ArgumentError, CompileError]
60
+ # @see https://sass-lang.com/documentation/js-api/functions/compile/
61
+ def compile(path,
62
+ load_paths: [],
63
+
64
+ charset: true,
65
+ source_map: false,
66
+ source_map_include_sources: false,
67
+ style: :expanded,
68
+
69
+ functions: {},
70
+ importers: [],
71
+
72
+ alert_ascii: false,
73
+ alert_color: nil,
74
+ logger: nil,
75
+ quiet_deps: false,
76
+ verbose: false)
77
+ raise ArgumentError, 'path must be set' if path.nil?
78
+
79
+ Host.new(@dispatcher).compile_request(
80
+ path:,
81
+ source: nil,
82
+ importer: nil,
83
+ load_paths:,
84
+ syntax: nil,
85
+ url: nil,
86
+ charset:,
87
+ source_map:,
88
+ source_map_include_sources:,
89
+ style:,
90
+ functions:,
91
+ importers:,
92
+ alert_color:,
93
+ alert_ascii:,
94
+ logger:,
95
+ quiet_deps:,
96
+ verbose:
97
+ )
98
+ end
99
+
100
+ # Compiles a stylesheet whose contents is +source+ to CSS.
101
+ # @param source [String]
102
+ # @param importer [Object] The importer to use to handle loads that are relative to the entrypoint stylesheet.
103
+ # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
104
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
105
+ # @param syntax [String, Symbol] The Syntax to use to parse the entrypoint stylesheet.
106
+ # @param url [String] The canonical URL of the entrypoint stylesheet. If this is passed along with +importer+, it's
107
+ # used to resolve relative loads in the entrypoint stylesheet.
108
+ # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
109
+ # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
110
+ # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
111
+ # @param source_map [Boolean] Whether or not Sass should generate a source map.
112
+ # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
113
+ # @param style [String, Symbol] The OutputStyle of the compiled CSS.
114
+ # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
115
+ # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
116
+ # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
117
+ # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
118
+ # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
119
+ # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
120
+ # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
121
+ # not to use colors depending on whether the user is using an interactive terminal.
122
+ # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
123
+ # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
124
+ # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
125
+ # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
126
+ # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
127
+ # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
128
+ # deprecation warning it encounters.
129
+ # @return [CompileResult]
130
+ # @raise [ArgumentError, CompileError]
131
+ # @see https://sass-lang.com/documentation/js-api/functions/compilestring/
132
+ def compile_string(source,
133
+ importer: nil,
134
+ load_paths: [],
135
+ syntax: :scss,
136
+ url: nil,
137
+
138
+ charset: true,
139
+ source_map: false,
140
+ source_map_include_sources: false,
141
+ style: :expanded,
142
+
143
+ functions: {},
144
+ importers: [],
145
+
146
+ alert_ascii: false,
147
+ alert_color: nil,
148
+ logger: nil,
149
+ quiet_deps: false,
150
+ verbose: false)
151
+ raise ArgumentError, 'source must be set' if source.nil?
152
+
153
+ Host.new(@dispatcher).compile_request(
154
+ path: nil,
155
+ source:,
156
+ importer:,
157
+ load_paths:,
158
+ syntax:,
159
+ url:,
160
+ charset:,
161
+ source_map:,
162
+ source_map_include_sources:,
163
+ style:,
164
+ functions:,
165
+ importers:,
166
+ alert_color:,
167
+ alert_ascii:,
168
+ logger:,
169
+ quiet_deps:,
170
+ verbose:
171
+ )
172
+ end
173
+
174
+ # @return [String] Information about the Sass implementation.
175
+ # @see https://sass-lang.com/documentation/js-api/variables/info/
176
+ def info
177
+ @info ||= <<~INFO.freeze
178
+ sass-embedded\t#{Embedded::VERSION}\t(Embedded Host)\t[Ruby]
179
+ #{Host.new(@dispatcher).version_request}
180
+ INFO
181
+ end
182
+
183
+ def close
184
+ @dispatcher.close
185
+ end
186
+
187
+ def closed?
188
+ @dispatcher.closed?
189
+ end
190
+ end
191
+ end
data/lib/sass/elf.rb CHANGED
@@ -150,7 +150,7 @@ module Sass
150
150
  def initialize(buffer)
151
151
  @buffer = buffer
152
152
  @ehdr = read_ehdr
153
- @buffer.seek(@ehdr[:e_phoff], :SET)
153
+ @buffer.seek(@ehdr[:e_phoff], IO::SEEK_SET)
154
154
  @proghdrs = Array.new(@ehdr[:e_phnum]) do
155
155
  read_phdr
156
156
  end
@@ -176,7 +176,7 @@ module Sass
176
176
  phdr = @proghdrs.find { |p| p[:p_type] == PT_INTERP }
177
177
  return if phdr.nil?
178
178
 
179
- @buffer.seek(phdr[:p_offset], :SET)
179
+ @buffer.seek(phdr[:p_offset], IO::SEEK_SET)
180
180
  interpreter = @buffer.read(phdr[:p_filesz])
181
181
  raise ArgumentError unless interpreter.end_with?("\0")
182
182
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sass
4
- class Embedded
5
- VERSION = '1.69.1'
4
+ module Embedded
5
+ VERSION = '1.69.7'
6
6
  end
7
7
  end
data/lib/sass/embedded.rb CHANGED
@@ -1,22 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../ext/sass/cli'
4
- require_relative 'canonicalize_context'
5
- require_relative 'compile_error'
6
- require_relative 'compile_result'
7
- require_relative 'embedded/connection'
8
- require_relative 'embedded/dispatcher'
9
- require_relative 'embedded/host'
10
- require_relative 'embedded/protofier'
11
- require_relative 'embedded/resilient_dispatcher'
12
- require_relative 'embedded/structifier'
13
- require_relative 'embedded/varint'
3
+ require_relative 'compiler'
14
4
  require_relative 'embedded/version'
15
- require_relative 'embedded_protocol'
16
- require_relative 'logger/silent'
17
- require_relative 'logger/source_location'
18
- require_relative 'logger/source_span'
19
- require_relative 'value'
20
5
 
21
6
  # The Sass module.
22
7
  #
@@ -28,224 +13,96 @@ require_relative 'value'
28
13
  # @example
29
14
  # Sass.compile_string('h1 { font-size: 40px; }')
30
15
  module Sass
31
- @instance = nil
16
+ @compiler = nil
32
17
  @mutex = Mutex.new
33
18
 
34
19
  # rubocop:disable Layout/LineLength
35
20
  class << self
36
21
  # Compiles the Sass file at +path+ to CSS.
37
22
  # @overload compile(path, load_paths: [], charset: true, source_map: false, source_map_include_sources: false, style: :expanded, functions: {}, importers: [], alert_ascii: false, alert_color: nil, logger: nil, quiet_deps: false, verbose: false)
38
- # @param (see Embedded#compile)
39
- # @return (see Embedded#compile)
40
- # @raise (see Embedded#compile)
41
- # @see Embedded#compile
23
+ # @param (see Compiler#compile)
24
+ # @return (see Compiler#compile)
25
+ # @raise (see Compiler#compile)
26
+ # @see Compiler#compile
42
27
  def compile(...)
43
- instance.compile(...)
28
+ compiler.compile(...)
44
29
  end
45
30
 
46
31
  # Compiles a stylesheet whose contents is +source+ to CSS.
47
32
  # @overload compile_string(source, importer: nil, load_paths: [], syntax: :scss, url: nil, charset: true, source_map: false, source_map_include_sources: false, style: :expanded, functions: {}, importers: [], alert_ascii: false, alert_color: nil, logger: nil, quiet_deps: false, verbose: false)
48
- # @param (see Embedded#compile_string)
49
- # @return (see Embedded#compile_string)
50
- # @raise (see Embedded#compile_string)
51
- # @see Embedded#compile_string
33
+ # @param (see Compiler#compile_string)
34
+ # @return (see Compiler#compile_string)
35
+ # @raise (see Compiler#compile_string)
36
+ # @see Compiler#compile_string
52
37
  def compile_string(...)
53
- instance.compile_string(...)
38
+ compiler.compile_string(...)
54
39
  end
55
40
 
56
- # @param (see Embedded#info)
57
- # @return (see Embedded#info)
58
- # @raise (see Embedded#info)
59
- # @see Embedded#info
41
+ # @param (see Compiler#info)
42
+ # @return (see Compiler#info)
43
+ # @raise (see Compiler#info)
44
+ # @see Compiler#info
60
45
  def info
61
- instance.info
46
+ compiler.info
62
47
  end
63
48
 
64
49
  private
65
50
 
66
- def instance
67
- return @instance if @instance
51
+ def compiler
52
+ return @compiler if @compiler
68
53
 
69
54
  @mutex.synchronize do
70
- return @instance if @instance
55
+ return @compiler if @compiler
56
+
57
+ compiler = Class.new(Compiler) do
58
+ def initialize
59
+ @dispatcher = Compiler.const_get(:DispatcherManager).new(Class.new(Compiler.const_get(:Dispatcher)) do
60
+ def initialize
61
+ super
62
+
63
+ idle_timeout = 10
64
+ @last_accessed_time = current_time
65
+
66
+ Thread.new do
67
+ Thread.current.name = 'sass-embedded-process-reaper'
68
+ duration = idle_timeout
69
+ loop do
70
+ sleep(duration.negative? ? idle_timeout : duration)
71
+ break if @mutex.synchronize do
72
+ raise Errno::EBUSY if _closed?
73
+
74
+ duration = idle_timeout - (current_time - @last_accessed_time)
75
+ duration.negative? && _idle? && _close
76
+ end
77
+ end
78
+ close
79
+ rescue Errno::EBUSY
80
+ # do nothing
81
+ end
82
+ end
83
+
84
+ private
85
+
86
+ def _idle
87
+ super
88
+
89
+ @last_accessed_time = current_time
90
+ end
91
+
92
+ def current_time
93
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
94
+ end
95
+ end)
96
+ end
97
+ end.new
71
98
 
72
- @instance = Embedded.new
73
99
  at_exit do
74
- @instance.close
100
+ compiler.close
75
101
  end
76
- end
77
102
 
78
- @instance
103
+ @compiler = compiler
104
+ end
79
105
  end
80
106
  end
81
107
  # rubocop:enable Layout/LineLength
82
-
83
- # The {Embedded} host for using dart-sass. Each instance creates its own
84
- # communication {Dispatcher} with a dedicated compiler process.
85
- #
86
- # @example
87
- # embedded = Sass::Embedded.new
88
- # result = embedded.compile_string('h1 { font-size: 40px; }')
89
- # result = embedded.compile('style.scss')
90
- # embedded.close
91
- class Embedded
92
- def initialize
93
- @dispatcher = ResilientDispatcher.new
94
- end
95
-
96
- # Compiles the Sass file at +path+ to CSS.
97
- # @param path [String]
98
- # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
99
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
100
- # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
101
- # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
102
- # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
103
- # @param source_map [Boolean] Whether or not Sass should generate a source map.
104
- # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
105
- # @param style [String, Symbol] The OutputStyle of the compiled CSS.
106
- # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
107
- # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
108
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
109
- # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
110
- # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
111
- # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
112
- # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
113
- # not to use colors depending on whether the user is using an interactive terminal.
114
- # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
115
- # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
116
- # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
117
- # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
118
- # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
119
- # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
120
- # deprecation warning it encounters.
121
- # @return [CompileResult]
122
- # @raise [ArgumentError, CompileError]
123
- # @see https://sass-lang.com/documentation/js-api/functions/compile/
124
- def compile(path,
125
- load_paths: [],
126
-
127
- charset: true,
128
- source_map: false,
129
- source_map_include_sources: false,
130
- style: :expanded,
131
-
132
- functions: {},
133
- importers: [],
134
-
135
- alert_ascii: false,
136
- alert_color: nil,
137
- logger: nil,
138
- quiet_deps: false,
139
- verbose: false)
140
- raise ArgumentError, 'path must be set' if path.nil?
141
-
142
- Host.new(@dispatcher).compile_request(
143
- path: path,
144
- source: nil,
145
- importer: nil,
146
- load_paths: load_paths,
147
- syntax: nil,
148
- url: nil,
149
- charset: charset,
150
- source_map: source_map,
151
- source_map_include_sources: source_map_include_sources,
152
- style: style,
153
- functions: functions,
154
- importers: importers,
155
- alert_color: alert_color,
156
- alert_ascii: alert_ascii,
157
- logger: logger,
158
- quiet_deps: quiet_deps,
159
- verbose: verbose
160
- )
161
- end
162
-
163
- # Compiles a stylesheet whose contents is +source+ to CSS.
164
- # @param source [String]
165
- # @param importer [Object] The importer to use to handle loads that are relative to the entrypoint stylesheet.
166
- # @param load_paths [Array<String>] Paths in which to look for stylesheets loaded by rules like
167
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
168
- # @param syntax [String, Symbol] The Syntax to use to parse the entrypoint stylesheet.
169
- # @param url [String] The canonical URL of the entrypoint stylesheet. If this is passed along with +importer+, it's
170
- # used to resolve relative loads in the entrypoint stylesheet.
171
- # @param charset [Boolean] By default, if the CSS document contains non-ASCII characters, Sass adds a +@charset+
172
- # declaration (in expanded output mode) or a byte-order mark (in compressed mode) to indicate its encoding to
173
- # browsers or other consumers. If +charset+ is +false+, these annotations are omitted.
174
- # @param source_map [Boolean] Whether or not Sass should generate a source map.
175
- # @param source_map_include_sources [Boolean] Whether Sass should include the sources in the generated source map.
176
- # @param style [String, Symbol] The OutputStyle of the compiled CSS.
177
- # @param functions [Hash<String, Proc>] Additional built-in Sass functions that are available in all stylesheets.
178
- # @param importers [Array<Object>] Custom importers that control how Sass resolves loads from rules like
179
- # {@use}[https://sass-lang.com/documentation/at-rules/use/] and {@import}[https://sass-lang.com/documentation/at-rules/import/].
180
- # @param alert_ascii [Boolean] If this is +true+, the compiler will exclusively use ASCII characters in its error
181
- # and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.
182
- # @param alert_color [Boolean] If this is +true+, the compiler will use ANSI color escape codes in its error and
183
- # warning messages. If it's +false+, it won't use these. If it's +nil+, the compiler will determine whether or
184
- # not to use colors depending on whether the user is using an interactive terminal.
185
- # @param logger [Object] An object to use to handle warnings and/or debug messages from Sass.
186
- # @param quiet_deps [Boolean] If this option is set to +true+, Sass won’t print warnings that are caused by
187
- # dependencies. A “dependency” is defined as any file that’s loaded through +load_paths+ or +importer+.
188
- # Stylesheets that are imported relative to the entrypoint are not considered dependencies.
189
- # @param verbose [Boolean] By default, Dart Sass will print only five instances of the same deprecation warning per
190
- # compilation to avoid deluging users in console noise. If you set verbose to +true+, it will instead print every
191
- # deprecation warning it encounters.
192
- # @return [CompileResult]
193
- # @raise [ArgumentError, CompileError]
194
- # @see https://sass-lang.com/documentation/js-api/functions/compilestring/
195
- def compile_string(source,
196
- importer: nil,
197
- load_paths: [],
198
- syntax: :scss,
199
- url: nil,
200
-
201
- charset: true,
202
- source_map: false,
203
- source_map_include_sources: false,
204
- style: :expanded,
205
-
206
- functions: {},
207
- importers: [],
208
-
209
- alert_ascii: false,
210
- alert_color: nil,
211
- logger: nil,
212
- quiet_deps: false,
213
- verbose: false)
214
- raise ArgumentError, 'source must be set' if source.nil?
215
-
216
- Host.new(@dispatcher).compile_request(
217
- path: nil,
218
- source: source,
219
- importer: importer,
220
- load_paths: load_paths,
221
- syntax: syntax,
222
- url: url,
223
- charset: charset,
224
- source_map: source_map,
225
- source_map_include_sources: source_map_include_sources,
226
- style: style,
227
- functions: functions,
228
- importers: importers,
229
- alert_color: alert_color,
230
- alert_ascii: alert_ascii,
231
- logger: logger,
232
- quiet_deps: quiet_deps,
233
- verbose: verbose
234
- )
235
- end
236
-
237
- # @return [String] Information about the Sass implementation.
238
- # @see https://sass-lang.com/documentation/js-api/variables/info/
239
- def info
240
- @info ||= Host.new(@dispatcher).version_request
241
- end
242
-
243
- def close
244
- @dispatcher.close
245
- end
246
-
247
- def closed?
248
- @dispatcher.closed?
249
- end
250
- end
251
108
  end