pixelpress 0.3.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1909db2ba4fba6b1fe1f7359a295f2f507df6e23fdc1566bab759cdb19e37fb5
4
- data.tar.gz: 2729d6d698cb9f0673518e406234a3a5fa89e90b9f0226fd8cad6f7dbad428d8
3
+ metadata.gz: c21e6e9bd0b516d40c41f5339ef30e315ccd08dc41abee55d67fe045f221efe9
4
+ data.tar.gz: 264dc423a451db64c9b9cd81e26a8753822cab3b593b337c82d633c453928454
5
5
  SHA512:
6
- metadata.gz: 6e39af4bc954110cedd403a805d2e23e21df42933254d661c724341e47e2bb9ca1d8e56a9644cfb7692a9d8b06a510885ec04919f000f6238b4f12d159848a08
7
- data.tar.gz: 302fbf7f92eb51ee9d43fa113a98066bda4c8afe7b2b8740f1d70d9d95173e42913f33c9d5f41e1280bd0854b3964474779c44f4f65d0733afa0cb30fdb7598b
6
+ metadata.gz: 13bcac2b3029ed48d4ceba627632a53a4c6c80cd739105ed5d07746e98d71412cbb62b2cd676bad5d399dc8cd2f205c6576bf91cecb50a566dfd10249a3cb8aa
7
+ data.tar.gz: 100bdb58452700ce9cd5ae4109feb3bffdbef0a8990328177724e8b62a5ced7141a3b82109123421b25b366d1834a89794d724383ea9345fe95a97f1c3d8093c
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "Pixelpress",
3
+ "dockerComposeFile": "docker-compose.yml",
4
+ "service": "app",
5
+ "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
6
+ "postCreateCommand": "bin/setup",
7
+ "remoteUser": "root",
8
+ "customizations": {
9
+ "vscode": {
10
+ "extensions": [
11
+ "dbaeumer.vscode-eslint",
12
+ "GitHub.copilot",
13
+ "esbenp.prettier-vscode",
14
+ "sianglim.slim",
15
+ "Shopify.ruby-lsp",
16
+ "EditorConfig.EditorConfig",
17
+ "eamodio.gitlens"
18
+ ],
19
+ "settings": {
20
+ "rubyLsp.rubyVersionManager": {
21
+ "identifier": "rvm"
22
+ },
23
+ "[ruby]": {
24
+ "editor.formatOnSave": true,
25
+ "editor.defaultFormatter": "Shopify.ruby-lsp"
26
+ }
27
+ }
28
+ }
29
+ },
30
+ "features": {},
31
+ "forwardPorts": []
32
+ }
@@ -0,0 +1,19 @@
1
+ version: '3'
2
+
3
+ services:
4
+ app:
5
+ image: ghcr.io/nerdgeschoss/nerdgeschoss/development-environment:3.4-22
6
+ volumes:
7
+ - ../..:/workspaces:cached
8
+ - ~/.netrc:/root/.netrc
9
+ - ~/.ssh:/root/.ssh
10
+ - ~/.config/gh:/root/.config/gh
11
+ - ~/.cache/devcontainer/playwright:/root/.cache/devcontainer/playwright
12
+ - ~/.aws:/root/.aws
13
+
14
+ # Overrides default command so things don't shut down after the process ends.
15
+ command: sleep infinity
16
+
17
+ environment:
18
+ TZ: Europe/Berlin
19
+ EDITOR: code --wait
@@ -14,7 +14,9 @@ jobs:
14
14
  - name: Install dependencies
15
15
  uses: awalsh128/cache-apt-pkgs-action@latest
16
16
  with:
17
- packages: weasyprint
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
@@ -8,6 +8,7 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /pixelpress-0.1.0.gem
11
+ .DS_Store
11
12
 
12
13
  # rspec failure tracking
13
14
  .rspec_status
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.1.4
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 as `.pdf.erb` files located in `app/views/printers/invoice/`:
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/bin/setup CHANGED
@@ -3,6 +3,4 @@ set -euo pipefail
3
3
  IFS=$'\n\t'
4
4
  set -vx
5
5
 
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
6
+ bundle install
@@ -1,5 +1,6 @@
1
1
  require 'action_controller'
2
2
  require_relative 'renderers/weasyprint_renderer'
3
+ require_relative 'renderers/weasyprint_renderer/zugferd'
3
4
  require_relative 'renderers/test_renderer'
4
5
  require_relative 'instance_invocation'
5
6
  require_relative 'rendering'
@@ -9,7 +9,7 @@ module Pixelpress
9
9
  end
10
10
 
11
11
  def html
12
- file.read
12
+ file.read.html_safe
13
13
  end
14
14
 
15
15
  def pdf
@@ -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
- success = system(executable_path, "--encoding", "utf-8", input.path, output.path)
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
- return output
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
 
@@ -1,3 +1,3 @@
1
1
  module Pixelpress
2
- VERSION = '0.3.4'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
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.3.4
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: 2025-04-08 00:00:00.000000000 Z
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
@@ -47,6 +45,8 @@ executables: []
47
45
  extensions: []
48
46
  extra_rdoc_files: []
49
47
  files:
48
+ - ".devcontainer/devcontainer.json"
49
+ - ".devcontainer/docker-compose.yml"
50
50
  - ".github/workflows/publish.yml"
51
51
  - ".github/workflows/test.yml"
52
52
  - ".gitignore"
@@ -80,6 +80,7 @@ files:
80
80
  - lib/pixelpress/renderers/test.pdf
81
81
  - lib/pixelpress/renderers/test_renderer.rb
82
82
  - lib/pixelpress/renderers/weasyprint_renderer.rb
83
+ - lib/pixelpress/renderers/weasyprint_renderer/zugferd.rb
83
84
  - lib/pixelpress/rendering.rb
84
85
  - lib/pixelpress/version.rb
85
86
  - pixelpress.gemspec
@@ -87,7 +88,6 @@ homepage: https://github.com/nerdgeschoss/pixelpress
87
88
  licenses:
88
89
  - MIT
89
90
  metadata: {}
90
- post_install_message:
91
91
  rdoc_options: []
92
92
  require_paths:
93
93
  - lib
@@ -102,8 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  requirements: []
105
- rubygems_version: 3.3.26
106
- signing_key:
105
+ rubygems_version: 4.0.20
107
106
  specification_version: 4
108
107
  summary: PDF printer
109
108
  test_files: []