class Sass::Tree::CommentNode
A static node representing a Sass
comment (silent or loud).
@see Sass::Tree
Attributes
The text of the comment after any interpolated SassScript has been resolved. Only set once {Tree::Visitors::Perform} has been run.
@return [String]
The type of the comment. ‘:silent` means it’s never output to CSS
, ‘:normal` means it’s output in every compile mode except ‘:compressed`, and `:loud` means it’s output even in ‘:compressed`.
@return [Symbol]
The text of the comment, not including ‘/*` and `*/`. Interspersed with {Sass::Script::Tree::Node}s representing `#{}`-interpolation if this is a loud comment.
@return [Array<String, Sass::Script::Tree::Node
>]
Public Class Methods
@param value [Array<String, Sass::Script::Tree::Node
>] See {#value} @param type [Symbol] See {#type}
# File lib/sass/tree/comment_node.rb, line 31 def initialize(value, type) @value = Sass::Util.with_extracted_values(value) {|str| normalize_indentation str} @type = type super() end
Public Instance Methods
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 42 def ==(other) self.class == other.class && value == other.value && type == other.type end
Returns ‘true` if this is a silent comment or the current style doesn’t render comments.
Comments starting with ! are never invisible (and the ! is removed from the output.)
@return [Boolean]
# File lib/sass/tree/comment_node.rb, line 52 def invisible? case @type when :loud; false when :silent; true else; style == :compressed end end
Returns the number of lines in the comment.
@return [Integer]
# File lib/sass/tree/comment_node.rb, line 63 def lines @value.inject(0) do |s, e| next s + e.count("\n") if e.is_a?(String) next s end end
Private Instance Methods
# File lib/sass/tree/comment_node.rb, line 72 def normalize_indentation(str) ind = str.split("\n").inject(str[/^[ \t]*/].split("")) do |pre, line| line[/^[ \t]*/].split("").zip(pre).inject([]) do |arr, (a, b)| break arr if a != b arr << a end end.join str.gsub(/^#{ind}/, '') end