Module: PrintDrivers
Class Method Summary collapse
Instance Method Summary collapse
-
#print_with(action_printer, args) ⇒ Object
called from the perform on the print_job print_with will use the action_printer to build the print and return the resulting filepath.
-
#rendered_on(*args) ⇒ Object
build PDF or somehow prepare printer output.
- #send_with(action_printer, context) ⇒ Object
- #set_default_args(args) ⇒ Object
Class Method Details
.included(base) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/print_drivers.rb', line 15 def self.included(base) # build PDF or somehow prepare printer output def rendered_on(*args) update_column(:state, "rendering") # TODO 2013-06-08 set the action_printer with respect to the selected output & printer action_printer = case print_driver when :pdf, "pdf" require 'oxen_printer/pdf_printer' PdfPrinter.new(printer, paper) when :cab, "cab" require 'oxen_printer/cab_printer' CabPrinter.new(printer, paper) when :label, "label" require 'oxen_printer/label_printer' LabelPrinter.new(printer, paper) when :html, "html" require 'oxen_printer/html_printer' HtmlPrinter.new(printer, paper) when :csv, "csv" require 'oxen_printer/csv_printer' CsvPrinter.new(printer, paper) end # print_job.action_printer.printer = print_job.printer # print_job.cycle if return action_printer if action_printer.do_render(self,args) update_column(:state, 'error rendering') raise PrintJobRenderingError end # # called from the perform on the print_job # print_with will use the action_printer to build the print # and return the resulting filepath # def print_with action_printer, args update_column(:state, "printing") args = set_default_args args status = case args[:medium] when "email" if action_printer printed_by.email = args[:email_to] action_printer.printer.command="email" action_printer.do_print(self,args) update_column(:state, 'done') action_printer.file_path else update_column(:state, 'error printing') raise PrintJobPrintingError.new t('print_drivers.print_with.email_error') end when "printer" if action_printer && action_printer.do_print(self,args) update_column(:state, 'done') action_printer.file_path else update_column(:state, 'error printing') raise PrintJobPrintingError.new I18n.t('print_drivers.print_with.print_error') end else raise PrintJobPrintingError.new I18n.t('print_drivers.print_with.case_error'); end end def send_with action_printer, context update_column(:state, 'sending') if action_printer && action_printer.send_print_file( context) update_column(:state, 'done') action_printer.file_path else update_column(:state, 'error sending') raise PrintJobPrintingError end end def set_default_args args args[0][:print] ||= {} args[0][:print][:copies] ||= 1 args[0][:print][:medium] ||= "printer" args[0][:print] rescue Rails.logger.error "#{args}" { copies: 1, medium: "printer" } end # q%{ # Problem with CUPS printer definitions - losing knowledge of attached printers # # D [08/Dec/2008:16:20:25 +0100] cupsdAuthorize: No authentication data provided. # D [08/Dec/2008:16:20:25 +0100] Print-Job ipp://localhost/printers/HP_LaserJet_M3035_MPF_192.168.105.78 # D [08/Dec/2008:16:20:25 +0100] print_job: auto-typing file... # D [08/Dec/2008:16:20:25 +0100] print_job: request file type is application/pdf. # D [08/Dec/2008:16:20:25 +0100] Print-Job client-error-not-found: The printer or class was not found. # D [08/Dec/2008:16:20:25 +0100] cupsdProcessIPPRequest: 8 status_code=406 (client-error-not-found) # D [08/Dec/2008:16:20:25 +0100] cupsdCloseClient: 8 # # } end |
Instance Method Details
#print_with(action_printer, args) ⇒ Object
called from the perform on the print_job print_with will use the action_printer to build the print and return the resulting filepath
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/print_drivers.rb', line 52 def print_with action_printer, args update_column(:state, "printing") args = set_default_args args status = case args[:medium] when "email" if action_printer printed_by.email = args[:email_to] action_printer.printer.command="email" action_printer.do_print(self,args) update_column(:state, 'done') action_printer.file_path else update_column(:state, 'error printing') raise PrintJobPrintingError.new t('print_drivers.print_with.email_error') end when "printer" if action_printer && action_printer.do_print(self,args) update_column(:state, 'done') action_printer.file_path else update_column(:state, 'error printing') raise PrintJobPrintingError.new I18n.t('print_drivers.print_with.print_error') end else raise PrintJobPrintingError.new I18n.t('print_drivers.print_with.case_error'); end end |
#rendered_on(*args) ⇒ Object
build PDF or somehow prepare printer output
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/print_drivers.rb', line 18 def rendered_on(*args) update_column(:state, "rendering") # TODO 2013-06-08 set the action_printer with respect to the selected output & printer action_printer = case print_driver when :pdf, "pdf" require 'oxen_printer/pdf_printer' PdfPrinter.new(printer, paper) when :cab, "cab" require 'oxen_printer/cab_printer' CabPrinter.new(printer, paper) when :label, "label" require 'oxen_printer/label_printer' LabelPrinter.new(printer, paper) when :html, "html" require 'oxen_printer/html_printer' HtmlPrinter.new(printer, paper) when :csv, "csv" require 'oxen_printer/csv_printer' CsvPrinter.new(printer, paper) end # print_job.action_printer.printer = print_job.printer # print_job.cycle if return action_printer if action_printer.do_render(self,args) update_column(:state, 'error rendering') raise PrintJobRenderingError end |
#send_with(action_printer, context) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/print_drivers.rb', line 80 def send_with action_printer, context update_column(:state, 'sending') if action_printer && action_printer.send_print_file( context) update_column(:state, 'done') action_printer.file_path else update_column(:state, 'error sending') raise PrintJobPrintingError end end |
#set_default_args(args) ⇒ Object
91 92 93 94 95 96 97 98 99 |
# File 'lib/print_drivers.rb', line 91 def set_default_args args args[0][:print] ||= {} args[0][:print][:copies] ||= 1 args[0][:print][:medium] ||= "printer" args[0][:print] rescue Rails.logger.error "#{args}" { copies: 1, medium: "printer" } end |