2008-10-15 20:36:39 -07:00
|
|
|
module Sass
|
|
|
|
module Tree
|
2009-04-25 12:36:33 -07:00
|
|
|
# A static node that wraps the {Sass::Tree} for an `@import`ed file.
|
|
|
|
# It doesn't have a functional purpose other than to add the `@import`ed file
|
|
|
|
# to the backtrace if an error occurs.
|
2009-09-14 01:34:16 -07:00
|
|
|
class ImportNode < RootNode
|
2009-07-12 10:21:21 -04:00
|
|
|
# @param imported_filename [String] The name of the imported file
|
|
|
|
def initialize(imported_filename)
|
|
|
|
@imported_filename = imported_filename
|
2009-09-14 02:11:02 -07:00
|
|
|
super(nil)
|
2008-10-15 20:36:39 -07:00
|
|
|
end
|
|
|
|
|
2009-09-14 01:34:16 -07:00
|
|
|
def invisible?; to_s.empty?; end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2009-04-25 12:36:33 -07:00
|
|
|
# Computes the CSS for the imported file.
|
|
|
|
#
|
|
|
|
# @param args [Array] Ignored
|
2009-09-14 01:34:16 -07:00
|
|
|
def _to_s(*args)
|
|
|
|
@to_s ||= (style == :compressed ? super.strip : super)
|
2008-10-15 20:36:39 -07:00
|
|
|
rescue Sass::SyntaxError => e
|
2009-09-13 19:46:41 -07:00
|
|
|
e.modify_backtrace(:filename => children.first.filename)
|
2009-09-13 15:52:59 -07:00
|
|
|
e.add_backtrace(:filename => @filename, :line => @line)
|
2008-10-15 20:36:39 -07:00
|
|
|
raise e
|
|
|
|
end
|
|
|
|
|
2009-04-25 12:52:46 -07:00
|
|
|
# Parses the imported file
|
|
|
|
# and runs the dynamic Sass for it.
|
2009-04-25 12:36:33 -07:00
|
|
|
#
|
|
|
|
# @param environment [Sass::Environment] The lexical environment containing
|
|
|
|
# variable and mixin values
|
2008-10-15 20:36:39 -07:00
|
|
|
def perform!(environment)
|
2009-07-12 10:21:21 -04:00
|
|
|
return unless full_filename = import
|
2009-09-14 02:11:02 -07:00
|
|
|
root = Sass::Files.tree_for(full_filename, @options)
|
|
|
|
@template = root.template
|
|
|
|
self.children = root.children
|
2008-10-15 20:36:39 -07:00
|
|
|
self.children = perform_children(environment)
|
|
|
|
rescue Sass::SyntaxError => e
|
2009-09-13 19:46:41 -07:00
|
|
|
e.modify_backtrace(:filename => full_filename)
|
2009-09-13 15:52:59 -07:00
|
|
|
e.add_backtrace(:filename => @filename, :line => @line)
|
2008-10-15 20:36:39 -07:00
|
|
|
raise e
|
|
|
|
end
|
2009-07-12 10:21:21 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def import_paths
|
|
|
|
paths = (@options[:load_paths] || []).dup
|
|
|
|
paths.unshift(File.dirname(@options[:filename])) if @options[:filename]
|
|
|
|
paths
|
|
|
|
end
|
|
|
|
|
|
|
|
def import
|
|
|
|
begin
|
|
|
|
full_filename = Sass::Files.find_file_to_import(@imported_filename, import_paths)
|
|
|
|
rescue Exception => e
|
2009-09-13 15:52:59 -07:00
|
|
|
raise SyntaxError.new(e.message, :line => self.line, :filename => @filename)
|
2009-07-12 10:21:21 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
if full_filename =~ /\.css$/
|
|
|
|
@to_s = "@import url(#{full_filename});"
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
return full_filename
|
|
|
|
end
|
2008-10-15 20:36:39 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|