bidi2pdf-rails 0.0.1.alpha.1 → 0.1.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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.idea/bidi2pdf-rails.iml +16 -8
  3. data/.rubocop.yml +11 -0
  4. data/CHANGELOG.md +33 -0
  5. data/README.md +104 -41
  6. data/Rakefile +2 -0
  7. data/cliff.toml +126 -0
  8. data/lib/bidi2pdf_rails/browser_console_log_subscriber.rb +1 -1
  9. data/lib/bidi2pdf_rails/chromedriver_manager_singleton.rb +10 -10
  10. data/lib/bidi2pdf_rails/config.rb +133 -0
  11. data/lib/bidi2pdf_rails/configurable.rb +106 -0
  12. data/lib/bidi2pdf_rails/main_log_subscriber.rb +1 -1
  13. data/lib/bidi2pdf_rails/network_log_subscriber.rb +1 -1
  14. data/lib/bidi2pdf_rails/railtie.rb +2 -0
  15. data/lib/bidi2pdf_rails/services/pdf_renderer.rb +9 -8
  16. data/lib/bidi2pdf_rails/version.rb +1 -1
  17. data/lib/bidi2pdf_rails.rb +28 -99
  18. data/lib/generators/bidi2pdf_rails/USAGE +12 -4
  19. data/lib/generators/bidi2pdf_rails/initializer_generator.rb +136 -31
  20. data/lib/generators/bidi2pdf_rails/templates/bidi2pdf_rails.rb.tt +15 -101
  21. data/spec/acceptance/user_can_download_report_pdf_spec.rb +133 -0
  22. data/spec/acceptance/user_can_generate_pdf_from_protected_remote_url_spec.rb +173 -0
  23. data/spec/dummy/app/controllers/reports_controller.rb +35 -2
  24. data/spec/dummy/app/controllers/secure_controller.rb +52 -0
  25. data/spec/dummy/app/views/layouts/simple.html.erb +17 -0
  26. data/spec/dummy/app/views/secure/show.html.erb +10 -0
  27. data/spec/dummy/config/initializers/bidi2pdf_rails.rb +64 -54
  28. data/spec/dummy/config/routes.rb +9 -1
  29. data/spec/dummy/log/development.log +3850 -0
  30. data/spec/dummy/log/test.log +53046 -0
  31. data/spec/dummy/tmp/pids/server.pid +1 -1
  32. data/spec/integration/generators/bidi2pdf_rails/initializer_generator_spec.rb +64 -0
  33. data/spec/rails_helper.rb +8 -1
  34. data/spec/spec_helper.rb +47 -5
  35. data/spec/support/default_dirs_helper.rb +32 -0
  36. data/spec/support/pdf_helper.rb +12 -0
  37. data/spec/support/render_setting_helpers.rb +28 -0
  38. data/spec/support/request_server_bootstrap.rb +44 -0
  39. data/spec/{bidi2pdf_rails → unit/bidi2pdf_rails}/bidi2pdf_rails_spec.rb +1 -1
  40. data/spec/unit/bidi2pdf_rails/configurable/base_nested_config_spec.rb +133 -0
  41. data/tasks/changelog.rake +29 -0
  42. data/tasks/coverage.rake +23 -0
  43. metadata +69 -20
  44. data/spec/dummy/spec/helpers/reports_helper_spec.rb +0 -15
  45. data/spec/dummy/spec/requests/reports_spec.rb +0 -10
  46. data/spec/dummy/spec/views/reports/show.html.erb_spec.rb +0 -5
  47. data/spec/generator/bidie2pdf_rails_initializer_generator_spec.rb +0 -5
  48. data/spec/generator/initializer_generator_spec.rb +0 -5
  49. data/spec/requests/reports_spec.rb +0 -17
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 197e7a27c88055b3b6420e05287b6aca37aad6067c048435f282ccad7f3ad29a
4
- data.tar.gz: 8cee08d82ac49412e260b5dc8f4f2a90a1dffd6cab69c1b84506d25fb36647c8
3
+ metadata.gz: 9d0aa5d0b7d83ed5324b0a8669672f08d7a3e7b22dc7f9d51994f59e4d503df5
4
+ data.tar.gz: 928af8b8e8646b13c027cf2fb88ca216f53d37abc808c325733e18ee1011e1b8
5
5
  SHA512:
