~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/rdoc/markup/to_tt_only.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
require 'rdoc/markup/formatter'
 
2
require 'rdoc/markup/inline'
 
3
 
 
4
##
 
5
# Extracts sections of text enclosed in plus, tt or code.  Used to discover
 
6
# undocumented parameters.
 
7
 
 
8
class RDoc::Markup::ToTtOnly < RDoc::Markup::Formatter
 
9
 
 
10
  ##
 
11
  # Stack of list types
 
12
 
 
13
  attr_reader :list_type
 
14
 
 
15
  ##
 
16
  # Output accumulator
 
17
 
 
18
  attr_reader :res
 
19
 
 
20
  ##
 
21
  # Creates a new tt-only formatter.
 
22
 
 
23
  def initialize markup = nil
 
24
    super
 
25
 
 
26
    add_tag :TT, nil, nil
 
27
  end
 
28
 
 
29
  ##
 
30
  # Pops the list type for +list+ from #list_type
 
31
 
 
32
  def accept_list_end list
 
33
    @list_type.pop
 
34
  end
 
35
 
 
36
  ##
 
37
  # Pushes the list type for +list+ onto #list_type
 
38
 
 
39
  def accept_list_start list
 
40
    @list_type << list.type
 
41
  end
 
42
 
 
43
  ##
 
44
  # Prepares the visitor for consuming +list_item+
 
45
 
 
46
  def accept_list_item_start list_item
 
47
    case @list_type.last
 
48
    when :NOTE, :LABEL then
 
49
      tt_sections(list_item.label)
 
50
    end
 
51
  end
 
52
 
 
53
  ##
 
54
  # Adds +paragraph+ to the output
 
55
 
 
56
  def accept_paragraph paragraph
 
57
    tt_sections(paragraph.text)
 
58
  end
 
59
 
 
60
  ##
 
61
  # Does nothing to +markup_item+ because it doesn't have any user-built
 
62
  # content
 
63
 
 
64
  def do_nothing markup_item
 
65
  end
 
66
 
 
67
  alias accept_blank_line    do_nothing # :nodoc:
 
68
  alias accept_heading       do_nothing # :nodoc:
 
69
  alias accept_list_item_end do_nothing # :nodoc:
 
70
  alias accept_raw           do_nothing # :nodoc:
 
71
  alias accept_rule          do_nothing # :nodoc:
 
72
  alias accept_verbatim      do_nothing # :nodoc:
 
73
 
 
74
  ##
 
75
  # Extracts tt sections from +text+
 
76
 
 
77
  def tt_sections text
 
78
    flow = @am.flow text.dup
 
79
 
 
80
    flow.each do |item|
 
81
      case item
 
82
      when String then
 
83
        @res << item if in_tt?
 
84
      when RDoc::Markup::AttrChanger then
 
85
        off_tags res, item
 
86
        on_tags res, item
 
87
      when RDoc::Markup::Special then
 
88
        @res << convert_special(item) if in_tt? # TODO can this happen?
 
89
      else
 
90
        raise "Unknown flow element: #{item.inspect}"
 
91
      end
 
92
    end
 
93
 
 
94
    res
 
95
  end
 
96
 
 
97
  ##
 
98
  # Returns an Array of items that were wrapped in plus, tt or code.
 
99
 
 
100
  def end_accepting
 
101
    @res.compact
 
102
  end
 
103
 
 
104
  ##
 
105
  # Prepares the visitor for gathering tt sections
 
106
 
 
107
  def start_accepting
 
108
    @res = []
 
109
 
 
110
    @list_type = []
 
111
  end
 
112
 
 
113
end
 
114