Class: Sass::Tree::Node
- Inherits:
-
Object
show all
- Defined in:
- lib/sass/css.rb,
lib/sass/tree/node.rb
Direct Known Subclasses
AttrNode, CommentNode, DebugNode, DirectiveNode, FileNode, ForNode, IfNode, MixinDefNode, MixinNode, RuleNode, VariableNode, WhileNode
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Node
Returns a new instance of Node.
9
10
11
|
# File 'lib/sass/tree/node.rb', line 9
def initialize
@children = []
end
|
Instance Attribute Details
Returns the value of attribute children.
4
5
6
|
# File 'lib/sass/tree/node.rb', line 4
def children
@children
end
|
18
19
20
|
# File 'lib/sass/tree/node.rb', line 18
def filename
@filename || @options[:filename]
end
|
Returns the value of attribute line.
5
6
7
|
# File 'lib/sass/tree/node.rb', line 5
def line
@line
end
|
Returns the value of attribute options.
7
8
9
|
# File 'lib/sass/tree/node.rb', line 7
def options
@options
end
|
Instance Method Details
#<<(child) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/sass/tree/node.rb', line 22
def <<(child)
if msg = invalid_child?(child)
raise Sass::SyntaxError.new(msg, child.line)
end
@children << child
end
|
#==(other) ⇒ Object
34
35
36
|
# File 'lib/sass/tree/node.rb', line 34
def ==(other)
self.class == other.class && other.children == children
end
|
#invisible? ⇒ Boolean
42
|
# File 'lib/sass/tree/node.rb', line 42
def invisible?; false; end
|
We need this because Node duck types as an Array in engine.rb
30
31
32
|
# File 'lib/sass/tree/node.rb', line 30
def last
children.last
end
|
59
60
61
62
63
|
# File 'lib/sass/tree/node.rb', line 59
def perform(environment)
environment.options = @options if self.class == Tree::Node
_perform(environment)
rescue Sass::SyntaxError => e; e.add_metadata(filename, line)
end
|
38
39
40
|
# File 'lib/sass/tree/node.rb', line 38
def render
perform(Environment.new).to_s
end
|
65
66
67
|
# File 'lib/sass/tree/node.rb', line 65
def style
@options[:style]
end
|
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/sass/tree/node.rb', line 44
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
next if child.invisible?
child_str = child.to_s(1)
result << child_str + (style == :compressed ? '' : "\n")
end
end
style == :compressed ? result+"\n" : result[0...-1]
rescue Sass::SyntaxError => e; e.add_metadata(filename, line)
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
|