diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/request_controller.rb | 21 | ||||
-rw-r--r-- | app/models/foi_attachment.rb | 3 |
2 files changed, 10 insertions, 14 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index d4c303e52..d66c28275 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -763,19 +763,14 @@ class RequestController < ApplicationController key_path = foi_fragment_cache_path(key) image_dir = File.dirname(key_path) FileUtils.mkdir_p(image_dir) - html = @attachment.body_as_html(image_dir, :attachment_url => CGI.escape(@attachment_url)) - - view_html_stylesheet = render_to_string(:partial => "request/view_html_stylesheet") - view_html_prefix = render_to_string(:partial => "request/view_html_prefix") - - # Parse the generated HTML so we can inject more stuff - parsed = Nokogiri::HTML.parse(html) - # Insert the stylesheet in the head - parsed.css('head').children.after(view_html_stylesheet) - # Insert the content prefix - parsed.css('body').children.before(view_html_prefix) - # Get the raw html to render - html = parsed.to_html + + html = @attachment.body_as_html(image_dir, + :attachment_url => Rack::Utils.escape(@attachment_url), + :content_for => { + :head_suffix => render_to_string(:partial => "request/view_html_stylesheet"), + :body_prefix => render_to_string(:partial => "request/view_html_prefix") + } + ) @incoming_message.html_mask_stuff!(html) diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index 6f46c6785..6f198249a 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -294,7 +294,8 @@ class FoiAttachment < ActiveRecord::Base # For "View as HTML" of attachment def body_as_html(dir, opts = {}) attachment_url = opts.fetch(:attachment_url, nil) - AttachmentToHTML.to_html(self, :tmpdir => dir, :attachment_url => attachment_url) + to_html_opts = opts.merge(:tmpdir => dir, :attachment_url => attachment_url) + AttachmentToHTML.to_html(self, to_html_opts) end end |