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