6
- metadata.gz: cb9aa352e8a713b4a24748676a9d80e1828e00a1584f2ff89da6f0fe41b98371639f15810adb5b8b294c2043a2997e84d5fc7278961b2e1a4f8d38195a412f4d
7
- data.tar.gz: 79c179181e2f9ff4de09585c5010b987e3fc37605ca93273575f3394ab1e9d3ae3bdd210e45c9a80353a041f120c941576acc9837b65e7445f6ab4321a54389e
6
+ metadata.gz: 01abea76bf14ed10a93abe22394621df080e864024ad828de8a7edcf36eed62b12f008e02db06cf6e0b2449408132467df90415918473eabb55bbeb1ca6c91f8
7
+ data.tar.gz: 0b99cbcb01e48f2577e0da652b5a20f6720bbd11feb6e0dc06bea684e4d5c40e8d94b4c72c83862e498ade59050c1ef72bb28902f1f334c0f250821854391fd3
@@ -102,6 +102,7 @@
102
102
  </excluded>
103
103
  </library>
104
104
  </orderEntry>
105
+ <orderEntry type="library" scope="PROVIDED" name="Ascii85 (v2.0.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
105
106
  <orderEntry type="library" scope="PROVIDED" name="actioncable (v7.2.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
106
107
  <orderEntry type="library" scope="PROVIDED" name="actionmailbox (v7.2.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
107
108
  <orderEntry type="library" scope="PROVIDED" name="actionmailer (v7.2.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
@@ -113,6 +114,8 @@
113
114
  <orderEntry type="library" scope="PROVIDED" name="activerecord (v7.2.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
114
115
  <orderEntry type="library" scope="PROVIDED" name="activestorage (v7.2.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
115
116
  <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.2.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
117
+ <orderEntry type="library" scope="PROVIDED" name="afm (v0.2.2, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
118
+ <orderEntry type="library" scope="PROVIDED" name="ammeter (v1.1.7, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
116
119
  <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.3, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
117
120
  <orderEntry type="library" scope="PROVIDED" name="benchmark (v0.4.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
118
121
  <orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.1.9, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
@@ -128,8 +131,9 @@
128
131
  <orderEntry type="library" scope="PROVIDED" name="drb (v2.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
129
132
  <orderEntry type="library" scope="PROVIDED" name="erubi (v1.13.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
130
133
  <orderEntry type="library" scope="PROVIDED" name="event_emitter (v0.2.6, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
131
- <orderEntry type="library" scope="PROVIDED" name="ffi (v1.17.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
134
+ <orderEntry type="library" scope="PROVIDED" name="ffi (v1.17.2, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
132
135
  <orderEntry type="library" scope="PROVIDED" name="globalid (v1.2.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
136
+ <orderEntry type="library" scope="PROVIDED" name="hashery (v2.1.2, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
133
137
  <orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.7, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
134
138
  <orderEntry type="library" scope="PROVIDED" name="io-console (v0.8.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
135
139
  <orderEntry type="library" scope="PROVIDED" name="irb (v1.15.2, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
@@ -148,8 +152,9 @@
148
152
  <orderEntry type="library" scope="PROVIDED" name="net-smtp (v0.5.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
149
153
  <orderEntry type="library" scope="PROVIDED" name="nio4r (v2.7.4, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
150
154
  <orderEntry type="library" scope="PROVIDED" name="nokogiri (v1.18.7, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
151
- <orderEntry type="library" scope="PROVIDED" name="parallel (v1.26.3, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
155
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.27.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
152
156
  <orderEntry type="library" scope="PROVIDED" name="parser (v3.3.8.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
157
+ <orderEntry type="library" scope="PROVIDED" name="pdf-reader (v2.14.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
153
158
  <orderEntry type="library" scope="PROVIDED" name="pp (v0.6.2, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
154
159
  <orderEntry type="library" scope="PROVIDED" name="prism (v1.4.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
155
160
  <orderEntry type="library" scope="PROVIDED" name="propshaft (v1.1.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
