Skip to content

Commit

Permalink
Set template encoding correctly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
drbrain committed Feb 8, 2013
1 parent eab2185 commit e12ca93
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
8 changes: 7 additions & 1 deletion History.rdoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
=== 4.0.0.rc.2 / 2013-02-05
=== 4.0.0.rc.2.1

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

* Bug fix
* Templates now use the correct encoding when generating pages. Issue #183
by Vít Ondruch

=== 4.0.0.rc.2 / 2013-02-05

* Minor enhancements
* Added current heading and page-top links to HTML headings.

Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Error < RuntimeError; end
##
# RDoc version you are using

VERSION = '4.0.0.rc.2'
VERSION = '4.0.0.rc.2.1'

##
# Method visibilities
Expand Down
23 changes: 11 additions & 12 deletions lib/rdoc/generator/darkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -698,18 +698,17 @@ def template_for file, page = true, klass = ERB

return template if template

template = if page then
assemble_template file
else
file.read
end

erbout = if page then
'io'
else
file_var = File.basename(file).sub(/\..*/, '')
"_erbout_#{file_var}"
end
if page then
template = assemble_template file
erbout = 'io'
else
template = file.read
template = template.encode @options.encoding

file_var = File.basename(file).sub(/\..*/, '')

erbout = "_erbout_#{file_var}"
end

template = klass.new template, nil, '<>', erbout
@template_cache[file] = template
Expand Down
10 changes: 10 additions & 0 deletions test/test_rdoc_generator_darkfish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,15 @@ def test_template_for_dry_run
assert_same template, @g.send(:template_for, classpage)
end

def test_template_for_partial
partial = Pathname.new @options.template_dir + '_sidebar_classes.rhtml'

template = @g.send(:template_for, partial, false, RDoc::ERBPartial)

assert_kind_of RDoc::ERBPartial, template

assert_same template, @g.send(:template_for, partial)
end

end

0 comments on commit e12ca93

Please sign in to comment.