Class: Sass::Embedded

Inherits:
Object
  • Object
show all
Defined in:
lib/sass/embedded.rb,
lib/sass/embedded/host.rb,
lib/sass/embedded/async.rb,
lib/sass/embedded/varint.rb,
lib/sass/embedded/channel.rb,
lib/sass/embedded/version.rb,
lib/sass/embedded/compiler.rb,
lib/sass/embedded/protofier.rb,
lib/sass/embedded/dispatcher.rb,
lib/sass/embedded/structifier.rb,
lib/sass/embedded/host/logger_registry.rb,
lib/sass/embedded/host/value_protofier.rb,
lib/sass/embedded/host/function_registry.rb,
lib/sass/embedded/host/importer_registry.rb

Overview

The Embedded host for using dart-sass-embedded. Each instance creates its own communication Channel with a dedicated compiler process.

Examples:

embedded = Sass::Embedded.new
result = embedded.compile_string('h1 { font-size: 40px; }')
result = embedded.compile('style.scss')
embedded.close

Constant Summary collapse

VERSION =
'1.53.0'

Instance Method Summary collapse

Constructor Details

#initializeEmbedded

Returns a new instance of Embedded.



82
83
84
# File 'lib/sass/embedded.rb', line 82

def initialize
  @channel = Channel.new
end

Instance Method Details

#closeObject



227
228
229
# File 'lib/sass/embedded.rb', line 227

def close
  @channel.close
end

#closed?Boolean

Returns:

  • (Boolean)


231
232
233
# File 'lib/sass/embedded.rb', line 231

def closed?
  @channel.closed?
end

#compile(path, load_paths: [], 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) ⇒ CompileResult

Compiles the Sass file at path to CSS.

Parameters:

  • path (String)
  • load_paths (Array<String>) (defaults to: [])

    Paths in which to look for stylesheets loaded by rules like @use and @import.

  • source_map (Boolean) (defaults to: false)

    Whether or not Sass should generate a source map.

  • source_map_include_sources (Boolean) (defaults to: false)

    Whether Sass should include the sources in the generated source map.

  • style (String, Symbol) (defaults to: :expanded)

    The OutputStyle of the compiled CSS.

  • functions (Hash<String, Proc>) (defaults to: {})

    Additional built-in Sass functions that are available in all stylesheets.

  • importers (Array<Object>) (defaults to: [])

    Custom importers that control how Sass resolves loads from rules like @use and @import.

  • alert_ascii (Boolean) (defaults to: false)

    If this is true, the compiler will exclusively use ASCII characters in its error and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.

  • alert_color (Boolean) (defaults to: nil)

    If this is true, the compiler will use ANSI color escape codes in its error and warning messages. If it’s false, it won’t use these. If it’s nil, the compiler will determine whether or not to use colors depending on whether the user is using an interactive terminal.

  • logger (Object) (defaults to: nil)

    An object to use to handle warnings and/or debug messages from Sass.

  • quiet_deps (Boolean) (defaults to: false)

    If this option is set to true, Sass won’t print warnings that are caused by dependencies. A “dependency” is defined as any file that’s loaded through load_paths or importer. Stylesheets that are imported relative to the entrypoint are not considered dependencies.

  • verbose (Boolean) (defaults to: false)

    By default, Dart Sass will print only five instances of the same deprecation warning per compilation to avoid deluging users in console noise. If you set verbose to true, it will instead print every deprecation warning it encounters.

Returns:

Raises:

See Also:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/sass/embedded.rb', line 111

def compile(path,
            load_paths: [],

            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)
  raise ArgumentError, 'path must be set' if path.nil?

  Protofier.from_proto_compile_response(
    Host.new(@channel).compile_request(
      path: path,
      source: nil,
      importer: nil,
      load_paths: load_paths,
      syntax: nil,
      url: nil,
      source_map: source_map,
      source_map_include_sources: source_map_include_sources,
      style: style,
      functions: functions,
      importers: importers,
      alert_color: alert_color,
      alert_ascii: alert_ascii,
      logger: logger,
      quiet_deps: quiet_deps,
      verbose: verbose
    )
  )
end

#compile_string(source, importer: nil, load_paths: [], syntax: :scss, url: nil, 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) ⇒ CompileResult

Compiles a stylesheet whose contents is source to CSS.

Parameters:

  • source (String)
  • importer (Object) (defaults to: nil)

    The importer to use to handle loads that are relative to the entrypoint stylesheet.

  • load_paths (Array<String>) (defaults to: [])

    Paths in which to look for stylesheets loaded by rules like @use and @import.

  • syntax (String, Symbol) (defaults to: :scss)

    The Syntax to use to parse the entrypoint stylesheet.

  • url (String) (defaults to: nil)

    The canonical URL of the entrypoint stylesheet. If this is passed along with importer, it’s used to resolve relative loads in the entrypoint stylesheet.

  • source_map (Boolean) (defaults to: false)

    Whether or not Sass should generate a source map.

  • source_map_include_sources (Boolean) (defaults to: false)

    Whether Sass should include the sources in the generated source map.

  • style (String, Symbol) (defaults to: :expanded)

    The OutputStyle of the compiled CSS.

  • functions (Hash<String, Proc>) (defaults to: {})

    Additional built-in Sass functions that are available in all stylesheets.

  • importers (Array<Object>) (defaults to: [])

    Custom importers that control how Sass resolves loads from rules like @use and @import.

  • alert_ascii (Boolean) (defaults to: false)

    If this is true, the compiler will exclusively use ASCII characters in its error and warning messages. Otherwise, it may use non-ASCII Unicode characters as well.

  • alert_color (Boolean) (defaults to: nil)

    If this is true, the compiler will use ANSI color escape codes in its error and warning messages. If it’s false, it won’t use these. If it’s nil, the compiler will determine whether or not to use colors depending on whether the user is using an interactive terminal.

  • logger (Object) (defaults to: nil)

    An object to use to handle warnings and/or debug messages from Sass.

  • quiet_deps (Boolean) (defaults to: false)

    If this option is set to true, Sass won’t print warnings that are caused by dependencies. A “dependency” is defined as any file that’s loaded through load_paths or importer. Stylesheets that are imported relative to the entrypoint are not considered dependencies.

  • verbose (Boolean) (defaults to: false)

    By default, Dart Sass will print only five instances of the same deprecation warning per compilation to avoid deluging users in console noise. If you set verbose to true, it will instead print every deprecation warning it encounters.

Returns:

Raises:

See Also:



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/sass/embedded.rb', line 179

def compile_string(source,
                   importer: nil,
                   load_paths: [],
                   syntax: :scss,
                   url: nil,

                   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)
  raise ArgumentError, 'source must be set' if source.nil?

  Protofier.from_proto_compile_response(
    Host.new(@channel).compile_request(
      path: nil,
      source: source,
      importer: importer,
      load_paths: load_paths,
      syntax: syntax,
      url: url,
      source_map: source_map,
      source_map_include_sources: source_map_include_sources,
      style: style,
      functions: functions,
      importers: importers,
      alert_color: alert_color,
      alert_ascii: alert_ascii,
      logger: logger,
      quiet_deps: quiet_deps,
      verbose: verbose
    )
  )
end

#infoString

Returns Information about the Sass implementation.

Returns:

  • (String)

    Information about the Sass implementation.

See Also:



223
224
225
# File 'lib/sass/embedded.rb', line 223

def info
  @info ||= "sass-embedded\t#{Host.new(@channel).version_request.implementation_version}"
end