summaryrefslogtreecommitdiff
path: root/lib/rdoc/markup/paragraph.rb
blob: bc23423dfcefcb3d7b202c9a2ce6f673ecff36bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
##
# A Paragraph of text

class RDoc::Markup::Paragraph

  ##
  # The component parts of the list

  attr_reader :parts

  ##
  # Creates a new Paragraph containing +parts+

  def initialize *parts
    @parts = []
    @parts.push(*parts)
  end

  ##
  # Appends +text+ to the Paragraph

  def << text
    @parts << text
  end

  def == other # :nodoc:
    self.class == other.class and text == other.text
  end

  def accept visitor
    visitor.accept_paragraph self
  end

  ##
  # Appends +other+'s parts into this Paragraph

  def merge other
    @parts.push(*other.parts)
  end

  def pretty_print q # :nodoc:
    self.class.name =~ /.*::(\w{4})/i

    q.group 2, "[#{$1.downcase}: ", ']' do
      q.seplist @parts do |part|
        q.pp part
      end
    end
  end

  ##
  # Appends +texts+ onto this Paragraph

  def push *texts
    self.parts.push(*texts)
  end

  ##
  # The text of this paragraph

  def text
    @parts.join ' '
  end

end