Class: Sass::Tree::RootNode

Inherits:
Node show all
Defined in:
lib/sass/tree/root_node.rb

Overview

A static node that is the root node of the Sass document.

Direct Known Subclasses

ImportNode

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #filename, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #==, #_cssize, #_perform, #balance, #interpolate, #invalid_child?, #invisible?, #last, #perform_children, #render, #style, #to_sass

Constructor Details

#initialize(template) ⇒ RootNode

Returns a new instance of RootNode.

Parameters:

  • template (String)

    The Sass template from which this node was created



11
12
13
14
# File 'lib/sass/tree/root_node.rb', line 11

def initialize(template)
  super()
  @template = template
end

Instance Attribute Details

#template (readonly)

The Sass template from which this node was created

Parameters:

  • template (String)


8
9
10
# File 'lib/sass/tree/root_node.rb', line 8

def template
  @template
end

Instance Method Details

#_to_s(*args) ⇒ String (protected)

Computes the CSS corresponding to this Sass tree.

Parameters:

  • args (Array)

    ignored

Returns:

  • (String)

    The resulting CSS

See Also:



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

def _to_s(*args)
  result = String.new
  children.each do |child|
    next if child.invisible?
    child_str = child.to_s(1)
    result << child_str + (style == :compressed ? '' : "\n")
  end
  result.rstrip!
  return "" if result.empty?
  return result + "\n"
end

#cssize(*args)

See Also:



34
35
36
37
38
39
# File 'lib/sass/tree/root_node.rb', line 34

def cssize(*args)
  super
rescue Sass::SyntaxError => e
  e.sass_template = @template
  raise e
end

#cssize!(parent) (protected)

Destructively converts this static Sass node into a static CSS node, and checks that there are no properties at root level.

Parameters:

  • parent (Node, nil)

    The parent node of this node. This should only be non-nil if the parent is the same class as this node

Raises:

See Also:



55
56
57
58
59
60
61
# File 'lib/sass/tree/root_node.rb', line 55

def cssize!(parent)
  super
  return unless child = children.find {|c| c.is_a?(PropNode)}
  message = "Properties aren't allowed at the root of a document." +
    child.pseudo_class_selector_message
  raise Sass::SyntaxError.new(message, :line => child.line)
end

#perform(environment)

See Also:



25
26
27
28
29
30
31
# File 'lib/sass/tree/root_node.rb', line 25

def perform(environment)
  environment.options = @options if environment.options.nil? || environment.options.empty?
  super
rescue Sass::SyntaxError => e
  e.sass_template = @template
  raise e
end

#perform!(environment)

See Also:

  • Sass::Tree::RootNode.\{Node\{Node#perform!}


42
43
44
45
# File 'lib/sass/tree/root_node.rb', line 42

def perform!(environment)
  environment.options = @options if environment.options.nil? || environment.options.empty?
  super
end

#to_s(*args)

See Also:



17
18
19
20
21
22
# File 'lib/sass/tree/root_node.rb', line 17

def to_s(*args)
  super
rescue Sass::SyntaxError => e
  e.sass_template = @template
  raise e
end