| Class | Sass::Engine |
| In: |
lib/sass/engine.rb
|
| Parent: | Object |
This is the class where all the parsing and processing of the Sass template is done. It can be directly used by the user by creating a new instance and calling render to render the template. For example:
template = File.load('stylesheets/sassy.sass')
sass_engine = Sass::Engine.new(template)
output = sass_engine.render
puts output
| ATTRIBUTE_CHAR | = | ?: | The character that begins a CSS attribute. | |
| SCRIPT_CHAR | = | ?= | The character that designates that an attribute should be assigned to the result of constant arithmetic. | |
| 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 | |
| ATTRIBUTE | = | /^:([^\s=:]+)\s*(=?)(?:\s+|$)(.*)/ | The regex that matches and extracts data from attributes of the form :name attr. | |
| ATTRIBUTE_ALTERNATE_MATCHER | = | /^[^\s:]+\s*[=:](\s|$)/ | The regex that matches attributes of the form name: attr. | |
| ATTRIBUTE_ALTERNATE | = | /^([^\s=:]+)(\s*=|:)(?:\s+|$)(.*)/ | The regex that matches and extracts data from attributes of the form name: attr. |
Creates a new instace of Sass::Engine that will compile the given template string when render is called. See README.rdoc for available options.
# File lib/sass/engine.rb, line 74
74: def initialize(template, options={})
75: @options = {
76: :style => :nested,
77: :load_paths => ['.']
78: }.merge! options
79: @template = template.split(/\r\n|\r|\n/)
80: @lines = []
81: @constants = {"important" => "!important"}
82: @mixins = {}
83: end
Processes the template and returns the result as a string.
# File lib/sass/engine.rb, line 86
86: def render
87: begin
88: render_to_tree.to_s
89: rescue SyntaxError => err
90: unless err.sass_filename
91: err.add_backtrace_entry(@options[:filename])
92: end
93: raise err
94: end
95: end
# File lib/sass/engine.rb, line 109
109: def render_to_tree
110: split_lines
111:
112: root = Tree::Node.new(@options[:style])
113: index = 0
114: while @lines[index]
115: old_index = index
116: child, index = build_tree(index)
117:
118: if child.is_a? Tree::Node
119: child.line = old_index + 1
120: root << child
121: elsif child.is_a? Array
122: child.each do |c|
123: root << c
124: end
125: end
126: end
127: @lines.clear
128:
129: root
130: end