jekyll-pdf 0.1.1 → 0.1.3

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
  SHA1:
3
- metadata.gz: f528a86edb39066d05296d4e90d9daec587fbe3a
4
- data.tar.gz: d7bae1c70e0528ce1b2db37637a0d50c3e8c8d29
3
+ metadata.gz: c0f8bd549af93a1701ca9536fe0ff023c65226ad
4
+ data.tar.gz: eb4af933b53461dd4560dd0ca2a7c5022cb0216e
5
5
  SHA512:
6
- metadata.gz: 8799316ad79950136609dc1ec7a2040a81f50462d9d22692ce504f4fde00b7ae46ce1900b9b8d11980a08381b4d792514e28aaf4385be238bf65dd099a3dddf3
7
- data.tar.gz: 52d509a1be9525b904a393838f4b50c44d808a3df5de4f25833283ba4bcb03aabd7c43db1c39ce289f7ef7d8e9d3f5cbdaa42020cf05ff670f2fed589f5a10e6
6
+ metadata.gz: 8003730882c935204be9e2069a0b9706cd04f91c19daccc5e50c9ce9cd9c5b47436703449c0113a84f9ce5bafe08fe51769a3507e7b26d429523d726fc94110c
7
+ data.tar.gz: 1afb93d28dc6978a01f2502339ef319d203c59fb7d042b256c197b6d041f021b260aab1f76907f78771e4a5852b3569c0fdea4d2efed77129f0f300d0e8e5ce0
data/README.md CHANGED
@@ -99,7 +99,7 @@ For asset URLs in CSS files we recommend creating a separate CSS file overriding
99
99
 
100
100
  ## To Do
101
101
 
102
- - Remove dependencies for ActiveSupport & PDFKit
102
+ - Remove PDFKit Dependency
103
103
  - Write tests (rspec)
104
104
  - Package default PDF layout file in Gem
105
105
  - Support layouts in partials
@@ -1,99 +1,99 @@
1
1
  require 'pdfkit'
2
-
2
+
3
3
  module Jekyll
4
4
  module PDF
5
5
  class Document < Jekyll::Page
6
6
  include Helper
7
-
7
+
8
8
  def initialize(site, base, page)
9
9
  @site = site
10
10
  @base = base
11
11
  @dir = File.dirname(page.url)
12
12
  @name = File.basename(page.url, File.extname(page.url)) + ".pdf"
13
- @settings = site.config['pdf'] || {}
13
+ @settings = site.config['pdf'].clone || {}
14
14
  @partials = ['cover','header_html','footer_html']
15
-
15
+
16
16
  self.process(@name)
17
17
  self.data = page.data.clone
18
18
  self.content = page.content.clone
19
-
19
+
20
20
  # Set layout to the PDF layout
21
21
  self.data['layout'] = layout
22
-
22
+
23
23
  # Get PDF settings from the layouts
24
24
  Jekyll::Utils.deep_merge_hashes!(@settings, self.getConfig(self.data))
25
-
25
+
26
26
  PDFKit.configure do |config|
27
27
  config.verbose = site.config['verbose']
28
28
  end
29
-
29
+
30
30
  # Set pdf_url variable in the source page (for linking to the PDF version)
31
31
  page.data['pdf_url'] = self.url
32
-
32
+
33
33
  # Set html_url variable in the source page (for linking to the HTML version)
34
34
  self.data['html_url'] = page.url
35
-
35
+
36
36
  # create the partial objects
37
37
  @partials.each do |partial|
38
38
  @settings[partial] = Jekyll::PDF::Partial.new(self, @settings[partial]) if @settings[partial] != nil
39
39
  end
40
40
  end
41
-
41
+
42
42
  # Recursively merge settings from the page, layout, site config & jekyll-pdf defaults
43
43
  # todo: use jekyll's merge function
44
44
  def getConfig(data)
45
45
  settings = data['pdf'].is_a?(Hash) ? data['pdf'] : {}
46
46
  layout = @site.layouts[data['layout']].data.clone if data['layout'] != nil
47
-
47
+
48
48
  # No parent layout found - return settings hash
49
49
  return settings if layout == nil
50
-
50
+
51
51
  # Merge settings with parent layout settings
52
52
  layout['pdf'] ||= {}
