Class: Sass::Tree::CommentNode

Inherits:
Node show all
Defined in:
lib/sass/tree/comment_node.rb

Overview

A static node representing a Sass comment (silent or loud).

See Also:

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #filename, #line, #options

Instance Method Summary collapse

Methods inherited from Node

#<<, #last, #perform, #render, #style, #to_sass

Constructor Details

#initialize(value, silent) ⇒ CommentNode

Returns a new instance of CommentNode.

Parameters:



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

#linesArray<Sass::Engine::Line>

The lines of text nested beneath the comment.

Returns:



11
12
13
# File 'lib/sass/tree/comment_node.rb', line 11

def lines
  @lines
end

#silentBoolean

Whether or not the comment is silent (that is, doesn’t output to CSS).

Returns:

  • (Boolean)


21
22
23
# File 'lib/sass/tree/comment_node.rb', line 21

def silent
  @silent
end

#valueString

The text on the same line as the comment starter.

Returns:

  • (String)


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.

Parameters:

  • other (Object)

    The object to compare with

Returns:

  • (Boolean)

    Whether or not this node and the other object are the same



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

#invisible?Boolean

Returns ‘true` if this is a silent comment or the current style doesn’t render comments.

Returns:

  • (Boolean)


66
67
68
# File 'lib/sass/tree/comment_node.rb', line 66

def invisible?
  style == :compressed || @silent
end

#to_s(tabs = 0) ⇒ String?

Computes the CSS for the comment.

Returns ‘nil` if this is a silent comment or the current style doesn’t render comments.

Parameters:

  • tabs (Fixnum) (defaults to: 0)

    The level of indentation for the CSS

Returns:

  • (String, nil)

    The resulting CSS

See Also:



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sass/tree/comment_node.rb', line 50

def to_s(tabs = 0, _ = nil)
  return if invisible?

  content = (value.split("\n") + lines.map {|l| l.text})
  content.map! {|l| (l.empty? ? "" : " ") + l}
  content.first.gsub!(/^ /, '')
  content.last.gsub!(%r{ ?\*/ *$}, '')

  spaces = '  ' * (tabs - 1)
  spaces + "/* " + content.join(style == :compact ? '' : "\n#{spaces} *") + " */"
end