2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# Parse a non-source file. We basically take the whole thing as one big
|
2010-12-19 22:22:49 -05:00
|
|
|
# comment.
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
class RDoc::Parser::Simple < RDoc::Parser
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
include RDoc::Parser::Text
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
parse_files_matching(//)
|
|
|
|
|
2010-04-22 22:32:20 -04:00
|
|
|
attr_reader :content # :nodoc:
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
##
|
|
|
|
# Prepare to parse a plain file
|
|
|
|
|
|
|
|
def initialize(top_level, file_name, content, options, stats)
|
|
|
|
super
|
|
|
|
|
|
|
|
preprocess = RDoc::Markup::PreProcess.new @file_name, @options.rdoc_include
|
|
|
|
|
2010-04-26 23:45:22 -04:00
|
|
|
preprocess.handle @content, @top_level
|
2008-07-17 20:46:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2010-04-01 03:45:16 -04:00
|
|
|
# Extract the file contents and attach them to the TopLevel as a comment
|
2008-07-17 20:46:16 -04:00
|
|
|
|
|
|
|
def scan
|
2010-04-10 02:36:13 -04:00
|
|
|
comment = remove_coding_comment @content
|
2012-11-26 23:28:14 -05:00
|
|
|
comment = remove_private_comment comment
|
|
|
|
|
|
|
|
comment = RDoc::Comment.new comment, @top_level
|
2010-04-10 02:36:13 -04:00
|
|
|
|
|
|
|
@top_level.comment = comment
|
2008-07-17 20:46:16 -04:00
|
|
|
@top_level
|
|
|
|
end
|
|
|
|
|
2010-12-19 22:22:49 -05:00
|
|
|
##
|
|
|
|
# Removes the encoding magic comment from +text+
|
|
|
|
|
2010-04-10 02:36:13 -04:00
|
|
|
def remove_coding_comment text
|
|
|
|
text.sub(/\A# .*coding[=:].*$/, '')
|
|
|
|
end
|
|
|
|
|
2012-11-26 23:28:14 -05:00
|
|
|
##
|
|
|
|
# Removes private comments.
|
|
|
|
#
|
|
|
|
# Unlike RDoc::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.
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2008-07-17 20:46:16 -04:00
|
|
|
end
|
|
|
|
|