53
53
  Jekyll::Utils.deep_merge_hashes!(layout['pdf'], settings)
54
-
54
+
55
55
  return self.getConfig(layout)
56
56
  end
57
-
57
+
58
58
  def write(dest_prefix, dest_suffix = nil)
59
59
  self.render(@site.layouts, @site.site_payload) if self.output == nil
60
-
60
+
61
61
  path = File.join(dest_prefix, CGI.unescape(self.url))
62
62
  dest = File.dirname(path)
63
-
63
+
64
64
  # Create directory
65
65
  FileUtils.mkdir_p(dest) unless File.exist?(dest)
66
-
66
+
67
67
  # write partials
68
68
  @partials.each do |partial|
69
69
  @settings[partial].write if @settings[partial] != nil
70
70
  end
71
-
71
+
72
72
  # Debugging - create html version of PDF
73
73
  File.open("#{path}.html", 'w') {|f| f.write(self.output) } if @settings["debug"]
74
74
  @settings.delete("debug")
75
-
75
+
76
76
  # Build PDF file
77
77
  fix_relative_paths
78
78
  kit = PDFKit.new(self.output, @settings)
79
79
  file = kit.to_file(path)
80
-
80
+
81
81
  #self.output = kit.to_pdf
82
82
  end
83
-
83
+
84
84
  def layout()
85
85
  # Set page layout to the PDF layout
86
86
  layout = self.data['pdf_layout'] || @settings['layout']
87
-
87
+
88
88
  # Check if a PDF version exists for the current layout (e.g. layout_pdf)
89
89
  if layout == nil && self.data['layout'] != nil && File.exist?("_layouts/" + self.data['layout'] + "_pdf.html")
90
- layout = self.data['layout'] + "_pdf"
90
+ layout = self.data['layout'] + "_pdf"
91
91
  end
92
-
92
+
93
93
  layout || 'pdf'
94
94
  end
95
-
95
+
96
96
  end
97
-
97
+
98
98
  end
99
99
  end
@@ -3,7 +3,7 @@ module Jekyll
3
3
  class Generator < Jekyll::Generator
4
4
  safe true
5
5
  priority :lowest
6
-
6
+
7
7
  def generate(site)
8
8
  # Loop through pages & documents and build PDFs
9
9
  [site.pages, site.documents].each do |items|
@@ -12,7 +12,7 @@ module Jekyll
12
12
  end
13
13
  end
14
14
  end
15
-
15
+
16
16
  end
17
17
  end
18
18
  end
@@ -5,16 +5,17 @@ module Jekyll
5
5
  module PDF
6
6
  class Partial
7
7
  extend Forwardable
8
-
8
+ include Helper
9
+
9
10
  attr_accessor :doc
10
11
  attr_accessor :partial
11
12
  attr_accessor :write
12
13
  attr_accessor :content, :ext
13
14
  attr_writer :output
14
-
15
+
15
16
  def_delegators :@doc, :site, :name, :ext, :relative_path, :extname,
16
17
  :render_with_liquid?, :collection, :related_posts
17
-
18
+
18
19
  # Initialize this Partial instance.
19
20
  #
20
21
  # doc - The Document.
@@ -25,7 +26,7 @@ module Jekyll
25
26
  self.partial = partial
26
27
  self.content = build_partial(partial)
27
28
  end
28
-
29
+
29
30
  # Fetch YAML front-matter data from related doc, without layout key
30
31
  #
31
32
  # Returns Hash of doc data
@@ -34,97 +35,98 @@ module Jekyll
34
35
  @data.delete("layout")
35
36
  @data
36
37
  end
37
-
38
+
38
39
  def trigger_hooks(*)
39
40
  end
40
-
41
+
41
42
  def path
42
43
  File.join(doc.path, partial)
43
44
  end
44
-
45
+
45
46
  def id
46
47
  File.basename(path, File.extname(path)) + "-" + Digest::MD5.hexdigest(to_s) + File.extname(path)
47
48
  end
48
-
49
+
49
50
  # Returns the cache directory
50
51
  def dir
51
52
  @dir ||= cache_dir
52
53
  end
53
-
54
+
54
55
  def to_s
55
56
  output || content
56
57
  end
57
-
58
+
58
59
  def to_liquid
59
60
  doc.data[partial] = nil
60
61
  @to_liquid ||= doc.to_liquid
