set/abstract/pdfjs.rb in card-mod-pdfjs-0.2 vs set/abstract/pdfjs.rb in card-mod-pdfjs-0.3
- old
+ new
@@ -1,36 +1,33 @@
format :html do
def pdf?
card.respond_to?(:file) && card.file.content_type == "application/pdf"
end
- def default_pdfjs_iframe_args args
- args[:pdf_url] ||= card.file.url if card.respond_to?(:file)
- args[:viewer_path] ||= "/mod/pdfjs/web/viewer.html"
- args[:viewer_path] << "?file=#{args[:pdf_url]}" if args[:pdf_url]
+ def pdfjs_iframe pdf_url: nil, viewer_path: nil
+ pdf_url ||= pdf_url_from_card
+ haml :pdfjs_iframe, viewer_path: pdf_viewer_path(viewer_path, pdf_url)
end
- def pdfjs_iframe args
- default_pdfjs_iframe_args args
- <<-HTML
- <iframe style="width: 100%"
- id="source-preview-iframe" class="pdfjs-iframe"
- src="#{args[:viewer_path]}"
- security="restricted"
- sandbox="allow-same-origin allow-scripts allow-forms allow-modals
- allow-top-navigation"
- allowfullscreen>
- </iframe>
- HTML
- end
-
view :pdf_preview do
wrap_with :div, id: "pdf-preview" do
pdfjs_iframe pdf_url: card.file_url
end
end
view :pdfjs_viewer do
# TODO: show pdfjs viewer directly without iframe
# Pdfjs.viewer
+ end
+
+ private
+
+ def pdf_url_from_card
+ card.file.url if card.respond_to? :file
+ end
+
+ def pdf_viewer_path viewer_path, pdf_url
+ viewer_path ||= card_path "/mod/pdfjs/web/viewer.html"
+ viewer_path << "?file=#{pdf_url}" if pdf_url
+ viewer_path
end
end