Skip to content

Commit e148008

Browse files
committed
Allow partial default values to be overridden with .rdoc_options
1 parent 3c7834d commit e148008

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

lib/rdoc/options.rb

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,9 @@ class RDoc::Options
338338

339339
attr_reader :visibility
340340

341-
def initialize # :nodoc:
341+
def initialize loaded_options = nil # :nodoc:
342342
init_ivars
343+
override loaded_options if loaded_options
343344
end
344345

345346
def init_ivars # :nodoc:
@@ -417,6 +418,37 @@ def yaml_initialize tag, map # :nodoc:
417418
init_with map
418419
end
419420

421+
def override map # :nodoc:
422+
if map.has_key?('encoding')
423+
encoding = map['encoding']
424+
@encoding = encoding ? Encoding.find(encoding) : encoding
425+
end
426+
427+
@charset = map['charset'] if map.has_key?('charset')
428+
@exclude = map['exclude'] if map.has_key?('exclude')
429+
@generator_name = map['generator_name'] if map.has_key?('generator_name')
430+
@hyperlink_all = map['hyperlink_all'] if map.has_key?('hyperlink_all')
431+
@line_numbers = map['line_numbers'] if map.has_key?('line_numbers')
432+
@locale_name = map['locale_name'] if map.has_key?('locale_name')
433+
@locale_dir = map['locale_dir'] if map.has_key?('locale_dir')
434+
@main_page = map['main_page'] if map.has_key?('main_page')
435+
@markup = map['markup'] if map.has_key?('markup')
436+
@op_dir = map['op_dir'] if map.has_key?('op_dir')
437+
@show_hash = map['show_hash'] if map.has_key?('show_hash')
438+
@tab_width = map['tab_width'] if map.has_key?('tab_width')
439+
@template_dir = map['template_dir'] if map.has_key?('template_dir')
440+
@title = map['title'] if map.has_key?('title')
441+
@visibility = map['visibility'] if map.has_key?('visibility')
442+
@webcvs = map['webcvs'] if map.has_key?('webcvs')
443+
444+
if map.has_key?('rdoc_include')
445+
@rdoc_include = sanitize_path map['rdoc_include']
446+
end
447+
if map.has_key?('static_path')
448+
@static_path = sanitize_path map['static_path']
449+
end
450+
end
451+
420452
def == other # :nodoc:
421453
self.class === other and
422454
@encoding == other.encoding and

lib/rdoc/rdoc.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,12 @@ def load_options
167167
end
168168

169169
raise RDoc::Error, "#{options_file} is not a valid rdoc options file" unless
170-
RDoc::Options === options
170+
RDoc::Options === options or Hash === options
171+
172+
if Hash === options
173+
# Override the default values with the contents of YAML file.
174+
options = RDoc::Options.new options
175+
end
171176

172177
options
173178
end

test/rdoc/test_rdoc_rdoc.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ def test_load_options_invalid
133133
end
134134
end
135135

136+
def test_load_options_partial_override
137+
temp_dir do
138+
File.open '.rdoc_options', 'w' do |io|
139+
io.write "markup: Markdown"
140+
end
141+
142+
options = @rdoc.load_options
143+
144+
assert_equal 'Markdown', options.markup
145+
end
146+
end
147+
136148
def load_options_no_file
137149
temp_dir do
138150
options = @rdoc.load_options

0 commit comments

Comments
 (0)