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
silent | [RW] |
Whether or not the comment is silent (that is, doesn‘t output to CSS).
@return [Boolean] |
value | [RW] |
The text of the comment, not including `/*` and `*/`.
@return [String] |
@param value [String] See \{value} @param silent [Boolean] See \{silent}
# File lib/sass/tree/comment_node.rb, line 20 20: def initialize(value, silent) 21: @lines = [] 22: @value = normalize_indentation value 23: @silent = silent 24: super() 25: 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 32 32: def ==(other) 33: self.class == other.class && value == other.value && silent == other.silent 34: 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 40 40: def invisible? 41: style == :compressed || @silent 42: end
@see Node#to_sass
# File lib/sass/tree/comment_node.rb, line 45 45: def to_sass(tabs, opts = {}) 46: content = value.gsub(/\*\/$/, '').rstrip 47: if content =~ /\A[ \t]/ 48: # Re-indent SCSS comments like this: 49: # /* foo 50: # bar 51: # baz */ 52: content.gsub!(/^/, ' ') 53: content.sub!(/\A([ \t]*)\/\*/, '/*\1') 54: end 55: 56: content = 57: unless content.include?("\n") 58: content 59: else 60: content.gsub!(/\n( \*|\/\/)/, "\n ") 61: spaces = content.scan(/\n( *)/).map {|s| s.first.size}.min 62: sep = silent ? "\n//" : "\n *" 63: if spaces >= 2 64: content.gsub(/\n /, sep) 65: else 66: content.gsub(/\n#{' ' * spaces}/, sep) 67: end 68: end 69: 70: content.gsub!(/\A\/\*/, '//') if silent 71: content.gsub!(/^/, ' ' * tabs) 72: content.rstrip + "\n" 73: end
@see Node#to_scss
# File lib/sass/tree/comment_node.rb, line 76 76: def to_scss(tabs, opts = {}) 77: spaces = (' ' * [tabs - value[/^ */].size, 0].max) 78: if silent 79: value.gsub(/^[\/ ]\*/, '//').gsub(/ *\*\/$/, '') 80: else 81: value 82: end.gsub(/^/, spaces) + "\n" 83: 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 111 111: def _perform(environment) 112: return [] if @silent 113: self 114: 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 96 96: def _to_s(tabs = 0, _ = nil) 97: return if invisible? 98: spaces = (' ' * [tabs - 1 - value[/^ */].size, 0].max) 99: 100: content = value.gsub(/^/, spaces) 101: content.gsub!(/\n +(\* *)?/, ' ') if style == :compact 102: content 103: end
# File lib/sass/tree/comment_node.rb, line 118 118: def normalize_indentation(str) 119: pre = str.split("\n").inject(str[/^[ \t]*/].split("")) do |pre, line| 120: line[/^[ \t]*/].split("").zip(pre).inject([]) do |arr, (a, b)| 121: break arr if a != b 122: arr + [a] 123: end 124: end.join 125: str.gsub(/^#{pre}/, '') 126: end