Class: Sass::Tree::Node

Inherits:
Object show all
Defined in:
lib/sass/css.rb,
lib/sass/tree/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Node

Returns a new instance of Node.



8
9
10
11
12
# File 'lib/sass/tree/node.rb', line 8

def initialize(options)
  @options = options
  @style = options[:style]
  @children = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/sass/tree/node.rb', line 4

def children
  @children
end

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/sass/tree/node.rb', line 6

def filename
  @filename
end

#lineObject

Returns the value of attribute line.



5
6
7
# File 'lib/sass/tree/node.rb', line 5

def line
  @line
end

Instance Method Details

#<<(child) ⇒ Object



14
15
16
17
18
19
# File 'lib/sass/tree/node.rb', line 14

def <<(child)
  if msg = invalid_child?(child)
    raise Sass::SyntaxError.new(msg, child.line)
  end
  @children << child
end

#==(other) ⇒ Object



26
27
28
# File 'lib/sass/tree/node.rb', line 26

def ==(other)
  self.class == other.class && other.children == children
end

#lastObject

We need this because Node duck types as an Array in engine.rb



22
23
24
# File 'lib/sass/tree/node.rb', line 22

def last
  children.last
end

#perform(environment) ⇒ Object



42
43
44
45
46
47
# File 'lib/sass/tree/node.rb', line 42

def perform(environment)
  _perform(environment)
rescue Sass::SyntaxError => e
  e.sass_line ||= line
  raise e
end

#to_sObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sass/tree/node.rb', line 30

def to_s
  result = String.new
  children.each do |child|
    if child.is_a? AttrNode
      raise Sass::SyntaxError.new('Attributes aren\'t allowed at the root of a document.', child.line)
    else
      result << "#{child.to_s(1)}" + (@style == :compressed ? '' : "\n")
    end
  end
  @style == :compressed ? result+"\n" : result[0...-1]
end

#to_sass(opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/sass/css.rb', line 9

def to_sass(opts = {})
  result = ''

  children.each do |child|
    result << "#{child.to_sass(0, opts)}\n"
  end

  result
end