Class: Sass::Tree::CommentNode
- Defined in:
- lib/sass/tree/comment_node.rb
Overview
A static node representing a Sass comment (silent or loud).
Instance Attribute Summary collapse
-
#lines ⇒ Array<Sass::Engine::Line>
The lines of text nested beneath the comment.
-
#silent ⇒ Boolean
Whether or not the comment is silent (that is, doesn't output to CSS).
-
#value ⇒ String
The text on the same line as the comment starter.
Attributes inherited from Node
#children, #filename, #line, #options
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the contents of two comments.
-
#_perform(environment) ⇒ Tree::Node+
protected
Removes this node from the tree if it's a silent comment.
-
#to_s(tabs = 0) ⇒ String?
protected
Computes the CSS for the comment.
-
#initialize(value, silent) ⇒ CommentNode
constructor
A new instance of CommentNode.
-
#invisible? ⇒ Boolean
Returns
true
if this is a silent comment or the current style doesn't render comments.
Methods inherited from Node
#<<, #balance, #interpolate, #invalid_child?, #last, #perform, #perform!, #perform_children, #render, #style, #to_s, #to_sass
Constructor Details
#initialize(value, silent) ⇒ CommentNode
Returns a new instance of CommentNode.
25 26 27 28 29 30 |
# File 'lib/sass/tree/comment_node.rb', line 25
def initialize(value, silent)
@lines = []
@value = value[2..-1].strip
@silent = silent
super()
end
|
Instance Attribute Details
#lines ⇒ Array<Sass::Engine::Line>
The lines of text nested beneath the comment.
11 12 13 |
# File 'lib/sass/tree/comment_node.rb', line 11
def lines
@lines
end
|
#silent ⇒ Boolean
Whether or not the comment is silent (that is, doesn't output to CSS).
21 22 23 |
# File 'lib/sass/tree/comment_node.rb', line 21
def silent
@silent
end
|
#value ⇒ String
The text on the same line as the comment starter.
16 17 18 |
# File 'lib/sass/tree/comment_node.rb', line 16
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares the contents of two comments.
37 38 39 |
# File 'lib/sass/tree/comment_node.rb', line 37
def ==(other)
self.class == other.class && value == other.value && silent == other.silent && lines == other.lines
end
|
#_perform(environment) ⇒ Tree::Node+ (protected)
Removes this node from the tree if it's a silent comment.
79 80 81 82 |
# File 'lib/sass/tree/comment_node.rb', line 79
def _perform(environment)
return [] if @silent
self
end
|
#to_s(tabs = 0) ⇒ String? (protected)
Computes the CSS for the comment.
Returns nil
if this is a silent comment
or the current style doesn't render comments.
60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sass/tree/comment_node.rb', line 60
def _to_s(tabs = 0, _ = nil)
return if invisible?
spaces = ' ' * (tabs - 1)
content = (value.split("\n") + lines.map {|l| l.text})
return spaces + "/* */" if content.empty?
content.map! {|l| (l.empty? ? "" : " ") + l}
content.first.gsub!(/^ /, '')
content.last.gsub!(%r{ ?\*/ *$}, '')
spaces + "/* " + content.join(style == :compact ? '' : "\n#{spaces} *") + " */"
end
|
#invisible? ⇒ Boolean
Returns true
if this is a silent comment
or the current style doesn't render comments.
45 46 47 |
# File 'lib/sass/tree/comment_node.rb', line 45
def invisible?
style == :compressed || @silent
end
|