pixelpress 0.3.1 → 0.3.2
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 +22 -20
- data/lib/pixelpress/renderers/weasyprint_renderer.rb +10 -2
- data/lib/pixelpress/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 54fcf4c2f566dca8d2ea089d1432841da7266c9729660740a40b75f06bdfd1aa
|
4
|
+
data.tar.gz: 160335c2409574f6d0a368191b0e2824fca8e731951d2a8147a440dbb326a627
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c4751c86a67a9f8922b7359afd76f34ea99973da54e73aa62cbc12ff83f2d2c55cf7bb420d5a46a43976c297cf4327968def7313acbe230d91084889d2b9828
|
7
|
+
data.tar.gz: a0c733d14738be7a0d757e673fe6b0be771c0f623b3987078b9e9c48d92dc5a909fae9fe42f23362609ee5f68484a1a623abb48a510cb6bc51599aa15a68efc8
|
data/README.md
CHANGED
@@ -1,23 +1,22 @@
|
|
1
1
|
# Pixelpress
|
2
|
-
[](https://circleci.com/gh/nerdgeschoss/pixelpress/tree/master)
|
3
2
|
|
4
|
-
Modeled after `ActionMailer
|
3
|
+
Modeled after `ActionMailer`, this gem allows you to render PDFs from HTML via Rails' templating engine. Additionally, you can preview your PDF templates via a supplied Rails engine during development.
|
5
4
|
|
6
5
|
## Installation
|
7
6
|
|
8
|
-
Add
|
7
|
+
Add Pixelpress to your application's Gemfile:
|
9
8
|
|
10
9
|
```ruby
|
11
|
-
gem
|
10
|
+
gem "pixelpress"
|
12
11
|
```
|
13
12
|
|
14
13
|
And then execute:
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
19
18
|
|
20
|
-
|
19
|
+
You'll also need [WeasyPrint](https://weasyprint.org/). It needs to be installed and added to your `PATH`, so that `which weasyprint` returns the location of the binary. Read their installation instructions here: https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#installation
|
21
20
|
|
22
21
|
## Usage
|
23
22
|
|
@@ -26,26 +25,29 @@ Run the printer generator providing the name of your printer with methods to be
|
|
26
25
|
rails generate pixelpress:printer NAME [method_name1 method_name2 ...] [options]
|
27
26
|
```
|
28
27
|
|
29
|
-
This creates
|
28
|
+
This creates the new printer in `app/printers`. If you run it the first time, it will also add an `ApplicationPrinter` and mount the Rails engine in your `config/routes.rb` file.
|
30
29
|
|
31
30
|
**Example**
|
31
|
+
|
32
32
|
```bash
|
33
|
-
$ rails g pixelpress:printer invoice customer_invoice delivery_document
|
33
|
+
$ rails g pixelpress:printer invoice customer_invoice delivery_document
|
34
34
|
```
|
35
|
-
|
35
|
+
|
36
|
+
will generate an `app/printers/invoice_printer.rb` file with this content:
|
37
|
+
|
36
38
|
```ruby
|
37
39
|
class InvoicePrinter < ApplicationPrinter
|
38
|
-
|
39
|
-
|
40
|
-
|
40
|
+
def customer_invoice
|
41
|
+
# put your code here
|
42
|
+
end
|
41
43
|
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
def delivery_document
|
45
|
+
# put your code here
|
46
|
+
end
|
45
47
|
end
|
46
48
|
```
|
47
49
|
|
48
|
-
|
50
|
+
The command will also generate corresponding templates as `.pdf.erb` files located in `app/views/printers/invoice/`:
|
49
51
|
|
50
52
|
- `customer_invoice.pdf.erb`
|
51
53
|
- `delivery_document.pdf.erb`
|
@@ -53,10 +55,10 @@ Also this command will generate the corresponding templates as `.pdf.erb` files
|
|
53
55
|
You can preview your documents by running `rails s` and go to
|
54
56
|
|
55
57
|
```
|
56
|
-
localhost:3000/rails/printers
|
58
|
+
http://localhost:3000/rails/printers
|
57
59
|
```
|
58
60
|
|
59
|
-
To use your printers in code, you can
|
61
|
+
To use your printers in code, you can use them similarly to how you'd use mailers:
|
60
62
|
|
61
63
|
```ruby
|
62
64
|
InvoicePrinter.customer_invoice.pdf # render a temporary pdf file
|
@@ -1,11 +1,13 @@
|
|
1
1
|
class Pixelpress::WeasyPrintRenderer
|
2
|
+
class WeasyPrintInstallationError < StandardError; end
|
3
|
+
|
2
4
|
def render(input)
|
3
5
|
output = Tempfile.new
|
4
6
|
|
5
7
|
system executable_path, "--encoding", "utf-8", input.path, output.path, exception: true
|
6
8
|
return output
|
7
9
|
end
|
8
|
-
|
10
|
+
|
9
11
|
def version
|
10
12
|
`#{executable_path} --version`.chomp.scan(/(\d+\.\d+)/).flatten.first
|
11
13
|
end
|
@@ -13,6 +15,12 @@ class Pixelpress::WeasyPrintRenderer
|
|
13
15
|
private
|
14
16
|
|
15
17
|
def executable_path
|
16
|
-
`which weasyprint`.chomp
|
18
|
+
path = `which weasyprint`.chomp
|
19
|
+
|
20
|
+
if path.blank?
|
21
|
+
raise WeasyPrintInstallationError.new("Unable to locate weasyprint binary. Please make sure it's in your PATH.")
|
22
|
+
end
|
23
|
+
|
24
|
+
path
|
17
25
|
end
|
18
26
|
end
|
data/lib/pixelpress/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixelpress
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-10-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|