aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/attachment_to_html/adapters/could_not_convert.rb44
-rw-r--r--spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb49
2 files changed, 24 insertions, 69 deletions
diff --git a/lib/attachment_to_html/adapters/could_not_convert.rb b/lib/attachment_to_html/adapters/could_not_convert.rb
index 9ce28a848..8e4bf39dc 100644
--- a/lib/attachment_to_html/adapters/could_not_convert.rb
+++ b/lib/attachment_to_html/adapters/could_not_convert.rb
@@ -2,26 +2,32 @@ module AttachmentToHTML
module Adapters
class CouldNotConvert
- attr_reader :attachment, :wrapper
+ attr_reader :attachment
- # Public: Initialize a Text converter
+ # Public: Initialize a PDF 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
+ # No options currently accepted
def initialize(attachment, opts = {})
@attachment = attachment
- @wrapper = opts.fetch(:wrapper, 'wrapper')
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?
# As this is a fallback option and not doing anything dynamic
# we're assuming this is successful whatever the case
@@ -33,27 +39,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
"<p>Sorry, we were unable to convert this file to HTML. " \
"Please use the download link at the top right.</p>"
end
diff --git a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb
index aee68e986..afdc5c552 100644
--- a/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb
+++ b/spec/lib/attachment_to_html/adapters/could_not_convert_spec.rb
@@ -3,55 +3,24 @@ require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
describe AttachmentToHTML::Adapters::CouldNotConvert do
let(:attachment) { FactoryGirl.build(:pdf_attachment) }
- let(:adapter) { AttachmentToHTML::Adapters::CouldNotConvert.new(attachment) }
-
- describe :wrapper do
+ let(:adapter) do
+ AttachmentToHTML::Adapters::CouldNotConvert.new(attachment)
+ end
- it 'defaults to wrapper' do
- adapter.wrapper.should == 'wrapper'
- end
+ describe :title do
- it 'accepts a wrapper option' do
- adapter = AttachmentToHTML::Adapters::CouldNotConvert.new(attachment, :wrapper => 'wrap')
- adapter.wrapper.should == 'wrap'
+ it 'uses the attachment filename for the title' do
+ adapter.title.should == attachment.display_filename
end
end
- describe :to_html do
-
- it 'should be a valid html document' do
- parsed = Nokogiri::HTML.parse(adapter.to_html) do |config|
- config.strict
- end
- parsed.errors.any?.should be_false
- end
-
- it 'contains the attachment filename in the title tag' do
- parsed = Nokogiri::HTML.parse(adapter.to_html) do |config|
- config.strict
- end
- parsed.css('title').inner_html.should == attachment.display_filename
- end
-
- it 'contains the wrapper div in the body tag' do
- adapter = AttachmentToHTML::Adapters::CouldNotConvert.new(attachment, :wrapper => 'wrap')
- parsed = Nokogiri::HTML.parse(adapter.to_html) do |config|
- config.strict
- end
- parsed.css('body div').first.attributes['id'].value.should == 'wrap'
- end
-
- it 'should contain text about the conversion failure' do
- adapter = AttachmentToHTML::Adapters::CouldNotConvert.new(attachment, :wrapper => 'wrap')
- parsed = Nokogiri::HTML.parse(adapter.to_html) do |config|
- config.strict
- end
+ describe :body do
+ it 'contains a message asking the user to download the file directly' do
expected = "<p>Sorry, we were unable to convert this file to HTML. " \
"Please use the download link at the top right.</p>"
-
- parsed.css('div#wrap div#view-html-content').inner_html.should == expected
+ adapter.body.should == expected
end
end