Class Sass::Tree::RootNode
In: lib/sass/tree/root_node.rb
Parent: Node

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

Methods

_to_s   cssize   invalid_child?   new   perform   perform!   render   to_s   to_sass   to_scss   to_src  

Attributes

template  [R]  The Sass template from which this node was created

@param template [String]

Public Class methods

@param template [String] The Sass template from which this node was created

[Source]

    # File lib/sass/tree/root_node.rb, line 11
11:       def initialize(template)
12:         super()
13:         @template = template
14:       end

Public Instance methods

Like {Node#cssize}, except that this method will create its own `extends` map if necessary, and it returns that map along with the cssized tree.

@return [(Tree::Node, Haml::Util::SubsetMap)] The resulting tree of static nodes

  *and* the extensions defined for this tree

[Source]

    # File lib/sass/tree/root_node.rb, line 49
49:       def cssize(extends = Haml::Util::SubsetMap.new, parent = nil)
50:         return super(extends), extends
51:       rescue Sass::SyntaxError => e
52:         e.sass_template = @template
53:         raise e
54:       end

@see Node#perform

[Source]

    # File lib/sass/tree/root_node.rb, line 35
35:       def perform(environment)
36:         environment.options = @options if environment.options.nil? || environment.options.empty?
37:         super
38:       rescue Sass::SyntaxError => e
39:         e.sass_template = @template
40:         raise e
41:       end

@see \{Node#perform!}

[Source]

    # File lib/sass/tree/root_node.rb, line 57
57:       def perform!(environment)
58:         environment.options = @options if environment.options.nil? || environment.options.empty?
59:         super
60:       end

Runs the dynamic Sass code and computes the CSS for the tree.

@see perform @see to_s

[Source]

    # File lib/sass/tree/root_node.rb, line 28
28:       def render
29:         result, extends = perform(Environment.new).cssize
30:         result = result.do_extend(extends) unless extends.empty?
31:         result.to_s
32:       end

@see Node#to_s

[Source]

    # File lib/sass/tree/root_node.rb, line 17
17:       def to_s(*args)
18:         super
19:       rescue Sass::SyntaxError => e
20:         e.sass_template = @template
21:         raise e
22:       end

Converts a node to Sass code that will generate it.

@param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize}) @return [String] The Sass code corresponding to the node

[Source]

    # File lib/sass/tree/root_node.rb, line 66
66:       def to_sass(opts = {})
67:         to_src(opts, :sass)
68:       end

Converts a node to SCSS code that will generate it.

@param opts [{Symbol => Object}] An options hash (see {Sass::CSS#initialize}) @return [String] The SCSS code corresponding to the node

[Source]

    # File lib/sass/tree/root_node.rb, line 74
74:       def to_scss(opts = {})
75:         to_src(opts, :scss)
76:       end

Protected Instance methods

Computes the CSS corresponding to this Sass tree.

@param args [Array] ignored @return [String] The resulting CSS @see Sass::Tree

[Source]

     # File lib/sass/tree/root_node.rb, line 100
100:       def _to_s(*args)
101:         result = String.new
102:         children.each do |child|
103:           next if child.invisible?
104:           child_str = child.to_s(1)
105:           result << child_str + (style == :compressed ? '' : "\n")
106:         end
107:         result.rstrip!
108:         return "" if result.empty?
109:         return result + "\n"
110:       end

Returns an error message if the given child node is invalid, and false otherwise.

Only property nodes are invalid at root level.

@see Node#invalid_child?

[Source]

     # File lib/sass/tree/root_node.rb, line 118
118:       def invalid_child?(child)
119:         return unless child.is_a?(Tree::PropNode)
120:         "Properties aren't allowed at the root of a document." +
121:           child.pseudo_class_selector_message
122:       end

@see Node#to_src

[Source]

    # File lib/sass/tree/root_node.rb, line 81
81:       def to_src(opts, fmt)
82:         Haml::Util.enum_cons(children + [nil], 2).map do |child, nxt|
83:           child.send("to_#{fmt}", 0, opts) +
84:             if nxt &&
85:                 (child.is_a?(CommentNode) && child.line + child.value.count("\n") + 1 == nxt.line) ||
86:                 (child.is_a?(ImportNode) && nxt.is_a?(ImportNode) && child.line + 1 == nxt.line) ||
87:                 (child.is_a?(VariableNode) && nxt.is_a?(VariableNode) && child.line + 1 == nxt.line)
88:               ""
89:             else
90:               "\n"
91:             end
92:         end.join.rstrip + "\n"
93:       end

[Validate]