jekyll-pdf 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4cf106be791a9f308c0de674aed203c8ecd1ef8
4
- data.tar.gz: 571837054e5dbddfeed124ec363423f76ed1304c
3
+ metadata.gz: f528a86edb39066d05296d4e90d9daec587fbe3a
4
+ data.tar.gz: d7bae1c70e0528ce1b2db37637a0d50c3e8c8d29
5
5
  SHA512:
6
- metadata.gz: 000375ef0c4fc01bca89baf80411b00abddb0fb4c900ef9c7d7422a61dfd65c8ef8283b07d3ba955bb51fbc22254c5f6b5101bbc663ceb067758e3e379174784
7
- data.tar.gz: 6c5309d325532b122926cd6da99eca07215f990b9fc3a97d3aac6a972622b2737a35d1a8e91c97570c6459c8e755e5a4fcad80903b3bfb242e48828c944ca177
6
+ metadata.gz: 8799316ad79950136609dc1ec7a2040a81f50462d9d22692ce504f4fde00b7ae46ce1900b9b8d11980a08381b4d792514e28aaf4385be238bf65dd099a3dddf3
7
+ data.tar.gz: 52d509a1be9525b904a393838f4b50c44d808a3df5de4f25833283ba4bcb03aabd7c43db1c39ce289f7ef7d8e9d3f5cbdaa42020cf05ff670f2fed589f5a10e6
data/Gemfile CHANGED
@@ -1,9 +1,8 @@
1
1
  source "https://rubygems.org"
2
+ gemspec
2
3
 
3
- gem 'wkhtmltopdf-installer'
4
- gem 'pdfkit'
5
- gem 'digest'
6
- gem 'activesupport'
4
+ group :test do
5
+ gem "rake"
6
+ end
7
7
 
8
-
9
- gem "jekyll-assets", "~> 2.0.0", :require => false
8
+ gem "jekyll-assets", "~> 2.2", :require => false
data/README.md CHANGED
@@ -2,27 +2,38 @@
2
2
 
3
3
  Dynamically generate PDFs from Jekyll pages, posts & documents.
4
4
 
