| Class | Sass::Engine |
| In: |
lib/sass/engine.rb
|
| Parent: | Object |
This class handles the parsing and compilation of the Sass template. Example usage:
template = File.load('stylesheets/sassy.sass')
sass_engine = Sass::Engine.new(template)
output = sass_engine.render
puts output
| PROPERTY_CHAR | = | ?: | The character that begins a CSS property. | |
| SCRIPT_CHAR | = | ?= | The character that designates that a property should be assigned to a SassScript expression. | |
| COMMENT_CHAR | = | ?/ | The character that designates the beginning of a comment, either Sass or CSS. | |
| SASS_COMMENT_CHAR | = | ?/ | The character that follows the general COMMENT_CHAR and designates a Sass comment, which is not output as a CSS comment. | |
| CSS_COMMENT_CHAR | = | ?* | The character that follows the general COMMENT_CHAR and designates a CSS comment, which is embedded in the CSS document. | |
| DIRECTIVE_CHAR | = | ?@ | The character used to denote a compiler directive. | |
| ESCAPE_CHAR | = | ?\\ | Designates a non-parsed rule. | |
| MIXIN_DEFINITION_CHAR | = | ?= | Designates block as mixin definition rather than CSS rules to output | |
| MIXIN_INCLUDE_CHAR | = | ?+ | Includes named mixin declared using MIXIN_DEFINITION_CHAR | |
| PROPERTY_NEW_MATCHER | = | /^[^\s:"]+\s*[=:](\s|$)/ | The regex that matches properties of the form name: prop. | |
| PROPERTY_NEW | = | /^([^\s=:"]+)(\s*=|:)(?:\s+|$)(.*)/ | The regex that matches and extracts data from properties of the form name: prop. | |
| PROPERTY_OLD | = | /^:([^\s=:"]+)\s*(=?)(?:\s+|$)(.*)/ | The regex that matches and extracts data from properties of the form :name prop. | |
| DEFAULT_OPTIONS | = | { :style => :nested, :load_paths => ['.'], :cache => true, :cache_location => './.sass-cache', }.freeze | The default options for Sass::Engine. |
@param template [String] The Sass template. @param options [Hash<Symbol, Object>] An options hash;
see {file:SASS_REFERENCE.md#sass_options the Sass options documentation}
# File lib/sass/engine.rb, line 131
131: def initialize(template, options={})
132: @options = DEFAULT_OPTIONS.merge(options)
133: @template = template
134:
135: # Backwards compatibility
136: @options[:property_syntax] ||= @options[:attribute_syntax]
137: case @options[:property_syntax]
138: when :alternate; @options[:property_syntax] = :new
139: when :normal; @options[:property_syntax] = :old
140: end
141: end
Render the template to CSS.
@return [String] The CSS @raise [Sass::SyntaxError] if there‘s an error in the document
# File lib/sass/engine.rb, line 147
147: def render
148: to_tree.render
149: end
Parses the document into its parse tree.
@return [Sass::Tree::Node] The root of the parse tree. @raise [Sass::SyntaxError] if there‘s an error in the document
# File lib/sass/engine.rb, line 157
157: def to_tree
158: root = Tree::Node.new
159: append_children(root, tree(tabulate(@template)).first, true)
160: root.options = @options
161: root
162: rescue SyntaxError => e; e.add_metadata(@options[:filename], @line)
163: end