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, #annotate, #apply_regexp_handling, #convert, #convert_string, gen_relative_url, #handle_BOLD, #handle_BOLD_WORD, #handle_EM, #handle_EM_WORD, #handle_HARD_BREAK, #handle_PLAIN_TEXT, #handle_REGEXP_HANDLING_TEXT, #handle_STRIKE, #handle_TEXT, #handle_TIDYLINK, #handle_TT, #handle_inline, #ignore, #parse_url, #traverse_inline_nodes, #tt?

Constructor Details

#initialize(markup = nil) ⇒ ToTtOnly

Creates a new tt-only formatter.



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

def initialize(markup = nil)
  super nil, markup
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



28
29
30
# File 'lib/rdoc/markup/to_tt_only.rb', line 28

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



35
36
37
# File 'lib/rdoc/markup/to_tt_only.rb', line 35

def accept_list_end(list)
  @list_type.pop
end

#accept_list_item_start(list_item) ⇒ Object

Prepares the visitor for consuming list_item



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

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



42
43
44
# File 'lib/rdoc/markup/to_tt_only.rb', line 42

def accept_list_start(list)
  @list_type << list.type
end

#accept_paragraph(paragraph) ⇒ Object

Adds paragraph to the output



61
62
63
# File 'lib/rdoc/markup/to_tt_only.rb', line 61

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



69
70
# File 'lib/rdoc/markup/to_tt_only.rb', line 69

def do_nothing(markup_item)
end

#end_acceptingObject

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



101
102
103
# File 'lib/rdoc/markup/to_tt_only.rb', line 101

def end_accepting
  @res.compact
end

#start_acceptingObject

Prepares the visitor for gathering tt sections



108
109
110
111
112
# File 'lib/rdoc/markup/to_tt_only.rb', line 108

def start_accepting
  @res = []

  @list_type = []
end

#tt_sections(text) ⇒ Object

Extracts tt sections from text



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/rdoc/markup/to_tt_only.rb', line 82

def tt_sections(text)
  parsed = RDoc::Markup::InlineParser.new(text).parse
  traverse = -> node {
    next if String === node
    if node[:type] == :TT
      res << nil
      res << node[:children][0] || ''
      res << nil
    else
      node[:children].each(&traverse)
    end
  }
  parsed.each(&traverse)
  res
end