diff --git a/lib/action_view/template/handlers/prawn.rb b/lib/action_view/template/handlers/prawn.rb new file mode 100755 index 0000000..fc87887 --- /dev/null +++ b/lib/action_view/template/handlers/prawn.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'prawn' + +module ActionView + module Template::Handlers + class Prawn + def self.register! + ::ActionView::Template.register_template_handler :prawn, self + end + + def self.call(template, source = template.source) + %(extend #{DocumentProxy}; #{source}; pdf.render) + end + + module DocumentProxy + def pdf + @pdf ||= ::Prawn::Document.new(::Spree::PrintInvoice::Config[:prawn_options]) + end + + private + + def method_missing(method, *args, &block) + pdf.respond_to?(method) ? pdf.send(method, *args, &block) : super + end + end + end + end +end + +::ActionView::Template::Handlers::Prawn.register! diff --git a/lib/prawn_handler.rb b/lib/prawn_handler.rb deleted file mode 100755 index 290f4e7..0000000 --- a/lib/prawn_handler.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require 'prawn' - -module ActionView - module Template - module Handlers - class Prawn - def self.register! - Template.register_template_handler :prawn, self - end - - def self.call(template, source = template.source) - %(extend #{DocumentProxy}; #{source}; pdf.render) - end - - module DocumentProxy - def pdf - @pdf ||= ::Prawn::Document.new(Spree::PrintInvoice::Config[:prawn_options]) - end - - private - - def method_missing(method, *args, &block) - pdf.respond_to?(method) ? pdf.send(method, *args, &block) : super - end - end - end - end - end -end - -ActionView::Template::Handlers::Prawn.register! diff --git a/lib/solidus_print_invoice.rb b/lib/solidus_print_invoice.rb index 1ba86a6..7a0c7fb 100755 --- a/lib/solidus_print_invoice.rb +++ b/lib/solidus_print_invoice.rb @@ -3,7 +3,7 @@ require 'solidus_print_invoice/version' require 'solidus_print_invoice/engine' -require 'prawn_handler' +require 'action_view/template/handlers/prawn' module Spree module PrintInvoice