middleman-pdfkit 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: 040fb551d9cfcd8c0a781f9b5798a012561e3624
4
- data.tar.gz: b88fb76c0fec4c04837ed8787fb566ca3f5922ac
2
+ SHA256:
3
+ metadata.gz: 3643f90a450e65e390ed37cf8b25254584031f0522f08ea54f82b02186c155cd
4
+ data.tar.gz: 223f2683b999f7e429654c90e526a0cc3db574c2b379fa0c2598e4dd72bfbb37
5
5
  SHA512:
6
- metadata.gz: a0dcc52e3ecb9c56ad471de2c3e483d85aeb8b19e436964680af2d6a55c86cc05fff5891f97aef22222d6d274f3f193a2451ff688b54f07e709da1e8c479082e
7
- data.tar.gz: 3aa828a6815e089ff201199013c1707c1a366f5e7ffe5a5bb1b5305724989d4f58a1b279877911eb590d15ba91427252baeae01cdd2c687313b8dcb52cf5afb3
6
+ metadata.gz: 3c36537737146f4b7fb89f6c7b6761e43e5eff508a965e67d6339601b3bcb3bee689e6749671b843cb9442e0af87f13bbf4b0635cfefd94d3627835e6eb2e1de
7
+ data.tar.gz: 3f41282d8c30f0cefcbce32f0b62d24c9b42ecd68d2f970147654f2cbae39a36704ca9b51da61b53cf2144216beb2f8130be27a0f6f4ef5af87951d00d4a8738
data/README.md CHANGED
@@ -19,7 +19,34 @@ Or install it yourself as:
19
19
 
20
20
  ## Usage
21
21
 
22
- TODO: Add link to example app
22
+ * Activate pdfkit in your [config.rb]
23
+
24
+ ```
25
+ configure :build do
26
+ activate :relative_assets
27
+ activate :pdfkit do |p|
28
+ # p.filenames = ['test/test_page1', 'test/test_page2']
29
+ # p.filenames = {
30
+ 'test/test_page1' => 'test/test_page1.pdf',
31
+ 'test/test_page2' => 'test/test_page2.pdf',
32
+ }
33
+ # p.disable_smart_shrinking = true
34
+ # p.quiet = false
35
+ # p.page_size = 'A5'
36
+ # p.margin_top = 10
37
+ # p.margin_right = 10
38
+ # p.margin_bottom = 10
39
+ # p.margin_left = 10
40
+ # p.print_media_type = true
41
+ # p.encoding = 'UTF-8'
42
+ end
43
+ end
44
+
45
+ ```
46
+
47
+
48
+
49
+ * Execute `middleman build`
23
50
 
24
51
  ## Contributing
25
52
 
@@ -11,51 +11,105 @@ module Middleman
11
11
  option :margin_right, '0', 'Margin right: 0'
12
12
  option :margin_bottom, '0', 'Margin bottom: 0'
13
13
  option :margin_left, '0', 'Margin left: 0'
14
+ option :print_media_type, true, 'Print media type'
14
15
  option :encoding, 'UTF-8', 'Encoding'
15
16
 
16
17
  def initialize(klass, options_hash={}, &block)
18
+ @prefix = "build/"
19
+
17
20
  super
18
21
  setup_filenames
19
22
  end
20
23
 
24
+ def manipulate_resource_list(resources)
25
+ # Add my @filenames to Sitemap
26
+ @filenames.each do |input, output|
27
+ resources << Middleman::Sitemap::Extensions::EndpointResource.new(app.sitemap, output, "/")
28
+ end
29
+
30
+ # Return the new list
31
+ resources
32
+ end
33
+
21
34
  def after_build(builder)
22
- @filenames.each do |pdfkit_filename|
23
- html_filename = "build/#{pdfkit_filename}.html"
24
- pdf_filename = "build/#{pdfkit_filename}.pdf"
25
- if File.exist?(html_filename)
26
- generate_pdf(html_filename, pdf_filename)
27
- builder.say_status "create", pdf_filename
28
- else
29
- builder.say_status "error", "#{pdf_filename} (HTML-File not found )", :red
30
- end
35
+ @filenames.each do |file, output|
36
+ puts "after_build: [#{file}] > [#{output}]"
37
+ # build_pdf_for(file, "#{@prefix}#{output}")
38
+ build_pdf_for(file, output)
31
39
  end
32
40
  end
33
41
 
34
- private
42
+ private
35
43
 
36
- def setup_filenames
37
- @filenames = options.filenames.empty? ? all_html_files : options.filenames
44
+ def build_pdf_for input, output
45
+ # Output file should be prefixed only here
46
+ input1 = "#{@prefix}#{input}"
47
+ input2 = "#{@prefix}#{input}.html"
48
+ outfile = "#{@prefix}#{output}"
49
+
50
+ # Test input flies presence
51
+ if File.exist?(input1)
52
+ puts "create", outfile
53
+ generate_pdf(input1, outfile)
54
+
55
+ elsif File.exist?(input2)
56
+ puts "create", outfile
57
+ generate_pdf(input2, outfile)
58
+
59
+ else
60
+ puts "error", "PDFKit: none of source HTML files [#{file1}, #{file2}] been found", :red
38
61
  end
39
62
 
40
- def all_html_files
41
- # TODO: find a better way?!
42
- Dir.glob(File.join('build', '**', '*.html')).map do |d|
43
- File.join(File.dirname(d).sub('build', ''), File.basename(d, '.html'))[1..-1]
63
+ end
64
+
65
+ def setup_filenames
66
+ # Init hash of file vectors
67
+ @filenames = {}
68
+
69
+ # If no filenames provided let's assume all detected files
70
+ if !options.filenames || options.filenames.empty?
71
+ all_html_files.filenames.each do |file|
72
+ @filenames[file] = "#{file}.pdf"
73
+ end
74
+
75
+ # If it's a legacy array, let's build the destination filename
76
+ elsif options.filenames.is_a?(Array)
77
+ options.filenames.each do |file|
78
+ @filenames[file] = "#{file}.pdf"
44
79
  end
