adzap-wicked_pdf 2.0.0.beta1 → 2.0.0.beta2

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
  SHA256:
3
- metadata.gz: 56cc9f21233c4aa590afe1bf5577c967a56abeec26c3fccbd302effe839c3421
4
- data.tar.gz: 9b0d47a24d5c9fe990efc2290fc64606b9177862217107186bea786955f93ac0
3
+ metadata.gz: a4ea1861662d27d078f0687835542b048648b15237258699e266f0ab018fd608
4
+ data.tar.gz: 47dc57c0ed8a638a3ab3921ad746248c6c2a72f2ab355b2448f2188ac2718388
5
5
  SHA512:
6
- metadata.gz: ee172642130eedcb6fbfed05656e9f420625e5fcd9be1763dec387b76d4b21051581bf7ba7dd9a4499b6941462a347e08c7bf8b279d100e56378610762d5dc5d
7
- data.tar.gz: 687d4369110d2c14e8d08fe4bad877fca2fc38182ab5632efb3dd903c341619e66bdc864e3a10f27f96a87f9c1444aa6022e59ead5bec20e176251778a9739fb
6
+ metadata.gz: 2a41b903e2d397afcf0f20fc0b72f5a9fbecf97f3e6f75f974fe0a827fa8f961dd09d9d0a29828c3b5cb3fd30f2c9066016eb9f88c3eb64892c4fa5a4a8606d7
7
+ data.tar.gz: 4730471489cd16958963fabacdf9bb25c4509539491c20ec9706ffecb0a678f8b5e8cf34e9aacfafc04ceb2b17ab670039e4558cc3b2639bcca35e2a4f11bbbe
@@ -1,4 +1,5 @@
1
1
  language: ruby
2
+ dist: xenial
2
3
  git:
3
4
  depth: 1
4
5
  quiet: true
@@ -10,9 +11,9 @@ before_install:
10
11
  bundler_args: --verbose
11
12
  before_script:
12
13
  - bundle list
13
- - sudo apt-get install -y wkhtmltopdf
14
+ - sudo apt-get install -y xvfb wkhtmltopdf
14
15
  - "export DISPLAY=:99.0"
15
- - "sh -e /etc/init.d/xvfb start"
16
+ - "sudo systemctl start xvfb"
16
17
  env: WKHTMLTOPDF_BIN=/usr/bin/wkhtmltopdf
17
18
  script:
