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.

.process_directive

Processes common directives for CodeObjects for the C and Ruby parsers.

.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

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 16

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

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

  preprocess.handle @content, @top_level
end

Instance Method Details

#remove_coding_comment(text)

Removes the encoding magic comment from text

[ GitHub ]

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

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 51

def remove_private_comment comment
  # Workaround for gsub encoding for Ruby 1.9.2 and earlier
  empty = ''
  empty.force_encoding comment.encoding if Object.const_defined? :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 27

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