jekyll-pdf-embed 1.1.1 → 1.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a200282b5c85cab73729e58efb740bed697c25868ba9181e4fd3db57b5ac799b
4
- data.tar.gz: ec680e5ceb0c41a4eb39048447c2a95cce698baedb35882b2525b9d774b9ea5f
3
+ metadata.gz: 23fdfecaf78fa83fd60548ca3b16a1aae5d6ca94b1bd4eb91514f1bff21e7740
4
+ data.tar.gz: 3d3399763419c9db90dd91aa5baec59226dce2e657e12268818ed1ac4f4f0a89
5
5
  SHA512:
6
- metadata.gz: 8b50713dbf73074347588e2115f4c5c3d4a0850702d8088a808386fd95bdd3979b18f678ba4a4334d38a91ff9e58aefbae2f608526d3309c37f88683eba1c149
7
- data.tar.gz: 44a29554ff3d855c665dff439718740e83406740b2536c1e43b53a49e3aa4fe6d91ea2204bb9c44ba157a91d103c7e1a96e950e84047eebf1fb5a617a918389b
6
+ metadata.gz: af8d5ff480c16c38aa1d67c5722cbd9ea0a53442f68e6c8ed4b3372b071598ca07e57ceea8f8cbf07ca4c69f7253f920cc3a68b331a2480fa1be76aaaafd3fac
7
+ data.tar.gz: 9f2a07aa8de291605cfc01429d7aae0c08e51cbc32bb17297b0db635071648f3a643b73828335b4ffee73a89cf0e52cf4d711087e55592169b7557d61330ce6a
@@ -1,98 +1,9 @@
1
- require "jekyll"
2
- require "securerandom"
1
+ # frozen_string_literal: true
3
2
 
4
- class PDFEmbedTest < Liquid::Tag
3
+ require 'jekyll-pdf-embed/version'
4
+ require 'jekyll-pdf-embed/pdf-tag'
5
5
 
6
- NO_LINK_ARG = "no_link".freeze
7
-
8
- def initialize(tagName, content, tokens)
9
- super
10
- @content = content
11
-
12
- # define allowed extensions
13
- @allowed_files = [".pdf", ".ppt", ".pptx"]
14
-
15
- # current container uuid
16
- @uuid = SecureRandom.uuid
6
+ module Jekyll
7
+ module JekyllPDFEmbed
17
8
  end
