Sha256: 555604c47280dc2e93d5ce5863b8847ddac34e9947abf95fae21a07dfa08b34e

Contents?: true

Size: 1.42 KB

Versions: 14

Compression:

Stored size: 1.42 KB

Contents

require 'sass/tree/node'

module Sass::Tree
  # A static node representing a Sass comment (silent or loud).
  #
  # @see Sass::Tree
  class CommentNode < Node
    # The text of the comment, not including `/*` and `*/`.
    #
    # @return [String]
    attr_accessor :value

    # Whether or not the comment is silent (that is, doesn't output to CSS).
    #
    # @return [Boolean]
    attr_accessor :silent

    # @param value [String] See \{#value}
    # @param silent [Boolean] See \{#silent}
    def initialize(value, silent)
      @lines = []
      @value = normalize_indentation value
      @silent = silent
      super()
    end

    # 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
    def ==(other)
      self.class == other.class && value == other.value && silent == other.silent
    end

    # Returns `true` if this is a silent comment
    # or the current style doesn't render comments.
    #
    # @return [Boolean]
    def invisible?
      style == :compressed || @silent
    end

    private

    def normalize_indentation(str)
      pre = str.split("\n").inject(str[/^[ \t]*/].split("")) do |pre, line|
        line[/^[ \t]*/].split("").zip(pre).inject([]) do |arr, (a, b)|
          break arr if a != b
          arr + [a]
        end
      end.join
      str.gsub(/^#{pre}/, '')
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
sass-3.1.0.alpha.221 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.218 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.217 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.216 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.212 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.214 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.210 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.206 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.205 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.204 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.200 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.51 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.50 lib/sass/tree/comment_node.rb
sass-3.1.0.alpha.49 lib/sass/tree/comment_node.rb