Skip to content

Commit 63976ac

Browse files
committed
change custom configuration setting
1 parent 736b217 commit 63976ac

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ You can also pass any options through meta tags in your HTML:
131131
Configuration
132132
-------------
133133

134-
Each API call takes an optional configuration paramater. This should be an instance of ``pdfkit.configuration.Configuration()`` - it takes the configuration options as initial paramaters. The available options are:
134+
Each API call takes an optional configuration paramater. This should be an instance of ``pdfkit.configuration()`` API call. It takes the configuration options as initial paramaters. The available options are:
135135

136136
* ``wkhtmltopdf`` - the location of the ``wkhtmltopdf`` binary. By default ``pdfkit`` will attempt to locate this using ``which`` (on UNIX type systems) or ``where`` (on Windows).
137137
* ``meta_tag_prefix`` - the prefix for ``pdfkit`` specific meta tags - by default this is ``pdfkit-``
@@ -140,7 +140,7 @@ Example - for when ``wkhtmltopdf`` is not on ``$PATH``:
140140

141141
.. code-block:: python
142142
143-
config = pdfkit.configuration.Configuration(wkhtmltopdf='/opt/bin/wkhtmltopdf'))
143+
config = pdfkit.configuration(wkhtmltopdf='/opt/bin/wkhtmltopdf'))
144144
pdfkit.from_string(html_string, output_file, configuration=config)
145145
146146

pdfkit/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,4 @@
88
__license__ = 'MIT'
99

1010
from .pdfkit import PDFKit
11-
from .api import from_url, from_file, from_string
12-
from .configuration import Configuration
11+
from .api import from_url, from_file, from_string, configuration

pdfkit/api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# -*- coding: utf-8 -*-
22

33
from .pdfkit import PDFKit
4+
from .pdfkit import Configuration
45

56

67
def from_url(url, output_path, options=None, toc=None, cover=None, configuration=None):
@@ -65,3 +66,14 @@ def from_string(input, output_path, options=None, toc=None, cover=None, css=None
6566
configuration=configuration)
6667

6768
return r.to_pdf(output_path)
69+
70+
71+
def configuration(**kwargs):
72+
"""
73+
Constructs and returns a :class:`Configuration` with given options
74+
75+
:param wkhtmltopdf: path to binary
76+
:param meta_tag_prefix: the prefix for ``pdfkit`` specific meta tags
77+
"""
78+
79+
return Configuration(**kwargs)

pdfkit/pdfkit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
class PDFKit(object):
1313
"""
14+
Main class that does all generation routine.
15+
1416
:param url_or_file: str - either a URL, a path to a file or a string containing HTML
1517
to convert
1618
:param type_: str - either 'url', 'file' or 'string'

tests/pdfkit-tests.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ def test_options_parsing_with_dashes(self):
4747
r = pdfkit.PDFKit('html', 'string', options={'--page-size': 'Letter'})
4848
self.assertTrue(r.options['--page-size'])
4949

50+
def test_custom_configuration(self):
51+
conf = pdfkit.configuration()
52+
self.assertEqual('pdfkit-', conf.meta_tag_prefix)
53+
conf = pdfkit.configuration(meta_tag_prefix='prefix-')
54+
self.assertEqual('prefix-', conf.meta_tag_prefix)
55+
with self.assertRaises(IOError):
56+
conf = pdfkit.configuration(wkhtmltopdf='wrongpath')
57+
5058

5159
class TestPDFKitCommandGeneration(unittest.TestCase):
5260
"""Test command() method"""

0 commit comments

Comments
 (0)