Class: Sass::Tree::Node

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

Direct Known Subclasses

ValueNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style) ⇒ Node

Returns a new instance of Node.



8
9
10
11
# File 'lib/gems/haml-2.0.4/lib/sass/tree/node.rb', line 8

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

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



4
5
6
# File 'lib/gems/haml-2.0.4/lib/sass/tree/node.rb', line 4

def children
  @children
end

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/gems/haml-2.0.4/lib/sass/tree/node.rb', line 6

def filename
  @filename
end

#lineObject

Returns the value of attribute line.



5
6
7
# File 'lib/gems/haml-2.0.4/lib/sass/tree/node.rb', line 5

def line
  @line
end

Instance Method Details

#<<(child) ⇒ Object



13
14
15
16
17
18
# File 'lib/gems/haml-2.0.4/lib/sass/tree/node.rb', line 13

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

#to_sObject



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gems/haml-2.0.4/lib/sass/tree/node.rb', line 20

def to_s
  result = String.new
  children.each do |child|
    if child.is_a? AttrNode
      raise 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/gems/haml-2.0.4/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