jekyll-pdf-embed 1.0.0 → 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 +56 -13
  3. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 766ffce9f19953669b33397e6ba65b1def8ec2e4414cf45868daca3f32836b72
4
- data.tar.gz: afadbb48a383cb6c883e9976bbdda8df6bee4231573c301d4eac718bc0cf1642
3
+ metadata.gz: 5dc9316cdf5ae27c45ef92242fd721d641d95c20d82280166aea2f24796959b8
4
+ data.tar.gz: 599ad2ab15f659694706d72ad23cc41f5ff2dce737b641921e3f3e20a9235640
5
5
  SHA512:
6
- metadata.gz: caf571403ff4213683a3161ba214b7b1ad1e5a9b8eaeaeb2028ed34bf100752b9e20a1a5f8dd7b95922a230c2ab634dfbc0b63a5a660877758a192d13f0b241e
7
- data.tar.gz: 61de17ba2dc786bb92ded9c821bcd58b0cd1c43e73d630100037ac0dc78d6f47bb6607327c562f40149ff458f111ddb403c6c66030f047a4ba74f34e4f7dcf0e
6
+ metadata.gz: f416785c75bf644eb469db9442f358659798966ddf7d30ca88a948e77b0031f9afbdda9f52ef3814f720165aef4d9514df7690a703446505689901ac28622953
7
+ data.tar.gz: 6cf605a961c55042ea9a7ce8817ff119d78a9afd413514be84119cabbfe6e5de8c3ddf1aee41a7a19749c3ba2c06cbfe398496a63561196e3b913a61d2df87fd
@@ -1,21 +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
- @text = text
8
- *@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
9
15
  end
10
-
16
+
11
17
  def render(context)
12
- if @params.length == 1
13
- %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="#{@text}" frameborder="0" allowfullscreen></iframe></div>}
14
- else
15
- raise ArgumentError, 'ERROR:bad_syntax'
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/, '')
16
23
  end
17
- end
18
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
+
31
+ if !@is_allowed
32
+ raise ArgumentError, 'ERROR:file_not_allowed -> ' + @link
33
+ end
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>}
38
+ 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>}
40
+ end
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'
50
+ else
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>}
58
+ end
59
+ end
60
+
61
+ end
62
+
19
63
  Liquid::Template.register_tag('pdf', self)
20
- end
21
-
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.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: 2019-09-08 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
@@ -24,7 +24,9 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description: Jekyll plugin to generate html snippets for embedding PDF files
27
+ description: "\n\tJekyll PDF Embed is a ruby gem for Jekyll static site generator.\n\tIt
28
+ allows user to easily embed external or local PDF files to any page or blog post.\n
29
+ \ "
28
30
  email: nesicmihajlo98@gmail.com
29
31
  executables: []
30
32
  extensions: []
@@ -33,7 +35,7 @@ files:
33
35
  - lib/jekyll-pdf-embed.rb
34
36
  homepage: https://github.com/MihajloNesic/jekyll-pdf-embed
35
37
  licenses:
36
- - MIT
38
+ - GPL-3.0
37
39
  metadata: {}
38
40
  post_install_message:
39
41
  rdoc_options: []
@@ -50,9 +52,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
52
  - !ruby/object:Gem::Version
51
53
  version: '0'
52
54
  requirements: []
53
- rubyforge_project:
54
- rubygems_version: 2.7.6.2
55
+ rubygems_version: 3.0.3
55
56
  signing_key:
56
57
  specification_version: 4
57
- summary: Jekyll plugin to generate html snippets for embedding PDF files
58
+ summary: Jekyll plugin for embedding PDF files to any page or post
58
59
  test_files: []