Class RI::AttributeFormatter
In: ri/ri_formatter.rb
Parent: TextFormatter

Handle text with attributes. We‘re a base class: there are different presentation classes (one, for example, uses overstrikes to handle bold and underlining, while another using ANSI escape sequences

Methods

Classes and Modules

Class RI::AttributeFormatter::AttrChar
Class RI::AttributeFormatter::AttributeString

Constants

BOLD = 1
ITALIC = 2
CODE = 4
ATTR_MAP = { "b" => BOLD, "code" => CODE, "em" => ITALIC, "i" => ITALIC, "tt" => CODE

Public Instance methods

overrides base class. Looks for etc sequences and generates an array of AttrChars. This array is then used as the basis for the split

[Source]

     # File ri/ri_formatter.rb, line 305
305:     def wrap(txt,  prefix=@indent, linelen=@width)
306:       return unless txt && !txt.empty?
307: 
308:       txt = add_attributes_to(txt)
309:       next_prefix = prefix.tr("^ ", " ")
310:       linelen -= prefix.size
311: 
312:       line = []
313: 
314:       until txt.empty?
315:         word = txt.next_word
316:         if word.size + line.size > linelen
317:           write_attribute_text(prefix, line)
318:           prefix = next_prefix
319:           line = []
320:         end
321:         line.concat(word)
322:       end
323: 
324:       write_attribute_text(prefix, line) if line.length > 0
325:     end

Protected Instance methods

again, overridden

[Source]

     # File ri/ri_formatter.rb, line 341
341:     def bold_print(txt)
342:       print txt
343:     end

overridden in specific formatters

[Source]

     # File ri/ri_formatter.rb, line 331
331:     def write_attribute_text(prefix, line)
332:       print prefix
333:       line.each do |achar|
334:         print achar.char
335:       end
336:       puts
337:     end

[Validate]