class Sass

Overview

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

Please refer to the libsass API documentation for further details.

Defined in:

compiler.cr
sass.cr
sass2scss.cr

Constant Summary

VERSION = "0.6.0"

DEPRECATED

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.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.


[View source]

Class Method Detail

def self.libsass_version #

Returns the version of libsass as a String


[View source]
def self.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

[View source]

Instance Method Detail

def compile(string) #

Compiles a Sass/SCSS string to CSS as String.

For available options see class description.


[View source]
def compile_file(file) #

Compiles a Sass/SCSS file to CSS as String.

For available options see class description.


[View source]
def include_path : String | Nil #

Gets libsass option #include_path.


def include_path=(value : String | Nil) #

Sets libsass option #include_path.


[View source]
def indent : String | Nil #

Gets libsass option #indent.


def indent=(value : String | Nil) #

Sets libsass option #indent.


[View source]
def input_path : String | Nil #

Gets libsass option #input_path.


def input_path=(value : String | Nil) #

Sets libsass option #input_path.


[View source]
def is_indented_syntax_src : Bool | Nil #

Gets libsass option #is_indented_syntax_src.


def is_indented_syntax_src=(is_indented_syntax_src : Bool | Nil) #

Sets libsass option #is_indented_syntax_src.


def linefeed : String | Nil #

Gets libsass option #linefeed.


def linefeed=(value : String | Nil) #

Sets libsass option #linefeed.


[View source]
def omit_source_map_url : Bool | Nil #

Gets libsass option #omit_source_map_url.


def omit_source_map_url=(omit_source_map_url : Bool | Nil) #

Sets libsass option #omit_source_map_url.


def options : Options #

Returns all options.


[View source]
def output_path : String | Nil #

Gets libsass option #output_path.


def output_path=(value : String | Nil) #

Sets libsass option #output_path.


[View source]
def output_style : LibSass::SassOutputStyle | Nil #

Gets libsass option #output_style.


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

Sets libsass option #output_style.


def plugin_path : String | Nil #

Gets libsass option #plugin_path.


def plugin_path=(value : String | Nil) #

Sets libsass option #plugin_path.


[View source]
def precision : Int32 | Nil #

Gets libsass option #precision.


def precision=(precision : Int32 | Nil) #

Sets libsass option #precision.


def source_comments : Bool | Nil #

Gets libsass option #source_comments.


def source_comments=(source_comments : Bool | Nil) #

Sets libsass option #source_comments.


def source_map_contents : Bool | Nil #

Gets libsass option #source_map_contents.


def source_map_contents=(source_map_contents : Bool | Nil) #

Sets libsass option #source_map_contents.


def source_map_embed : Bool | Nil #

Gets libsass option #source_map_embed.


def source_map_embed=(source_map_embed : Bool | Nil) #

Sets libsass option #source_map_embed.


def source_map_file : String | Nil #

Gets libsass option #source_map_file.


def source_map_file=(value : String | Nil) #

Sets libsass option #source_map_file.


[View source]
def source_map_file_urls : Bool | Nil #

Gets libsass option #source_map_file_urls.


def source_map_file_urls=(source_map_file_urls : Bool | Nil) #

Sets libsass option #source_map_file_urls.


def source_map_root : String | Nil #

Gets libsass option #source_map_root.


def source_map_root=(value : String | Nil) #

Sets libsass option #source_map_root.


[View source]