18
-
19
- def render(context)
20
- @parsed_content = Liquid::Template.parse(@content).render(context)
21
- @args = @parsed_content.split(/ /)
22
-
23
- @link_raw = @args.first
24
- @link = @link_raw.tr('\"', '')
25
-
26
- @no_link = @args.include? NO_LINK_ARG
27
- @extension = File.extname(@link)
28
- @is_allowed = @allowed_files.include? @extension
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
-
50
- if !@is_allowed
51
- raise ArgumentError, 'ERROR:file_not_allowed -> ' + @link
52
- end
53
-
54
- if @extension == ".pdf"
55
- if @no_link
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>}
57
- else
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>}
59
- end
60
- elsif @extension == ".ppt" or @extension == ".pptx"
61
-
62
- # checks if the presentation is not on remote address
63
- if !@link.include? "http://" and !@link.include? "https://"
64
- # get base url and appent file location to it
65
- @baseurl = "#{context.registers[:site].config['url']}"
66
- @link = "https://view.officeapps.live.com/op/embed.aspx?src=#{@baseurl}#{@link}"
67
- # locally, this will not work
68
- # but once the Jekyll site is hosted remotely, the baseurl will not be 'localhost'
69
- else
70
- @link = "https://view.officeapps.live.com/op/embed.aspx?src=#{@link}"
71
- end
72
-
73
- if @no_link
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>}
75
- else
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>}
77
- end
78
- end
79
-
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
96
-
97
- Liquid::Template.register_tag('pdf', self)
98
- end
9
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll'
4
+ require 'securerandom'
5
+
6
+ class JekyllPDFEmbed < Liquid::Tag
7
+
8
+ NO_LINK_ARG = 'no_link'
9
+
10
+ def initialize(tag_name, content, tokens)
11
+ super
12
+ @content = content
13
+
14
+ # define allowed extensions
15
+ @allowed_files = %w[.pdf .ppt .pptx]
16
+
17
+ # current container uuid
18
+ @uuid = SecureRandom.uuid
19
+ end
20
+
21
+ def render(context)
22
+ @parsed_content = Liquid::Template.parse(@content).render(context)
23
+ @args = @parsed_content.split(/ /)
24
+
25
+ @link_raw = @args.first
26
+ @link = @link_raw.tr('\"', '')
27
+
28
+ @no_link = @args.include? NO_LINK_ARG
29
+ @extension = File.extname(@link)
30
+ @is_allowed = @allowed_files.include? @extension
31
+
32
+ @other_args_raw = @parsed_content.clone
33
+ @other_args_raw.slice! @link_raw
34
+ @other_args_raw.slice! NO_LINK_ARG
35
+ @other_args_raw.strip!
36
+
37
+ @other_args_array = @other_args_raw.split(/ /)
38
+
39
+ @other_args = hash_from_args(@other_args_array)
40
+ @width = @other_args['width']
41
+ @height = @other_args['height']
42
+
43
+ # default width and height values
44
+ @width = '100%' if @width.nil?
45
+ @height = '650px' if @height.nil?
46
+
47
+ raise ArgumentError, "ERROR:file_not_allowed -> #{@link}" unless @is_allowed
48
+
49
+ @label = ''
50
+
51
+ case @extension
52
+ when '.pdf'
53
+ @label = 'View PDF'
54
+ when '.ppt', '.pptx'
55
+ @label = 'View presentation'
56
+ # checks if the presentation is not on remote address
57
+ if !@link.include? 'http://' and !@link.include? 'https://'
58
+ # get base url and append file location to it
59
+ @baseurl = context.registers[:site].config['url'].to_s
60
+ @link = "https://view.officeapps.live.com/op/embed.aspx?src=#{@baseurl}#{@link}"
61
+ # locally, this will not work
62
+ # but once the Jekyll site is hosted remotely, the baseurl will not be 'localhost'
63
+ else
64
+ @link = "https://view.officeapps.live.com/op/embed.aspx?src=#{@link}"
65
+ end
66
+ else
67
+ raise ArgumentError, "ERROR:extension_not_recognized -> #{@extension} for link -> #{@link}"
68
+ end
69
+
70
+ if @no_link
71
+ %Q(<style> .pdf-embed-wrap-#{@uuid} { display:flex; flex-direction: column; width: #{@width}; height: #{@height}; } .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 src="#{@link}" frameborder="0" allowfullscreen></iframe> </div> </div>)
72
+ else
73
+ %Q(<style> .pdf-embed-wrap-#{@uuid} { display:flex; flex-direction: column; width: #{@width}; height: #{@height}; } .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">#{@label}</a> </div> <div class="pdf-embed-container-#{@uuid}"> <iframe src="#{@link}" frameborder="0" allowfullscreen></iframe> </div> </div>)
74
+ end
75
+ end
76
+
77
+ # Transform 'a=b c=d' into hash
78
+ def hash_from_args(args_array)
79
+ keys_values = args_array.map { |item| item.split /\s*=\s*/ }
80
+ Hash[keys_values]
81
+ end
82
+
83
+ # Remove first and last quotation from string
84
+ def remove_quotations(str)
85
+ str = str.slice(1..-1) if str.start_with?('"')
86
+ str = str.slice(0..-2) if str.end_with?('"')
87
+ end
88
+
89
+ Liquid::Template.register_tag('pdf', self)
90
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module JekyllPDFEmbed
5
+ VERSION = '1.1.2'
6
+ end
7
+ 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.1
4
+ version: 1.1.2
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-04-21 00:00:00.000000000 Z
11
+ date: 2021-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -33,6 +33,8 @@ extensions: []
33
33
  extra_rdoc_files: []
34
34
  files:
35
35
  - lib/jekyll-pdf-embed.rb
36
+ - lib/jekyll-pdf-embed/pdf-tag.rb
37
+ - lib/jekyll-pdf-embed/version.rb
36
38
  homepage: https://github.com/MihajloNesic/jekyll-pdf-embed
37
39
  licenses:
38
40
  - GPL-3.0