Module Sass::Files
In: lib/sass/files.rb

This module contains various bits of functionality related to finding and caching Sass files.

Methods

Public Instance methods

Find the full filename of a Sass or CSS file to import. This follows Sass‘s import rules: if the filename given ends in `".sass"` or `".css"`, it will try to find that type of file; otherwise, it will try to find the corresponding Sass file and fall back on CSS if it‘s not available.

Any Sass filename returned will correspond to an actual Sass file on the filesystem. CSS filenames, however, may not; they‘re expected to be put through directly to the stylesheet as CSS `@import` statements.

@param filename [String] The filename to search for @param load_paths [Array<String>] The set of filesystem paths

  to search for Sass files.

@return [String] The filename of the imported file.

  This is an absolute path if the file is a `".sass"` file.

@raise [Sass::SyntaxError] if `filename` ends in ``".sass"``

  and no corresponding Sass file could be found.

[Source]

    # File lib/sass/files.rb, line 65
65:     def find_file_to_import(filename, load_paths)
66:       was_sass = false
67:       original_filename = filename
68: 
69:       if filename[-5..-1] == ".sass"
70:         filename = filename[0...-5]
71:         was_sass = true
72:       elsif filename[-4..-1] == ".css"
73:         return filename
74:       end
75: 
76:       new_filename = find_full_path("#{filename}.sass", load_paths)
77: 
78:       return new_filename if new_filename
79:       return filename + '.css' unless was_sass
80:       raise SyntaxError.new("File to import not found or unreadable: #{original_filename}.", @line)
81:     end

Returns the {Sass::Tree} for the given file, reading it from the Sass cache if possible.

@param filename [String] The path to the Sass file @param options [Hash<Symbol, Object>] The options hash.

  Only the {file:SASS_REFERENCE.md#cache-option `:cache_location`} option is used

@raise [Sass::SyntaxError] if there‘s an error in the document

[Source]

    # File lib/sass/files.rb, line 17
17:     def tree_for(filename, options)
18:       options = Sass::Engine::DEFAULT_OPTIONS.merge(options)
19:       text = File.read(filename)
20: 
21:       if options[:cache]
22:         compiled_filename = sassc_filename(filename, options)
23:         sha = Digest::SHA1.hexdigest(text)
24: 
25:         if root = try_to_read_sassc(filename, compiled_filename, sha)
26:           root.options = options.merge(:filename => filename)
27:           return root
28:         end
29:       end
30: 
31:       engine = Sass::Engine.new(text, options.merge(:filename => filename))
32: 
33:       begin
34:         root = engine.to_tree
35:       rescue Sass::SyntaxError => err
36:         err.add_backtrace_entry(filename)
37:         raise err
38:       end
39: 
40:       try_to_write_sassc(root, compiled_filename, sha, options) if options[:cache]
41: 
42:       root
43:     end

[Validate]