18
19
  - bundle exec rake
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'byebug'
4
+
3
5
  gemspec
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Wicked PDF [![Gem Version](https://badge.fury.io/rb/adzap-wicked_pdf.svg)](http://badge.fury.io/rb/adzap-wicked_pdf) [![Build Status](https://secure.travis-ci.org/adzap/wicked_pdf.svg)](http://travis-ci.org/adzap/wicked_pdf)
2
2
 
3
- _This is a fork of the [original](https://github.com/milesz/wicked_pdf) to redesign the internals for a much lighter footprint on your app and offer greater extensibility_
3
+ _This is a fork of the [original](https://github.com/milesz/wicked_pdf) that modernises all dependencies and redesign the internals for a much lighter footprint on your app and offer greater extensibility._
4
4
 
5
5
  ## A PDF generation plugin for Ruby on Rails
6
6
 
7
- Wicked PDF uses the shell utility [wkhtmltopdf](http://wkhtmltopdf.org) to serve a PDF file to a user from HTML. In other words, rather than dealing with a PDF generation DSL of some sort, you simply write an HTML view as you would normally, then let Wicked PDF take care of the hard stuff.
7
+ Wicked PDF uses the shell utility [wkhtmltopdf](http://wkhtmltopdf.org) v0.12.x to serve a PDF file to a user from HTML. In other words, rather than dealing with a PDF generation DSL of some sort, you simply write an HTML view as you would normally, then let Wicked PDF take care of the hard stuff.
8
8
 
9
- _Wicked PDF has been verified to work on Ruby versions 2.3 through 2.6; Rails 4.2 through 5.2_
9
+ _Wicked PDF has been verified to work on Ruby versions 2.3 through 2.6; Rails 4.2 through 5.2; Minimum supported version of wkhtmltopdf is 0.12.0._
10
10
 
11
11
  ### Installation
12
12
 
@@ -20,7 +20,7 @@ Then create the initializer with
20
20
 
21
21
  rails generate wicked_pdf
22
22
 
23
- Because `wicked_pdf` is a wrapper for [wkhtmltopdf](http://wkhtmltopdf.org/), you'll need to install that, too.
23
+ Because `wicked_pdf` is a wrapper for [wkhtmltopdf](http://wkhtmltopdf.org/), you'll need to install that, too.
24
24
 
25
25
  The simplest way to install all of the binaries on most Linux or OSX systems is through the gem [wkhtmltopdf-binary](https://github.com/zakird/wkhtmltopdf_binary_gem). Builds for other systems are available [here](https://wkhtmltopdf.org/downloads.html)
26
26
  To install that gem, add this:
@@ -31,7 +31,7 @@ gem 'wkhtmltopdf-binary'
31
31
 
32
32
  To your Gemfile and run `bundle install`.
33
33
 
34
- This gem currently installs version 0.12.x of `wkhtmltopdf`. Some of the options listed below are specific 0.9 or below, and others are for 0.12 and up.
34
+ This gem currently installs version 0.12.x of `wkhtmltopdf`. Support for some of the options listed below may vary with release.
35
35
 
36
36
  You can see what flags are supported for the current version in [wkhtmltopdf's auto-generated manual](https://wkhtmltopdf.org/usage/wkhtmltopdf.txt)
37
37
 
@@ -1,29 +1,26 @@
1
1
  module WickedPdf
2
2
  class Binary
3
3
  EXE_NAME = 'wkhtmltopdf'.freeze
4
- DEFAULT_BINARY_VERSION = Gem::Version.new('0.9.9')
4
+ MINIMUM_BINARY_VERSION = Gem::Version.new('0.12.0')
5
5
 
6
- attr_reader :path, :default_version
6
+ attr_reader :path, :version
7
7
 
8
- def initialize(binary_path = nil, default_version = DEFAULT_BINARY_VERSION)
8
+ def initialize(binary_path = nil)
9
9
  @path = binary_path || find_binary_path
10
- @default_version = default_version
10
+ @version = retrieve_binary_version
11
11
 
12
+ raise "Minimum version of wkhtmltopdf is #{MINIMUM_BINARY_VERSION}. Version found was #{@version}." if @version < MINIMUM_BINARY_VERSION
12
13
  raise "Location of #{EXE_NAME} unknown" if @path.empty?
13
14
  raise "Bad #{EXE_NAME}'s path: #{@path}" unless File.exist?(@path)
14
15
  raise "#{EXE_NAME} is not executable" unless File.executable?(@path)
15
16
  end
16
17
 
17
- def version
18
- @version ||= retrieve_binary_version
19
- end
20
-
21
18
  def parse_version_string(version_info)
22
19
  match_data = /wkhtmltopdf\s*(\d*\.\d*\.\d*\w*)/.match(version_info)
23
20
  if match_data && (match_data.length == 2)
24
21
  Gem::Version.new(match_data[1])
25
22
  else
26
- default_version
23
+ MINIMUM_BINARY_VERSION
27
24
  end
28
25
  end
29
26
 
@@ -33,7 +30,7 @@ module WickedPdf
33
30
  _stdin, stdout, _stderr = Open3.popen3(@path + ' -V')
34
31
  parse_version_string(stdout.gets(nil))
35
32
  rescue StandardError
36
- default_version
33
+ MINIMUM_BINARY_VERSION
37
34
  end
38
35
 
39
36
  def find_binary_path
@@ -49,7 +46,7 @@ module WickedPdf
49
46
  possible_locations = (ENV['PATH'].split(':') + %w[/usr/bin /usr/local/bin]).uniq
50
47
  possible_locations += %w[~/bin] if ENV.key?('HOME')
51
48
 
52
- exe_path ||= possible_locations.map { |l| File.expand_path("#{l}/#{EXE_NAME}") }.find { |location| File.exist?(location) }
49
+ exe_path = possible_locations.map { |l| File.expand_path("#{l}/#{EXE_NAME}") }.find { |location| File.exist?(location) }
53
50
  exe_path || ''
54
51
  end
55
52
  end
@@ -2,9 +2,9 @@ module WickedPdf
2
2
  class Command
3
3
  attr_reader :binary, :option_parser
4
4
 
5
- def initialize(binary: Binary.new, option_parser: nil)
5
+ def initialize(binary: Binary.new, option_parser: OptionParser.new)
6
6
  @binary = binary
7
- @option_parser = option_parser || OptionParser.new(@binary.version)
7
+ @option_parser = option_parser
8
8
  end
9
9
 
10
10
  def execute(options, *args)
@@ -1,13 +1,5 @@
1
1
  module WickedPdf
2
2
  class OptionParser
3
- BINARY_VERSION_WITHOUT_DASHES = Gem::Version.new('0.12.0')
4
-
5
- attr_reader :binary_version
6
-
7
- def initialize(binary_version = WickedPdf::Binary::DEFAULT_BINARY_VERSION)
8
- @binary_version = binary_version
9
- end
10
-
11
3
  def parse(options)
12
4
  [
13
5
  parse_extra(options),
@@ -23,14 +15,6 @@ module WickedPdf
23
15
  ].flatten
24
16
  end
25
17
 
26
- def format_option(name)
27
- if binary_version < BINARY_VERSION_WITHOUT_DASHES
28
- "--#{name}"
29
- else
30
- name
31
- end
32
- end
33
-
34
18
  private
35
19
 
36
20
  def parse_extra(options)
@@ -78,19 +62,19 @@ module WickedPdf
78
62
  return [] if arg.blank?
79
63
  # Filesystem path or URL - hand off to wkhtmltopdf
80
64
  if argument.is_a?(Pathname) || (arg[0, 4] == 'http')
81
- [format_option('cover'), arg]
65
+ ['cover', arg]
82
66
  else # HTML content
83
67
  @hf_tempfiles ||= []
84
68
  @hf_tempfiles << tf = WickedPdf::Tempfile.new('wicked_cover_pdf.html')
85
69
  tf.write arg
86
70
  tf.flush
87
- [format_option('cover'), tf.path]
71
+ ['cover', tf.path]
88
72
  end
89
73
  end
90
74
 
91
75
  def parse_toc(options)
92
76
  return [] if options.nil?
93
- r = [format_option('toc')]
77
+ r = ['toc']
94
78
  unless options.blank?
95
79
  r += make_options(options, [:font_name, :header_text], 'toc')
96
80
  r += make_options(options, [:xsl_style_sheet])
@@ -1,3 +1,3 @@
1
1
  module WickedPdf
2
- VERSION = '2.0.0.beta1'.freeze
2
+ VERSION = '2.0.0.beta2'.freeze
3
3
  end
@@ -2,6 +2,7 @@
2
2
  ENV['RAILS_ENV'] = 'test'
3
3
 
4
4
  require 'combustion'
5
+ require 'byebug'
5
6
 
6
7
  Combustion.path = 'test/dummy'
7
8
  Combustion.initialize!(:all) do
@@ -1,23 +1,32 @@
1
1
  require 'test_helper'
2
2
 
3
3
  class WickedPdfBinaryTest < ActiveSupport::TestCase
4
+ setup do
5
+ @saved_config = WickedPdf.config
6
+ WickedPdf.config = {}
7
+ end
8
+
9
+ teardown do
10
+ WickedPdf.config = @saved_config
11
+ end
12
+
4
13
  test 'should extract old wkhtmltopdf version' do
5
- version_info_sample = "Name:\n wkhtmltopdf 0.9.9\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
6
- assert_equal WickedPdf::Binary::DEFAULT_BINARY_VERSION, binary.parse_version_string(version_info_sample)
14
+ version_info_sample = "Name:V\n wkhtmltopdf 0.9.9\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
15
+ assert_equal Gem::Version.new('0.9.9'), binary.parse_version_string(version_info_sample)
7
16
  end
8
17
 
9
18
  test 'should extract new wkhtmltopdf version' do
10
- version_info_sample = "Name:\n wkhtmltopdf 0.11.0 rc2\n\nLicense:\n Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.\n\n\n\n License LGPLv3+: GNU Lesser General Public License version 3 or later\n <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to\n change and redistribute it. There is NO WARRANTY, to the extent permitted by\n law.\n\nAuthors:\n Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by\n Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and\n Mario Silva."
11
- assert_equal Gem::Version.new('0.11.0'), binary.parse_version_string(version_info_sample)
19
+ version_info_sample = "Name:\n wkhtmltopdf 0.12.0 rc2\n\nLicense:\n Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.\n\n\n\n License LGPLv3+: GNU Lesser General Public License version 3 or later\n <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to\n change and redistribute it. There is NO WARRANTY, to the extent permitted by\n law.\n\nAuthors:\n Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by\n Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and\n Mario Silva."
20
+ assert_equal Gem::Version.new('0.12.0'), binary.parse_version_string(version_info_sample)
12
21
  end
13
22
 
14
23
  test 'should extract wkhtmltopdf version with nondigit symbols' do
15
- version_info_sample = "Name:\n wkhtmltopdf 0.10.4b\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
16
- assert_equal Gem::Version.new('0.10.4b'), binary.parse_version_string(version_info_sample)
24
+ version_info_sample = "Name:\n wkhtmltopdf 0.12.4b\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
25
+ assert_equal Gem::Version.new('0.12.4b'), binary.parse_version_string(version_info_sample)
17
26
  end
18
27
 
19
- test 'should fallback to default version on parse error' do
20
- assert_equal WickedPdf::Binary::DEFAULT_BINARY_VERSION, binary.parse_version_string('')
28
+ test 'should fallback to minimum version on parse error' do
29
+ assert_equal WickedPdf::Binary::MINIMUM_BINARY_VERSION, binary.parse_version_string('')
21
30
  end
22
31
 
23
32
  test 'should raise exception when no path to wkhtmltopdf' do
@@ -46,6 +55,53 @@ class WickedPdfBinaryTest < ActiveSupport::TestCase
46
55
  end
47
56
  end
48
57
 
58
+ test 'should raise exception if binary version is less than minimum' do
59
+ version_info_sample = "Name:V\n wkhtmltopdf 0.9.9\n\nLicense:\n Copyright (C) 2008,2009 Wkhtmltopdf Authors.\n\n\n\n License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n This is free software: you are free to change and redistribute it. There is NO\n WARRANTY, to the extent permitted by law.\n\nAuthors:\n Written by Jakob Truelsen. Patches by Mrio Silva, Benoit Garret and Emmanuel\n Bouthenot.\n"
60
+ Open3.expects(:popen3).returns([nil, mock('stdout', :gets => version_info_sample), nil])
61
+
62
+ assert_raise RuntimeError do
63
+ WickedPdf::Binary.new
64
+ end
65
+ end
66
+
67
+ test 'should correctly locate wkhtmltopdf without bundler' do
68
+ bundler_module = Bundler
69
+ Object.send(:remove_const, :Bundler)
70
+
71
+ assert_nothing_raised do
72
+ WickedPdf::Binary.new
73
+ end
74
+
75
+ Object.const_set(:Bundler, bundler_module)
76
+ end
77
+
78
+ test 'should correctly locate wkhtmltopdf with bundler' do
79
+ assert_nothing_raised do
80
+ WickedPdf::Binary.new
81
+ end
82
+ end
83
+
84
+ class LocationNonWritableTest < ActiveSupport::TestCase
85
+ setup do
86
+ @saved_config = WickedPdf.config
87
+ WickedPdf.config = {}
88
+
89
+ @old_home = ENV['HOME']
90
+ ENV['HOME'] = '/not/a/writable/directory'
91
+ end
92
+
93
+ teardown do
94
+ WickedPdf.config = @saved_config
95
+ ENV['HOME'] = @old_home
96
+ end
97
+
98
+ test 'should correctly locate wkhtmltopdf with bundler while HOME is set to a non-writable directory' do
99
+ assert_nothing_raised do
100
+ WickedPdf::Binary.new
101
+ end
102
+ end
103
+ end
104
+
49
105
  def binary(path = nil)
50
106
  WickedPdf::Binary.new(path)
51
107
  end
@@ -21,7 +21,7 @@ class WickedPdfOptionParserTest < ActiveSupport::TestCase
21
21
  end
22
22
 
23
23
  test 'should parse toc options' do
24
- toc_option = option_parser.format_option('toc')
24
+ toc_option = 'toc'
25
25
 
26
26
  [:font_name, :header_text].each do |o|
27
27
  assert_equal "#{toc_option} --toc-#{o.to_s.tr('_', '-')} toc",
@@ -60,7 +60,7 @@ class WickedPdfOptionParserTest < ActiveSupport::TestCase
60
60
  end
61
61
 
62
62
  test 'should parse cover' do
63
- cover_option = option_parser.format_option('cover')
63
+ cover_option = 'cover'
64
64
 
65
65
  pathname = Rails.root.join('app', 'views', 'pdf', 'file.html')
66
66
  assert_equal "#{cover_option} http://example.org", parse_options(:cover => 'http://example.org').strip, 'URL'
@@ -96,33 +96,13 @@ class WickedPdfOptionParserTest < ActiveSupport::TestCase
96
96
  end
97
97
  end
98
98
 
99
- test 'should not use double dash options for version without dashes' do
100
- op = option_parser(WickedPdf::OptionParser::BINARY_VERSION_WITHOUT_DASHES)
101
-
102
- %w[toc cover].each do |name|
103
- assert_equal op.format_option(name), name
104
- end
105
- end
106
-
107
- test 'should use double dash options for version with dashes' do
108
- op = option_parser(Gem::Version.new('0.11.0'))
109
-
110
- %w[toc cover].each do |name|
111
- assert_equal op.format_option(name), "--#{name}"
112
- end
113
- end
114
-
115
99
  test '-- options should not be given after object' do
116
100
  options = { :header => { :center => 3 }, :cover => 'http://example.org', :disable_javascript => true }
117
- cover_option = option_parser.format_option('cover')
101
+ cover_option = 'cover'
118
102
  assert_equal parse_options(options), "--disable-javascript --header-center 3 #{cover_option} http://example.org"
119
103
  end
120
104
 
121
- def parse_options(options, version = WickedPdf::Binary::DEFAULT_BINARY_VERSION)
122
- option_parser(version).parse(options).join(' ')
123
- end
124
-
125
- def option_parser(version = WickedPdf::Binary::DEFAULT_BINARY_VERSION)
126
- WickedPdf::OptionParser.new(version)
105
+ def parse_options(options)
106
+ WickedPdf::OptionParser.new.parse(options).join(' ')
127
107
  end
128
108
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adzap-wicked_pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.beta1
4
+ version: 2.0.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Z. Sterrett
@@ -196,7 +196,6 @@ files:
196
196
  - test/unit/wicked_pdf_option_parser_test.rb
197
197
  - test/unit/wicked_pdf_renderer_test.rb
198
198
  - test/unit/wicked_pdf_test.rb
199
- - test/unit/wkhtmltopdf_location_test.rb
200
199
  - wicked_pdf.gemspec
201
200
  homepage: https://github.com/adzap/wicked_pdf
202
201
  licenses:
@@ -246,4 +245,3 @@ test_files:
246
245
  - test/unit/wicked_pdf_option_parser_test.rb
247
246
  - test/unit/wicked_pdf_renderer_test.rb
248
247
  - test/unit/wicked_pdf_test.rb
249
- - test/unit/wkhtmltopdf_location_test.rb
@@ -1,50 +0,0 @@
1
-
2
-
3
- class WkhtmltopdfLocationTest < ActiveSupport::TestCase
4
- setup do
5
- @saved_config = WickedPdf.config
6
- WickedPdf.config = {}
7
- end
8
-
9
- teardown do
10
- WickedPdf.config = @saved_config
11
- end
12
-
13
- test 'should correctly locate wkhtmltopdf without bundler' do
14
- bundler_module = Bundler
15
- Object.send(:remove_const, :Bundler)
16
-
17
- assert_nothing_raised do
18
- WickedPdf.new
19
- end
20
-
21
- Object.const_set(:Bundler, bundler_module)
22
- end
23
-
24
- test 'should correctly locate wkhtmltopdf with bundler' do
25
- assert_nothing_raised do
26
- WickedPdf.new
27
- end
28
- end
29
-
30
- class LocationNonWritableTest < ActiveSupport::TestCase
31
- setup do
32
- @saved_config = WickedPdf.config
33
- WickedPdf.config = {}
34
-
35
- @old_home = ENV['HOME']
36
- ENV['HOME'] = '/not/a/writable/directory'
37
- end
38
-
39
- teardown do
40
- WickedPdf.config = @saved_config
41
- ENV['HOME'] = @old_home
42
- end
43
-
44
- test 'should correctly locate wkhtmltopdf with bundler while HOME is set to a non-writable directory' do
45
- assert_nothing_raised do
46
- WickedPdf.new
47
- end
48
- end
49
- end
50
- end