Class: RDoc::Markup::Verbatim

Inherits:
Markup::Raw
  • Object
show all
Defined in:
lib/rdoc/markup/verbatim.rb

Overview

A section of verbatim text

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*parts) ⇒ Verbatim

:nodoc:



14
15
16
17
18
# File 'lib/rdoc/markup/verbatim.rb', line 14

def initialize(*parts) # :nodoc:
  super

  @format = nil
end

Instance Attribute Details

#format ⇒ Object

Format of this verbatim section



12
13
14
# File 'lib/rdoc/markup/verbatim.rb', line 12

def format
  @format
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



20
21
22
# File 'lib/rdoc/markup/verbatim.rb', line 20

def ==(other) # :nodoc:
  super and @format == other.format
end

#accept(visitor) ⇒ Object

Calls #accept_verbatim on visitor



27
28
29
# File 'lib/rdoc/markup/verbatim.rb', line 27

def accept(visitor)
  visitor.accept_verbatim self
end

#normalize ⇒ Object

Collapses 3+ newlines into two newlines



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rdoc/markup/verbatim.rb', line 34

def normalize
  parts = []

  newlines = 0

  @parts.each do |part|
    case part
    when /^\s*\n/
      newlines += 1
      parts << part if newlines == 1
    else
      newlines = 0
      parts << part
    end
  end

  parts.pop if parts.last =~ /\A\r?\n\z/

  @parts = parts
end

#pretty_print(q) ⇒ Object

:nodoc:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/rdoc/markup/verbatim.rb', line 55

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

  q.group 2, "[#{$1.downcase}: ", ']' do
    if @format
      q.text "format: #{@format}"
      q.breakable
    end

    q.seplist @parts do |part|
      q.pp part
    end
  end
end

#ruby? ⇒ Boolean

Is this verbatim section Ruby code?

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/rdoc/markup/verbatim.rb', line 73

def ruby?
  @format ||= nil # TODO for older ri data, switch the tree to marshal_dump
  @format == :ruby || @format == :rb
end

#text ⇒ Object

The text of the section



81
82
83
# File 'lib/rdoc/markup/verbatim.rb', line 81

def text
  @parts.join
end