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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pdf-embed.rb +50 -30
  3. metadata +4 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 888469f8bfacc1099507591ff273cd4232a1bf1839933ddcc9cfc5f643a83df0
4
- data.tar.gz: 83c548429ed46cbc2b751b337aaa411f930b6708e5495d96b8effd980571959c
3
+ metadata.gz: 5dc9316cdf5ae27c45ef92242fd721d641d95c20d82280166aea2f24796959b8
4
+ data.tar.gz: 599ad2ab15f659694706d72ad23cc41f5ff2dce737b641921e3f3e20a9235640
5
5
  SHA512:
6
- metadata.gz: 35a245969599306c9c7852f92acd808d874771c8f3899416aa59bbaf2fb0c37db5cf80e860ba352d749bd8378bcbbcc2d52f36fb5dd8c28dae6a78872a9c0252
7
- data.tar.gz: f6b09be69b53dae11b5af3fa0ef1a95e2466e8edff20f08546a4b3a759dae116a9fe32a2841e26be4349a7c1e4a71b0da90c940ba3f9486b6cf45ca2911139ce
6
+ metadata.gz: f416785c75bf644eb469db9442f358659798966ddf7d30ca88a948e77b0031f9afbdda9f52ef3814f720165aef4d9514df7690a703446505689901ac28622953
7
+ data.tar.gz: 6cf605a961c55042ea9a7ce8817ff119d78a9afd413514be84119cabbfe6e5de8c3ddf1aee41a7a19749c3ba2c06cbfe398496a63561196e3b913a61d2df87fd
@@ -1,44 +1,64 @@
1
1
  require "jekyll"
2
2
 
3
- class PDFEmbed < Liquid::Tag
4
-
5
- def initialize(tag_name, text, tokens)
3
+ class PDFEmbedTest < Liquid::Tag
4
+
5
+ def initialize(tagName, content, tokens)
6
6
  super
7
- @allowed_files = [".pdf\"", ".ppt\""]
8
- @link = text[/".*?"/]
9
- @link_escaped = @link.gsub(" ", "%20")
10
- @raw_link = @link_escaped.gsub("\"", "")
11
- @ext = File.extname(@link_escaped)
12
- @is_allowed = @allowed_files.include? @ext
13
- @text = text.gsub(@link, @link_escaped)
14
- *@params = @text.split(/ /)
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 @ext == ".pdf\""
23
- if @params.length == 1
24
- %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_escaped} target="_blank">View PDF</a></div><div class='pdf-embed-container'><iframe title="PDF file" width="640" height="390" src=#{@link_escaped} frameborder="0" allowfullscreen></iframe></div>}
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
- raise ArgumentError, 'ERROR:bad_syntax'
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 @ext == ".ppt\""
31
- if @params.length == 1
32
- %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="https://view.officeapps.live.com/op/embed.aspx?src=#{@raw_link}" target="_blank">View presentation</a></div><div class='pdf-embed-container'><iframe title="PDF file" width="640" height="390" src="https://view.officeapps.live.com/op/embed.aspx?src=#{@raw_link}" frameborder="0" allowfullscreen></iframe></div>}
33
- elsif @params.length == 2 && @params[1] == 'no_link'
34
- %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="https://view.officeapps.live.com/op/embed.aspx?src=#{@raw_link}" frameborder="0" allowfullscreen></iframe></div>}
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
- raise ArgumentError, 'ERROR:bad_syntax'
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
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: 2020-03-27 00:00:00.000000000 Z
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
- - MIT
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
- rubyforge_project:
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