| Class | Sass::Tree::CommentNode |
| In: |
lib/sass/tree/comment_node.rb
|
| Parent: | Node |
A static node representing a Sass comment (silent or loud).
@see Sass::Tree
| lines | [RW] |
The lines of text nested beneath the comment.
@return [Array<Sass::Engine::Line>] |
| silent | [RW] |
Whether or not the comment is silent (that is, doesn‘t output to CSS).
@return [Boolean] |
| value | [RW] |
The text on the same line as the comment starter.
@return [String] |
@param value [String] See \{value} @param silent [Boolean] See \{silent}
# File lib/sass/tree/comment_node.rb, line 25
25: def initialize(value, silent)
26: @lines = []
27: @value = value[2..-1].strip
28: @silent = silent
29: super()
30: end
Compares the contents of two comments.
@param other [Object] The object to compare with @return [Boolean] Whether or not this node and the other object
are the same
# File lib/sass/tree/comment_node.rb, line 37
37: def ==(other)
38: self.class == other.class && value == other.value && silent == other.silent && lines == other.lines
39: end
Returns `true` if this is a silent comment or the current style doesn‘t render comments.
@return [Boolean]
# File lib/sass/tree/comment_node.rb, line 67
67: def invisible?
68: style == :compressed || @silent
69: end
Computes the CSS for the comment.
Returns `nil` if this is a silent comment or the current style doesn‘t render comments.
@overload to_s(tabs = 0) @param tabs [Fixnum] The level of indentation for the CSS @return [String, nil] The resulting CSS @see invisible?
# File lib/sass/tree/comment_node.rb, line 50
50: def to_s(tabs = 0, _ = nil)
51: return if invisible?
52: spaces = ' ' * (tabs - 1)
53:
54: content = (value.split("\n") + lines.map {|l| l.text})
55: return spaces + "/* */" if content.empty?
56: content.map! {|l| (l.empty? ? "" : " ") + l}
57: content.first.gsub!(/^ /, '')
58: content.last.gsub!(%r{ ?\*/ *$}, '')
59:
60: spaces + "/* " + content.join(style == :compact ? '' : "\n#{spaces} *") + " */"
61: end
Removes this node from the tree if it‘s a silent comment.
@param environment [Sass::Environment] The lexical environment containing
variable and mixin values
@return [Tree::Node, Array<Tree::Node>] The resulting static nodes @see Sass::Tree
# File lib/sass/tree/comment_node.rb, line 79
79: def _perform(environment)
80: return [] if @silent
81: self
82: end