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.

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, #cssize, #invalid_child?, #perform, #to_s, #to_src

Methods inherited from Node

#<<, #==, #_to_s, #balance, #check_child!, #children_to_src, #cssize, #cssize!, #dasherize, #do_extend, #each, #invalid_child?, #perform, #perform_children, #render, #run_interp, #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:



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

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



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

def _perform(environment)
  return DirectiveNode.new("@import url(#{full_filename})") if full_filename =~ /\.css$/
  super
end

#full_filenameString

Returns the resolved name of the imported file, as returned by Files#find_file_to_import.

Returns:

  • (String)

    The filename of the imported file. This is an absolute path if the file is a ".sass" or ".scss" file.

Raises:

  • (Sass::SyntaxError)

    if filename ends in ".sass" or ".scss" and no corresponding Sass file could be found.



27
28
29
# File 'lib/sass/tree/import_node.rb', line 27

def full_filename
  @full_filename ||= 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



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/sass/tree/import_node.rb', line 66

def perform!(environment)
  environment.push_frame(:filename => @filename, :line => @line)
  root = Sass::Files.tree_for(full_filename, @options)
  @template = root.template
  self.children = root.children
  self.children = perform_children(environment)
rescue Sass::SyntaxError => e
  e.modify_backtrace(:filename => full_filename)
  e.add_backtrace(:filename => @filename, :line => @line)
  raise e
ensure
  environment.pop_frame
end

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

See Also:



32
33
34
# File 'lib/sass/tree/import_node.rb', line 32

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

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

See Also:



37
38
39
# File 'lib/sass/tree/import_node.rb', line 37

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