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
Methods
public class
public instance
protected instance
Public class methods
new
(template, options={})
Creates a new instace of Sass::Engine that will compile the given template string when render is called. See README.rdoc for available options.
[show source]
# 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
Public instance methods
render
()
Processes the template and returns the result as a string.
[show source]
# 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
Protected instance methods
constants
()
[show source]
# File lib/sass/engine.rb, line 101 101: def constants 102: @constants 103: end
render_to_tree
()
[show source]
# 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: child, index = build_tree(index) 116: 117: if child.is_a? Tree::Node 118: child.line = index 119: root << child 120: elsif child.is_a? Array 121: child.each do |c| 122: root << c 123: end 124: end 125: end 126: @lines.clear 127: 128: root 129: end