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 01:45:17 -07:00
|
|
|
# @param value [String] See \{#value}
|
|
|
|
# @param options [Hash<Symbol, Object>] An options hash;
|
|
|
|
# see [the Sass options documentation](../../Sass.html#sass_options)
|
2008-10-13 09:49:35 -07:00
|
|
|
def initialize(value, options)
|
2009-04-25 00:09:44 -07:00
|
|
|
@lines = []
|
2008-10-13 09:49:35 -07:00
|
|
|
@value = value[2..-1].strip
|
|
|
|
super(options)
|
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 00:09:44 -07:00
|
|
|
self.class == other.class && value == other.value && lines == other.lines
|
2007-03-17 23:34:26 +00:00
|
|
|
end
|
|
|
|
|
2009-04-25 01:45:17 -07:00
|
|
|
# @return [Boolean] Whether or not this is a silent comment
|
2009-02-21 18:09:14 -08:00
|
|
|
def silent?
|
|
|
|
!!@options[:silent]
|
|
|
|
end
|
|
|
|
|
2009-04-25 01:45:17 -07:00
|
|
|
# Computes the CSS for the comment.
|
|
|
|
#
|
|
|
|
# @call-seq to_s(tabs = 0)
|
|
|
|
# @param tabs [Fixnum] The level of indentation for the CSS
|
|
|
|
# @return [String] The resulting CSS
|
|
|
|
def to_s(tabs = 0, _ = nil)
|
2009-02-21 18:09:14 -08:00
|
|
|
return if (@style == :compressed || silent?)
|
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-03-01 12:38:18 -08:00
|
|
|
map{|l| l.sub(%r{ ?\*/ *$},'')}.join(@style == :compact ? ' ' : "\n#{spaces} * ") + " */"
|
2007-03-17 23:34:26 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|