render_to_string with rtex
Reported by Hans-Jürgen Husel | June 26th, 2008 @ 02:34 PM
There is no render_to_string with tex templates. It is not possible to do something like
a = render_to_string :template => 'projects/index.pdf.rtex'
send_data a, :type => 'application/pdf', :disposition => 'inline'
A possible solution is this new function in lib/rtex/framework/rails.rb
def render_to_string_with_rtex(options=nil, *args, &block)
@internal_rtex_call = true
result = render_to_string_without_rtex(options, *args, &block)
@internal_rtex_call = nil
if result.is_a?(String) && @template.template_format == :pdf
options ||= {}
::RTeX::Document.new(result, options.merge(:processed => true)).to_pdf
else
result
end
end
But this is not enough. render_to_string and send_data both call render to do the real work and render is mapped to render_with_rtex. And render_with_rtex will always generate a PDF if the template format is pdf. So the first if statement in render_with_rtex must be modified.
Old condition
if result.is_a?(String) && @template.template_format == :pdf
New condition
if result.is_a?(String) && @template.template_format == :pdf && @internal_rtex_call != true && result[0,5] != '%PDF-'
The modified version of lib/rtex/framework/rails.rb is attached to this ticket.
Comments and changes to this ticket
-
Joachim Garth August 9th, 2008 @ 04:27 PM
- Tag set to feature-request
+1 Thanks! Just what I needed.
-
Bruce Williams August 17th, 2008 @ 04:16 PM
- State changed from new to open
Opening ticket for work, testing against stable and edge versions of Rails.
-
Bruce Williams September 20th, 2008 @ 02:01 PM
- State changed from open to hold
- Tag changed from feature-request to feature-request
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
RTeX is a Ruby library (and web framework plugin) used to generate PDF documents on-the-fly using the LaTeX typesetting system.
People watching this ticket
Attachments
Tags
Referenced by
- 12 render_to_string fails with RTeX Note, this is not the same as ticket #3 because I'm not t...