oxen_printer 0.3.3 → 0.3.4
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.
- checksums.yaml +4 -4
- data/app/mailers/printer_mailer.rb +18 -0
- data/app/models/ox_template.rb +20 -0
- data/lib/action_printer.rb +47 -28
- data/lib/oxen_printer/cab_printer.rb +22 -21
- data/lib/oxen_printer/pdf_printer.rb +25 -35
- data/lib/oxen_printer/version.rb +1 -1
- data/lib/print_drivers.rb +1 -1
- data/lib/print_engine.rb +3 -6
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2856583ac970726480283ef1ffcbc0443e0a902a
|
4
|
+
data.tar.gz: 5481a1caeae750b7caf77783d6533572b0f799f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da1d19e301d9253df75b949376925d96c25be759385bbcfcf29b30aa5be020decd301dcc7c026b6cd567b4bc462f7d8aede878a20582a7bb09406fe75533edeb
|
7
|
+
data.tar.gz: 52dd2b0e5d641f417ba286f078f45fe41fbea96db9f6d31a85cbe293d1efae7f250c120f10fd2c4417ee18d3ef2c0499aeac390caac003b10ab50442ad6abadc
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class PrinterMailer < ActionMailer::Base
|
2
|
+
layout 'mailer'
|
3
|
+
|
4
|
+
def send_print usr, file
|
5
|
+
@usr = User.find(usr)
|
6
|
+
fname = case file
|
7
|
+
when /\/pdf.*$/; 'print%s.pdf' % DateTime.now.nsec
|
8
|
+
else 'print%s.label' % DateTime.now.nsec
|
9
|
+
end
|
10
|
+
attachments[fname] = File.read(file) unless file.blank?
|
11
|
+
@logo = @usr.account.logos.first.image.url rescue ""
|
12
|
+
@msg = "Der er ikke defineret nogen printere til dette job, for dig - så jeg er nødt til at sende dig filen vedhæftet denne email! ;)Du bør kontakte din system administrator og bede om at der bliver oprettet en printer definition til denne printer jobtype, for dig!"
|
13
|
+
|
14
|
+
mail from: 'no-reply@wheelstore.space',
|
15
|
+
to: @usr.email,
|
16
|
+
subject: "Kontakt administrator! Der mangler en printer definition!"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class OxTemplate < AbstractResource
|
2
|
+
self.table_name = 'templates'
|
3
|
+
establish_connection ((Rails.env=="development") ? :dev_oxen_tables : :oxen_tables )
|
4
|
+
|
5
|
+
has_many :photos, foreign_key: 'template_id'
|
6
|
+
|
7
|
+
has_paper_trail
|
8
|
+
|
9
|
+
validates :template_key, presence: true
|
10
|
+
validates :template_path, presence: true
|
11
|
+
|
12
|
+
def list_title
|
13
|
+
template_key
|
14
|
+
end
|
15
|
+
|
16
|
+
def name
|
17
|
+
template_key
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/lib/action_printer.rb
CHANGED
@@ -1,17 +1,7 @@
|
|
1
1
|
#encoding: utf-8
|
2
|
-
class ActionPrinter < ActionView::Base
|
2
|
+
class ActionPrinter < ActionView::Base
|
3
3
|
|
4
|
-
|
5
|
-
# include AbstractController::Rendering
|
6
|
-
# include AbstractController::Helpers
|
7
|
-
# include AbstractController::Translation
|
8
|
-
# include AbstractController::AssetPaths
|
9
|
-
# include Rails.application.routes.url_helpers
|
10
|
-
|
11
|
-
# helper ApplicationHelper
|
12
|
-
# self.view_paths = "app/views"
|
13
|
-
|
14
|
-
# prepend_view_path ViewTemplate::Resolver.instance
|
4
|
+
include Exceptions
|
15
5
|
|
16
6
|
attr_accessor :printer, :paper
|
17
7
|
|
@@ -25,15 +15,54 @@ class ActionPrinter < ActionView::Base #AbstractController::Base
|
|
25
15
|
@printer.command
|
26
16
|
end
|
27
17
|
|
28
|
-
# def printer
|
29
|
-
# @printer
|
30
|
-
# end
|
31
18
|
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
19
|
+
# the default rendering is from a string of chars to an html file - statically placed
|
20
|
+
# for who ever knows the exact path to the file, to see
|
21
|
+
#
|
22
|
+
def do_render(print_job,*args)
|
23
|
+
path = print_job.view_template_path
|
24
|
+
# TODO vi får en fejl her når vi begynder at mixe modellerne f.eks. Employee.find_by_sql('select * from products')
|
25
|
+
rc = print_job.printing_class.constantize
|
26
|
+
coll = rc.find_by_sql( print_job.print_sql)
|
27
|
+
locals = { resource_class: rc, collection: coll, resource: coll.first }
|
28
|
+
#
|
29
|
+
# TODO args must be mergeable ;)
|
30
|
+
# if args.flatten.compact.any?
|
31
|
+
# locals.merge! args
|
32
|
+
# end
|
35
33
|
|
34
|
+
#
|
35
|
+
# this is WorkInProgress
|
36
|
+
#
|
37
|
+
if (path =~/^---/) # this will return falsy if found
|
38
|
+
of = html_file render_string_in path.gsub( /^---/, ''), locals
|
39
|
+
else
|
40
|
+
of = html_file render( file: path, formats: [:html], handlers: [:haml,:erb], locals: locals)
|
41
|
+
end
|
42
|
+
#
|
43
|
+
#
|
44
|
+
logit :info, "created a html file: #{of.path}"
|
45
|
+
|
46
|
+
of.path
|
47
|
+
end
|
36
48
|
|
49
|
+
# the default print is sending a link to the user who ordered the print
|
50
|
+
def do_print copies, usr=nil
|
51
|
+
# move pdf_file_path to a static place where it will not be accidentally deleted from
|
52
|
+
# static_path = File.join(Rails.root,'public','files','1.pdf')
|
53
|
+
# var = %x[ mv #{pdf_file_path} #{static_path} 2>&1 ]
|
54
|
+
# send email to usr with link
|
55
|
+
# raise MovingFileFailedError.new(var) unless var.blank?
|
56
|
+
PrinterMailer.send_print(usr,file_path).deliver_now if usr
|
57
|
+
true
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# this is WorkInProgress !!
|
62
|
+
#
|
63
|
+
def render_string_in content, locals
|
64
|
+
render body: Haml::Engine.new( ERB.new(content).result ).render
|
65
|
+
end
|
37
66
|
|
38
67
|
#
|
39
68
|
# build a temp file with the HTML string rendered and provided as argument str
|
@@ -77,14 +106,4 @@ class ActionPrinter < ActionView::Base #AbstractController::Base
|
|
77
106
|
Rails.logger.send(log_type, "[OXEN] #{Time.now} [#{log_type.to_s}] #{msg}")
|
78
107
|
end
|
79
108
|
|
80
|
-
# class Pushable
|
81
|
-
# def initialize(channel, pushtext)
|
82
|
-
# @channel = channel
|
83
|
-
# @pushtext = pushtext
|
84
|
-
# end
|
85
|
-
#
|
86
|
-
# def push
|
87
|
-
# Pusher[@channel].trigger('rjs_push', @pushtext )
|
88
|
-
# end
|
89
|
-
# end
|
90
109
|
end
|
@@ -17,15 +17,11 @@ class CabPrinter < ActionPrinter
|
|
17
17
|
# if args.flatten.compact.any?
|
18
18
|
# locals.merge! args
|
19
19
|
# end
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
# locals: { variable: 'value' }
|
26
|
-
# )
|
27
|
-
#
|
28
|
-
of = text_file render( file: path, formats: [:html], handlers: [:haml,:erb], locals: locals)
|
20
|
+
if (path =~/^---/) # this will return falsy if found
|
21
|
+
of = text_file render_string_in path.gsub( /^---/, ''), locals
|
22
|
+
else
|
23
|
+
of = text_file render( file: path, formats: [:html], handlers: [:haml,:erb], locals: locals)
|
24
|
+
end
|
29
25
|
logit :info, "created a label file: #{of.path}"
|
30
26
|
var = %x[ mv #{of.path} #{label_file_path} ]
|
31
27
|
logit :info, "moved it to: #{label_file_path}"
|
@@ -36,21 +32,26 @@ class CabPrinter < ActionPrinter
|
|
36
32
|
end
|
37
33
|
|
38
34
|
# CAB print last command is "A n" where n is the number of copies - an information which we add at print time
|
39
|
-
def do_print copies=1
|
35
|
+
def do_print copies=1, usr=nil
|
40
36
|
result = nil
|
41
37
|
prn = printer
|
42
38
|
unless prn.command.blank?
|
43
|
-
if
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
39
|
+
if prn.command=="email"
|
40
|
+
prn.delete
|
41
|
+
return super
|
42
|
+
else
|
43
|
+
if copies.to_i > 0
|
44
|
+
cpcmd = `echo 'A #{copies.to_i}\n' >> #{label_file_path}`
|
45
|
+
label_path = label_file_path.split("/")[-1]
|
46
|
+
pap = paper || prn.paper
|
47
|
+
cmd = prn.command.gsub(/\$1/, prn.cups_printer).gsub(/\$2/, label_file_path)
|
48
|
+
# Here we start actually printing
|
49
|
+
# $1 is the CUPS printer
|
50
|
+
# $2 is the PDF file_path_and_name
|
51
|
+
# $3 is the PDF filename
|
52
|
+
# the command being something along the lines of: lp -d $1 -o media=a4 $2
|
53
|
+
result = `#{cmd}`
|
54
|
+
end
|
54
55
|
end
|
55
56
|
end
|
56
57
|
!result.blank?
|
@@ -1,27 +1,11 @@
|
|
1
1
|
class PdfPrinter < ActionPrinter
|
2
2
|
#IKKE FÆRDIG
|
3
3
|
def do_render(print_job,*args)
|
4
|
-
|
5
|
-
|
6
|
-
locals = { resource_class: print_job.printing_class.constantize, collection: print_job.printing_class.constantize.find_by_sql( print_job.print_sql) }
|
7
|
-
#
|
8
|
-
# TODO args must be mergeable ;)
|
9
|
-
# if args.flatten.compact.any?
|
10
|
-
# locals.merge! args
|
11
|
-
# end
|
12
|
-
# html = ActionView::Base.new(Rails.configuration.paths['app/views']).render(
|
13
|
-
# file: 'accounts/record.html.haml',
|
14
|
-
# # partial: 'test',
|
15
|
-
# formats: [:html],
|
16
|
-
# handlers: [:erb,:haml],
|
17
|
-
# locals: { variable: 'value' }
|
18
|
-
# )
|
19
|
-
#
|
20
|
-
of = html_file render( file: path, formats: [:html], handlers: [:haml,:erb], locals: locals)
|
21
|
-
logit :info, "created a html file: #{of.path}"
|
4
|
+
# first we will call super to do the html thing
|
5
|
+
html_path = super
|
22
6
|
#
|
23
7
|
# calls java -jar with the oxen_printer gem lib/java_pdf/barcodeprinter.jar - as in java -jar /Users/walther/Projects/Gems/oxen_printer/lib/java_pdf/barcodeprinter.jar $1 $2
|
24
|
-
var = %x[ bin/printer_cmd.sh #{
|
8
|
+
var = %x[ bin/printer_cmd.sh #{html_path} #{pdf_file_path} ]
|
25
9
|
logit :info, "converted the html file to a PDF file: #{pdf_file_path}"
|
26
10
|
true
|
27
11
|
rescue => e
|
@@ -29,27 +13,33 @@ class PdfPrinter < ActionPrinter
|
|
29
13
|
false
|
30
14
|
end
|
31
15
|
|
32
|
-
def do_print copies
|
16
|
+
def do_print copies, usr=nil
|
33
17
|
result = nil
|
34
18
|
prn = printer
|
35
19
|
unless prn.command.blank?
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
20
|
+
if prn.command=="email"
|
21
|
+
prn.delete
|
22
|
+
return super
|
23
|
+
else
|
24
|
+
pdf_path = pdf_file_path.split("/")[-1]
|
25
|
+
pap = paper || prn.paper
|
26
|
+
cmd = prn.command.gsub( /\$1/, prn.cups_printer ).gsub( /\$2/, pap ).gsub( /\$3/, pdf_file_path ).gsub( /\$4/, pdf_path )
|
27
|
+
if copies > 1
|
28
|
+
cmdargs = cmd.split(" ")
|
29
|
+
f = cmdargs.pop
|
30
|
+
cmdargs.push "-n", copies, f
|
31
|
+
cmd = cmdargs.join(" ")
|
32
|
+
end
|
33
|
+
# Here we start actually printing
|
34
|
+
# $1 is the CUPS printer
|
35
|
+
# $2 is the PDF file_path_and_name
|
36
|
+
# $3 is the PDF filename
|
37
|
+
# the command being something along the lines of: lp -d $1 -o media=a4 $2
|
38
|
+
return `#{cmd}`
|
44
39
|
end
|
45
|
-
# Here we start actually printing
|
46
|
-
# $1 is the CUPS printer
|
47
|
-
# $2 is the PDF file_path_and_name
|
48
|
-
# $3 is the PDF filename
|
49
|
-
# the command being something along the lines of: lp -d $1 -o media=a4 $2
|
50
|
-
return `#{cmd}`
|
51
40
|
end
|
52
|
-
rescue
|
41
|
+
rescue => e
|
42
|
+
logit :error, "Printing failed! The error was #{e.message}"
|
53
43
|
false
|
54
44
|
end
|
55
45
|
|
data/lib/oxen_printer/version.rb
CHANGED
data/lib/print_drivers.rb
CHANGED
@@ -55,7 +55,7 @@ module PrintDrivers
|
|
55
55
|
#
|
56
56
|
def print_with action_printer
|
57
57
|
update_column(:state, "printing")
|
58
|
-
if action_printer && action_printer.do_print(copies)
|
58
|
+
if action_printer && action_printer.do_print(copies,printed_by_id)
|
59
59
|
update_column(:state, 'done')
|
60
60
|
action_printer.file_path
|
61
61
|
else
|
data/lib/print_engine.rb
CHANGED
@@ -8,7 +8,6 @@
|
|
8
8
|
#- - - - - - - - - - - - - - - - - - - - - */
|
9
9
|
# the <b>PrintEngine</b> module ...
|
10
10
|
|
11
|
-
# TODO build the print_engine as a Gem
|
12
11
|
# http://rarlindseysmash.com/posts/config-and-generators-in-gems
|
13
12
|
#
|
14
13
|
|
@@ -36,8 +35,9 @@ module PrintEngine
|
|
36
35
|
|
37
36
|
# raise PrintJobPrinterNotAvailableError
|
38
37
|
printer || Printer.first
|
39
|
-
|
40
|
-
|
38
|
+
rescue NoPreferredPrintersFound
|
39
|
+
logit :error, 'No preferred printers found! Sending PDF by email to %s (%s) ' % [usr.name,usr.email]
|
40
|
+
Printer.create paper: paper, command: 'email', name: 'tmp printer - will be deleted shortly - DONT TOUCH!!', account_id: usr.account.id
|
41
41
|
end
|
42
42
|
|
43
43
|
#
|
@@ -62,9 +62,6 @@ module PrintEngine
|
|
62
62
|
logit :error, 'PrintJob could not be created - the user has no printers attached!!'
|
63
63
|
return false
|
64
64
|
|
65
|
-
rescue NoPreferredPrintersFound
|
66
|
-
logit :error, 'PrintJob could not be created - the user has no preferred printers attached!!'
|
67
|
-
false
|
68
65
|
end
|
69
66
|
|
70
67
|
begin
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oxen_printer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Walther H Diechmann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oxen_job
|
@@ -68,9 +68,11 @@ files:
|
|
68
68
|
- app/controllers/oxen/print_jobs_controller.rb
|
69
69
|
- app/controllers/oxen/printers_controller.rb
|
70
70
|
- app/jobs/background_printer_job.rb
|
71
|
+
- app/mailers/printer_mailer.rb
|
71
72
|
- app/models/ox_print_job.rb
|
72
73
|
- app/models/ox_printable.rb
|
73
74
|
- app/models/ox_printer.rb
|
75
|
+
- app/models/ox_template.rb
|
74
76
|
- app/policies/oxen/print_job_policy.rb
|
75
77
|
- app/views/oxen/print_jobs/_form.html.haml
|
76
78
|
- app/views/oxen/print_jobs/_print_job.html.haml
|