Class: Sass::Tree::ImportNode

Inherits:
RootNode show all
Defined in:
lib/sass/tree/import_node.rb

Overview

A static node that wraps the Sass::Tree for an @imported file. It doesn't have a functional purpose other than to add the @imported file to the backtrace if an error occurs.

Constant Summary

Constants inherited from Node

Node::SAVED_OPTIONS

Instance Attribute Summary collapse

Attributes inherited from RootNode

#template

Attributes inherited from Node

#children, #filename, #has_children, #line, #options

Instance Method Summary collapse

Methods inherited from RootNode

#_to_s, #invalid_child?, #perform, #render, #to_s, #to_src

Methods inherited from Node

#<<, #==, #_around_dump, #_to_s, #balance, #check_child!, #children_to_src, #cssize!, #dasherize, #do_extend, #each, #invalid_child?, #perform, #perform_children, #run_interp, #selector_to_sass, #selector_to_scss, #selector_to_src, #semi, #style, #to_s, #to_src

Constructor Details

#initialize(imported_filename) ⇒ ImportNode

Returns a new instance of ImportNode.

Parameters:

  • imported_filename (String)

    The name of the imported file



13
14
15
16
# File 'lib/sass/tree/import_node.rb', line 13

def initialize(imported_filename)
  @imported_filename = imported_filename
  super(nil)
end

Instance Attribute Details

#imported_filenameString (readonly)

The name of the imported file as it appears in the Sass document.

Returns:

  • (String)


10
11
12
# File 'lib/sass/tree/import_node.rb', line 10

def imported_filename
  @imported_filename
end

Instance Method Details

#_cssize(*args) (protected)

See Also:



57
58
59
60
61
62
63
# File 'lib/sass/tree/import_node.rb', line 57

def _cssize(*args)
  super.children
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => children.first.filename)
  e.add_backtrace(:filename => @filename, :line => @line)
  raise e
end

#_perform(environment) (protected)

Returns a static DirectiveNode if this is importing a CSS file, or parses and includes the imported Sass file.

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values



70
71
72
73
74
75
# File 'lib/sass/tree/import_node.rb', line 70

def _perform(environment)
  if path = css_import?
    return DirectiveNode.new("@import url(#{path})")
  end
  super
end

#css_import?Boolean

Returns whether or not this import should emit a CSS @import declaration

Returns:

  • (Boolean)

    Whether or not this is a simple CSS @import declaration.



46
47
48
49
50
51
52
# File 'lib/sass/tree/import_node.rb', line 46

def css_import?
  if @imported_filename =~ /\.css$/
    @imported_filename
  elsif imported_file.is_a?(String) && imported_file =~ /\.css$/
    imported_file
  end
end

#cssize(*args)

See Also:



39
40
41
# File 'lib/sass/tree/import_node.rb', line 39

def cssize(*args)
  super.first
end

#imported_fileSass::Engine

Returns the imported file.

Returns:

Raises:



24
25
26
# File 'lib/sass/tree/import_node.rb', line 24

def imported_file
  @imported_file ||= import
end

#invisible?Boolean

Returns:

  • (Boolean)


18
# File 'lib/sass/tree/import_node.rb', line 18

def invisible?; to_s.empty?; end

#perform!(environment) (protected)

Parses the imported file and runs the dynamic Sass for it.

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/sass/tree/import_node.rb', line 81

def perform!(environment)
  environment.push_frame(:filename => @filename, :line => @line)
  # TODO: re-enable caching
  root = imported_file.to_tree
  self.children = root.children
  self.children = perform_children(environment)
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => imported_file.options[:filename])
  e.add_backtrace(:filename => @filename, :line => @line)
  raise e
ensure
  environment.pop_frame
end

#to_sass(tabs = 0, opts = {})

See Also:



29
30
31
# File 'lib/sass/tree/import_node.rb', line 29

def to_sass(tabs = 0, opts = {})
  "#{'  ' * tabs}@import #{@imported_filename}\n"
end

#to_scss(tabs = 0, opts = {})

See Also:



34
35
36
# File 'lib/sass/tree/import_node.rb', line 34

def to_scss(tabs = 0, opts = {})
  "#{'  ' * tabs}@import \"#{@imported_filename}\";\n"
end