| 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. | |
| 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 for available options.
# File lib/sass/engine.rb, line 69
69: def initialize(template, options={})
70: @options = {
71: :style => :nested,
72: :load_paths => ['.']
73: }.merge! options
74: @template = template.split(/\n?\r|\r?\n/)
75: @lines = []
76: @constants = {"important" => "!important"}
77: end
Processes the template and returns the result as a string.
# File lib/sass/engine.rb, line 80
80: def render
81: begin
82: render_to_tree.to_s
83: rescue SyntaxError => err
84: unless err.sass_filename
85: err.add_backtrace_entry(@options[:filename])
86: end
87: raise err
88: end
89: end
# File lib/sass/engine.rb, line 99
99: def render_to_tree
100: split_lines
101:
102: root = Tree::Node.new(@options[:style])
103: index = 0
104: while @lines[index]
105: child, index = build_tree(index)
106:
107: if child.is_a? Tree::Node
108: child.line = index
109: root << child
110: elsif child.is_a? Array
111: child.each do |c|
112: root << c
113: end
114: end
115: end
116: @line = nil
117:
118: root
119: end