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