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:

sass.cr
compiler.cr
sass2scss.cr

Constant Summary

VERSION = "0.4.0"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(*, precision : Int32? = nil, output_style : LibSass::SassOutputStyle? = nil, source_comments : Bool? = nil, source_map_embed : Bool? = nil, source_map_contents : Bool? = nil, source_map_file_urls : Bool? = nil, omit_source_map_url : Bool? = nil, is_indented_syntax_src : Bool? = nil, indent : String? = nil, linefeed : String? = nil, input_path : String? = nil, output_path : String? = nil, plugin_path : String? = nil, include_path : String? = nil, source_map_file : String? = nil, source_map_root : String? = 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? #

Gets libsass option #include_path.


def include_path=(value : String?) #

Sets libsass option #include_path.


[View source]
def indent : String? #

Gets libsass option #indent.


def indent=(value : String?) #

Sets libsass option #indent.


[View source]
def input_path : String? #

Gets libsass option #input_path.


def input_path=(value : String?) #

Sets libsass option #input_path.


[View source]
def is_indented_syntax_src : Bool? #

Gets libsass option #is_indented_syntax_src.


def is_indented_syntax_src=(is_indented_syntax_src : Bool?) #

Sets libsass option #is_indented_syntax_src.


def linefeed : String? #

Gets libsass option #linefeed.


def linefeed=(value : String?) #

Sets libsass option #linefeed.


[View source]
def omit_source_map_url : Bool? #

Gets libsass option #omit_source_map_url.


def omit_source_map_url=(omit_source_map_url : Bool?) #

Sets libsass option #omit_source_map_url.


def options : Options #

Returns all options.


[View source]
def output_path : String? #

Gets libsass option #output_path.


def output_path=(value : String?) #

Sets libsass option #output_path.


[View source]
def output_style : LibSass::SassOutputStyle? #

Gets libsass option #output_style.


def output_style=(output_style : LibSass::SassOutputStyle?) #

Sets libsass option #output_style.


def plugin_path : String? #

Gets libsass option #plugin_path.


def plugin_path=(value : String?) #

Sets libsass option #plugin_path.


[View source]
def precision : Int32? #

Gets libsass option #precision.


def precision=(precision : Int32?) #

Sets libsass option #precision.


def source_comments : Bool? #

Gets libsass option #source_comments.


def source_comments=(source_comments : Bool?) #

Sets libsass option #source_comments.


def source_map_contents : Bool? #

Gets libsass option #source_map_contents.


def source_map_contents=(source_map_contents : Bool?) #

Sets libsass option #source_map_contents.


def source_map_embed : Bool? #

Gets libsass option #source_map_embed.


def source_map_embed=(source_map_embed : Bool?) #

Sets libsass option #source_map_embed.


def source_map_file : String? #

Gets libsass option #source_map_file.


def source_map_file=(value : String?) #

Sets libsass option #source_map_file.


[View source]
def source_map_file_urls : Bool? #

Gets libsass option #source_map_file_urls.


def source_map_file_urls=(source_map_file_urls : Bool?) #

Sets libsass option #source_map_file_urls.


def source_map_root : String? #

Gets libsass option #source_map_root.


def source_map_root=(value : String?) #

Sets libsass option #source_map_root.


[View source]