Class: Sass::Tree::CommentNode
- Defined in:
- lib/sass/tree/comment_node.rb
Overview
A static node representing a Sass comment (silent or loud).
Constant Summary
Constants inherited from Node
Instance Attribute Summary collapse
-
#silent ⇒ Boolean
Whether or not the comment is silent (that is, doesn't output to CSS).
-
#value ⇒ String
The text of the comment, not including
/*
and*/
.
Attributes inherited from Node
#children, #filename, #has_children, #line, #options
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares the contents of two comments.
-
#_perform(environment) ⇒ Tree::Node+
protected
Removes this node from the tree if it's a silent comment.
-
#to_s(tabs = 0) ⇒ String?
protected
Computes the CSS for the comment.
-
#initialize(value, silent) ⇒ CommentNode
constructor
A new instance of CommentNode.
-
#invisible? ⇒ Boolean
Returns
true
if this is a silent comment or the current style doesn't render comments. - #to_sass(tabs, opts = {})
- #to_scss(tabs, opts = {})
Methods inherited from Node
#<<, #_around_dump, #_cssize, #balance, #check_child!, #children_to_src, #cssize, #cssize!, #dasherize, #do_extend, #each, #invalid_child?, #perform, #perform!, #perform_children, #run_interp, #selector_to_sass, #selector_to_scss, #selector_to_src, #semi, #style, #to_s, #to_src
Constructor Details
#initialize(value, silent) ⇒ CommentNode
Returns a new instance of CommentNode.
20 21 22 23 24 25 |
# File 'lib/sass/tree/comment_node.rb', line 20
def initialize(value, silent)
@lines = []
@value = normalize_indentation value
@silent = silent
super()
end
|
Instance Attribute Details
#silent ⇒ Boolean
Whether or not the comment is silent (that is, doesn't output to CSS).
16 17 18 |
# File 'lib/sass/tree/comment_node.rb', line 16
def silent
@silent
end
|
#value ⇒ String
The text of the comment, not including /*
and */
.
11 12 13 |
# File 'lib/sass/tree/comment_node.rb', line 11
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Boolean
Compares the contents of two comments.
32 33 34 |
# File 'lib/sass/tree/comment_node.rb', line 32
def ==(other)
self.class == other.class && value == other.value && silent == other.silent
end
|
#_perform(environment) ⇒ Tree::Node+ (protected)
Removes this node from the tree if it's a silent comment.
111 112 113 114 |
# File 'lib/sass/tree/comment_node.rb', line 111
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.
96 97 98 99 100 101 102 103 |
# File 'lib/sass/tree/comment_node.rb', line 96
def _to_s(tabs = 0, _ = nil)
return if invisible?
spaces = (' ' * [tabs - 1 - value[/^ */].size, 0].max)
content = value.gsub(/^/, spaces)
content.gsub!(/\n +(\* *(?!\/))?/, ' ') if style == :compact
content
end
|
#invisible? ⇒ Boolean
Returns true
if this is a silent comment
or the current style doesn't render comments.
40 41 42 |
# File 'lib/sass/tree/comment_node.rb', line 40
def invisible?
style == :compressed || @silent
end
|
#to_sass(tabs, opts = {})
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/sass/tree/comment_node.rb', line 45
def to_sass(tabs, opts = {})
content = value.gsub(/\*\/$/, '').rstrip
if content =~ /\A[ \t]/
# Re-indent SCSS comments like this:
# /* foo
# bar
# baz */
content.gsub!(/^/, ' ')
content.sub!(/\A([ \t]*)\/\*/, '/*\1')
end
content =
unless content.include?("\n")
content
else
content.gsub!(/\n( \*|\/\/)/, "\n ")
spaces = content.scan(/\n( *)/).map {|s| s.first.size}.min
sep = silent ? "\n//" : "\n *"
if spaces >= 2
content.gsub(/\n /, sep)
else
content.gsub(/\n#{' ' * spaces}/, sep)
end
end
content.gsub!(/\A\/\*/, '//') if silent
content.gsub!(/^/, ' ' * tabs)
content.rstrip + "\n"
end
|
#to_scss(tabs, opts = {})
76 77 78 79 80 81 82 83 |
# File 'lib/sass/tree/comment_node.rb', line 76
def to_scss(tabs, opts = {})
spaces = (' ' * [tabs - value[/^ */].size, 0].max)
if silent
value.gsub(/^[\/ ]\*/, '//').gsub(/ *\*\/$/, '')
else
value
end.gsub(/^/, spaces) + "\n"
end
|