Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added name-value options COOKIE and POST #72

Merged
merged 1 commit into from

2 participants

@rosic

Added name-value options support and namely added cookie an post ones. This relates to my issue #43, I found especially cookie useful when I wanted to access certain resources as an authenticated user, i.e. based on the auth cookie info.

@unixmonkey unixmonkey merged commit ed25509 into mileszs:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 28, 2011
  1. @rosic
This page is out of date. Refresh to see the latest.
View
2  README.md
@@ -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,
View
6 lib/wicked_pdf.rb
@@ -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
@@ -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)
View
1  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
View
7 test/wicked_pdf_test.rb
@@ -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
Something went wrong with that request. Please try again.