@@ -181,8 +186,9 @@
181
186
  <orderEntry type="library" scope="PROVIDED" name="rubocop-rails (v2.31.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
182
187
  <orderEntry type="library" scope="PROVIDED" name="rubocop-rails-omakase (v1.1.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
183
188
  <orderEntry type="library" scope="PROVIDED" name="rubocop-rake (v0.7.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
184
- <orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v3.5.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
189
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-rspec (v3.6.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
185
190
  <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
191
+ <orderEntry type="library" scope="PROVIDED" name="ruby-rc4 (v0.1.5, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
186
192
  <orderEntry type="library" scope="PROVIDED" name="rubyzip (v2.4.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
187
193
  <orderEntry type="library" scope="PROVIDED" name="securerandom (v0.4.1, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
188
194
  <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.22.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
@@ -192,9 +198,11 @@
192
198
  <orderEntry type="library" scope="PROVIDED" name="sys-proctable (v1.3.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
193
199
  <orderEntry type="library" scope="PROVIDED" name="thor (v1.3.2, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
194
200
  <orderEntry type="library" scope="PROVIDED" name="timeout (v0.4.3, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
201
+ <orderEntry type="library" scope="PROVIDED" name="ttfunk (v1.8.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
195
202
  <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
196
203
  <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v3.1.4, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
197
204
  <orderEntry type="library" scope="PROVIDED" name="unicode-emoji (v4.0.4, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
205
+ <orderEntry type="library" scope="PROVIDED" name="unicode_utils (v1.4.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
198
206
  <orderEntry type="library" scope="PROVIDED" name="useragent (v0.16.11, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
199
207
  <orderEntry type="library" scope="PROVIDED" name="websocket (v1.2.11, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
200
208
  <orderEntry type="library" scope="PROVIDED" name="websocket-client-simple (v0.9.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
@@ -410,21 +418,21 @@
410
418
  <option name="myRootTask">
411
419
  <RakeTaskImpl id="rake">
412
420
  <subtasks>
413
- <RakeTaskImpl description="Build bidi2pdf-rails-0.0.1.pre.alpha.gem into the pkg directory" fullCommand="build" id="build" />
421
+ <RakeTaskImpl description="Build bidi2pdf-rails-0.0.1.alpha.1.gem into the pkg directory" fullCommand="build" id="build" />
414
422
  <RakeTaskImpl id="build">
415
423
  <subtasks>
416
- <RakeTaskImpl description="Generate SHA512 checksum of bidi2pdf-rails-0.0.1.pre.alpha.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
424
+ <RakeTaskImpl description="Generate SHA512 checksum of bidi2pdf-rails-0.0.1.alpha.1.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
417
425
  </subtasks>
418
426
  </RakeTaskImpl>
419
427
  <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
420
428
  <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
421
- <RakeTaskImpl description="Build and install bidi2pdf-rails-0.0.1.pre.alpha.gem into system gems" fullCommand="install" id="install" />
429
+ <RakeTaskImpl description="Build and install bidi2pdf-rails-0.0.1.alpha.1.gem into system gems" fullCommand="install" id="install" />
422
430
  <RakeTaskImpl id="install">
423
431
  <subtasks>
424
- <RakeTaskImpl description="Build and install bidi2pdf-rails-0.0.1.pre.alpha.gem into system gems without network access" fullCommand="install:local" id="local" />
432
+ <RakeTaskImpl description="Build and install bidi2pdf-rails-0.0.1.alpha.1.gem into system gems without network access" fullCommand="install:local" id="local" />
425
433
  </subtasks>
426
434
  </RakeTaskImpl>
427
- <RakeTaskImpl description="Create tag v0.0.1.pre.alpha and build and push bidi2pdf-rails-0.0.1.pre.alpha.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
435
+ <RakeTaskImpl description="Create tag v0.0.1.alpha.1 and build and push bidi2pdf-rails-0.0.1.alpha.1.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
428
436
  <RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
429
437
  <RakeTaskImpl id="rubocop">
430
438
  <subtasks>
data/.rubocop.yml CHANGED
@@ -50,6 +50,12 @@ Layout/BeginEndAlignment:
50
50
  Layout/ArrayAlignment:
51
51
  Enabled: false
52
52
 
53
+ Layout/ElseAlignment:
54
+ Enabled: false
55
+
56
+ Layout/EndAlignment:
57
+ Enabled: false
58
+
53
59
  Layout/LineLength:
54
60
  Enabled: false
55
61
 
@@ -88,6 +94,11 @@ RSpec/DescribeClass:
88
94
  Exclude:
89
95
  - 'spec/acceptance/**/*_spec.rb'
90
96
 
97
+ RSpec/MultipleExpectations:
98
+ Enabled: true
99
+ Exclude:
100
+ - 'spec/acceptance/**/*_spec.rb'
101
+
91
102
  plugins:
92
103
  - rubocop-rake
93
104
  - rubocop-rspec
data/CHANGELOG.md ADDED
@@ -0,0 +1,33 @@
1
+ <!-- generated by git-cliff start -->
2
+
3
+ # Changelog
4
+
5
+ All notable changes to this project will be documented in this file.
6
+
7
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
+
10
+ <!-- generated by git-cliff end -->
11
+
12
+ ## [0.1.0] - 2025-04-21
13
+
14
+ ### 🐛 Fixed
15
+
16
+ - Add PDF rendering from protected remote URLs by @dieter-medium
17
+ - Add acceptance tests for PDF generation with bidi2pdf-rails by @dieter-medium
18
+ - Allow forcing chromedriver manager initialization by @dieter-medium
19
+ - Add unit tests for BaseNestedConfig behavior by @dieter-medium
20
+
21
+ ### 📝 Docs
22
+
23
+ - Enhance README with usage and config examples by @dieter-medium
24
+ - Add CORS configuration details for asset access by @dieter-medium
25
+
26
+ ### 🚀 Added
27
+
28
+ - Enhance configuration and logging for Bidi2pdfRails by @dieter-medium
29
+ - Ensure custom HTML can be used in PDF rendering by @dieter-medium
30
+
31
+ [unreleased](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.1.0..HEAD)
32
+ [0.1.0](https://github.com/dieter-medium/bidi2pdf-rails/compare/v0.0.1.alpha.1..v0.1.0)
33
+
data/README.md CHANGED
@@ -1,102 +1,165 @@
1
1
  [![Build Status](https://github.com/dieter-medium/bidi2pdf-rails/actions/workflows/ruby.yml/badge.svg)](https://github.com/dieter-medium/bidi2pdf-rails/blob/main/.github/workflows/ruby.yml)
2
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/6425d9893aa3a9ca243e/maintainability)](https://codeclimate.com/github/dieter-medium/bidi2pdf-rails/maintainability)
3
- [![Gem Version](https://badge.fury.io/rb/bidi2pdf-rails.svg)](https://badge.fury.io/rb/bidi2pdf-rails)
4
3
  [![Test Coverage](https://api.codeclimate.com/v1/badges/6425d9893aa3a9ca243e/test_coverage)](https://codeclimate.com/github/dieter-medium/bidi2pdf-rails/test_coverage)
4
+ [![Gem Version](https://badge.fury.io/rb/bidi2pdf-rails.svg)](https://badge.fury.io/rb/bidi2pdf-rails)
5
5
  [![Open Source Helpers](https://www.codetriage.com/dieter-medium/bidi2pdf-rails/badges/users.svg)](https://www.codetriage.com/dieter-medium/bidi2pdf-rails)
6
6
 
7
7
  # 📄 Bidi2pdfRails
8
8
 
9
- **Bidi2pdfRails** is the official Rails integration for [Bidi2pdf](https://github.com/dieter-medium/bidi2pdf) a
10
- modern, browser-based solution for converting HTML to high-quality PDFs.
11
- It leverages headless browsing and offers a simple, flexible interface for PDF generation directly from your Rails
12
- application.
9
+ **Bidi2pdfRails** is the official Rails integration for [Bidi2pdf](https://github.com/dieter-medium/bidi2pdf) a
10
+ modern, headless-browser-based PDF rendering engine.
11
+ Generate high-fidelity PDFs directly from your Rails views or external URLs with minimal setup.
13
12
 
14
- > **⚠️ Note:** This project is currently **under development** and **not yet recommended for production use**.
13
+ > ⚠️ **Project status:** _Under active development_. Not yet recommended for production use.
15
14
 
16
15
  ---
17
16
 
18
- ## 🚀 Why Bidi2pdfRails?
17
+ ## Features
19
18
 
20
- - Utilizes modern browser technologies for accurate rendering (similar to `grover` or `wicked_pdf`)
21
- - Easy to integrate into existing Rails projects
22
- - Configurable options: URL, output path, rendering settings
19
+ - 🔍 Accurate PDF rendering using a real browser engine
20
+ - 💾 Supports both HTML string rendering and remote URL conversion
21
+ - 🔐 Built-in support for authentication (Basic Auth, cookies, headers)
22
+ - 🧰 Full test suite with examples for Rails controller integration
23
+ - 🧠 Sensible defaults, yet fully configurable
23
24
 
24
25
  ---
25
26
 
26
27
  ## 🔧 Installation
27
28
 
28
- Add the following lines to your `Gemfile`:
29
+ Add to your Gemfile:
29
30
 
30
31
  ```ruby
31
- gem "bidi2pdf-rails"
32
- # As long as the gem is not published, use:
32
+ # Until released, use the GitHub repo
33
33
  gem "bidi2pdf-rails", github: "dieter-medium/bidi2pdf-rails", branch: "main"
34
34
  gem "bidi2pdf", github: "dieter-medium/bidi2pdf", branch: "main"
35
35
 
36
- # if you want a small performance boost, you can use the following:
36
+ # Optional for performance:
37
37
  # gem "websocket-native"
38
38
  ```
39
39
 
40
- Then install the dependencies:
40
+ Install it:
41
41
 
42
42
  ```bash
43
- bundle
43
+ bundle install
44
44
  ```
45
45
 
46
- Generate the initializer:
46
+ Generate the config initializer:
47
47
 
48
48
  ```bash
49
49
  bin/rails generate bidi2pdf_rails:initializer
50
50
  ```
51
51
 
52
- Alternatively, install it manually:
53
-
54
- ```bash
55
- gem install bidi2pdf-rails
56
- ```
57
-
58
52
  ---
59
53
 
60
- ## 🧪 Example & Getting Started
54
+ ## 📦 Usage Examples
61
55
 
62
- You can find a full example inside the [`spec/dummy`](spec/dummy) directory of this repository.
63
- This demonstrates how to use `Bidi2pdfRails` in a realistic mini Rails application setup.
64
-
65
- ### Basic Usage
56
+ ### 📄 Rendering a Rails View as PDF
66
57
 
67
58
  ```ruby
68
- # Render html via controller action `render_to_string`
69
- # Any controller action:
59
+ # app/controllers/invoices_controller.rb
60
+
70
61
  def show
71
62
  render pdf: "invoice",
72
63
  template: "invoices/show",
73
64
  layout: "pdf",
74
65
  locals: { invoice: @invoice },
75
66
  print_options: { landscape: true },
76
- wait_for_network_idle: true,
77
- asset_host: "https://assets.example.com"
67
+ wait_for_network_idle: true
78
68
  end
69
+ ```
79
70
 
80
- # Render pdf via direct url call
81
- def show
82
- # See: PdfRenderer for all options
83
- render pdf: 'remote-report', url: "http://example.com", wait_for_page_loaded: false, print_options: { page: { format: :A4 } }
71
+ ### 🌐 Rendering a Remote URL to PDF
72
+
73
+ ```ruby
74
+
75
+ def convert
76
+ render pdf: "external-report",
77
+ url: "https://example.com/dashboard",
78
+ wait_for_page_loaded: false,
79
+ print_options: { page: { format: :A4 } }
80
+ end
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 🛡️ Authentication Support
86
+
87
+ Need to convert pages that require authentication? No problem. Use:
88
+
89
+ - `auth: { username:, password: }`
90
+ - `cookies: { session_key: value }`
91
+ - `headers: { "Authorization" => "Bearer ..." }`
92
+
93
+ Example:
94
+
95
+ ```ruby
96
+ render pdf: "secure",
97
+ url: secure_report_url,
98
+ auth: { username: "admin", password: "secret" }
99
+ ```
100
+
101
+ Or use global config in `bidi2pdf_rails.rb` initializer:
102
+
103
+ ```ruby
104
+ config.render_remote_settings.basic_auth_user = ->(_) { "admin" }
105
+ config.render_remote_settings.basic_auth_pass = ->(_) { Rails.application.credentials.dig(:pdf, :auth_pass) }
106
+ ```
107
+
108
+ ---
109
+
110
+ ## 📂 Asset Access via CORS
111
+
112
+ When rendering HTML with `render_to_string`, Chromium needs access to your assets (CSS, images, fonts).
113
+ Enable CORS for `/assets` using `rack-cors`:
114
+
115
+ ```ruby
116
+ # Gemfile
117
+ gem 'rack-cors'
118
+
119
+ # config/initializers/cors.rb
120
+ Rails.application.config.middleware.insert_before 0, Rack::Cors do
121
+ allow do
122
+ origins '*'
123
+ resource '/assets/*', headers: :any, methods: [:get, :options]
124
+ end
84
125
  end
126
+ ```
127
+
128
+ ---
129
+
130
+ ## 🧪 Acceptance Examples
131
+
132
+ This repo includes **real integration tests** that serve as usage documentation:
133
+
134
+ - [Download PDF with `.pdf` format](spec/acceptance/user_can_download_report_pdf_spec.rb)
135
+ - [Render protected remote URLs using Basic Auth, cookies, and headers](spec/acceptance/user_can_generate_pdf_from_protected_remote_url_spec.rb)
136
+
137
+ ---
85
138
 
139
+ ## 🧠 Configuration
140
+
141
+ Bidi2pdfRails is highly configurable.
142
+
143
+ See full config options in:
144
+
145
+ ```bash
146
+ bin/rails generate bidi2pdf_rails:initializer
86
147
  ```
87
148
 
149
+ Or explore `Bidi2pdfRails::Configuration` in the source.
150
+
88
151
  ---
89
152
 
90
153
  ## 🙌 Contributing
91
154
 
92
- Want to contribute?
93
- Pull requests, bug reports, and ideas are warmly welcome!
155
+ Pull requests, issues, and ideas are all welcome 🙏
156
+ Want to contribute? Just fork, branch, and PR like a boss.
94
157
 
95
- *Contribution guidelines will be added soon.*
158
+ > Contribution guide coming soon!
96
159
 
97
160
  ---
98
161
 
99
162
  ## 📄 License
100
163
 
101
- This gem is open-source and available under the terms of the [MIT License](https://opensource.org/licenses/MIT).
102
- Free to use with responsibility.
164
+ This gem is released under the [MIT License](https://opensource.org/licenses/MIT).
165
+ Use freely and responsibly.
data/Rakefile CHANGED
@@ -9,3 +9,5 @@ RSpec::Core::RakeTask.new(:spec)
9
9
  require "rubocop/rake_task"
10
10
 
11
11
  RuboCop::RakeTask.new
12
+
13
+ Dir.glob("tasks/*.rake").each { |r| load r }
data/cliff.toml ADDED
@@ -0,0 +1,126 @@
1
+ # git-cliff ~ configuration file
2
+ # https://git-cliff.org/docs/configuration
3
+
4
+ [changelog]
5
+ # template for the changelog header
6
+ header = """
7
+ <!-- generated by git-cliff start -->
8
+ # Changelog\n
9
+ All notable changes to this project will be documented in this file.
10
+
11
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
12
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).\n
13
+ """
14
+ # template for the changelog body
15
+ # https://keats.github.io/tera/docs/#introduction
16
+ body = """
17
+ {%- macro remote_url() -%}
18
+ https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
19
+ {%- endmacro -%}
20
+
21
+ {% if version -%}
22
+ ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }}
23
+ {% else -%}
24
+ ## [Unreleased]
25
+ {% endif -%}
26
+
27
+ {% for group, commits in commits | group_by(attribute="group") %}
28
+ ### {{ group | upper_first }}
29
+ {%- for commit in commits %}
30
+ - {{ commit.message | split(pat="\n") | first | upper_first | trim }}\
31
+ {% if commit.remote.username %} by @{{ commit.remote.username }}{%- endif -%}
32
+ {% if commit.remote.pr_number %} in \
33
+ [#{{ commit.remote.pr_number }}]({{ self::remote_url() }}/pull/{{ commit.remote.pr_number }}) \
34
+ {%- endif -%}
35
+ {% endfor %}
36
+ {% endfor %}
37
+
38
+ {%- if github.contributors | filter(attribute="is_first_time", value=true) | length != 0 %}
39
+ ## New Contributors
40
+ {%- endif -%}
41
+
42
+ {% for contributor in github.contributors | filter(attribute="is_first_time", value=true) %}
43
+ * @{{ contributor.username }} made their first contribution
44
+ {%- if contributor.pr_number %} in \
45
+ [#{{ contributor.pr_number }}]({{ self::remote_url() }}/pull/{{ contributor.pr_number }}) \
46
+ {%- endif %}
47
+ {%- endfor %}\n
48
+ """
49
+ # template for the changelog footer
50
+ footer = """
51
+ {%- macro remote_url() -%}
52
+ https://github.com/{{ remote.github.owner }}/{{ remote.github.repo }}
53
+ {%- endmacro -%}
54
+
55
+ {% for release in releases -%}
56
+ {% if release.version -%}
57
+ {% if release.previous.version -%}
58
+ [{{ release.version | trim_start_matches(pat="v") }}]: \
59
+ {{ self::remote_url() }}/compare/{{ release.previous.version }}..{{ release.version }}
60
+ {% endif -%}
61
+ {% else -%}
62
+ [unreleased]: {{ self::remote_url() }}/compare/{{ release.previous.version }}..HEAD
63
+ {% endif -%}
64
+ {% endfor %}
65
+ <!-- generated by git-cliff end -->
66
+ """
67
+ # remove the leading and trailing whitespace from the templates
68
+ trim = true
69
+
70
+ [git]
71
+ # parse the commits based on https://www.conventionalcommits.org
72
+ conventional_commits = true
73
+ # filter out the commits that are not conventional
74
+ filter_unconventional = false
75
+ # regex for preprocessing the commit messages
76
+ commit_preprocessors = [
77
+ # remove issue numbers from commits
78
+ { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "" },
79
+ ]
80
+ # regex for parsing and grouping commits
81
+ commit_parsers = [
82
+ # ✅ Features (additions)
83
+ { message = "^feat(?:\\([^)]+\\))?!?:", group = "🚀 Added" },
84
+ { message = "^[aA]dd", group = "🚀 Added" },
85
+ { message = "^[sS]upport", group = "🚀 Added" },
86
+ # ❌ Removals
87
+ { message = "^[rR]emove", group = "🗑️ Removed" },
88
+ { message = "^[dD]elete", group = "🗑️ Removed" },
89
+ # 🐛 Fixes
90
+ { message = "^fix(?:\\([^)]+\\))?!?:", group = "🐛 Fixed" },
91
+ { message = "^[tT]est", group = "🐛 Fixed" },
92
+ { message = "^[fF]ix", group = "🐛 Fixed" },
93
+ # 🎨 Refactors
94
+ { message = "^refactor(?:\\([^)]+\\))?!?:", group = "🎨 Refactored" },
95
+ # ⚡️ Performance
96
+ { message = "^perf(?:\\([^)]+\\))?!?:", group = "⚡️ Performance" },
97
+ # 📝 Docs
98
+ { message = "^docs(?:\\([^)]+\\))?!?:", group = "📝 Docs" },
99
+ # 💄 Style (formatting, whitespace, etc.)
100
+ { message = "^style(?:\\([^)]+\\))?!?:", group = "💄 Style" },
101
+ # 🧪 Tests
102
+ { message = "^test(?:\\([^)]+\\))?!?:", group = "🧪 Tests" },
103
+ # 🔧 Build
104
+ { message = "^build(?:\\([^)]+\\))?!?:", group = "🔧 Build" },
105
+ # 🛠️ CI
106
+ { message = "^ci(?:\\([^)]+\\))?!?:", skip = true },
107
+ # 🧹 Chores (skip)
108
+ { message = "^chore\\(release\\): prepare for", skip = true },
109
+ { message = "^chore\\(deps.*\\)", skip = true },
110
+ { message = "^chore\\(pr\\)", skip = true },
111
+ { message = "^chore\\(pull\\)", skip = true },
112
+ { message = "^chore(?:\\([^)]+\\))?!?:", skip = true },
113
+ { message = "^\\s*chore", skip = true },
114
+ # ⏪ Reverts
115
+ { message = "^revert(?:\\([^)]+\\))?!?:", group = "⏪ Reverted" },
116
+ # 🌀 Catch-all (only if nothing else matched)
117
+ { message = "^.*", group = "🔄 Changed" }
118
+ ]
119
+
120
+
121
+ # filter out the commits that are not matched by commit parsers
122
+ filter_commits = false
123
+ # sort the tags topologically
124
+ topo_order = false
125
+ # sort the commits inside sections by oldest/newest order
126
+ sort_commits = "newest"
@@ -9,7 +9,7 @@ module Bidi2pdfRails
9
9
  timestamp = Bidi2pdf::Bidi::BrowserConsoleLogger.format_timestamp(payload[:timestamp])
10
10
 
11
11
  logger.tagged("bidi2pdf_rails", "browser_console", timestamp) do |tagged_logger|
12
- verbose_logger = Bidi2pdf::VerboseLogger.new(tagged_logger, Bidi2pdfRails.verbosity)
12
+ verbose_logger = Bidi2pdf::VerboseLogger.new(tagged_logger, Bidi2pdfRails.config.general_options.verbosity_value)
13
13
  Bidi2pdf::Bidi::BrowserConsoleLogger.new(verbose_logger)
14
14
  .builder
15
15
  .with_level(payload[:level])
@@ -5,28 +5,28 @@ module Bidi2pdfRails
5
5
  class << self
6
6
  attr_reader :manager, :session
7
7
 
8
- def initialize_manager
9
- return unless running_as_server?
8
+ def initialize_manager(force: false)
9
+ return unless running_as_server? || force
10
10
 
11
11
  @mutex ||= Mutex.new
12
12
  @mutex.synchronize do
13
13
  return if @manager && @session
14
14
 
15
- msg = Bidi2pdfRails.remote_browser_url ? "Remote session" : "ChromeDriver manager"
15
+ msg = Bidi2pdfRails.use_remote_browser? ? "Remote session" : "ChromeDriver manager"
16
16
 
17
17
  Bidi2pdfRails.logger.info "Initializing Bidi2pdf #{msg}"
18
18
 
19
19
  if Bidi2pdfRails.use_remote_browser?
20
20
  @session = Bidi::Session.new(
21
- session_url: Bidi2pdfRails.remote_browser_url,
22
- headless: Bidi2pdfRails.headless,
23
- chrome_args: Bidi2pdfRails.chrome_session_args
21
+ session_url: Bidi2pdfRails.config.render_remote_settings.browser_url_value,
22
+ headless: Bidi2pdfRails.config.general_options.headless_value,
23
+ chrome_args: Bidi2pdfRails.config.general_options.chrome_session_args_value
24
24
  )
25
25
  else
26
26
  @manager = Bidi2pdf::ChromedriverManager.new(
27
- port: Bidi2pdfRails.chromedriver_port,
28
- headless: Bidi2pdfRails.headless,
29
- chrome_args: Bidi2pdfRails.chrome_session_args
27
+ port: Bidi2pdfRails.config.chromedriver_settings.port_value,
28
+ headless: Bidi2pdfRails.config.general_options.headless_value,
29
+ chrome_args: Bidi2pdfRails.config.general_options.chrome_session_args_value
30
30
  )
31
31
  @manager.start
32
32
  @session = @manager.session
@@ -42,7 +42,7 @@ module Bidi2pdfRails
42
42
 
43
43
  @mutex ||= Mutex.new
44
44
  @mutex.synchronize do
45
- msg = Bidi2pdfRails.remote_browser_url ? "Remote session" : "ChromeDriver manager"
45
+ msg = Bidi2pdfRails.use_remote_browser? ? "Remote session" : "ChromeDriver manager"
46
46
  Bidi2pdfRails.logger.info "Shutting down Bidi2pdf #{msg}"
47
47
  @session&.close
48
48
  @manager&.stop