Class: Sass::Tree::CommentNode
Overview
A static node representing a Sass comment (silent or loud).
Instance Attribute Summary
- - (Boolean) silent Whether or not the comment is silent (that is, doesn’t output to CSS).
-
- (String) value
The text of the comment, not including
/*and*/.
Instance Method Summary
- - (Boolean) =(other) Compares the contents of two comments.
- - (Tree::Node+) _perform(environment) protected Removes this node from the tree if it’s a silent comment.
- - to_s(tabs = 0) protected Computes the CSS for the comment.
- - (CommentNode) initialize(value, silent) constructor A new instance of CommentNode.
-
- (Boolean) invisible?
Returns
trueif 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
#<<, #_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
- (CommentNode) initialize(value, silent)
A new instance of CommentNode
20 21 22 23 24 25 |
# File '/var/www/haml-pages/.haml/lib/sass/tree/comment_node.rb', line 20
def initialize(value, silent)
@lines = []
@value = normalize_indentation value
@silent = silent
super()
end
|
Instance Attribute Details
- (Boolean) silent
Whether or not the comment is silent (that is, doesn’t output to CSS).
16 17 18 |
# File '/var/www/haml-pages/.haml/lib/sass/tree/comment_node.rb', line 16
def silent
@silent
end
|
- (String) value
The text of the comment, not including /* and */.
11 12 13 |
# File '/var/www/haml-pages/.haml/lib/sass/tree/comment_node.rb', line 11
def value
@value
end
|
Instance Method Details
- (Boolean) ==(other)
Compares the contents of two comments.
32 33 34 |
# File '/var/www/haml-pages/.haml/lib/sass/tree/comment_node.rb', line 32
def ==(other)
self.class == other.class && value == other.value && silent == other.silent
end
|
- (Tree::Node+) _perform(environment) (protected)
Removes this node from the tree if it’s a silent comment.
111 112 113 114 |
# File '/var/www/haml-pages/.haml/lib/sass/tree/comment_node.rb', line 111
def _perform(environment)
return [] if @silent
self
end
|
- to_s(tabs = 0) (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 '/var/www/haml-pages/.haml/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
|
- (Boolean) invisible?
Returns true if this is a silent comment or the current style doesn’t render comments.
40 41 42 |
# File '/var/www/haml-pages/.haml/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 '/var/www/haml-pages/.haml/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 '/var/www/haml-pages/.haml/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
|