123456789_123456789_123456789_123456789_123456789_

Class: RDoc::Parser::Simple

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: RDoc::Parser
Defined in: lib/rdoc/parser/simple.rb

Overview

Parse a non-source file. We basically take the whole thing as one big comment.

Class Attribute Summary

::RDoc::Parser - Inherited

.parsers

An Array of arrays that maps file extension (or name) regular expressions to parser classes that will parse matching filenames.

Class Method Summary

::RDoc::Parser - Inherited

.alias_extension

::RDoc::Alias an extension to another extension.

.binary?

Determines if the file is a “binary” file which basically means it has content that an ::RDoc::RDoc parser shouldn’t try to consume.

.can_parse

Return a parser that can handle a particular extension.

.can_parse_by_name

Returns a parser that can handle the extension for #file_name.

.check_modeline

Returns the file type from the modeline in #file_name

.for

Finds and instantiates the correct parser for the given #file_name and #content.

.new

Creates a new ::RDoc::Parser storing top_level, #file_name, #content, options and stats in instance variables.

.parse_files_matching

Record which file types this parser can understand.

.remove_modeline

Removes an emacs-style modeline from the first line of the document.

.use_markup

If there is a markup: parser_name comment at the front of the file, use it to determine the parser.

.zip?

Checks if file is a zip file in disguise.

Instance Attribute Summary

::RDoc::Parser - Inherited

#file_name

The name of the file being parsed.

Instance Method Summary

::RDoc::Parser - Inherited

#handle_tab_width

Normalizes tabs in body

Constructor Details

.new(top_level, file_name, content, options, stats) ⇒ Simple

Prepare to parse a plain file

[ GitHub ]

  
# File 'lib/rdoc/parser/simple.rb', line 17

def initialize(top_level, file_name, content, options, stats)
  super

  preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include

  @content = preprocess.handle @content, @top_level
end

Instance Attribute Details

#content (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rdoc/parser/simple.rb', line 12

attr_reader :content # :nodoc:

Instance Method Details

#remove_coding_comment(text)

Removes the encoding magic comment from text

[ GitHub ]

  
# File 'lib/rdoc/parser/simple.rb', line 41

def remove_coding_comment text
  text.sub(/\A# .*coding[=:].*$/, '')
end

#remove_private_comment(comment)

Removes private comments.

Unlike Comment#remove_private this implementation only looks for two dashes at the beginning of the line. Three or more dashes are considered to be a rule and ignored.

[ GitHub ]

  
# File 'lib/rdoc/parser/simple.rb', line 52

def remove_private_comment comment
  # Workaround for gsub encoding for Ruby 1.9.2 and earlier
  empty = ''
  empty = RDoc::Encoding.change_encoding empty, comment.encoding

  comment = comment.gsub(%r%^--\n.*?^\\\n?%m, empty)
  comment.sub(%r%^--\n.*%m, empty)
end

#scan

Extract the file contents and attach them to the ::RDoc::TopLevel as a comment

[ GitHub ]

  
# File 'lib/rdoc/parser/simple.rb', line 28

def scan
  comment = remove_coding_comment @content
  comment = remove_private_comment comment

  comment = RDoc::Comment.new comment, @top_level

  @top_level.comment = comment
  @top_level
end