Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions wkhtmltopdf/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ def test_options_to_args(self):
file_name='file-name'),
['--file-name', 'file-name',
'--heart', u'♥'])
self.assertEqual(_options_to_args(
custom_header='Authentication mytoken',
cookie='key1 value1'),
['--cookie', 'key1', 'value1',
'--custom-header', 'Authentication', 'mytoken'])

def test_wkhtmltopdf(self):
"""Should run wkhtmltopdf to generate a PDF"""
Expand Down
7 changes: 6 additions & 1 deletion wkhtmltopdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
'--enable-toc-back-links', '--footer-line', '--no-footer-line',
'--header-line', '--no-header-line', '--disable-dotted-lines',
'--disable-toc-links', '--verbose']
MULTI_VALUE_OPTIONS = ['--custom-header', '--cookie']


def _options_to_args(**options):
Expand All @@ -60,12 +61,16 @@ def _options_to_args(**options):
formatted_flag = '--%s' % name if len(name) > 1 else '-%s' % name
formatted_flag = formatted_flag.replace('_', '-')
accepts_no_arguments = formatted_flag in NO_ARGUMENT_OPTIONS
is_multi_value_option = formatted_flag in MULTI_VALUE_OPTIONS
if value is None or (value is False and accepts_no_arguments):
continue
flags.append(formatted_flag)
if accepts_no_arguments:
continue
flags.append(six.text_type(value))
if is_multi_value_option:
flags.extend(value.split())
else:
flags.append(six.text_type(value))
return flags


Expand Down