Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Options enhancement #122

Merged
merged 2 commits into from

2 participants

Jean le Roux Devin Walters
Jean le Roux

Currently not possible to pass --replace foo bar options to PDFKit.

I've added very minor changes to allow Hash and Array classes as valid values, instead of just printing them verbatim.

Tests included and passing.

Devin Walters
Owner

Could you update the README to reflect this change as part of your PR? Thanks!

Devin Walters
Owner

@elarex Thoughts on #130 ?

Devin Walters devn merged commit 3e836ab into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 2 deletions.
  1. +5 −1 lib/pdfkit/pdfkit.rb
  2. +8 −1 spec/pdfkit_spec.rb
6 lib/pdfkit/pdfkit.rb
View
@@ -127,8 +127,12 @@ def normalize_arg(arg)
def normalize_value(value)
case value
- when TrueClass
+ when TrueClass #ie, ==true, see http://www.ruby-doc.org/core-1.9.3/TrueClass.html
nil
+ when Hash
+ value.to_a.flatten.collect{|x| x.to_s}
+ when Array
+ value.flatten.collect{|x| x.to_s}
else
value.to_s
end
9 spec/pdfkit_spec.rb
View
@@ -28,6 +28,11 @@
pdfkit.options.should have_key('--page-size')
end
+ it "should parse complex options into a cmd line friedly format" do
+ pdfkit = PDFKit.new('html', :replace => {'value' => 'something else'} )
+ pdfkit.options.should have_key('--replace')
+ end
+
it "should provide default options" do
pdfkit = PDFKit.new('<h1>Oh Hai</h1>')
['--margin-top', '--margin-right', '--margin-bottom', '--margin-left'].each do |option|
@@ -48,10 +53,12 @@
context "command" do
it "should contstruct the correct command" do
- pdfkit = PDFKit.new('html', :page_size => 'Letter', :toc_l1_font_size => 12)
+ pdfkit = PDFKit.new('html', :page_size => 'Letter', :toc_l1_font_size => 12, :replace => {'foo' => 'bar'})
pdfkit.command[0].should include('wkhtmltopdf')
pdfkit.command[pdfkit.command.index('"--page-size"') + 1].should == '"Letter"'
pdfkit.command[pdfkit.command.index('"--toc-l1-font-size"') + 1].should == '"12"'
+ pdfkit.command[pdfkit.command.index('"--replace"') + 1].should == '"foo"'
+ pdfkit.command[pdfkit.command.index('"--replace"') + 2].should == '"bar"'
end
it "will not include default options it is told to omit" do
Something went wrong with that request. Please try again.