jekyll-pdf-embed 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll-pdf-embed.rb +49 -15
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dc9316cdf5ae27c45ef92242fd721d641d95c20d82280166aea2f24796959b8
4
- data.tar.gz: 599ad2ab15f659694706d72ad23cc41f5ff2dce737b641921e3f3e20a9235640
3
+ metadata.gz: a200282b5c85cab73729e58efb740bed697c25868ba9181e4fd3db57b5ac799b
4
+ data.tar.gz: ec680e5ceb0c41a4eb39048447c2a95cce698baedb35882b2525b9d774b9ea5f
5
5
  SHA512:
6
- metadata.gz: f416785c75bf644eb469db9442f358659798966ddf7d30ca88a948e77b0031f9afbdda9f52ef3814f720165aef4d9514df7690a703446505689901ac28622953
7
- data.tar.gz: 6cf605a961c55042ea9a7ce8817ff119d78a9afd413514be84119cabbfe6e5de8c3ddf1aee41a7a19749c3ba2c06cbfe398496a63561196e3b913a61d2df87fd
6
+ metadata.gz: 8b50713dbf73074347588e2115f4c5c3d4a0850702d8088a808386fd95bdd3979b18f678ba4a4334d38a91ff9e58aefbae2f608526d3309c37f88683eba1c149
7
+ data.tar.gz: 44a29554ff3d855c665dff439718740e83406740b2536c1e43b53a49e3aa4fe6d91ea2204bb9c44ba157a91d103c7e1a96e950e84047eebf1fb5a617a918389b
@@ -1,7 +1,10 @@
1
1
  require "jekyll"
2
+ require "securerandom"
2
3
 
3
4
  class PDFEmbedTest < Liquid::Tag
4
5
 
6
+ NO_LINK_ARG = "no_link".freeze
7
+
5
8
  def initialize(tagName, content, tokens)
6
9
  super
7
10
  @content = content
@@ -9,34 +12,50 @@ class PDFEmbedTest < Liquid::Tag
9
12
  # define allowed extensions
10
13
  @allowed_files = [".pdf", ".ppt", ".pptx"]
11
14
 
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
+ # current container uuid
16
+ @uuid = SecureRandom.uuid
15
17
  end
16
18
 
17
19
  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
20
+ @parsed_content = Liquid::Template.parse(@content).render(context)
21
+ @args = @parsed_content.split(/ /)
24
22
 
25
- @link = "#{context[@content.strip]}"
23
+ @link_raw = @args.first
24
+ @link = @link_raw.tr('\"', '')
26
25
 
27
- # get extension and check if it is allowed
26
+ @no_link = @args.include? NO_LINK_ARG
28
27
  @extension = File.extname(@link)
29
28
  @is_allowed = @allowed_files.include? @extension
30
29
 
30
+ @other_args_raw = @parsed_content.clone
31
+ @other_args_raw.slice! @link_raw
32
+ @other_args_raw.slice! NO_LINK_ARG
33
+ @other_args_raw.strip!
34
+
35
+ @other_args_array = @other_args_raw.split(/ /)
36
+
37
+ @other_args = hash_from_args(@other_args_array)
38
+ @w = @other_args["width"]
39
+ @h = @other_args["height"]
40
+
41
+ # default width and height values
42
+ if @w == nil
43
+ @w = "100%"
44
+ end
45
+
46
+ if @h == nil
47
+ @h = "500px"
48
+ end
49
+
31
50
  if !@is_allowed
32
51
  raise ArgumentError, 'ERROR:file_not_allowed -> ' + @link
33
52
  end
34
53
 
35
54
  if @extension == ".pdf"
36
55
  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>}
56
+ %Q{<style>.pdf-embed-wrap-#{@uuid} { display:flex; flex-direction: column; width: #{@w}; height: #{@h}; } .pdf-embed-container-#{@uuid} { height: 100%; } .pdf-embed-container-#{@uuid} iframe { width: 100%; height: 100%; }</style><div class="pdf-embed-wrap-#{@uuid}"><div class='pdf-embed-container-#{@uuid}'><iframe title="PDF file" src="#{@link}" frameborder="0" allowfullscreen></iframe></div></div>}
38
57
  else
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>}
58
+ %Q{<style>.pdf-embed-wrap-#{@uuid} { display:flex; flex-direction: column; width: #{@w}; height: #{@h}; } .pdf-embed-container-#{@uuid} { height: 100%; } .pdf-link-#{@uuid} { background-color: white; text-align: center; border-style: solid; } .pdf-embed-container-#{@uuid} iframe { width: 100%; height: 100%; }</style><div class="pdf-embed-wrap-#{@uuid}"><div class='pdf-link-#{@uuid}'><a href="#{@link}" target="_blank">View PDF</a></div><div class='pdf-embed-container-#{@uuid}'><iframe title="PDF file" src="#{@link}" frameborder="0" allowfullscreen></iframe></div></div>}
40
59
  end
41
60
  elsif @extension == ".ppt" or @extension == ".pptx"
42
61
 
@@ -52,13 +71,28 @@ class PDFEmbedTest < Liquid::Tag
52
71
  end
53
72
 
54
73
  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>}
74
+ %Q{<style>.pdf-embed-wrap-#{@uuid} { display:flex; flex-direction: column; width: #{@w}; height: #{@h}; } .pdf-embed-container-#{@uuid} { height: 100%; } .pdf-embed-container-#{@uuid} iframe { width: 100%; height: 100%; }</style><div class="pdf-embed-wrap-#{@uuid}"><div class='pdf-embed-container-#{@uuid}'><iframe title="Presentation file" src="#{@link}" frameborder="0" allowfullscreen></iframe></div></div>}
56
75
  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>}
76
+ %Q{<style>.pdf-embed-wrap-#{@uuid} { display:flex; flex-direction: column; width: #{@w}; height: #{@h}; } .pdf-embed-container-#{@uuid} { height: 100%; } .pdf-link-#{@uuid} { background-color: white; text-align: center; border-style: solid; } .pdf-embed-container-#{@uuid} iframe { width: 100%; height: 100%; }</style><div class="pdf-embed-wrap-#{@uuid}"><div class='pdf-link-#{@uuid}'><a href="#{@link}" target="_blank">View presentation</a></div><div class='pdf-embed-container-#{@uuid}'><iframe title="Presentation file" src="#{@link}" frameborder="0" allowfullscreen></iframe></div></div>}
58
77
  end
59
78
  end
60
79
 
61
80
  end
81
+
82
+ # Transform 'a=b c=d' into hash
83
+ def hash_from_args(args_array)
84
+ keys_values = args_array.map {|item| item.split /\s*=\s*/ }
85
+ return Hash[keys_values]
86
+ end
87
+
88
+ def remove_quotations(str)
89
+ if str.start_with?('"')
90
+ str = str.slice(1..-1)
91
+ end
92
+ if str.end_with?('"')
93
+ str = str.slice(0..-2)
94
+ end
95
+ end
62
96
 
63
97
  Liquid::Template.register_tag('pdf', self)
64
98
  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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mihajlo Nesic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-17 00:00:00.000000000 Z
11
+ date: 2021-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll