Class: PdfViewer

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-pdfviewer.rb

Instance Method Summary collapse

Constructor Details

#initialize(tagName, content, tokens) ⇒ PdfViewer

Returns a new instance of PdfViewer.



5
6
7
8
# File 'lib/jekyll-pdfviewer.rb', line 5

def initialize(tagName, content, tokens)
  super
  @content = content
end

Instance Method Details

#render(context) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# 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