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

#<<, #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.

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

#_perform(environment) ⇒ Tree::Node+ (protected)

Removes this node from the tree if it's a silent comment.

Parameters:

  • environment (Sass::Environment)

    The lexical environment containing variable and mixin values

Returns:

See Also:



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.

Parameters:

  • tabs (Fixnum) (defaults to: 0)

    The level of indentation for the CSS

Returns:

  • (String, nil)

    The resulting CSS

See Also:



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.

Returns:

  • (Boolean)


45
46
47
# File 'lib/sass/tree/comment_node.rb', line 45

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