Skip to content

Commit e12ca93

Browse files
committed
Set template encoding correctly
When partials for templates were created the encoding of the output was not properly set. This would lead to encoding errors when invalid characters where generated while writing to the main page. Now the template source is transcoded to the output encoding which allows the template result encoding to be correct. This issue resisted efforts to write a proper test-case. Fixes #183
1 parent eab2185 commit e12ca93

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

History.rdoc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
=== 4.0.0.rc.2 / 2013-02-05
1+
=== 4.0.0.rc.2.1
22

33
As a preview release, please file bugs for any problems you have with rdoc at
44
https://github.com/rdoc/rdoc/issues
@@ -10,6 +10,12 @@ Notable feature additions are markdown support and an WEBrick servlet that can
1010
serve HTML from an ri store. (This means that RubyGems 2.0+ no longer needs
1111
to build HTML documentation when installing gems.)
1212

13+
* Bug fix
14+
* Templates now use the correct encoding when generating pages. Issue #183
15+
by Vít Ondruch
16+
17+
=== 4.0.0.rc.2 / 2013-02-05
18+
1319
* Minor enhancements
1420
* Added current heading and page-top links to HTML headings.
1521

lib/rdoc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class Error < RuntimeError; end
6464
##
6565
# RDoc version you are using
6666

67-
VERSION = '4.0.0.rc.2'
67+
VERSION = '4.0.0.rc.2.1'
6868

6969
##
7070
# Method visibilities

lib/rdoc/generator/darkfish.rb

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -698,18 +698,17 @@ def template_for file, page = true, klass = ERB
698698

699699
return template if template
700700

701-
template = if page then
702-
assemble_template file
703-
else
704-
file.read
705-
end
706-
707-
erbout = if page then
708-
'io'
709-
else
710-
file_var = File.basename(file).sub(/\..*/, '')
711-
"_erbout_#{file_var}"
712-
end
701+
if page then
702+
template = assemble_template file
703+
erbout = 'io'
704+
else
705+
template = file.read
706+
template = template.encode @options.encoding
707+
708+
file_var = File.basename(file).sub(/\..*/, '')
709+
710+
erbout = "_erbout_#{file_var}"
711+
end
713712

714713
template = klass.new template, nil, '<>', erbout
715714
@template_cache[file] = template

test/test_rdoc_generator_darkfish.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,15 @@ def test_template_for_dry_run
173173
assert_same template, @g.send(:template_for, classpage)
174174
end
175175

176+
def test_template_for_partial
177+
partial = Pathname.new @options.template_dir + '_sidebar_classes.rhtml'
178+
179+
template = @g.send(:template_for, partial, false, RDoc::ERBPartial)
180+
181+
assert_kind_of RDoc::ERBPartial, template
182+
183+
assert_same template, @g.send(:template_for, partial)
184+
end
185+
176186
end
177187

0 commit comments

Comments
 (0)