Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added name-value options COOKIE and POST #72

Merged
merged 1 commit into from Feb 22, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -60,6 +60,8 @@ or add this to your Gemfile:
:dpi => 'dpi',
:encoding => 'TEXT',
:user_style_sheet => 'URL',
:cookie => ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format
:post => ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format
:redirect_delay => NUMBER,
:zoom => FLOAT,
:page_offset => NUMBER,
Expand Down
6 changes: 6 additions & 0 deletions lib/wicked_pdf.rb
Expand Up @@ -64,9 +64,13 @@ def parse_basic_auth(options)
end

def make_option(name, value, type=:string)
if value.respond_to? :each
return value.collect { |v| make_option(name, v, type) }.join('')
end
"--#{name.gsub('_', '-')} " + case type
when :boolean then ""
when :numeric then value.to_s
when :name_value then value.to_s
else "'#{value}'"
end + " "
end
Expand Down Expand Up @@ -140,6 +144,8 @@ def parse_others(options)
:dpi,
:encoding,
:user_style_sheet])
r +=make_options(options, [ :cookie,
:post], "", :name_value)
r +=make_options(options, [ :redirect_delay,
:zoom,
:page_offset], "", :numeric)
Expand Down
1 change: 1 addition & 0 deletions test/wicked_pdf_helper_test.rb
@@ -1,4 +1,5 @@
require 'test_helper'
require 'action_view/test_case'

class WickedPdfHelperTest < ActionView::TestCase
test 'wicked_pdf_stylesheet_link_tag should inline the stylesheets passed in' do
Expand Down
7 changes: 7 additions & 0 deletions test/wicked_pdf_test.rb
Expand Up @@ -126,6 +126,13 @@ class WickedPdfTest < ActiveSupport::TestCase
assert_equal "--#{o.to_s.gsub('_', '-')} 'opts'", wp.get_parsed_options(o => "opts").strip
end

[:cookie, :post].each do |o|
assert_equal "--#{o.to_s.gsub('_', '-')} name value", wp.get_parsed_options(o => "name value").strip

nv_formatter = ->(number){ "--#{o.to_s.gsub('_', '-')} par#{number} val#{number}" }
assert_equal "#{nv_formatter.call(1)} #{nv_formatter.call(2)}", wp.get_parsed_options(o => ['par1 val1', 'par2 val2']).strip
end

[:redirect_delay, :zoom, :page_offset].each do |o|
assert_equal "--#{o.to_s.gsub('_', '-')} 5", wp.get_parsed_options(o => 5).strip
end
Expand Down