class PdfViewer

Public Class Methods

new(tagName, content, tokens) click to toggle source
Calls superclass method
# File lib/jekyll-pdfviewer.rb, line 5
def initialize(tagName, content, tokens)
  super
  @content = content
end

Public Instance Methods

render(context) click to toggle source
# File lib/jekyll-pdfviewer.rb, line 10
def render(context)
  pdf_url = "#{context[@content.strip]}"
  # if pdf_url[/youtu\.be\/([^\?]*)/]
  #   @youtube_id = $1
  # else
  #   # Regex from # http://stackoverflow.com/questions/3452546/javascript-regex-how-to-get-youtube-video-id-from-url/4811367#4811367
  #   pdf_url[/^.*((v\/)|(embed\/)|(watch\?))\??v?=?([^\&\?]*).*/]
  #   @youtube_id = $5
  # end
  
  tmpl_path = File.join Dir.pwd, "_includes", "pdfviewer.html"
  if File.exist?(tmpl_path)
    tmpl = File.read tmpl_path
    site = context.registers[:site]
    tmpl = (Liquid::Template.parse tmpl).render site.site_payload.merge!({"pdf_url" => @pdf_url})
  else
    %Q{<object data='#{ @pdf_url }#search=study&highlight=20,20,20,20' type='application/pdf' width='50%' height='50%'><p>It appears your Web browser is not configured to display PDF files. No worries, just <a href='#{ @pdf_url }'>click here to download the PDF file.</a></p></object>}
  end
end