class

Sass

Inherits Reference / Object

This compiler provides a simple API to compile Sass and SCSS with libsass.

Usage examples:

require "sass"

# Compile a Sass/SCSS file:
css = Sass.compile_file("application.scss")

# Compile a Sass/SCSS file with options:
css = Sass.compile_file("application.sass", include_path: "includes")

# Compile a Sass/SCSS string:
css = Sass.compile("body { div { color: red; } }")

Re-use compiler with options:
compiler = Sass.new(include_path: "_scss")
compiler.compile_file("main.scss")     # Compile file main.scss
compiler.compile(%(@import "helper";)) # Import file _scss/helper.scss or _scss/_helper.scss

Options

  • precision: Int32 – Precision for fractional numbers.
  • output_style: OutputStyle – Output style for the generated CSS code.
  • source_comments: Bool – Emit comments in the generated CSS indicating the corresponding source line.
  • source_map_embed: Bool – embed sourceMappingUrl as data uri.
  • source_map_contents: Bool – embed include contents in maps.
  • source_map_file_urls: Bool – create file urls for sources.
  • omit_source_map_url: Bool – Disable sourceMappingUrl in css output.
  • is_indented_syntax_src: Bool – Treat source_string as sass (as opposed to scss)
  • input_path: String – The input path is used for source map generating. It can be used to define something with string compilation or to overload the input file path. It is set to "stdin" for data contexts and to the input file on file contexts.
  • output_path: String – The output path is used for source map generating. LibSass will not write to this file, it is just used to create information in source-maps etc.
  • indent: String – String to be used for indentation.
  • linefeed: String – String to be used to for line feeds.
  • include_path: String – Colon-separated list of paths where @import directive looks for include files (semicolon-separated on Windows).
  • plugin_path: String – Colon-separated list of paths for libsass plugins (semicolon-separated on Windows).
  • source_map_file: String – Path to source map file. Enables the source map generating used to create sourceMappingUrl.
  • source_map_root: String – Directly inserted in source maps.

Please refer to the libsass API documentation for further details.

Constants

VERSION = "0.6.0"

Constructors

new(*, precision : Int32 | Nil = nil, output_style : LibSass::SassOutputStyle | Nil = nil, source_comments : Bool | Nil = nil, source_map_embed : Bool | Nil = nil, source_map_contents : Bool | Nil = nil, source_map_file_urls : Bool | Nil = nil, omit_source_map_url : Bool | Nil = nil, is_indented_syntax_src : Bool | Nil = nil, indent : String | Nil = nil, linefeed : String | Nil = nil, input_path : String | Nil = nil, output_path : String | Nil = nil, plugin_path : String | Nil = nil, include_path : String | Nil = nil, source_map_file : String | Nil = nil, source_map_root : String | Nil = nil)

Creates a new compiler. All options can be assigned as named arguments.

Source

Class methods

libsass_version

Returns the version of libsass as a String

Source
sass2scss(content : String, prettify = :allman_style, comments = :convert) : String

Converts a String with Sass code into SCSS.

prettify takes the following values:

  • :minimized: Write everything on one line (minimized)
  • :lisp_style: Add lf after opening bracket (lisp style)
  • :otbs_style: Add lf after opening and before closing bracket (1TBS style)
  • :allman_style: Add lf before/after opening and before closing (allman style) (default)

comments takes these values:

  • :convert: convert all comments to /*and */ delimiters (default)
  • :keep: keep comments
  • :strip: strip all comments
Source

Instance methods

compile(string)

Compiles a Sass/SCSS string to CSS as String.

For available options see class description.

Source
compile_file(file)

Compiles a Sass/SCSS file to CSS as String.

For available options see class description.

Source
include_path

Gets libsass option include_path.

include_path=(value : String | Nil)

Sets libsass option include_path.

Source
indent

Gets libsass option indent.

indent=(value : String | Nil)

Sets libsass option indent.

Source
input_path

Gets libsass option input_path.

input_path=(value : String | Nil)

Sets libsass option input_path.

Source
is_indented_syntax_src

Gets libsass option is_indented_syntax_src.

is_indented_syntax_src=(is_indented_syntax_src : Bool | Nil)

Sets libsass option is_indented_syntax_src.

linefeed

Gets libsass option linefeed.

linefeed=(value : String | Nil)

Sets libsass option linefeed.

Source
omit_source_map_url

Gets libsass option omit_source_map_url.

omit_source_map_url=(omit_source_map_url : Bool | Nil)

Sets libsass option omit_source_map_url.

options

Returns all options.

Source
output_path

Gets libsass option output_path.

output_path=(value : String | Nil)

Sets libsass option output_path.

Source
output_style

Gets libsass option output_style.

output_style=(output_style : LibSass::SassOutputStyle | Nil)

Sets libsass option output_style.

plugin_path

Gets libsass option plugin_path.

plugin_path=(value : String | Nil)

Sets libsass option plugin_path.

Source
precision

Gets libsass option precision.

precision=(precision : Int32 | Nil)

Sets libsass option precision.

source_comments

Gets libsass option source_comments.

source_comments=(source_comments : Bool | Nil)

Sets libsass option source_comments.

source_map_contents

Gets libsass option source_map_contents.

source_map_contents=(source_map_contents : Bool | Nil)

Sets libsass option source_map_contents.

source_map_embed

Gets libsass option source_map_embed.

source_map_embed=(source_map_embed : Bool | Nil)

Sets libsass option source_map_embed.

source_map_file

Gets libsass option source_map_file.

source_map_file=(value : String | Nil)

Sets libsass option source_map_file.

Source
source_map_file_urls

Gets libsass option source_map_file_urls.

source_map_file_urls=(source_map_file_urls : Bool | Nil)

Sets libsass option source_map_file_urls.

source_map_root

Gets libsass option source_map_root.

source_map_root=(value : String | Nil)

Sets libsass option source_map_root.

Source

Nested types