61
62
  doc.data[partial] = self
62
63
  @to_liquid
63
64
  end
64
-
65
+
65
66
  # Returns the shorthand String identifier of this doc.
66
67
  def inspect
67
68
  "<Partial: #{self.id}>"
68
69
  end
69
-
70
+
70
71
  def output
71
72
  @output ||= Renderer.new(doc.site, self, site.site_payload).run
72
73
  end
73
-
74
+
74
75
  # generate temp file & set output to it's path
75
76
  def write
76
77
  tempfile = File.absolute_path(File.join(dir, id))
77
78
  unless File.exist?(tempfile)
78
79
  FileUtils.mkdir_p(File.dirname(tempfile)) unless File.exist?(File.dirname(tempfile))
80
+ fix_relative_paths
79
81
  File.open(tempfile, 'w') {|f| f.write(to_s) }
80
82
  end
81
83
  @output = tempfile
82
-
84
+
83
85
  # store path for cleanup
84
86
  site.data[:jekyll_pdf_partials] ||= []
85
87
  site.data[:jekyll_pdf_partials] << "#{self}"
86
88
  end
87
-
89
+
88
90
  def place_in_layout?
89
91
  false
90
92
  end
91
-
93
+
92
94
  protected
93
-
95
+
94
96
  def cache_dir
95
97
  return site.config["pdf"]["cache"] if site.config["pdf"] != nil && site.config["pdf"].has_key?('cache')
96
-
98
+
97
99
  # Use jekyll-assets cache directory if it exists
98
100
  cache_dir = site.config["assets"]["cache"] || '.asset-cache' if site.config["assets"] != nil
99
-
101
+
100
102
  File.join(cache_dir || Dir.tmpdir(), 'pdf')
101
103
  end
102
-
104
+
103
105
  # Internal: Generate partial html
104
106
  #
105
107
  # Partials are rendered same time as content is rendered.
106
108
  #
107
109
  # Returns partial html String
108
110
  def build_partial(path)
109
-
111
+
110
112
  # vars to insert into partial
111
113
  vars = ['frompage','topage','page','webpage','section','subsection','subsubsection']
112
114
  doc.data["pdf"] = {}
113
115
  vars.each { |var| doc.data["pdf"][var] = "<span class='__#{var}'></span>" }
114
-
116
+
115
117
  # JavaScript to replace var placeholders with content
116
118
  script = "<script>!function(){var t={},n=document.location.search.substring(1).split('&');for(var e in n){var o=n[e].split('=',2);t[o[0]]=decodeURIComponent(o[1])}var n=#{vars};for(var e in n)for(var r=document.getElementsByClassName('__'+n[e]),a=0;a<r.length;++a)r[a].textContent=t[n[e]]}();</script>\n"
117
-
119
+
118
120
  # Parse & render
119
121
  content = File.read(File.join("_includes", path))
120
-
122
+
121
123
  # Add replacer script to body
122
124
  if content =~ /<\/body>/i
123
125
  content[/(<\/body>)/i] = script + content[/(<\/body>)/i]
124
126
  else
125
127
  Jekyll.logger.warn <<-eos
126
128
  Couldn't find <body> in #{path}. Make sure your partial is a properly formatted HTML document (including DOCTYPE) e.g.
127
-
129
+
128
130
  <!DOCTYPE html>
129
131
  <html>
130
132
  <head>
@@ -145,9 +147,9 @@ module Jekyll
145
147
  </html>
146
148
  }
147
149
  end
148
-
150
+
149
151
  content
150
-
152
+
151
153
  end
152
154
  end
153
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Bouqdib
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-31 00:00:00.000000000 Z
11
+ date: 2016-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wkhtmltopdf-installer
@@ -86,8 +86,8 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '1.6'
89
- description: |2
90
- A Jekyll plugin, that allows you to create PDF versions of your pages & documents.
89
+ description: " A Jekyll plugin, that allows you to create PDF versions of your
90
+ pages & documents.\n"
91
91
  email:
92
92
  - adam@abemedia.co.uk
93
93
  executables: []
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  version: '0'
126
126
  requirements: []
127
127
  rubyforge_project:
128
- rubygems_version: 2.4.6
128
+ rubygems_version: 2.5.1
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: PDF generator for Jekyll