jekyll-pdf-embed 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jekyll-pdf-embed.rb +50 -30
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5dc9316cdf5ae27c45ef92242fd721d641d95c20d82280166aea2f24796959b8
|
4
|
+
data.tar.gz: 599ad2ab15f659694706d72ad23cc41f5ff2dce737b641921e3f3e20a9235640
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f416785c75bf644eb469db9442f358659798966ddf7d30ca88a948e77b0031f9afbdda9f52ef3814f720165aef4d9514df7690a703446505689901ac28622953
|
7
|
+
data.tar.gz: 6cf605a961c55042ea9a7ce8817ff119d78a9afd413514be84119cabbfe6e5de8c3ddf1aee41a7a19749c3ba2c06cbfe398496a63561196e3b913a61d2df87fd
|
data/lib/jekyll-pdf-embed.rb
CHANGED
@@ -1,44 +1,64 @@
|
|
1
1
|
require "jekyll"
|
2
2
|
|
3
|
-
class
|
4
|
-
|
5
|
-
def initialize(
|
3
|
+
class PDFEmbedTest < Liquid::Tag
|
4
|
+
|
5
|
+
def initialize(tagName, content, tokens)
|
6
6
|
super
|
7
|
-
@
|
8
|
-
|
9
|
-
|
10
|
-
@
|
11
|
-
|
12
|
-
|
13
|
-
@
|
14
|
-
|
7
|
+
@content = content
|
8
|
+
|
9
|
+
# define allowed extensions
|
10
|
+
@allowed_files = [".pdf", ".ppt", ".pptx"]
|
11
|
+
|
12
|
+
# get the 'no_link' param and check if it is present
|
13
|
+
@param = @content.split(/ /).last
|
14
|
+
@no_link = @param == 'no_link' ? true : false
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def render(context)
|
18
|
+
if @no_link
|
19
|
+
# if 'no_link' is present then
|
20
|
+
# remove only the last occurence of 'no_link' keyword
|
21
|
+
# https://www.regular-expressions.info/keep.html
|
22
|
+
@content = @content.sub(/.*\K no_link/, '')
|
23
|
+
end
|
24
|
+
|
25
|
+
@link = "#{context[@content.strip]}"
|
26
|
+
|
27
|
+
# get extension and check if it is allowed
|
28
|
+
@extension = File.extname(@link)
|
29
|
+
@is_allowed = @allowed_files.include? @extension
|
30
|
+
|
18
31
|
if !@is_allowed
|
19
|
-
raise ArgumentError, 'ERROR:file_not_allowed'
|
32
|
+
raise ArgumentError, 'ERROR:file_not_allowed -> ' + @link
|
20
33
|
end
|
21
|
-
|
22
|
-
if @
|
23
|
-
if @
|
24
|
-
%Q{<style>.pdf-embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin-bottom: 20px;
|
25
|
-
elsif @params.length == 2 && @params[1] == 'no_link'
|
26
|
-
%Q{<style>.pdf-embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin-bottom: 20px; } .pdf-embed-container iframe, .pdf-embed-container object, .pdf-embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='pdf-embed-container'><iframe title="PDF file" width="640" height="390" src=#{@link_escaped} frameborder="0" allowfullscreen></iframe></div>}
|
34
|
+
|
35
|
+
if @extension == ".pdf"
|
36
|
+
if @no_link
|
37
|
+
%Q{<style>.pdf-embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin-bottom: 20px; } .pdf-embed-container iframe, .pdf-embed-container object, .pdf-embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='pdf-embed-container'><iframe title="PDF file" width="640" height="390" src="#{@link}" frameborder="0" allowfullscreen></iframe></div>}
|
27
38
|
else
|
28
|
-
|
39
|
+
%Q{<style>.pdf-embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin-bottom: 20px; border-style: solid; } .pdf-link { background-color: white; text-align: center; border-style: solid; } .pdf-embed-container iframe, .pdf-embed-container object, .pdf-embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='pdf-link'><a href="#{@link}" target="_blank">View PDF</a></div><div class='pdf-embed-container'><iframe title="PDF file" width="640" height="390" src="#{@link}" frameborder="0" allowfullscreen></iframe></div>}
|
29
40
|
end
|
30
|
-
elsif @
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
elsif @extension == ".ppt" or @extension == ".pptx"
|
42
|
+
|
43
|
+
# checks if the presentation is not on remote address
|
44
|
+
if !@link.include? "http://" and !@link.include? "https://"
|
45
|
+
# get base url and appent file location to it
|
46
|
+
@baseurl = "#{context.registers[:site].config['url']}"
|
47
|
+
@link = "https://view.officeapps.live.com/op/embed.aspx?src=#{@baseurl}#{@link}"
|
48
|
+
# locally, this will not work
|
49
|
+
# but once the Jekyll site is hosted remotely, the baseurl will not be 'localhost'
|
35
50
|
else
|
36
|
-
|
51
|
+
@link = "https://view.officeapps.live.com/op/embed.aspx?src=#{@link}"
|
52
|
+
end
|
53
|
+
|
54
|
+
if @no_link
|
55
|
+
%Q{<style>.pdf-embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin-bottom: 20px; } .pdf-embed-container iframe, .pdf-embed-container object, .pdf-embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='pdf-embed-container'><iframe title="PDF file" width="640" height="390" src="#{@link}" frameborder="0" allowfullscreen></iframe></div>}
|
56
|
+
else
|
57
|
+
%Q{<style>.pdf-embed-container { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; margin-bottom: 20px; border-style: solid; } .pdf-link { background-color: white; text-align: center; border-style: solid; } .pdf-embed-container iframe, .pdf-embed-container object, .pdf-embed-container embed { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }</style><div class='pdf-link'><a href="#{@link}" target="_blank">View presentation</a></div><div class='pdf-embed-container'><iframe title="Presentation file" width="640" height="390" src="#{@link}" frameborder="0" allowfullscreen></iframe></div>}
|
37
58
|
end
|
38
|
-
else
|
39
|
-
raise ArgumentError, 'ERROR:bad_syntax'
|
40
59
|
end
|
41
|
-
end
|
42
60
|
|
61
|
+
end
|
62
|
+
|
43
63
|
Liquid::Template.register_tag('pdf', self)
|
44
|
-
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-pdf-embed
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mihajlo Nesic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -35,7 +35,7 @@ files:
|
|
35
35
|
- lib/jekyll-pdf-embed.rb
|
36
36
|
homepage: https://github.com/MihajloNesic/jekyll-pdf-embed
|
37
37
|
licenses:
|
38
|
-
-
|
38
|
+
- GPL-3.0
|
39
39
|
metadata: {}
|
40
40
|
post_install_message:
|
41
41
|
rdoc_options: []
|
@@ -52,8 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
requirements: []
|
55
|
-
|
56
|
-
rubygems_version: 2.7.6.2
|
55
|
+
rubygems_version: 3.0.3
|
57
56
|
signing_key:
|
58
57
|
specification_version: 4
|
59
58
|
summary: Jekyll plugin for embedding PDF files to any page or post
|