Module: Sass::Files
Overview
This module contains various bits of functionality related to finding and caching Sass files.
Instance Method Summary collapse
-
#find_file_to_import(filename, load_paths) ⇒ String
Find the full filename of a Sass or CSS file to import.
-
#tree_for(filename, options) ⇒ Object
Returns the Tree for the given file, reading it from the Sass cache if possible.
Instance Method Details
#find_file_to_import(filename, load_paths) ⇒ String
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.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sass/files.rb', line 59
def find_file_to_import(filename, load_paths)
was_sass = false
original_filename = filename
if filename[-5..-1] == ".sass"
filename = filename[0...-5]
was_sass = true
elsif filename[-4..-1] == ".css"
return filename
end
new_filename = find_full_path("#{filename}.sass", load_paths)
return new_filename if new_filename
return filename + '.css' unless was_sass
raise SyntaxError.new("File to import not found or unreadable: #{original_filename}.")
end
|
#tree_for(filename, options) ⇒ Object
Returns the Tree for the given file, reading it from the Sass cache if possible.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sass/files.rb', line 18
def tree_for(filename, options)
options = Sass::Engine::DEFAULT_OPTIONS.merge(options)
text = File.read(filename)
if options[:cache]
compiled_filename = sassc_filename(filename, options)
sha = Digest::SHA1.hexdigest(text)
if root = try_to_read_sassc(filename, compiled_filename, sha)
root.options = options.merge(:filename => filename)
return root
end
end
engine = Sass::Engine.new(text, options.merge(:filename => filename))
root = engine.to_tree
try_to_write_sassc(root, compiled_filename, sha, options) if options[:cache]
root
end
|