#encoding: utf-8 class ActionPrinter < ActionView::Base #AbstractController::Base # previously # include AbstractController::Rendering # include AbstractController::Helpers # include AbstractController::Translation # include AbstractController::AssetPaths # include Rails.application.routes.url_helpers # helper ApplicationHelper # self.view_paths = "app/views" # prepend_view_path ViewTemplate::Resolver.instance attr_accessor :printer, :paper def initialize(printer,paper) @printer=printer @paper=paper super(Rails.configuration.paths['app/views']) end def command @printer.command end # def printer # @printer # end # # def printer=value # @printer = value # end # # build a temp file with the HTML string rendered and provided as argument str def html_file str, type='html' f = Tempfile.new(['print', ".#{type}"]) f.puts str f.close Rails.logger.info "oxen: wrote #{f.path}" f end def text_file str html_file str, 'label' end def file_path raise "must be implemented on the driver!!" end def label_file_path @label_file_path ||= `mktemp -t lblXXXX`[0..-2] end def pdf_file_path @pdf_file_path ||= `mktemp -t pdfXXXX`[0..-2] end def get_file_type raise "you must implement this on the driver!!" end def send_print_file context context.send_file pdf_file_path, filename: 'oxen_file', type: get_file_type, disposition: "attachment" # context.cookies['fileDownload'] = 'true' # File.open(pdf_file_path, 'r') do |fp| # context.send_data fp.read.force_encoding('BINARY'), filename: 'oxen_file', type: "application/pdf", disposition: "attachment" # end end def logit( log_type, msg ) Rails.logger.send(log_type, "[OXEN] #{Time.now} [#{log_type.to_s}] #{msg}") end # class Pushable # def initialize(channel, pushtext) # @channel = channel # @pushtext = pushtext # end # # def push # Pusher[@channel].trigger('rjs_push', @pushtext ) # end # end end