Skip to content

Commit

Permalink
Add Zeitwerk and a helper to stream PDFs via send_pdf
Browse files Browse the repository at this point in the history
  • Loading branch information
bradgessler committed Feb 28, 2024
1 parent 0cc6ed2 commit 908791c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ PATH
phlex-pdf (0.1.2)
matrix (~> 0.4)
prawn (~> 2.0)
zeitwerk (~> 2.0)

GEM
remote: https://rubygems.org/
Expand Down Expand Up @@ -41,6 +42,7 @@ GEM
rspec-support (3.13.0)
ruby-rc4 (0.1.5)
ttfunk (1.7.0)
zeitwerk (2.6.13)

PLATFORMS
arm64-darwin-23
Expand Down
7 changes: 7 additions & 0 deletions lib/phlex/pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
require_relative "pdf/version"
require "prawn"
require "matrix"
require "zeitwerk"

module Phlex
class PDF
Loader = Zeitwerk::Loader.for_gem.tap do |loader|
loader.ignore "#{__dir__}/generators"
loader.inflector.inflect("pdf" => "PDF")
loader.setup
end

include Prawn::View

def document = @document
Expand Down
11 changes: 11 additions & 0 deletions lib/phlex/pdf/rails/helpers.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Phlex::PDF::Rails::Helpers
# Sends a PDF to the browser via Rails controllers.
def send_pdf(pdf, disposition: "inline", type: "application/pdf", **kwargs)
send_data(
pdf.to_pdf,
disposition: disposition,
type: type,
**kwargs
)
end
end
1 change: 1 addition & 0 deletions phlex-pdf.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
# Uncomment to register a new dependency of your gem
spec.add_dependency "prawn", "~> 2.0"
spec.add_dependency "matrix", "~> 0.4"
spec.add_dependency "zeitwerk", "~> 2.0"

spec.add_development_dependency("pdf-inspector", "~> 1.0")

Expand Down

0 comments on commit 908791c

Please sign in to comment.