Skip to content

Commit 491feae

Browse files
committed
Respect --template flag for custom theme support
The standalone Aliki generator was hardcoding @template_dir to its own template directory, ignoring @options.template_dir. This broke the --template flag, preventing third-party themes like rorvswild-theme-rdoc from rendering with their own templates. - Use @options.template_dir instead of hardcoded path - Generalize write_style_sheet to copy css/, js/, fonts/, and images/ subdirectories so custom templates with fonts and extra assets work correctly
1 parent b233a5a commit 491feae

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

lib/rdoc/generator/aliki.rb

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def initialize(store, options)
9393
@base_dir = Pathname.pwd.expand_path
9494
@dry_run = @options.dry_run
9595
@file_output = true
96-
@template_dir = Pathname.new(File.expand_path(File.join(__dir__, 'template', 'aliki')))
96+
@template_dir = Pathname.new(@options.template_dir)
9797
@template_cache = {}
9898

9999
@classes = nil
@@ -120,27 +120,26 @@ def gen_sub_directories
120120
end
121121

122122
##
123-
# Copy only the static assets required by Aliki.
124-
# Aliki does not ship embedded fonts or image sprites, keeping
125-
# generated documentation lightweight.
123+
# Copy static assets (CSS, JS, fonts) from the template directory
124+
# to the output directory.
126125

127126
def write_style_sheet
128-
debug_msg "Copying Aliki static files"
127+
debug_msg "Copying static files"
129128
options = { verbose: $DEBUG_RDOC, noop: @dry_run }
130129

131-
install_rdoc_static_file @template_dir + 'css/rdoc.css', "./css/rdoc.css", options
130+
%w[css js fonts images].each do |subdir|
131+
Dir[(@template_dir + "#{subdir}/**/*").to_s].each do |path|
132+
next if File.directory?(path)
133+
next if File.basename(path).start_with?('.')
132134

133-
unless @options.template_stylesheets.empty?
134-
FileUtils.cp @options.template_stylesheets, '.', **options
135-
end
136-
137-
Dir[(@template_dir + 'js/**/*').to_s].each do |path|
138-
next if File.directory?(path)
139-
next if File.basename(path).start_with?('.')
135+
dst = Pathname.new(path).relative_path_from(@template_dir)
140136

141-
dst = Pathname.new(path).relative_path_from(@template_dir)
137+
install_rdoc_static_file @template_dir + path, dst, options
138+
end
139+
end
142140

143-
install_rdoc_static_file @template_dir + path, dst, options
141+
unless @options.template_stylesheets.empty?
142+
FileUtils.cp @options.template_stylesheets, '.', **options
144143
end
145144
end
146145

test/rdoc/generator/aliki_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def teardown
6161

6262
def test_template_dir
6363
assert_kind_of RDoc::Generator::Aliki, @g
64-
assert_match %r{/template/aliki\z}, @g.template_dir.to_s
64+
assert_match %r{/template/aliki/?$}, @g.template_dir.to_s
6565
end
6666

6767
def test_aliased_classes_full_name

0 commit comments

Comments
 (0)