2015-12-16 08:07:31 +03:00
|
|
|
# frozen_string_literal: false
|
2008-07-18 04:46:16 +04:00
|
|
|
##
|
|
|
|
# Parse a non-source file. We basically take the whole thing as one big
|
2010-12-20 06:22:49 +03:00
|
|
|
# comment.
|
2008-07-18 04:46:16 +04:00
|
|
|
|
|
|
|
class RDoc::Parser::Simple < RDoc::Parser
|
|
|
|
|
2012-11-27 08:28:14 +04:00
|
|
|
include RDoc::Parser::Text
|
|
|
|
|
2008-07-18 04:46:16 +04:00
|
|
|
parse_files_matching(//)
|
|
|
|
|
2010-04-23 06:32:20 +04:00
|
|
|
attr_reader :content # :nodoc:
|
|
|
|
|
2008-07-18 04: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-27 07:45:22 +04:00
|
|
|
preprocess.handle @content, @top_level
|
2008-07-18 04:46:16 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2010-04-01 11:45:16 +04:00
|
|
|
# Extract the file contents and attach them to the TopLevel as a comment
|
2008-07-18 04:46:16 +04:00
|
|
|
|
|
|
|
def scan
|
2010-04-10 10:36:13 +04:00
|
|
|
comment = remove_coding_comment @content
|
2012-11-27 08:28:14 +04:00
|
|
|
comment = remove_private_comment comment
|
|
|
|
|
|
|
|
comment = RDoc::Comment.new comment, @top_level
|
2010-04-10 10:36:13 +04:00
|
|
|
|
|
|
|
@top_level.comment = comment
|
2008-07-18 04:46:16 +04:00
|
|
|
@top_level
|
|
|
|
end
|
|
|
|
|
2010-12-20 06:22:49 +03:00
|
|
|
##
|
|
|
|
# Removes the encoding magic comment from +text+
|
|
|
|
|
2010-04-10 10:36:13 +04:00
|
|
|
def remove_coding_comment text
|
|
|
|
text.sub(/\A# .*coding[=:].*$/, '')
|
|
|
|
end
|
|
|
|
|
2012-11-27 08:28:14 +04: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-18 04:46:16 +04:00
|
|
|
end
|
|
|
|
|