jekyll-pdf-embed 1.0.4 → 1.1.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 888469f8bfacc1099507591ff273cd4232a1bf1839933ddcc9cfc5f643a83df0
4
- data.tar.gz: 83c548429ed46cbc2b751b337aaa411f930b6708e5495d96b8effd980571959c
3
+ metadata.gz: 6d06b611d6f7cf682294c57fee183629534b4370cdb0f00abcf51c8e582c7686
4
+ data.tar.gz: d6f9de223e5598cca77006411dafd94116a6430f7ff7346cb981a962d61e9597
5
5
  SHA512:
6
- metadata.gz: 35a245969599306c9c7852f92acd808d874771c8f3899416aa59bbaf2fb0c37db5cf80e860ba352d749bd8378bcbbcc2d52f36fb5dd8c28dae6a78872a9c0252
7
- data.tar.gz: f6b09be69b53dae11b5af3fa0ef1a95e2466e8edff20f08546a4b3a759dae116a9fe32a2841e26be4349a7c1e4a71b0da90c940ba3f9486b6cf45ca2911139ce
6
+ metadata.gz: b70f37431269b124c2889f24989128114c59582721902e56e45a58aac6ae09585a46e59da9963c57de0909e4b63daa0ec4095ff60bac2e9141b18db6f61fa25c
7
+ data.tar.gz: 5abe32bb2cd60e71f5aa9d0e8fcc7a02d0a6aebc41e19b79647a47c91fe8fe4a8215e0e98a35beb4ce50b6608cee8e0b6c3f3b141b92dd639b668f2f40de6205
@@ -0,0 +1,84 @@
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
+ Liquid::Template.register_tag('pdf', self)
84
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jekyll
4
+ module JekyllPDFEmbed
5
+ VERSION = '1.1.2.1'
6
+ end
7
+ end
@@ -1,44 +1,9 @@
1
- require "jekyll"
2
-
3
- class PDFEmbed < Liquid::Tag
4
-
5
- def initialize(tag_name, text, tokens)
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(/ /)
15
- end
16
-
17
- def render(context)
18
- if !@is_allowed
19
- raise ArgumentError, 'ERROR:file_not_allowed'
20
- 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>}
27
- else
28
- raise ArgumentError, 'ERROR:bad_syntax'
29
- 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>}
35
- else
36
- raise ArgumentError, 'ERROR:bad_syntax'
37
- end
38
- else
39
- raise ArgumentError, 'ERROR:bad_syntax'
40
- end
41
- end
42
-
43
- Liquid::Template.register_tag('pdf', self)
44
- end
1
+ # frozen_string_literal: true
2
+
3
+ require 'jekyll-pdf-embed/version'
4
+ require 'jekyll-pdf-embed/pdf-tag'
5
+
6
+ module Jekyll
7
+ module JekyllPDFEmbed
8
+ end
9
+ 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.2.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: 2020-03-27 00:00:00.000000000 Z
11
+ date: 2021-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -33,9 +33,11 @@ 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
- - MIT
40
+ - GPL-3.0
39
41
  metadata: {}
40
42
  post_install_message:
41
43
  rdoc_options: []
@@ -52,8 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
54
  - !ruby/object:Gem::Version
53
55
  version: '0'
54
56
  requirements: []
55
- rubyforge_project:
56
- rubygems_version: 2.7.6.2
57
+ rubygems_version: 3.0.3.1
57
58
  signing_key:
58
59
  specification_version: 4
59
60
  summary: Jekyll plugin for embedding PDF files to any page or post