From 50ed310bed98ea23f813a5abd4210e34711dfb4c Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Wed, 2 Apr 2014 12:20:02 +0100 Subject: Simpler AttachmentToHTML::Adapters::GoogleDocsViewer interface --- .../adapters/google_docs_viewer.rb | 43 +++++++--------------- 1 file changed, 13 insertions(+), 30 deletions(-) (limited to 'lib/attachment_to_html') diff --git a/lib/attachment_to_html/adapters/google_docs_viewer.rb b/lib/attachment_to_html/adapters/google_docs_viewer.rb index 86908ad5c..991fbb757 100644 --- a/lib/attachment_to_html/adapters/google_docs_viewer.rb +++ b/lib/attachment_to_html/adapters/google_docs_viewer.rb @@ -3,28 +3,31 @@ module AttachmentToHTML # Renders the attachment in a Google Docs Viewer class GoogleDocsViewer - attr_reader :attachment, :wrapper, :attachment_url + attr_reader :attachment, :attachment_url - # Public: Initialize a PDF converter + # Public: Initialize a GoogleDocsViewer converter # # attachment - the FoiAttachment to convert to HTML # opts - a Hash of options (default: {}): - # :wrapper - String id of the div that wraps the - # attachment body - # (default: 'wrapper_google_embed') # :attachment_url - a String url to the attachment for # Google to render (default: nil) def initialize(attachment, opts = {}) @attachment = attachment - @wrapper = opts.fetch(:wrapper, 'wrapper_google_embed') @attachment_url = opts.fetch(:attachment_url, nil) end - # Public: Convert the attachment to HTML + # Public: The title to use in the tag # # Returns a String - def to_html - @html ||= generate_html + def title + @title ||= attachment.display_filename + end + + # Public: The contents of the extracted html <body> tag + # + # Returns a String + def body + @body ||= parse_body end # Public: Was the document conversion successful? @@ -40,27 +43,7 @@ module AttachmentToHTML private - def generate_html - html = "<!DOCTYPE html>" - html += "<html>" - html += "<head>" - html += "<title>#{ title }" - html += "" - html += "" - html += "
" - html += "
" - html += body - html += "
" - html += "
" - html += "" - html += "" - end - - def title - @title ||= attachment.display_filename - end - - def body + def parse_body %Q() end -- cgit v1.2.3