2007-03-17 23:34:26 +00:00
|
|
|
require 'sass/tree/node'
|
|
|
|
|
|
|
|
module Sass::Tree
|
2009-04-25 01:45:17 -07:00
|
|
|
# A static node representing a Sass comment (silent or loud).
|
|
|
|
#
|
|
|
|
# @see Sass::Tree
|
2008-10-13 09:49:35 -07:00
|
|
|
class CommentNode < Node
|
2009-04-25 01:45:17 -07:00
|
|
|
# The lines of text nested beneath the comment.
|
|
|
|
#
|
|
|
|
# @return [Array<Sass::Engine::Line>]
|
2009-04-25 00:09:44 -07:00
|
|
|
attr_accessor :lines
|
2009-04-25 01:45:17 -07:00
|
|
|
|
|
|
|
# The text on the same line as the comment starter.
|
|
|
|
#
|
|
|
|
# @return [String]
|
2008-10-13 09:49:35 -07:00
|
|
|
attr_accessor :value
|
|
|
|
|
2009-04-25 12:52:46 -07:00
|
|
|
# Whether or not the comment is silent (that is, doesn't output to CSS).
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
2009-04-25 01:44:28 -07:00
|
|
|
attr_accessor :silent
|
2008-10-13 09:49:35 -07:00
|
|
|
|
2009-04-25 01:45:17 -07:00
|
|
|
# @param value [String] See \{#value}
|
2009-04-25 12:52:46 -07:00
|
|
|
# @param silent [Boolean] See \{#silent}
|
2009-04-21 19:25:18 -07:00
|
|
|
def initialize(value, silent)
|
2009-04-25 00:09:44 -07:00
|
|
|
@lines = []
|
2008-10-13 09:49:35 -07:00
|
|
|
@value = value[2..-1].strip
|
2009-04-21 19:22:52 -07:00
|
|
|
@silent = silent
|
2009-04-21 19:25:18 -07:00
|
|
|
super()
|
2007-03-17 23:34:26 +00:00
|
|
|
end
|
|
|
|
|
2009-04-25 01:45:17 -07:00
|
|
|
# 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
|
2009-02-19 20:12:23 -08:00
|
|
|
def ==(other)
|
2009-04-25 01:44:28 -07:00
|
|
|
self.class == other.class && value == other.value && silent == other.silent && lines == other.lines
|
2009-02-21 18:09:14 -08:00
|
|
|
end
|
|
|
|
|
2009-04-25 01:45:17 -07:00
|
|
|
# Computes the CSS for the comment.
|
|
|
|
#
|
2009-05-08 13:49:45 -07:00
|
|
|
# Returns `nil` if this is a silent comment
|
|
|
|
# or the current style doesn't render comments.
|
|
|
|
#
|
2009-05-13 20:29:49 -07:00
|
|
|
# @overload to_s(tabs = 0)
|
2009-04-25 01:45:17 -07:00
|
|
|
# @param tabs [Fixnum] The level of indentation for the CSS
|
2009-05-08 13:49:45 -07:00
|
|
|
# @return [String, nil] The resulting CSS
|
|
|
|
# @see #invisible?
|
2009-04-25 01:45:17 -07:00
|
|
|
def to_s(tabs = 0, _ = nil)
|
2009-05-08 13:42:39 -07:00
|
|
|
return if invisible?
|
2007-12-07 20:30:36 +00:00
|
|
|
|
|
|
|
spaces = ' ' * (tabs - 1)
|
2009-04-25 00:09:44 -07:00
|
|
|
spaces + "/* " + ([value] + lines.map {|l| l.text}).
|
2009-04-21 18:39:34 -07:00
|
|
|
map{|l| l.sub(%r{ ?\*/ *$},'')}.join(style == :compact ? ' ' : "\n#{spaces} * ") + " */"
|
2007-03-17 23:34:26 +00:00
|
|
|
end
|
2009-05-08 13:42:39 -07:00
|
|
|
|
2009-05-08 13:49:45 -07:00
|
|
|
# Returns `true` if this is a silent comment
|
|
|
|
# or the current style doesn't render comments.
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
2009-05-08 13:42:39 -07:00
|
|
|
def invisible?
|
2009-05-08 13:53:18 -07:00
|
|
|
style == :compressed || @silent
|
2009-05-08 13:42:39 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
2009-05-08 13:49:45 -07:00
|
|
|
# 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
|
2009-05-08 13:42:39 -07:00
|
|
|
def _perform(environment)
|
2009-05-08 13:53:18 -07:00
|
|
|
return [] if @silent
|
2009-05-08 13:42:39 -07:00
|
|
|
self
|
|
|
|
end
|
2007-03-17 23:34:26 +00:00
|
|
|
end
|
|
|
|
end
|