Class: RDoc::Markup::ToTtOnly

Inherits:
Formatter show all
Defined in:
lib/rdoc/markup/to_tt_only.rb

Overview

Extracts sections of text enclosed in plus, tt or code. Used to discover undocumented parameters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Formatter

#accept_document, #add_regexp_handling_RDOCLINK, #add_regexp_handling_TIDYLINK, #add_tag, #annotate, #convert, #convert_flow, #convert_regexp_handling, #convert_string, gen_relative_url, #ignore, #in_tt?, #off_tags, #on_tags, #parse_url, #tt?

Constructor Details

#initialize(markup = nil) ⇒ ToTtOnly

Creates a new tt-only formatter.



21
22
23
24
25
# File 'lib/rdoc/markup/to_tt_only.rb', line 21

def initialize markup = nil
  super nil, markup

  add_tag :TT, nil, nil
end

Instance Attribute Details

#list_typeObject (readonly)

Stack of list types



11
12
13
# File 'lib/rdoc/markup/to_tt_only.rb', line 11

def list_type
  @list_type
end

#resObject (readonly)

Output accumulator



16
17
18
# File 'lib/rdoc/markup/to_tt_only.rb', line 16

def res
  @res
end

Instance Method Details

#accept_block_quote(block_quote) ⇒ Object

Adds tts from block_quote to the output



30
31
32
# File 'lib/rdoc/markup/to_tt_only.rb', line 30

def accept_block_quote block_quote
  tt_sections block_quote.text
end

#accept_list_end(list) ⇒ Object

Pops the list type for list from #list_type



37
38
39
# File 'lib/rdoc/markup/to_tt_only.rb', line 37

def accept_list_end list
  @list_type.pop
end

#accept_list_item_start(list_item) ⇒ Object

Prepares the visitor for consuming list_item



51
52
53
54
55
56
57
58
# File 'lib/rdoc/markup/to_tt_only.rb', line 51

def accept_list_item_start list_item
  case @list_type.last
  when :NOTE, :LABEL then
    Array(list_item.label).map do |label|
      tt_sections label
    end.flatten
  end
end

#accept_list_start(list) ⇒ Object

Pushes the list type for list onto #list_type



44
45
46
# File 'lib/rdoc/markup/to_tt_only.rb', line 44

def accept_list_start list
  @list_type << list.type
end

#accept_paragraph(paragraph) ⇒ Object

Adds paragraph to the output



63
64
65
# File 'lib/rdoc/markup/to_tt_only.rb', line 63

def accept_paragraph paragraph
  tt_sections(paragraph.text)
end

#do_nothing(markup_item) ⇒ Object Also known as: accept_blank_line, accept_heading, accept_list_item_end, accept_raw, accept_rule, accept_verbatim

Does nothing to markup_item because it doesn’t have any user-built content



71
72
# File 'lib/rdoc/markup/to_tt_only.rb', line 71

def do_nothing markup_item
end

#end_acceptingObject

Returns an Array of items that were wrapped in plus, tt or code.



107
108
109
# File 'lib/rdoc/markup/to_tt_only.rb', line 107

def end_accepting
  @res.compact
end

#start_acceptingObject

Prepares the visitor for gathering tt sections



114
115
116
117
118
# File 'lib/rdoc/markup/to_tt_only.rb', line 114

def start_accepting
  @res = []

  @list_type = []
end

#tt_sections(text) ⇒ Object

Extracts tt sections from text



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rdoc/markup/to_tt_only.rb', line 84

def tt_sections text
  flow = @am.flow text.dup

  flow.each do |item|
    case item
    when String then
      @res << item if in_tt?
    when RDoc::Markup::AttrChanger then
      off_tags res, item
      on_tags res, item
    when RDoc::Markup::RegexpHandling then
      @res << convert_regexp_handling(item) if in_tt? # TODO can this happen?
    else
      raise "Unknown flow element: #{item.inspect}"
    end
  end

  res
end