Class: Sass::Engine
- Inherits:
-
Object
- Object
- Sass::Engine
- Includes:
- Util
- Defined in:
- /var/www/sass-pages/.sass/lib/sass/engine.rb
Overview
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
Constant Summary
- DEFAULT_OPTIONS = The default options for Sass::Engine.
{ :style => :nested, :load_paths => ['.'], :cache => true, :cache_location => './.sass-cache', :syntax => :sass, :filesystem_importer => Sass::Importers::Filesystem }.freeze
Constants included from Util
Instance Attribute Summary
- - ({Symbol => Object}) options readonly The options for the Sass engine.
Class Method Summary
- + (Sass::Engine) for_file(filename, options) Returns the Sass::Engine for the given file.
Instance Method Summary
- - ([Sass::Engine]) dependencies Gets a set of all the documents that are (transitive) dependencies of this document, not including the document itself.
- - (Engine) initialize(template, options = {}) constructor Creates a new Engine.
- - (String) render (also: #to_css) Render the template to CSS.
-
- (Encoding?) source_encoding
Returns the original encoding of the document, or
nilunder Ruby 1.8. - - (Sass::Tree::Node) to_tree Parses the document into its parse tree.
Methods included from Util
#abstract, #ap_geq?, #ap_geq_3?, #av_template_class, #caller_info, #check_encoding, #check_range, #check_sass_encoding, #enum_cons, #enum_slice, #enum_with_index, #extract!, #extract_values, #flatten, #glob, #has?, #hash_to_a, #inject_values, #inspect_obj, #intersperse, #ironruby?, #lcs, #map_hash, #map_keys, #map_vals, #merge_adjacent_strings, #ord, #paths, #powerset, #rails_env, #rails_root, #restrict, #ruby1_8?, #ruby1_8_6?, #sass_warn, #scope, #set_eql?, #set_hash, #silence_sass_warnings, #silence_warnings, #strip_string_array, #substitute, #to_hash, #version_geq, #version_gt, #windows?, #with_extracted_values
Constructor Details
- (Engine) initialize(template, options = {})
Creates a new Engine. Note that Engine should only be used directly when compiling in-memory Sass code. If you’re compiling a single Sass file from the filesystem, use Sass::Engine.for_file. If you’re compiling multiple files from the filesystem, use Sass::Plugin.
233 234 235 236 |
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 233
def initialize(template, options={})
@options = self.class.normalize_options(options)
@template = template
end
|
Instance Attribute Details
- ({Symbol => Object}) options (readonly)
The options for the Sass engine. See the Sass options documentation.
214 215 216 |
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 214
def options
@options
end
|
Class Method Details
+ (Sass::Engine) for_file(filename, options)
Returns the Sass::Engine for the given file. This is preferable to Sass::Engine.new when reading from a file because it properly sets up the Engine’s metadata, enables parse-tree caching, and infers the syntax from the filename.
196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 196
def self.for_file(filename, options)
had_syntax = options[:syntax]
if had_syntax
# Use what was explicitly specificed
elsif filename =~ /\.scss$/
options.merge!(:syntax => :scss)
elsif filename =~ /\.sass$/
options.merge!(:syntax => :sass)
end
Sass::Engine.new(File.read(filename), options.merge(:filename => filename))
end
|
Instance Method Details
- ([Sass::Engine]) dependencies
Gets a set of all the documents that are (transitive) dependencies of this document, not including the document itself.
278 279 280 281 |
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 278
def dependencies
_dependencies(Set.new, engines = Set.new)
engines - [self]
end
|
- (String) render Also known as: to_css
Render the template to CSS.
245 246 247 248 |
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 245
def render
return _render unless @options[:quiet]
Sass::Util.silence_sass_warnings {_render}
end
|
- (Encoding?) source_encoding
Returns the original encoding of the document, or nil under Ruby 1.8.
268 269 270 271 |
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 268
def source_encoding
check_encoding!
@original_encoding
end
|
- (Sass::Tree::Node) to_tree
Parses the document into its parse tree. Memoized.
255 256 257 258 259 |
# File '/var/www/sass-pages/.sass/lib/sass/engine.rb', line 255
def to_tree
@tree ||= @options[:quiet] ?
Sass::Util.silence_sass_warnings {_to_tree} :
_to_tree
end
|