80
+
81
+ # If it's a new hash, the destination filename is provided
82
+ elsif options.filenames.is_a?(Hash)
83
+ options.filenames.each do |file, output|
84
+ @filenames[file] = "#{output}"
85
+ end
86
+
45
87
  end
46
88
 
47
- def generate_pdf(html_filename, pdf_filename)
48
- kit = ::PDFKit.new(File.new(html_filename),
49
- disable_smart_shrinking: options.disable_smart_shrinking,
50
- quiet: options.quiet,
51
- page_size: options.page_size,
52
- margin_top: options.margin_top,
53
- margin_right: options.margin_right,
54
- margin_bottom: options.margin_bottom,
55
- margin_left: options.margin_left,
56
- encoding: options.encoding)
57
- file = kit.to_file(pdf_filename)
89
+ @filenames
90
+ end
91
+
92
+ def all_html_files
93
+ # TODO: find a better way?!
94
+ Dir.glob(File.join(@prefix, '**', '*.html')).map do |d|
95
+ File.join(File.dirname(d).sub(@prefix, ''), File.basename(d, '.html'))[1..-1]
58
96
  end
97
+ end
98
+
99
+ def generate_pdf(html_filename, pdf_filename)
100
+ kit = ::PDFKit.new(File.new(html_filename),
101
+ disable_smart_shrinking: options.disable_smart_shrinking,
102
+ quiet: options.quiet,
103
+ page_size: options.page_size,
104
+ margin_top: options.margin_top,
105
+ margin_right: options.margin_right,
106
+ margin_bottom: options.margin_bottom,
107
+ margin_left: options.margin_left,
108
+ print_media_type: options.print_media_type,
109
+ encoding: options.encoding)
110
+ file = kit.to_file(pdf_filename)
111
+ # puts "pdfkit: #{kit.command}"
112
+ end
59
113
 
60
114
  end
61
115
  end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module PDFKit
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -6,11 +6,11 @@ require 'middleman-pdfkit/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "middleman-pdfkit"
8
8
  spec.version = Middleman::PDFKit::VERSION
9
- spec.authors = ["Matthias Döring"]
10
- spec.email = ["matt@foryourcontent.de"]
9
+ spec.authors = ["Matthias Döring", "Naadir Jeewa", "Bruno Medici"]
10
+ spec.email = ["matt@foryourcontent.de", "", "opensource@bmconseil.com"]
11
11
  spec.summary = %q{PDFKit extension for middleman}
12
12
  spec.description = %q{Generate PDFs from HTML/CSS with middleman}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/matt-hh/middleman-pdfkit"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_dependency "middleman-core", ">= 3.0.0"
22
- spec.add_dependency "pdfkit", "~> 0.6.2"
21
+ spec.add_dependency "middleman-core", ">= 4"
22
+ spec.add_dependency "pdfkit", "~> 0.8"
23
23
  spec.add_dependency "wkhtmltopdf_binary_provider"
24
24
 
25
25
  spec.add_development_dependency "bundler", "~> 1.6"
metadata CHANGED
@@ -1,14 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-pdfkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthias Döring
8
+ - Naadir Jeewa
9
+ - Bruno Medici
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2014-08-16 00:00:00.000000000 Z
13
+ date: 2018-07-17 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
16
  name: middleman-core
@@ -16,28 +18,28 @@ dependencies:
16
18
  requirements:
17
19
  - - ">="
18
20
  - !ruby/object:Gem::Version
19
- version: 3.0.0
21
+ version: '4'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
26
  - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: 3.0.0
28
+ version: '4'
27
29
  - !ruby/object:Gem::Dependency
28
30
  name: pdfkit
29
31
  requirement: !ruby/object:Gem::Requirement
30
32
  requirements:
31
33
  - - "~>"
32
34
  - !ruby/object:Gem::Version
33
- version: 0.6.2
35
+ version: '0.8'
34
36
  type: :runtime
35
37
  prerelease: false
36
38
  version_requirements: !ruby/object:Gem::Requirement
37
39
  requirements:
38
40
  - - "~>"
39
41
  - !ruby/object:Gem::Version
40
- version: 0.6.2
42
+ version: '0.8'
41
43
  - !ruby/object:Gem::Dependency
42
44
  name: wkhtmltopdf_binary_provider
43
45
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +85,8 @@ dependencies:
83
85
  description: Generate PDFs from HTML/CSS with middleman
84
86
  email:
85
87
  - matt@foryourcontent.de
88
+ - ''
89
+ - opensource@bmconseil.com
86
90
  executables: []
87
91
  extensions: []
88
92
  extra_rdoc_files: []
@@ -97,7 +101,7 @@ files:
97
101
  - lib/middleman-pdfkit/version.rb
98
102
  - lib/middleman_extension.rb
99
103
  - middleman-pdfkit.gemspec
100
- homepage: ''
104
+ homepage: https://github.com/matt-hh/middleman-pdfkit
101
105
  licenses:
102
106
  - MIT
103
107
  metadata: {}
@@ -117,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
121
  version: '0'
118
122
  requirements: []
119
123
  rubyforge_project:
120
- rubygems_version: 2.2.2
124
+ rubygems_version: 2.7.6
121
125
  signing_key:
122
126
  specification_version: 4
123
127
  summary: PDFKit extension for middleman