5
- ## Using Jekyll Assets with Jekyll
5
+ [![Build Status](https://travis-ci.org/abeMedia/jekyll-pdf.svg?branch=master)](https://travis-ci.org/abeMedia/jekyll-pdf)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/abeMedia/jekyll-pdf.svg)](https://gemnasium.com/github.com/abeMedia/jekyll-pdf)
6
7
 
7
- Add `gem "jekyll-pdf"` to your `Gemfile` and add `jekyll-pdf` to your `_config.yml` like the following:
8
+ ## Usage
9
+
10
+ Add `gem "jekyll-pdf"` to your `Gemfile` and run `bundle`, then add `jekyll-pdf` to your `_config.yml` like so:
8
11
 
9
12
  ```yaml
10
13
  gems:
11
14
  - jekyll-pdf
12
15
  ```
13
16
 
14
- Now add the following to any page's or document's front-matter, that you'd like to create a PDF version of.
17
+ Now add `pdf: true` to any page's or document's front-matter, that you'd like to create a PDF version of.
18
+
19
+ To activate **Jekyll PDF** for multiple pages or entire collections you can use Jekyll's [front-matter defaults](https://jekyllrb.com/docs/configuration/#front-matter-defaults). The following example will create PDFs for each post in your blog.
15
20
 
16
21
  ```yaml
17
- pdf: true
22
+ defaults:
23
+ -
24
+ scope:
25
+ path: ""
26
+ type: "posts"
27
+ values:
28
+ pdf: true
18
29
  ```
19
30
 
20
- To activate **Jekyll PDF** for multiple pages or entire collections you can use Jekyll's [front-matter defaults](https://jekyllrb.com/docs/configuration/#front-matter-defaults).
31
+ Link to the PDF using the `{{ page.pdf_url }}` liquid variable.
21
32
 
22
33
 
23
34
  ## Configuration
24
35
 
25
- **Jekyll PDF** uses [wkhtmltopdf](http://wkhtmltopdf.org/) to generate the PDFs. For a full list of configuration parameters it supports see http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
36
+ **Jekyll PDF** supports any configuration parameters [wkhtmltopdf](http://wkhtmltopdf.org/) does. For a full list of configuration parameters it supports see http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
26
37
 
27
38
  ```yaml
28
39
  pdf:
@@ -31,32 +42,64 @@ pdf:
31
42
  layout: layout | default: pdf
32
43
  ```
33
44
 
34
- ## PDF Layouts
45
+ All configuration parameters (with exception of `cache`) can be overridden from your page's or it's PDF layout's front-matter.
46
+
47
+ ### Cache Folder
48
+
49
+ If Jekyll Assets is installed, Jekyll PDF will automatically use the same cache folder as Jekyll Assets (unless specified otherwise).
50
+
51
+ ## Layouts
35
52
 
36
53
  **Jekyll PDF** will check for your current layout suffixed with `_pdf` e.g. if you're using a layout called `post`, it will look for `_layouts/post_pdf.html`, falling back to your default PDF layout (usually `_layouts/pdf.html`).
37
54
 
38
- To override this add the `pdf_layout` variable to your page's YAML front-matter. For example:
55
+ To override this behaviour, add the `pdf_layout` variable to your page's YAML front-matter. For example:
39
56
 
40
57
  ```yaml
41
58
  pdf_layout: my_custom_pdf_layout
42
59
  ```
43
60
 
44
- ## Partials - Headers, Footers & Covers
61
+ ## Partials (Header, Footer & Cover Page)
45
62
 
46
- We'll automatically look for all partials in `_includes` directory, e.g. `header_html: pdf_header.html` will tell Jekyll PDF use `_includes/pdf_header.html`. Please note that wkhtmltopdf requires all partials to be valid HTML documents (including DOCTYPE).
63
+ We'll automatically look for all partials in `_includes` directory, e.g. `header_html: pdf_header.html` will tell Jekyll PDF use `_includes/pdf_header.html`.
47
64
 
48
- ## Cache Folder
65
+ Please note that wkhtmltopdf requires all partials to be valid HTML documents for example:
66
+
67
+ ```html
68
+ <!DOCTYPE html>
69
+ <html>
70
+ <head>
71
+ <meta charset="utf-8" />
72
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css">
73
+ </head>
74
+ <body>
75
+ Page {{ page.pdf.page }} of {{ page.pdf.topage }}
76
+ </body>
77
+ </html>
78
+ ```
79
+
80
+ ### Supported header & footer variables
81
+
82
+ | Liquid | Description |
83
+ |--------------------------------|-------------------------------------------------------------|
84
+ | `{{ page.pdf.page }}` | Replaced by the number of the pages currently being printed |
85
+ | `{{ page.pdf.topage }}` | Replaced by the number of the last page to be printed |
86
+ | `{{ page.pdf.section }}` | Replaced by the content of the current h1 tag |
87
+ | `{{ page.pdf.subsection }}` | Replaced by the content of the current h2 tag |
88
+ | `{{ page.pdf.subsubsection }}` | Replaced by the content of the current h3 tag |
49
89
 
50
- If Jekyll Assets is installed, Jekyll PDF will automatically use the same cache folder as Jekyll Assets unless specified otherwise.
51
90
 
52
91
  ## Troubleshooting
53
92
 
54
- ### Resources aren't included in the PDF
93
+ ### Images aren't displaying in the PDF
94
+
95
+ If your images aren't displaying in the PDF, this is most likely due to the fact that wkhtmltopdf doesn't know where to look. Try prefixing your image URLs with `file://{{ site.dest }}`.
96
+ For asset URLs in CSS files we recommend creating a separate CSS file overriding the URLs with the prefix mentioned above.
55
97
 
56
- If your Images, CSS, or JavaScript aren't displaying in the PDF, this is most likely due to the fact that wkhtmltopdf doesn't know where to look. Try prefixing your asset URLs with `file://{{ site.dest }}`. For asset URLs in CSS files we recommend creating a separate CSS file overriding the URLs will the mentioned prefix.
98
+ ---
57
99
 
58
100
  ## To Do
59
101
 
60
- - Support layouts in partials
61
- - Default PDF layout file in Gem
62
- - Write tests
102
+ - Remove dependencies for ActiveSupport & PDFKit
103
+ - Write tests (rspec)
104
+ - Package default PDF layout file in Gem
105
+ - Support layouts in partials
@@ -1,5 +1,4 @@
1
1
  require 'pdfkit'
2
- require 'active_support/core_ext/hash/deep_merge'
3
2
 
4
3
  module Jekyll
5
4
  module PDF
@@ -22,7 +21,7 @@ module Jekyll
22
21
  self.data['layout'] = layout
23
22
 
24
23
  # Get PDF settings from the layouts
25
- @settings = (site.config['pdf'] || {}).deep_merge(self.getConfig(self.data))
24
+ Jekyll::Utils.deep_merge_hashes!(@settings, self.getConfig(self.data))
26
25
 
27
26
  PDFKit.configure do |config|
28
27
  config.verbose = site.config['verbose']
@@ -50,7 +49,8 @@ module Jekyll
50
49
  return settings if layout == nil
51
50
 
52
51
  # Merge settings with parent layout settings
53
- layout['pdf'] = (layout['pdf'] || {}).deep_merge(settings)
52
+ layout['pdf'] ||= {}
53
+ Jekyll::Utils.deep_merge_hashes!(layout['pdf'], settings)
54
54
 
55
55
  return self.getConfig(layout)
56
56
  end
@@ -2,8 +2,7 @@ module Jekyll
2
2
  module PDF
3
3
  module Helper
4
4
  def fix_relative_paths
5
- prefix = "file://#{site.dest}/"
6
- output = output.gsub(/(href|src)=(['"])\/([^\/"']([^\"']*|[^"']*))?['"]/, "\\1=\\2#{prefix}\\3\\2")
5
+ output.gsub!(/(href|src)=(['"])\/([^\/"']([^\"']*|[^"']*))?['"]/, "\\1=\\2file://#{site.dest}/\\3\\2") if output != nil
7
6
  end
8
7
  end
9
8
  end
@@ -2,7 +2,7 @@
2
2
  Jekyll::Hooks.register :site, :post_write do |jekyll, payload|
3
3
  if jekyll.data[:jekyll_pdf_partials]
4
4
  jekyll.data[:jekyll_pdf_partials].each do |partial|
5
- partial.clean
5
+ File.delete(partial) if File.exist?(partial)
6
6
  end
7
7
  jekyll.data.delete(:jekyll_pdf_partials)
8
8
  end
@@ -42,8 +42,7 @@ module Jekyll
42
42
  File.join(doc.path, partial)
43
43
  end
44
44
 
45
- # Returns the file name for the temporary file
46
- def filename
45
+ def id
47
46
  File.basename(path, File.extname(path)) + "-" + Digest::MD5.hexdigest(to_s) + File.extname(path)
48
47
  end
49
48
 
@@ -74,19 +73,16 @@ module Jekyll
74
73
 
75
74
  # generate temp file & set output to it's path
76
75
  def write
77
- tempfile = File.join(dir, filename)
76
+ tempfile = File.absolute_path(File.join(dir, id))
78
77
  unless File.exist?(tempfile)
79
78
  FileUtils.mkdir_p(File.dirname(tempfile)) unless File.exist?(File.dirname(tempfile))
80
79
  File.open(tempfile, 'w') {|f| f.write(to_s) }
81
80
  end
82
- site.data[:jekyll_pdf_partials] ||= []
83
- site.data[:jekyll_pdf_partials] << self
84
81
  @output = tempfile
85
- end
86
-
87
- # delete temp file
88
- def clean
89
- File.delete(@output)
82
+
83
+ # store path for cleanup
84
+ site.data[:jekyll_pdf_partials] ||= []
85
+ site.data[:jekyll_pdf_partials] << "#{self}"
90
86
  end
91
87
 
92
88
  def place_in_layout?
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.0
4
+ version: 0.1.1
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-30 00:00:00.000000000 Z
11
+ date: 2016-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wkhtmltopdf-installer
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: activesupport
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '4.2'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '4.2'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: jekyll
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,20 +72,6 @@ dependencies:
86
72
  - - "~>"
87
73
  - !ruby/object:Gem::Version
88
74
  version: '3.1'
89
- - !ruby/object:Gem::Dependency
90
- name: rspec
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '3.4'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '3.4'
103
75
  - !ruby/object:Gem::Dependency
104
76
  name: bundler
105
77
  requirement: !ruby/object:Gem::Requirement