Class: PDFEmbedder::PDFTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- PDFEmbedder::PDFTag
- Defined in:
- lib/embed_pdf.rb
Instance Method Summary collapse
-
#initialize(tag_name, url, tokens) ⇒ PDFTag
constructor
A new instance of PDFTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, url, tokens) ⇒ PDFTag
Returns a new instance of PDFTag.
6 7 8 9 |
# File 'lib/embed_pdf.rb', line 6 def initialize(tag_name, url, tokens) super @url = url end |
Instance Method Details
#render(context) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/embed_pdf.rb', line 11 def render(context) # current directory filedir = File.dirname(context.registers[:page]["path"]) # if the path is relative than we have escape up one level if !Pathname.new(@url.strip).absolute? pdfpath = File.path(File.join("..", @url.strip)) else pdfpath = @url.strip end result = "<div class=\"pdf-wrapper\">" result += "<embed src=\"#{pdfpath}\"/>" result += "<div class=\"caption\">Original file: <a href=\"#{pdfpath}\">#{File.basename(pdfpath)}</a></div>" result += "</div>" end |