Class Sass::Tree::CommentNode
In: lib/sass/tree/comment_node.rb
Parent: Node
Haml::Util Engine Color SyntaxError UnitConversionError StandardError AbstractSequence CommaSequence Sequence SimpleSequence Simple Parent Universal Class Negation Id Pseudo Attribute Interpolation Element Node Operation Literal UnaryOperation StringInterpolation Funcall Variable Interpolation Lexer CssLexer Number String Bool Parser Parser CssParser EvaluationContext StaticParser SassParser CssParser Node DebugNode IfNode CommentNode ForNode PropNode MixinNode DirectiveNode VariableNode RootNode WarnNode ExtendNode RuleNode MixinDefNode WhileNode Enumerable ImportNode Merb::BootLoader MerbBootLoader Repl CSS Environment Rack StalenessChecker lib/sass/repl.rb lib/sass/css.rb lib/sass/environment.rb lib/sass/error.rb lib/sass/engine.rb lib/sass/selector/simple_sequence.rb lib/sass/selector/abstract_sequence.rb lib/sass/selector/sequence.rb lib/sass/selector/comma_sequence.rb lib/sass/selector/simple.rb lib/sass/selector.rb Selector lib/sass/script/css_parser.rb lib/sass/script/lexer.rb lib/sass/script/color.rb lib/sass/script/string.rb lib/sass/script/unary_operation.rb lib/sass/script/variable.rb lib/sass/script/funcall.rb lib/sass/script/string_interpolation.rb lib/sass/script/operation.rb lib/sass/script/bool.rb lib/sass/script/parser.rb lib/sass/script/node.rb lib/sass/script/literal.rb lib/sass/script/interpolation.rb lib/sass/script/css_lexer.rb lib/sass/script/number.rb lib/sass/script/functions.rb Functions Script lib/sass/scss/sass_parser.rb lib/sass/scss/static_parser.rb lib/sass/scss/parser.rb lib/sass/scss/css_parser.rb ScriptParser ScriptLexer RX SCSS Files Callbacks lib/sass/tree/while_node.rb lib/sass/tree/if_node.rb lib/sass/tree/mixin_def_node.rb lib/sass/tree/debug_node.rb lib/sass/tree/root_node.rb lib/sass/tree/for_node.rb lib/sass/tree/import_node.rb lib/sass/tree/prop_node.rb lib/sass/tree/node.rb lib/sass/tree/comment_node.rb lib/sass/tree/extend_node.rb lib/sass/tree/mixin_node.rb lib/sass/tree/warn_node.rb lib/sass/tree/directive_node.rb lib/sass/tree/rule_node.rb lib/sass/tree/variable_node.rb Tree lib/sass/plugin/rack.rb lib/sass/plugin/staleness_checker.rb lib/sass/plugin/merb.rb Plugin Sass dot/m_61_0.png

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

@see Sass::Tree

Methods

Attributes

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]

Public Class methods

@param value [String] See \{value} @param silent [Boolean] See \{silent}

[Source]

    # 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

Public Instance methods

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

[Source]

    # 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]

[Source]

    # File lib/sass/tree/comment_node.rb, line 40
40:     def invisible?
41:       style == :compressed || @silent
42:     end

@see Node#to_sass

[Source]

    # 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

[Source]

    # 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

Protected Instance methods

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

[Source]

     # 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?

[Source]

     # 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

Private Instance methods

[Source]

     # 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

[Validate]