pixelpress 0.3.1 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72fc075971593953c3a7056f7001d50348f9b8d685ad08fe96b80dcd4151436a
4
- data.tar.gz: 72c713f2b2aa16d3437bf0ed335d158cfd32048487aa5626a4236976c3cbe76c
3
+ metadata.gz: 0cc5425ba75f2b3d99b63622b074e34922e734bd6fba94306a94cd84088e882e
4
+ data.tar.gz: 1907176157c4a6fa50f77c9479cc39c36f37fe74ed73d81633d812703fe483bd
5
5
  SHA512:
6
- metadata.gz: d89b7c28c2a0a9193281eb5d1b8c3e9da7bc100772a41628c5c85b9ba3216e3ff6f00de6c9566238dfc63e9cf9dde026efe7c6c1c0d5e7aeb926ff634c5ba9eb
7
- data.tar.gz: 56c91b7091209f81d7447de720c3b5ffa3e523a89599a23c6363434866d14fa6f671aab7bfb2504c895647878c7b2a78d8fbe47e045df69f025d0764847b36ba
6
+ metadata.gz: 1ce2a0d492ab4376ddc0d50f132d0e91515fc927f8d67487fcb34935e6ee93b8fb9f0f98df40e571bfb43a9663b020a1d62bd9e69930b5950a7ff2d5f046a59b
7
+ data.tar.gz: 7303ace72f3b012e4162ce976494b199dc5c0fdae59d0825ed01f5d0de21b943ddf72073b390fe3ac3dd911d73ff3217bfa9328d97648d6ce9c4c247e4384229
data/README.md CHANGED
@@ -1,23 +1,22 @@
1
1
  # Pixelpress
2
- [![CircleCI](https://circleci.com/gh/nerdgeschoss/pixelpress/tree/master.svg?style=svg)](https://circleci.com/gh/nerdgeschoss/pixelpress/tree/master)
3
2
 
4
- Modeled after `ActionMailer` this gem allows you to render PDFs from HTML via Rails templating engine. Also you can preview your PDF templates via a supplied engine during development.
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 this line to your application's Gemfile:
7
+ Add Pixelpress to your application's Gemfile:
9
8
 
10
9
  ```ruby
11
- gem 'pixelpress'
10
+ gem "pixelpress"
12
11
  ```
13
12
 
14
13
  And then execute:
15
14
 
16
- $ bundle
17
-
18
- Or install it yourself as:
15
+ ```bash
16
+ $ bundle
17
+ ```
19
18
 
20
- $ gem install pixelpress
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 an `ApplicationPrinter` in `app/printers` and the corresponding subclass and also mounts the engine in your `config/routes.rb` file.
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
- will generate `app/printers/invoice_printer.rb` file which looks like this:
35
+
36
+ will generate an `app/printers/invoice_printer.rb` file with this content:
37
+
36
38
  ```ruby
37
39
  class InvoicePrinter < ApplicationPrinter
38
- def customer_invoice
39
- # put your code here
40
- end
40
+ def customer_invoice
41
+ # put your code here
42
+ end
41
43
 
42
- def delivery_document
43
- # put your code here
44
- end
44
+ def delivery_document
45
+ # put your code here
46
+ end
45
47
  end
46
48
  ```
47
49
 
48
- Also this command will generate the corresponding templates as `.pdf.erb` files located in `app/views/printers/invoice/`:
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 instantiate them just like mailers:
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,2 +1,2 @@
1
- Rails.application.config.autoload_paths << Rails.root.join('app', 'printers')
2
- Rails.application.config.autoload_paths << Rails.root.join('spec', 'printer', 'previews') if Rails.env.development?
1
+ Rails.application.config.autoload_paths << Rails.root.join('app/printers')
2
+ Rails.application.config.autoload_paths << Rails.root.join('spec/printers/previews') if Rails.env.development?
@@ -1,7 +1,7 @@
1
1
  module Pixelpress
2
2
  class Preview
3
3
  def self.all
4
- Dir[Rails.root.join('spec', 'printers', 'previews', '**', '*_preview.rb')].map do |file|
4
+ Dir[Rails.root.join('spec/printers/previews/**/*_preview.rb')].map do |file|
5
5
  require_dependency file
6
6
  file.split('printers/previews/').last.sub('.rb', '').classify.constantize.new
7
7
  end
@@ -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 || raise(StandardError, "could not find weasyprint")
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
@@ -1,3 +1,3 @@
1
1
  module Pixelpress
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.3.3'.freeze
3
3
  end
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.1
4
+ version: 0.3.3
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-05-23 00:00:00.000000000 Z
12
+ date: 2025-01-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack