Skip to content

Commit 857002a

Browse files
committed
Add tests for --template-stylesheets option
Also flattens `@options.template_stylesheets` when parsing the command lines. Fixes #205 Fixes #828 too
1 parent 89a59f2 commit 857002a

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

lib/rdoc/generator/darkfish.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ def write_style_sheet
220220
install_rdoc_static_file @template_dir + item, "./#{item}", options
221221
end
222222

223-
@options.template_stylesheets.each do |stylesheet|
224-
FileUtils.cp stylesheet, '.', options
223+
unless @options.template_stylesheets.empty?
224+
FileUtils.cp @options.template_stylesheets, '.', **options
225225
end
226226

227227
Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|

lib/rdoc/generator/template/darkfish/_head.rhtml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
<link href="<%= asset_rel_prefix %>/css/fonts.css" rel="stylesheet">
1717
<link href="<%= asset_rel_prefix %>/css/rdoc.css" rel="stylesheet">
18-
<%- if @options.template_stylesheets.flatten.any? then -%>
19-
<%- @options.template_stylesheets.flatten.each do |stylesheet| -%>
18+
<%- @options.template_stylesheets.each do |stylesheet| -%>
2019
<link href="<%= asset_rel_prefix %>/<%= File.basename stylesheet %>" rel="stylesheet">
21-
<%- end -%>
2220
<%- end -%>

lib/rdoc/options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ def parse argv
971971
opt.on("--template-stylesheets=FILES", PathArray,
972972
"Set (or add to) the list of files to",
973973
"include with the html template.") do |value|
974-
@template_stylesheets << value
974+
@template_stylesheets.concat value
975975
end
976976

977977
opt.separator nil

test/rdoc/test_rdoc_generator_darkfish.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ def test_generated_method_with_html_tag_yield
220220
assert_includes method_name, '{ |%&lt;&lt;script&gt;alert(&quot;atui&quot;)&lt;/script&gt;&gt;, yield_arg| ... }'
221221
end
222222

223+
def test_template_stylesheets
224+
css = Tempfile.create(%W'hoge .css', Dir.mktmpdir('tmp', '.'))
225+
File.write(css, '')
226+
base = File.basename(css)
227+
refute_file(base)
228+
229+
@options.template_stylesheets << css
230+
231+
@g.generate
232+
233+
assert_file base
234+
assert_include File.read('index.html'), %Q[href="./#{base}"]
235+
end
236+
223237
##
224238
# Asserts that +filename+ has a link count greater than 1 if hard links to
225239
# @tmpdir are supported.

test/rdoc/test_rdoc_options.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,21 @@ def test_parse_template_load_path
632632
$LOAD_PATH.replace orig_LOAD_PATH
633633
end
634634

635+
def test_parse_template_stylesheets
636+
css = nil
637+
Dir.mktmpdir do |dir|
638+
css = File.join(dir, "hoge.css")
639+
File.write(css, "")
640+
out, err = capture_output do
641+
@options.parse %W[--template-stylesheets #{css}]
642+
end
643+
644+
assert_empty out
645+
assert_empty err
646+
end
647+
assert_include @options.template_stylesheets, css
648+
end
649+
635650
def test_parse_visibility
636651
@options.parse %w[--visibility=public]
637652
assert_equal :public, @options.visibility

0 commit comments

Comments
 (0)