pixelpress 0.3.5 → 0.4.0
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/.github/workflows/test.yml +3 -1
- data/.gitignore +1 -0
- data/.ruby-version +1 -1
- data/README.md +40 -2
- data/lib/pixelpress/base.rb +1 -0
- data/lib/pixelpress/renderers/weasyprint_renderer/zugferd.rb +71 -0
- data/lib/pixelpress/renderers/weasyprint_renderer.rb +43 -3
- data/lib/pixelpress/version.rb +1 -1
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c21e6e9bd0b516d40c41f5339ef30e315ccd08dc41abee55d67fe045f221efe9
|
|
4
|
+
data.tar.gz: 264dc423a451db64c9b9cd81e26a8753822cab3b593b337c82d633c453928454
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13bcac2b3029ed48d4ceba627632a53a4c6c80cd739105ed5d07746e98d71412cbb62b2cd676bad5d399dc8cd2f205c6576bf91cecb50a566dfd10249a3cb8aa
|
|
7
|
+
data.tar.gz: 100bdb58452700ce9cd5ae4109feb3bffdbef0a8990328177724e8b62a5ced7141a3b82109123421b25b366d1834a89794d724383ea9345fe95a97f1c3d8093c
|
data/.github/workflows/test.yml
CHANGED
|
@@ -14,7 +14,9 @@ jobs:
|
|
|
14
14
|
- name: Install dependencies
|
|
15
15
|
uses: awalsh128/cache-apt-pkgs-action@latest
|
|
16
16
|
with:
|
|
17
|
-
packages:
|
|
17
|
+
packages: pipx
|
|
18
18
|
version: 1.0
|
|
19
|
+
- name: Install WeasyPrint
|
|
20
|
+
run: pipx install weasyprint==70.0
|
|
19
21
|
- name: Test
|
|
20
22
|
run: bundle exec rspec
|
data/.gitignore
CHANGED
data/.ruby-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
4.0.10
|
data/README.md
CHANGED
|
@@ -21,6 +21,7 @@ You'll also need [WeasyPrint](https://weasyprint.org/). It needs to be installed
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
Run the printer generator providing the name of your printer with methods to be generated:
|
|
24
|
+
|
|
24
25
|
```bash
|
|
25
26
|
rails generate pixelpress:printer NAME [method_name1 method_name2 ...] [options]
|
|
26
27
|
```
|
|
@@ -47,7 +48,7 @@ class InvoicePrinter < ApplicationPrinter
|
|
|
47
48
|
end
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
The command will also generate corresponding templates
|
|
51
|
+
The command will also generate corresponding templates as `.pdf.erb` files located in `app/views/printers/invoice/`:
|
|
51
52
|
|
|
52
53
|
- `customer_invoice.pdf.erb`
|
|
53
54
|
- `delivery_document.pdf.erb`
|
|
@@ -79,6 +80,44 @@ class InvoicesController < ApplicationController
|
|
|
79
80
|
end
|
|
80
81
|
```
|
|
81
82
|
|
|
83
|
+
You can also pass additional arguments to the underlying renderer, if it supports it. For example, to pass CLI flags to WeasyPrint, you can do:
|
|
84
|
+
|
|
85
|
+
```ruby
|
|
86
|
+
class InvoicePrinter < ApplicationPrinter
|
|
87
|
+
def customer_invoice
|
|
88
|
+
renderer.set_flags(
|
|
89
|
+
attachment: "factur-x.xml",
|
|
90
|
+
attachment_relationship: "Alternative",
|
|
91
|
+
xmp_metadata: "rdf.xml",
|
|
92
|
+
pdf_variant: "pdf/a-3a"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# rest of your code here
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Which gets transformed to:
|
|
101
|
+
|
|
102
|
+
```sh
|
|
103
|
+
weasyprint --attachment "factur-x.xml" --attachment-relationship "Data" --xmp-metadata "rdf.xml" --pdf-variant "pdf/a-3a"
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
If you want to include ZUGFeRD data for electronic invoices, you can use this shortcut:
|
|
107
|
+
|
|
108
|
+
```rb
|
|
109
|
+
class InvoicePrinter < ApplicationPrinter
|
|
110
|
+
def customer_invoice
|
|
111
|
+
zugferd_data = generate_zugferd_data.to_s # this is on you
|
|
112
|
+
renderer.attach_zugferd_data(data: zugferd_data)
|
|
113
|
+
|
|
114
|
+
# rest of your code here
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
This is basically equivalent to the example above. Pixelpress will attach the provided data as `factur-x.xml` and refer to it from a `rdf.xml` that it generates for you.
|
|
120
|
+
|
|
82
121
|
## Development
|
|
83
122
|
|
|
84
123
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
@@ -89,7 +128,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
|
89
128
|
|
|
90
129
|
Bug reports and pull requests are welcome on GitHub at https://github.com/Alex/pixelpress.
|
|
91
130
|
|
|
92
|
-
|
|
93
131
|
## License
|
|
94
132
|
|
|
95
133
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/lib/pixelpress/base.rb
CHANGED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
class Pixelpress::WeasyPrintRenderer::Zugferd
|
|
2
|
+
def initialize(
|
|
3
|
+
data:,
|
|
4
|
+
document_file_name: "factur-x.xml",
|
|
5
|
+
document_type: "INVOICE",
|
|
6
|
+
conformance_level: "EN 16931",
|
|
7
|
+
version: "1.0"
|
|
8
|
+
)
|
|
9
|
+
@attachment_data = data
|
|
10
|
+
|
|
11
|
+
@document_file_name = document_file_name
|
|
12
|
+
@document_type = document_type
|
|
13
|
+
@conformance_level = conformance_level
|
|
14
|
+
@version = version
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def with_files(&block)
|
|
18
|
+
Dir.mktmpdir do |dir|
|
|
19
|
+
xml_file_path = File.join(dir, @document_file_name)
|
|
20
|
+
File.write(xml_file_path, @attachment_data)
|
|
21
|
+
|
|
22
|
+
xmp_file_path = File.join(dir, "xmp_rdf.xml")
|
|
23
|
+
File.write(xmp_file_path, xmp_metadata)
|
|
24
|
+
|
|
25
|
+
block.call(cli_flags(xml_file_path, xmp_file_path))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def cli_flags(xml_file_path, xmp_file_path)
|
|
32
|
+
[
|
|
33
|
+
"--attachment", xml_file_path,
|
|
34
|
+
"--attachment-relationship", "Alternative",
|
|
35
|
+
"--xmp-metadata", xmp_file_path,
|
|
36
|
+
"--pdf-variant", "pdf/a-3a"
|
|
37
|
+
]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def xmp_metadata
|
|
41
|
+
<<~XML
|
|
42
|
+
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
|
|
43
|
+
<rdf:Description rdf:about="" xmlns:fx="urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#">
|
|
44
|
+
<fx:DocumentType>#{@document_type}</fx:DocumentType>
|
|
45
|
+
<fx:DocumentFileName>#{@document_file_name}</fx:DocumentFileName>
|
|
46
|
+
<fx:Version>#{@version}</fx:Version>
|
|
47
|
+
<fx:ConformanceLevel>#{@conformance_level}</fx:ConformanceLevel>
|
|
48
|
+
</rdf:Description>
|
|
49
|
+
<rdf:Description rdf:about="" xmlns:pdfaExtension="http://www.aiim.org/pdfa/ns/extension/" xmlns:pdfaSchema="http://www.aiim.org/pdfa/ns/schema#" xmlns:pdfaProperty="http://www.aiim.org/pdfa/ns/property#">
|
|
50
|
+
<pdfaExtension:schemas>
|
|
51
|
+
<rdf:Bag>
|
|
52
|
+
<rdf:li rdf:parseType="Resource">
|
|
53
|
+
<pdfaSchema:schema>Factur-X PDFA Extension Schema</pdfaSchema:schema>
|
|
54
|
+
<pdfaSchema:namespaceURI>urn:factur-x:pdfa:CrossIndustryDocument:invoice:1p0#</pdfaSchema:namespaceURI>
|
|
55
|
+
<pdfaSchema:prefix>fx</pdfaSchema:prefix>
|
|
56
|
+
<pdfaSchema:property>
|
|
57
|
+
<rdf:Seq>
|
|
58
|
+
<rdf:li rdf:parseType="Resource"><pdfaProperty:name>DocumentFileName</pdfaProperty:name><pdfaProperty:valueType>Text</pdfaProperty:valueType><pdfaProperty:category>external</pdfaProperty:category><pdfaProperty:description>The name of the embedded XML document</pdfaProperty:description></rdf:li>
|
|
59
|
+
<rdf:li rdf:parseType="Resource"><pdfaProperty:name>DocumentType</pdfaProperty:name><pdfaProperty:valueType>Text</pdfaProperty:valueType><pdfaProperty:category>external</pdfaProperty:category><pdfaProperty:description>The type of the hybrid document</pdfaProperty:description></rdf:li>
|
|
60
|
+
<rdf:li rdf:parseType="Resource"><pdfaProperty:name>Version</pdfaProperty:name><pdfaProperty:valueType>Text</pdfaProperty:valueType><pdfaProperty:category>external</pdfaProperty:category><pdfaProperty:description>The version of the XML schema</pdfaProperty:description></rdf:li>
|
|
61
|
+
<rdf:li rdf:parseType="Resource"><pdfaProperty:name>ConformanceLevel</pdfaProperty:name><pdfaProperty:valueType>Text</pdfaProperty:valueType><pdfaProperty:category>external</pdfaProperty:category><pdfaProperty:description>The conformance level of the XML document</pdfaProperty:description></rdf:li>
|
|
62
|
+
</rdf:Seq>
|
|
63
|
+
</pdfaSchema:property>
|
|
64
|
+
</rdf:li>
|
|
65
|
+
</rdf:Bag>
|
|
66
|
+
</pdfaExtension:schemas>
|
|
67
|
+
</rdf:Description>
|
|
68
|
+
</rdf:RDF>
|
|
69
|
+
XML
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -2,24 +2,64 @@ class Pixelpress::WeasyPrintRenderer
|
|
|
2
2
|
class WeasyPrintInstallationError < StandardError; end
|
|
3
3
|
class WeasyPrintExecutionError < StandardError; end
|
|
4
4
|
|
|
5
|
+
def initialize
|
|
6
|
+
@flags = {}
|
|
7
|
+
end
|
|
8
|
+
|
|
5
9
|
def render(input)
|
|
6
10
|
output = Tempfile.new
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
success = with_cli_flags do |cli_flags|
|
|
12
|
+
system(executable_path, *cli_flags, input.path, output.path)
|
|
13
|
+
end
|
|
9
14
|
|
|
10
15
|
unless success
|
|
11
16
|
raise WeasyPrintExecutionError.new("WeasyPrint execution failed with exit code #{$?.exitstatus}")
|
|
12
17
|
end
|
|
13
18
|
|
|
14
|
-
|
|
19
|
+
output
|
|
15
20
|
end
|
|
16
21
|
|
|
17
22
|
def version
|
|
18
23
|
`#{executable_path} --version`.chomp.scan(/(\d+\.\d+)/).flatten.first
|
|
19
24
|
end
|
|
20
25
|
|
|
26
|
+
def attach_zugferd_data(...)
|
|
27
|
+
@zugferd = Zugferd.new(...)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def set_flags(**flags)
|
|
31
|
+
@flags = flags.stringify_keys
|
|
32
|
+
end
|
|
33
|
+
|
|
21
34
|
private
|
|
22
35
|
|
|
36
|
+
def with_cli_flags(&block)
|
|
37
|
+
if @zugferd
|
|
38
|
+
@zugferd.with_files do |more_cli_flags|
|
|
39
|
+
block.call([*more_cli_flags, *cli_flags])
|
|
40
|
+
end
|
|
41
|
+
else
|
|
42
|
+
block.call(cli_flags)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def cli_flags
|
|
47
|
+
cli_flags = []
|
|
48
|
+
|
|
49
|
+
# Default to utf-8 encoding, unless another one is specified
|
|
50
|
+
unless @flags.key?("encoding")
|
|
51
|
+
cli_flags += ["--encoding", "utf-8"]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
@flags.each do |key, value|
|
|
55
|
+
Array(value).each do
|
|
56
|
+
cli_flags += ["--#{key.dasherize}", value]
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
cli_flags
|
|
61
|
+
end
|
|
62
|
+
|
|
23
63
|
def executable_path
|
|
24
64
|
path = `which weasyprint`.chomp
|
|
25
65
|
|
data/lib/pixelpress/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pixelpress
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alex
|
|
8
8
|
- Jens Ravens
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: exe
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: actionpack
|
|
@@ -39,7 +38,6 @@ dependencies:
|
|
|
39
38
|
- - ">="
|
|
40
39
|
- !ruby/object:Gem::Version
|
|
41
40
|
version: '0'
|
|
42
|
-
description:
|
|
43
41
|
email:
|
|
44
42
|
- aleksandra@nerdgeschoss.de
|
|
45
43
|
- jens@nerdgeschoss.de
|
|
@@ -82,6 +80,7 @@ files:
|
|
|
82
80
|
- lib/pixelpress/renderers/test.pdf
|
|
83
81
|
- lib/pixelpress/renderers/test_renderer.rb
|
|
84
82
|
- lib/pixelpress/renderers/weasyprint_renderer.rb
|
|
83
|
+
- lib/pixelpress/renderers/weasyprint_renderer/zugferd.rb
|
|
85
84
|
- lib/pixelpress/rendering.rb
|
|
86
85
|
- lib/pixelpress/version.rb
|
|
87
86
|
- pixelpress.gemspec
|
|
@@ -89,7 +88,6 @@ homepage: https://github.com/nerdgeschoss/pixelpress
|
|
|
89
88
|
licenses:
|
|
90
89
|
- MIT
|
|
91
90
|
metadata: {}
|
|
92
|
-
post_install_message:
|
|
93
91
|
rdoc_options: []
|
|
94
92
|
require_paths:
|
|
95
93
|
- lib
|
|
@@ -104,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
104
102
|
- !ruby/object:Gem::Version
|
|
105
103
|
version: '0'
|
|
106
104
|
requirements: []
|
|
107
|
-
rubygems_version:
|
|
108
|
-
signing_key:
|
|
105
|
+
rubygems_version: 4.0.20
|
|
109
106
|
specification_version: 4
|
|
110
107
|
summary: PDF printer
|
|
111
108
|
test_files: []
|