1require "rexml/child"
2
3module REXML
4  ##
5  # Represents an XML comment; that is, text between \<!-- ... -->
6  class Comment < Child
7    include Comparable
8    START = "<!--"
9    STOP = "-->"
10
11    # The content text
12
13    attr_accessor :string
14
15    ##
16    # Constructor.  The first argument can be one of three types:
17    # @param first If String, the contents of this comment are set to the
18    # argument.  If Comment, the argument is duplicated.  If
19    # Source, the argument is scanned for a comment.
20    # @param second If the first argument is a Source, this argument
21    # should be nil, not supplied, or a Parent to be set as the parent
22    # of this object
23    def initialize( first, second = nil )
24      #puts "IN COMMENT CONSTRUCTOR; SECOND IS #{second.type}"
25      super(second)
26      if first.kind_of? String
27        @string = first
28      elsif first.kind_of? Comment
29        @string = first.string
30      end
31    end
32
33    def clone
34      Comment.new self
35    end
36
37    # == DEPRECATED
38    # See REXML::Formatters
39    #
40    # output::
41    #    Where to write the string
42    # indent::
43    #    An integer.    If -1, no indenting will be used; otherwise, the
44    #    indentation will be this number of spaces, and children will be
45    #    indented an additional amount.
46    # transitive::
47    #    Ignored by this class. The contents of comments are never modified.
48    # ie_hack::
49    #    Needed for conformity to the child API, but not used by this class.
50    def write( output, indent=-1, transitive=false, ie_hack=false )
51      Kernel.warn("Comment.write is deprecated.  See REXML::Formatters")
52      indent( output, indent )
53      output << START
54      output << @string
55      output << STOP
56    end
57
58    alias :to_s :string
59
60    ##
61    # Compares this Comment to another; the contents of the comment are used
62    # in the comparison.
63    def <=>(other)
64      other.to_s <=> @string
65    end
66
67    ##
68    # Compares this Comment to another; the contents of the comment are used
69    # in the comparison.
70    def ==( other )
71      other.kind_of? Comment and
72      (other <=> self) == 0
73    end
74
75    def node_type
76      :comment
77    end
78  end
79end
80#vim:ts=2 sw=2 noexpandtab:
81