Class: RDoc::Markup::ToTtOnly
- 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
-
#list_type ⇒ Object
readonly
Stack of list types.
-
#res ⇒ Object
readonly
Output accumulator.
Instance Method Summary collapse
-
#accept_block_quote(block_quote) ⇒ Object
Adds tts from
block_quote
to the output. -
#accept_list_end(list) ⇒ Object
Pops the list type for
list
from #list_type. -
#accept_list_item_start(list_item) ⇒ Object
Prepares the visitor for consuming
list_item
. -
#accept_list_start(list) ⇒ Object
Pushes the list type for
list
onto #list_type. -
#accept_paragraph(paragraph) ⇒ Object
Adds
paragraph
to the output. -
#do_nothing(markup_item) ⇒ Object
(also: #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. -
#end_accepting ⇒ Object
Returns an Array of items that were wrapped in plus, tt or code.
-
#initialize(markup = nil) ⇒ ToTtOnly
constructor
Creates a new tt-only formatter.
-
#start_accepting ⇒ Object
Prepares the visitor for gathering tt sections.
-
#tt_sections(text) ⇒ Object
Extracts tt sections from
text
.
Methods inherited from Formatter
#accept_document, #add_special_RDOCLINK, #add_special_TIDYLINK, #add_tag, #annotate, #convert, #convert_flow, #convert_special, #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.
20 21 22 23 24 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 20 def initialize markup = nil super nil, markup add_tag :TT, nil, nil end |
Instance Attribute Details
#list_type ⇒ Object (readonly)
Stack of list types
10 11 12 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 10 def list_type @list_type end |
#res ⇒ Object (readonly)
Output accumulator
15 16 17 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 15 def res @res end |
Instance Method Details
#accept_block_quote(block_quote) ⇒ Object
Adds tts from block_quote
to the output
29 30 31 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 29 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
36 37 38 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 36 def accept_list_end list @list_type.pop end |
#accept_list_item_start(list_item) ⇒ Object
Prepares the visitor for consuming list_item
50 51 52 53 54 55 56 57 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 50 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
43 44 45 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 43 def accept_list_start list @list_type << list.type end |
#accept_paragraph(paragraph) ⇒ Object
Adds paragraph
to the output
62 63 64 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 62 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
70 71 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 70 def do_nothing markup_item end |
#end_accepting ⇒ Object
Returns an Array of items that were wrapped in plus, tt or code.
106 107 108 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 106 def end_accepting @res.compact end |
#start_accepting ⇒ Object
Prepares the visitor for gathering tt sections
113 114 115 116 117 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 113 def start_accepting @res = [] @list_type = [] end |
#tt_sections(text) ⇒ Object
Extracts tt sections from text
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rdoc/markup/to_tt_only.rb', line 83 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 res, item res, item when RDoc::Markup::Special then @res << convert_special(item) if in_tt? # TODO can this happen? else raise "Unknown flow element: #{item.inspect}" end end res end |