From b6561750b971030767a0e8146be1414471518086 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 19 Mar 2014 11:40:59 +0000 Subject: Use AttachmentToHTML to generate FoiAttachment#body_as_html --- app/controllers/request_controller.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'app/controllers/request_controller.rb') diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 6445dd685..d4c303e52 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -763,18 +763,22 @@ class RequestController < ApplicationController key_path = foi_fragment_cache_path(key) image_dir = File.dirname(key_path) FileUtils.mkdir_p(image_dir) - html, wrapper_id = @attachment.body_as_html(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" - html.sub!(//i, "" + view_html_stylesheet) - html.sub!(/]*>/i, '
') - html.sub!(/<\/body[^>]*>/i, '
') + view_html_stylesheet = render_to_string(:partial => "request/view_html_stylesheet") + view_html_prefix = render_to_string(:partial => "request/view_html_prefix") - view_html_prefix = render_to_string :partial => "request/view_html_prefix" - html.sub!("", view_html_prefix) - html.sub!("", CGI.escape(@attachment_url)) + # 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 @incoming_message.html_mask_stuff!(html) + response.content_type = 'text/html' render :text => html end -- cgit v1.2.3 From 9f283e2e48e859d1ba6a31baa783feb177cccb17 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 2 Apr 2014 17:43:04 +0100 Subject: Update gubbins to call AttachmentToHTML --- app/controllers/request_controller.rb | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'app/controllers/request_controller.rb') 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) -- cgit v1.2.3