@@ -234,15 +234,67 @@ def output_flag_file(op_dir)
234234 # The .document file contains a list of file and directory name patterns,
235235 # representing candidates for documentation. It may also contain comments
236236 # (starting with '#')
237+ #
238+ # If the first line is the comment starts with +rdoc.document:+
239+ # (case-insensitive) followed by a version string, the file is
240+ # parsed as per the version. If a version is not written, it is
241+ # defaulted to 0.
242+ #
243+ # version 0::
244+ #
245+ # The file will be parsed as white-space separated glob patterns.
246+ #
247+ # - A <tt>#</tt> in middle starts a comment.
248+ #
249+ # - Multiple patterns can be in a single line.
250+ #
251+ # - That means patterns cannot contain white-spaces and <tt>#</tt>
252+ # marks.
253+ #
254+ # version 1::
255+ #
256+ # The file will be parsed as single glob pattern per each line.
257+ #
258+ # - Only lines starting with <tt>#</tt> at the first colmun are
259+ # comments. A <tt>#</tt> in middle is a part of the pattern.
260+ #
261+ # - Patterns starting with <tt>#</tt> need to be prefixed with a
262+ # backslash (<tt>\\</tt>).
263+ #
264+ # - Leading spaces are not stripped while trailing spaces which
265+ # are not escaped with a backslash are stripped.
266+ #
267+ # - The pattern starting with <tt>!</tt> is a negative pattern,
268+ # which rejects matching files.
237269
238270 def parse_dot_doc_file in_dir , filename
239- # read and strip comments
240- patterns = File . read ( filename ) . gsub ( /#.*/ , '' )
241-
242271 result = { }
272+ patterns = rejects = nil
273+
274+ content = File . read ( filename )
275+ version = content [ /\A #+\s *rdoc\. document:\s *\K \S +/i ] &.to_i || 0
276+ if version >= 1
277+ content . each_line ( chomp : true ) do |line |
278+ next if line . start_with? ( "#" ) # skip comments
279+ line . sub! ( /(?<!\\ )\s *$/ , "" ) # rstrip unescaped trailing spaces
280+ ( line . sub! ( /\A !/ , "" ) ? ( rejects ||= [ ] ) : ( patterns ||= [ ] ) ) << line
281+ end
282+ else
283+ # read and strip comments
284+ patterns = content . gsub ( /#.*/ , '' ) . split ( ' ' )
285+ end
243286
244- patterns . split ( ' ' ) . each do |patt |
245- candidates = Dir . glob ( File . join ( in_dir , patt ) )
287+ if patterns
288+ patterns . each { |patt | patt . sub! ( /\A \/ +/ , "" ) }
289+ candidates = Dir . glob ( patterns , base : in_dir )
290+ if rejects
291+ rejects . each { |patt | patt . sub! ( /\A \/ +/ , "" ) }
292+ flag = File ::FNM_PATHNAME
293+ candidates . delete_if do |name |
294+ rejects . any? { |patt | File . fnmatch? ( patt , name , flag ) }
295+ end
296+ end
297+ candidates . map! { |name | File . join ( in_dir , name ) }
246298 result . update normalized_file_list ( candidates , false , @options . exclude )
247299 end
248300
0 commit comments