breezy_pdf 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -42
- data/lib/breezy_pdf.rb +21 -0
- data/lib/breezy_pdf/html/publicize.rb +1 -1
- data/lib/breezy_pdf/html_2_pdf.rb +7 -2
- data/lib/breezy_pdf/intercept/base.rb +2 -2
- data/lib/breezy_pdf/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f96e0707087a6ec855ab37b985ee3ff85462cd0f
|
4
|
+
data.tar.gz: a194a4f380f659fa12f695ccd83047649a858d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 880c5ba65853fb17df0f3be7893b7e75a2b3542d4b2874fa2df27bd8b61020d1976aeee5469f2b5c6aefac1ce78a9a26a6a2c6a8c19dd545ed65b3d553cc1354
|
7
|
+
data.tar.gz: b747791a6b0c9418e91b027b2244235b86be9337022e279a674cd33fbfbdd6b1d792d3886076c3abfecbd7d136bc99d8904310b9e122d1feab6f27f1816ff06c
|
data/README.md
CHANGED
@@ -140,7 +140,7 @@ BreezyPDF.setup do |config|
|
|
140
140
|
#
|
141
141
|
# Cache asset URL's to prevent re-uploading of assets. Assets are cached based on asset_path,
|
142
142
|
# so fingerprinting or digests are recommended before turning on. The default cache store is
|
143
|
-
# a null store, which won't
|
143
|
+
# a null store, which won't actually store anything. An in-memory store is also provided, but
|
144
144
|
# this store won't share values across threads. Alternatively, use an external store which
|
145
145
|
# implements a `fetch(key, opts={}, &blk) API, such as the Rails.cache.
|
146
146
|
#
|
@@ -161,7 +161,7 @@ BreezyPDF.setup do |config|
|
|
161
161
|
# Extract Metadata
|
162
162
|
#
|
163
163
|
# BreezyPDF supports specifying how a page should be rendered through meta tags within
|
164
|
-
# the HTML to be rendered.
|
164
|
+
# the HTML to be rendered. Visit https://docs.breezypdf.com for metadata information. Default is
|
165
165
|
# true.
|
166
166
|
#
|
167
167
|
# Only applicable when `treat_urls_as_private == true`
|
@@ -207,6 +207,16 @@ BreezyPDF.setup do |config|
|
|
207
207
|
# Configure the logger, if you're into that sort of thing.
|
208
208
|
#
|
209
209
|
# config.logger = Logger.new(STDOUT).tap { |logger| logger.level = Logger::FATAL }
|
210
|
+
|
211
|
+
# Default Meta Data
|
212
|
+
#
|
213
|
+
# Define default meta data which will be included with every render. Extracted metadata
|
214
|
+
# will override these values. Visit https://docs.breezypdf.com for metadata information.
|
215
|
+
#
|
216
|
+
# config.default_metadata = {
|
217
|
+
# width: 23.4,
|
218
|
+
# height: 33.1
|
219
|
+
# }
|
210
220
|
end
|
211
221
|
```
|
212
222
|
|
@@ -219,48 +229,28 @@ If you want to show a loading animation on the current page, you can simply load
|
|
219
229
|
Here is a contrived example:
|
220
230
|
|
221
231
|
```html
|
222
|
-
<a href="/this/path.pdf" class="
|
232
|
+
<a href="/this/path.pdf" class="pdf-link">Download as PDF</a>
|
223
233
|
|
224
234
|
<script type="text/javascript">
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
// Listen for a click on the link, then start handling the change of state
|
238
|
-
linkEl.addEventListener('click', function(ev) {
|
239
|
-
loadingEl.style.display = "block"; // Display ad-hoc loading element
|
240
|
-
ev.preventDefault();
|
241
|
-
|
242
|
-
var i = 1;
|
243
|
-
var interval = setInterval(function() {
|
244
|
-
progressEl.innerText = i / 10.0 + ' waiting seconds so far...';
|
245
|
-
i++;
|
246
|
-
}, 100);
|
247
|
-
|
248
|
-
var ajaxRequest = new XMLHttpRequest();
|
249
|
-
|
250
|
-
ajaxRequest.addEventListener('load', function(ev) {
|
251
|
-
clearInterval(interval);
|
252
|
-
console.log("Done waiting. We'd close modals or remove loading animations here before setting the location.")
|
253
|
-
loadingEl.style.display = "none";
|
254
|
-
|
255
|
-
// Redirect the eventual URL of the PDF
|
256
|
-
// If the browser downloads the file, the current page's HTML will still be shown
|
257
|
-
window.location = ev.currentTarget.responseURL;
|
258
|
-
})
|
259
|
-
|
260
|
-
ajaxRequest.open('GET', pdfUrl);
|
261
|
-
ajaxRequest.send();
|
235
|
+
$('.pdf-link').on('click', function(clickEv) {
|
236
|
+
var startTime = new Date();
|
237
|
+
var targetEl = $(clickEv.target);
|
238
|
+
var modalEl = $('#pdf-loading'); // An existing bootstrap modal in this example
|
239
|
+
var ajaxRequest = new XMLHttpRequest();
|
240
|
+
|
241
|
+
clickEv.preventDefault();
|
242
|
+
|
243
|
+
ajaxRequest.addEventListener('load', function(ev) {
|
244
|
+
modalEl.modal('hide');
|
245
|
+
|
246
|
+
window.location = ev.currentTarget.responseURL;
|
262
247
|
})
|
263
|
-
|
248
|
+
|
249
|
+
modalEl.modal('show');
|
250
|
+
|
251
|
+
ajaxRequest.open('GET', targetEl.attr('href'));
|
252
|
+
ajaxRequest.send();
|
253
|
+
})
|
264
254
|
</script>
|
265
255
|
```
|
266
256
|
|
@@ -274,8 +264,10 @@ Here is an example of how you might do that:
|
|
274
264
|
def invoice_mailer(user, invoice)
|
275
265
|
asset_host = Rails.env.production? ? Rails.application.config.action_controller.asset_host : "http://localhost:3000"
|
276
266
|
|
267
|
+
metadata = { width: 8.5, width: 11 }
|
268
|
+
|
277
269
|
html = ActionController::Renderer.render(template "invoices/show", assigns: { invoice: invoice }, locals: { current_user: user })
|
278
|
-
pdf = BreezyPDF::HTML2PDF.new(, html)
|
270
|
+
pdf = BreezyPDF::HTML2PDF.new(asset_host, html, metadata)
|
279
271
|
|
280
272
|
attachments["invoice-#{invoice.id}.pdf"] = pdf.to_file.read
|
281
273
|
@pdf_url = pdf.to_url
|
data/lib/breezy_pdf.rb
CHANGED
@@ -75,6 +75,22 @@ module BreezyPDF
|
|
75
75
|
mattr_accessor :filter_elements_selectors
|
76
76
|
@@filtered_element_selectors = %w[.breezy-pdf-remove]
|
77
77
|
|
78
|
+
mattr_writer :default_metadata
|
79
|
+
@@default_metadata = {
|
80
|
+
width: 8.5,
|
81
|
+
height: 11,
|
82
|
+
cssPageSize: false,
|
83
|
+
marginTop: 0.04,
|
84
|
+
marginRight: 0.04,
|
85
|
+
marginBottom: 0.04,
|
86
|
+
marginLeft: 0.04,
|
87
|
+
landscape: false,
|
88
|
+
scale: 1,
|
89
|
+
displayBackground: false,
|
90
|
+
headerTemplate: "",
|
91
|
+
footerTemplate: ""
|
92
|
+
}
|
93
|
+
|
78
94
|
mattr_accessor :logger
|
79
95
|
@@logger = Logger.new(STDOUT)
|
80
96
|
@@logger.level = Logger::FATAL
|
@@ -82,4 +98,9 @@ module BreezyPDF
|
|
82
98
|
def self.setup
|
83
99
|
yield self
|
84
100
|
end
|
101
|
+
|
102
|
+
# Support proper merging of hash rocket and symbol keys
|
103
|
+
def self.default_metadata
|
104
|
+
@@jsonified_metadata ||= JSON.parse(@@default_metadata.to_json)
|
105
|
+
end
|
85
106
|
end
|
@@ -14,7 +14,7 @@ module BreezyPDF::HTML
|
|
14
14
|
def public_fragment
|
15
15
|
@public_fragment ||= parsed_document.tap do
|
16
16
|
publicize!
|
17
|
-
BreezyPDF.logger.info("[BreezyPDF] Replaced assets in
|
17
|
+
BreezyPDF.logger.info("[BreezyPDF] Replaced assets in #{timing} seconds")
|
18
18
|
end.to_html
|
19
19
|
end
|
20
20
|
|
@@ -4,9 +4,10 @@ module BreezyPDF
|
|
4
4
|
# Transform an HTML slug to a PDF
|
5
5
|
# Access it's URL or download it locally and access it as a Tempfile
|
6
6
|
class HTML2PDF
|
7
|
-
def initialize(asset_host, html_string)
|
7
|
+
def initialize(asset_host, html_string, metadata = {})
|
8
8
|
@asset_host = asset_host
|
9
9
|
@html_string = html_string
|
10
|
+
@metadata = metadata
|
10
11
|
end
|
11
12
|
|
12
13
|
def to_url
|
@@ -30,7 +31,11 @@ module BreezyPDF
|
|
30
31
|
end
|
31
32
|
|
32
33
|
def url
|
33
|
-
@url ||= BreezyPDF::RenderRequest.new(public_url,
|
34
|
+
@url ||= BreezyPDF::RenderRequest.new(public_url, combined_metadata).submit.download_url
|
35
|
+
end
|
36
|
+
|
37
|
+
def combined_metadata
|
38
|
+
@combined_metadata ||= BreezyPDF.default_metadata.merge(@metadata).merge(html_private_asset.metadata)
|
34
39
|
end
|
35
40
|
|
36
41
|
def io_object
|
data/lib/breezy_pdf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: breezy_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Westendorf
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-04-
|
11
|
+
date: 2018-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|