Class: Sass::Tree::RootNode
Overview
A static node that is the root node of the Sass document.
Direct Known Subclasses
Instance Attribute Summary
- - template readonly The Sass template from which this node was created.
Instance Method Summary
- - (String) _to_s(*args) protected Computes the CSS corresponding to this Sass tree.
-
- ((Tree::Node, Haml::Util::SubsetMap)) cssize(extends = Haml::Util::SubsetMap.new, parent = nil)
Like Node#cssize, except that this method will create its own
extendsmap if necessary, and it returns that map along with the cssized tree. - - (RootNode) initialize(template) constructor A new instance of RootNode.
- - (Boolean) invalid_child?(child) protected Returns an error message if the given child node is invalid, and false otherwise.
- - perform(environment)
- - perform!(environment)
- - render Runs the dynamic Sass code and computes the CSS for the tree.
- - to_s(*args)
- - (String) to_sass(opts = {}) Converts a node to Sass code that will generate it.
- - (String) to_scss(opts = {}) Converts a node to SCSS code that will generate it.
- - to_src(opts, fmt) protected
Methods inherited from Node
#<<, #==, #_cssize, #_perform, #balance, #check_child!, #children_to_src, #cssize!, #dasherize, #do_extend, #each, #invisible?, #perform_children, #run_interp, #selector_to_sass, #selector_to_scss, #selector_to_src, #semi, #style
Constructor Details
- (RootNode) initialize(template)
A new instance of RootNode
11 12 13 14 |
# File '/var/www/sass-pages/.haml/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
8 9 10 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 8
def template
@template
end
|
Instance Method Details
- (String) _to_s(*args) (protected)
Computes the CSS corresponding to this Sass tree.
100 101 102 103 104 105 106 107 108 109 110 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 100
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
|
- ((Tree::Node, Haml::Util::SubsetMap)) cssize(extends = Haml::Util::SubsetMap.new, parent = nil)
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.
49 50 51 52 53 54 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 49
def cssize(extends = Haml::Util::SubsetMap.new, parent = nil)
return super(extends), extends
rescue Sass::SyntaxError => e
e.sass_template = @template
raise e
end
|
- (Boolean) invalid_child?(child) (protected)
Returns an error message if the given child node is invalid, and false otherwise.
Only property nodes are invalid at root level.
118 119 120 121 122 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 118
def invalid_child?(child)
return unless child.is_a?(Tree::PropNode)
"Properties aren't allowed at the root of a document." +
child.pseudo_class_selector_message
end
|
- perform(environment)
35 36 37 38 39 40 41 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 35
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)
57 58 59 60 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 57
def perform!(environment)
environment.options = @options if environment.options.nil? || environment.options.empty?
super
end
|
- render
Runs the dynamic Sass code and computes the CSS for the tree.
28 29 30 31 32 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 28
def render
result, extends = perform(Environment.new).cssize
result = result.do_extend(extends) unless extends.empty?
result.to_s
end
|
- to_s(*args)
17 18 19 20 21 22 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 17
def to_s(*args)
super
rescue Sass::SyntaxError => e
e.sass_template = @template
raise e
end
|
- (String) to_sass(opts = {})
Converts a node to Sass code that will generate it.
66 67 68 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 66
def to_sass(opts = {})
to_src(opts, :sass)
end
|
- (String) to_scss(opts = {})
Converts a node to SCSS code that will generate it.
74 75 76 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 74
def to_scss(opts = {})
to_src(opts, :scss)
end
|
- to_src(opts, fmt) (protected)
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File '/var/www/sass-pages/.haml/lib/sass/tree/root_node.rb', line 81
def to_src(opts, fmt)
Haml::Util.enum_cons(children + [nil], 2).map do |child, nxt|
child.send("to_#{fmt}", 0, opts) +
if nxt &&
(child.is_a?(CommentNode) && child.line + child.value.count("\n") + 1 == nxt.line) ||
(child.is_a?(ImportNode) && nxt.is_a?(ImportNode) && child.line + 1 == nxt.line) ||
(child.is_a?(VariableNode) && nxt.is_a?(VariableNode) && child.line + 1 == nxt.line)
""
else
"\n"
end
end.join.rstrip + "\n"
end
|