diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/attachment_to_html/adapters/google_docs_viewer.rb | 43 |
1 files changed, 13 insertions, 30 deletions
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 <title> 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 }</title>" - html += "</head>" - html += "<body>" - html += "<div id=\"#{ wrapper }\">" - html += "<div id=\"view-html-content\">" - html += body - html += "</div>" - html += "</div>" - html += "</body>" - html += "</html>" - end - - def title - @title ||= attachment.display_filename - end - - def body + def parse_body %Q(<iframe src="#{ protocol }://docs.google.com/viewer?url=#{ attachment_url }&embedded=true" width="100%" height="100%" style="border: none;"></iframe>) end |