Skip to content

Commit

Permalink
Add tests for --template-stylesheets option
Browse files Browse the repository at this point in the history
Fixes ruby#205
Fixes ruby#828 too
  • Loading branch information
nobu committed Aug 18, 2021
1 parent 89a59f2 commit 1f14e44
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/rdoc/generator/darkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def write_style_sheet
install_rdoc_static_file @template_dir + item, "./#{item}", options
end

@options.template_stylesheets.each do |stylesheet|
FileUtils.cp stylesheet, '.', options
unless @options.template_stylesheets.empty?
FileUtils.cp @options.template_stylesheets, '.', **options
end

Dir[(@template_dir + "{js,images}/**/*").to_s].each do |path|
Expand Down
4 changes: 1 addition & 3 deletions lib/rdoc/generator/template/darkfish/_head.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

<link href="<%= asset_rel_prefix %>/css/fonts.css" rel="stylesheet">
<link href="<%= asset_rel_prefix %>/css/rdoc.css" rel="stylesheet">
<%- if @options.template_stylesheets.flatten.any? then -%>
<%- @options.template_stylesheets.flatten.each do |stylesheet| -%>
<%- @options.template_stylesheets.each do |stylesheet| -%>
<link href="<%= asset_rel_prefix %>/<%= File.basename stylesheet %>" rel="stylesheet">
<%- end -%>
<%- end -%>
2 changes: 1 addition & 1 deletion lib/rdoc/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ def parse argv
opt.on("--template-stylesheets=FILES", PathArray,
"Set (or add to) the list of files to",
"include with the html template.") do |value|
@template_stylesheets << value
@template_stylesheets.concat value
end

opt.separator nil
Expand Down
14 changes: 14 additions & 0 deletions test/rdoc/test_rdoc_generator_darkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ def test_generated_method_with_html_tag_yield
assert_includes method_name, '{ |%&lt;&lt;script&gt;alert(&quot;atui&quot;)&lt;/script&gt;&gt;, yield_arg| ... }'
end

def test_template_stylesheeds
css = Tempfile.create(%W'hoge .css', Dir.mktmpdir('tmp', '.'))
File.write(css, '')
base = File.basename(css)
refute_file(base)

@options.template_stylesheets << css

@g.generate

assert_file base
assert_include File.read('index.html'), %Q[href="./#{base}"]
end

##
# Asserts that +filename+ has a link count greater than 1 if hard links to
# @tmpdir are supported.
Expand Down
15 changes: 15 additions & 0 deletions test/rdoc/test_rdoc_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,21 @@ def test_parse_template_load_path
$LOAD_PATH.replace orig_LOAD_PATH
end

def test_parse_template_stylesheets
css = nil
Dir.mktmpdir do |dir|
css = File.join(dir, "hoge.css")
File.write(css, "")
out, err = capture_output do
@options.parse %W[--template-stylesheets #{css}]
end

assert_empty out
assert_empty err
end
assert_include @options.template_stylesheets, css
end

def test_parse_visibility
@options.parse %w[--visibility=public]
assert_equal :public, @options.visibility
Expand Down

0 comments on commit 1f14e44

Please sign in to comment.