diff options
author | Nobuyoshi Nakada <[email protected]> | 2021-09-15 17:26:14 +0900 |
---|---|---|
committer | git <[email protected]> | 2022-02-12 16:15:08 +0900 |
commit | 3b3fb73d6107f64b4c71472de36c4debaf41cd42 (patch) | |
tree | 3d932694b9364b59ae10622a739a227f92b7008f /lib | |
parent | 11f3882173e1efbc62a3a5bb667acf69ec7e8161 (diff) |
[ruby/rdoc] Dump plain objects as `RDoc::Options`
So that the generated `.rdoc_options` file is loadable.
https://github.com/ruby/rdoc/commit/6cf6e1647b
Diffstat (limited to 'lib')
-rw-r--r-- | lib/rdoc/options.rb | 39 | ||||
-rw-r--r-- | lib/rdoc/rdoc.rb | 2 |
2 files changed, 22 insertions, 19 deletions
diff --git a/lib/rdoc/options.rb b/lib/rdoc/options.rb index 792b473b79..55994c9dcc 100644 --- a/lib/rdoc/options.rb +++ b/lib/rdoc/options.rb @@ -106,6 +106,7 @@ class RDoc::Options generator_options generators op_dir + page_dir option_parser pipe rdoc_include @@ -434,6 +435,7 @@ class RDoc::Options @main_page = map['main_page'] if map.has_key?('main_page') @markup = map['markup'] if map.has_key?('markup') @op_dir = map['op_dir'] if map.has_key?('op_dir') + @page_dir = map['page_dir'] if map.has_key?('page_dir') @show_hash = map['show_hash'] if map.has_key?('show_hash') @tab_width = map['tab_width'] if map.has_key?('tab_width') @template_dir = map['template_dir'] if map.has_key?('template_dir') @@ -513,19 +515,22 @@ class RDoc::Options ## # For dumping YAML - def encode_with coder # :nodoc: + def to_yaml(*options) # :nodoc: encoding = @encoding ? @encoding.name : nil - coder.add 'encoding', encoding - coder.add 'static_path', sanitize_path(@static_path) - coder.add 'rdoc_include', sanitize_path(@rdoc_include) + yaml = {} + yaml['encoding'] = encoding + yaml['static_path'] = sanitize_path(@static_path) + yaml['rdoc_include'] = sanitize_path(@rdoc_include) + yaml['page_dir'] = (sanitize_path([@page_dir]).first if @page_dir) ivars = instance_variables.map { |ivar| ivar.to_s[1..-1] } ivars -= SPECIAL ivars.sort.each do |ivar| - coder.add ivar, instance_variable_get("@#{ivar}") + yaml[ivar] = instance_variable_get("@#{ivar}") end + yaml.to_yaml end ## @@ -548,6 +553,11 @@ class RDoc::Options # #template. def finish + if @write_options then + write_options + exit + end + @op_dir ||= 'doc' @rdoc_include << "." if @rdoc_include.empty? @@ -585,14 +595,14 @@ class RDoc::Options def finish_page_dir return unless @page_dir - @files << @page_dir.to_s + @files << @page_dir - page_dir = nil + page_dir = Pathname(@page_dir) begin - page_dir = @page_dir.expand_path.relative_path_from @root + page_dir = page_dir.expand_path.relative_path_from @root rescue ArgumentError # On Windows, sometimes crosses different drive letters. - page_dir = @page_dir.expand_path + page_dir = page_dir.expand_path end @page_dir = page_dir @@ -847,7 +857,7 @@ Usage: #{opt.program_name} [options] [names...] "such files at your project root.", "NOTE: Do not use the same file name in", "the page dir and the root of your project") do |page_dir| - @page_dir = Pathname(page_dir) + @page_dir = page_dir end opt.separator nil @@ -1159,13 +1169,6 @@ Usage: #{opt.program_name} [options] [names...] @files = argv.dup - finish - - if @write_options then - write_options - exit - end - self end @@ -1278,7 +1281,7 @@ Usage: #{opt.program_name} [options] [names...] File.open '.rdoc_options', 'w' do |io| io.set_encoding Encoding::UTF_8 - YAML.dump self, io + io.print to_yaml end end diff --git a/lib/rdoc/rdoc.rb b/lib/rdoc/rdoc.rb index ca48f2de81..400f9b5bc3 100644 --- a/lib/rdoc/rdoc.rb +++ b/lib/rdoc/rdoc.rb @@ -440,11 +440,11 @@ The internal error was: if RDoc::Options === options then @options = options - @options.finish else @options = RDoc::Options.load_options @options.parse options end + @options.finish if @options.pipe then handle_pipe |