oxen_printer 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +31 -0
  6. data/Rakefile +8 -0
  7. data/app/controllers/oxen/print_jobs_controller.rb +10 -0
  8. data/app/controllers/oxen/printers_controller.rb +33 -0
  9. data/app/jobs/background_printer_job.rb +14 -0
  10. data/app/models/ox_print_job.rb +47 -0
  11. data/app/models/ox_printable.rb +17 -0
  12. data/app/models/ox_printer.rb +36 -0
  13. data/app/policies/oxen/print_job_policy.rb +51 -0
  14. data/app/views/oxen/print_jobs/_form.html.haml +45 -0
  15. data/app/views/oxen/print_jobs/_print_job.html.haml +3 -0
  16. data/app/views/oxen/print_jobs/_print_jobs.html.haml +11 -0
  17. data/app/views/oxen/print_jobs/_printer_print_job.html.haml +12 -0
  18. data/app/views/oxen/print_jobs/_printer_print_jobs.html.haml +11 -0
  19. data/app/views/oxen/print_jobs/_show.html.haml +0 -0
  20. data/app/views/oxen/printers/_account_printer.html.haml +11 -0
  21. data/app/views/oxen/printers/_account_printers.html.haml +14 -0
  22. data/app/views/oxen/printers/_form.html.haml +31 -0
  23. data/app/views/oxen/printers/_new.html.haml +68 -0
  24. data/app/views/oxen/printers/_printer.html.haml +3 -0
  25. data/app/views/oxen/printers/_printers.html.haml +11 -0
  26. data/app/views/oxen/printers/_user_printer.html.haml +18 -0
  27. data/app/views/oxen/printers/_user_printers.html.haml +14 -0
  28. data/app/views/oxen/printers/create.html.haml +5 -0
  29. data/bin/rails +12 -0
  30. data/config/locales/da.yml +7 -0
  31. data/config/routes.rb +47 -0
  32. data/lib/action_printer.rb +90 -0
  33. data/lib/c4_label_print_provider.rb +215 -0
  34. data/lib/generators/printer/install_generator.rb +14 -0
  35. data/lib/generators/printer/printer_generator.rb +27 -0
  36. data/lib/generators/printer/templates/print_job.rb +21 -0
  37. data/lib/generators/printer/templates/printable.rb +13 -0
  38. data/lib/generators/printer/templates/printer.rb +15 -0
  39. data/lib/java_pdf/LICENSE +71 -0
  40. data/lib/java_pdf/LICENSE-LGPL-2.1.txt +504 -0
  41. data/lib/java_pdf/LICENSE-W3C-TEST +28 -0
  42. data/lib/java_pdf/README +92 -0
  43. data/lib/java_pdf/about.jar +0 -0
  44. data/lib/java_pdf/barbecue-1.5-beta1.jar +0 -0
  45. data/lib/java_pdf/barcodeprinter.jar +0 -0
  46. data/lib/java_pdf/browser.jar +0 -0
  47. data/lib/java_pdf/core-renderer-minimal.jar +0 -0
  48. data/lib/java_pdf/core-renderer.jar +0 -0
  49. data/lib/java_pdf/docbook.jar +0 -0
  50. data/lib/java_pdf/iText-2.0.8.jar +0 -0
  51. data/lib/java_pdf/itext-paulo-155.jar +0 -0
  52. data/lib/java_pdf/lib/LICENSE +71 -0
  53. data/lib/java_pdf/lib/LICENSE-LGPL-2.1.txt +504 -0
  54. data/lib/java_pdf/lib/LICENSE-W3C-TEST +28 -0
  55. data/lib/java_pdf/lib/README +92 -0
  56. data/lib/java_pdf/lib/core-renderer-minimal.jar +0 -0
  57. data/lib/java_pdf/lib/core-renderer.jar +0 -0
  58. data/lib/java_pdf/lib/iText-2.0.8.jar +0 -0
  59. data/lib/java_pdf/lib/itext-paulo-155.jar +0 -0
  60. data/lib/java_pdf/lib/minium.jar +0 -0
  61. data/lib/java_pdf/minium.jar +0 -0
  62. data/lib/java_pdf/pd4ml_demo.jar +0 -0
  63. data/lib/java_pdf/ss_css2.jar +0 -0
  64. data/lib/java_pdf/svg.jar +0 -0
  65. data/lib/oxen_printer.rb +8 -0
  66. data/lib/oxen_printer/cab_printer.rb +101 -0
  67. data/lib/oxen_printer/csv_printer.rb +12 -0
  68. data/lib/oxen_printer/engine.rb +19 -0
  69. data/lib/oxen_printer/html_printer.rb +12 -0
  70. data/lib/oxen_printer/label_printer.rb +12 -0
  71. data/lib/oxen_printer/pdf_printer.rb +66 -0
  72. data/lib/oxen_printer/version.rb +3 -0
  73. data/lib/print_drivers.rb +94 -0
  74. data/lib/print_engine.rb +135 -0
  75. data/lib/tasks/oxen_printer_tasks.rake +4 -0
  76. data/oxen_printer.gemspec +25 -0
  77. metadata +163 -0
@@ -0,0 +1,135 @@
1
+ # encoding: UTF-8
2
+ #/* - - - - - - - - - - - - - - - - - - - - -
3
+ #
4
+ # Title : WEB Appliances Crest Inc, Web Form Framework
5
+ # Author : Enrique Phillips
6
+ # URL : http://www.wac.bz
7
+ #
8
+ #- - - - - - - - - - - - - - - - - - - - - */
9
+ # the <b>PrintEngine</b> module ...
10
+
11
+ # TODO build the print_engine as a Gem
12
+ # http://rarlindseysmash.com/posts/config-and-generators-in-gems
13
+ #
14
+
15
+
16
+ #
17
+ module PrintEngine
18
+
19
+ include Exceptions
20
+
21
+ def self.included(base)
22
+
23
+ #
24
+ # find the best printer for the job
25
+ def base.default_printer usr, printer_name, paper=nil
26
+ if printer_name=="default"
27
+ if paper.nil?
28
+ printer = (usr.printers.empty? ? nil : usr.printers.active.preferred_printer.first) or raise NoPreferredPrintersFound.new('No preferred printers were found!')
29
+ else
30
+ printer = (usr.printers.empty? ? nil : (usr.printers.active.preferred_printer.on_paper(paper).first || usr.printers.on_paper(paper).first ) ) or raise NoPreferredPrintersFound.new('No preferred printers were found!')
31
+ end
32
+ else
33
+ printer = Printer.active.find_by( 'name like ?', "%#{printer_name.downcase}%")
34
+ end
35
+ # usr.printers.where{ (printownerables.preferred==true) & (printownerables.preferred==true) }
36
+
37
+ # raise PrintJobPrinterNotAvailableError
38
+ printer || Printer.first
39
+ # rescue
40
+ # Printer.new
41
+ end
42
+
43
+ #
44
+ # def base.default_print_template_path(params,usr)
45
+ # # TODO 2013-09-02 - select template according to the user/employee
46
+ # params[:print_job][:view_template_path] || "/test.html.haml"
47
+ # end
48
+
49
+ # Creates the PrintJob for any model in need of printing
50
+ # If creating the PrintJob is successful, cycle will be called in print_job.rb
51
+ # and the PrintJob will be enqueued in the delayed_job queue called 'printing'.
52
+ # cycle_error will be called in print_job.rb if it cannot be enqueued sucessfully.
53
+ def base.print( resources, params )
54
+ begin
55
+ pj = create_print_job( resources, params )
56
+ return false unless pj
57
+ rescue PrintJobResourceError
58
+ base.logit :error, 'PrintJob could not be created - no records!?'
59
+ return false
60
+
61
+ rescue PrintJobPrinterNotAvailableError
62
+ logit :error, 'PrintJob could not be created - the user has no printers attached!!'
63
+ return false
64
+ end
65
+
66
+ begin
67
+ if Rails.env=='development' or pj.download
68
+ return pj if pj.perform params
69
+ else
70
+ user = User.find(pj.printed_by_id)
71
+ BackgroundPrinterJob.perform_later pj, queue: "printing", account_id: user.account.id
72
+ # Delayed::Job.enqueue pj, :queue => 'printing'
73
+ # pj.cycle if Delayed::Job.enqueue pj, :queue => 'printing'
74
+ # If you comment out above line and use below line with pj.perform instead, you thereby surpass delayed_job, and thus don't have to wait for it
75
+ # pj.perform
76
+ return pj
77
+ end
78
+ rescue => e
79
+ # self.logit :error, 'PrintJob could not be enqueued'
80
+ pj.update_columns( state: "could not be queued for printing - #{e}" )
81
+ return nil
82
+ end
83
+ end
84
+
85
+ #
86
+ #
87
+ def base.create_print_job( resources, params )
88
+ printer_name = params.delete(:printer_name) || "default"
89
+ params = ActionController::Parameters.new( params) unless params.class == ActionController::Parameters
90
+ params = set_print_job_defaults(resources,params, printer_name)
91
+ return nil if params[:print_job][:printer_id].nil?
92
+ PrintJob.create( params[:print_job].permit(:download, :snap_shot, :account_id, :printer_id, :printed_by_id, :printed_by_type, :view_template_path, :name, :printing_class, :print_driver, :print_format, :paper, :copies, :state, :print_sql) )
93
+ end
94
+
95
+ # Sets print_job defaults using the provided params
96
+ # and looks up any print_job settings to be tweaked
97
+ # as per klass and user
98
+ def base.set_print_job_defaults(resources, params, printer_name)
99
+ klass = resources.first.class.to_s rescue "class not found!"
100
+ params[:print_job] ||= {}
101
+ params[:user] ||= User.first
102
+ user = params[:user]
103
+ params[:print_job][:account_id] ||= user.account.id
104
+ params[:print_job][:paper] ||= nil
105
+ params[:print_job][:printer_id] ||= self.default_printer(user,printer_name,params[:print_job][:paper]).id
106
+ params[:print_job][:printed_by_id] = user.id
107
+ params[:print_job][:printed_by_type] = user.class.to_s
108
+ params[:print_job][:name] ||= "#{klass} print at #{I18n.l Time.now, format: :short_date }"
109
+ params[:print_job][:printing_class] ||= klass
110
+ params[:print_job][:print_driver] ||= :pdf
111
+ params[:print_job][:copies] ||= 1
112
+ params[:print_job][:print_format] ||= "list"
113
+ params[:print_job][:state] = "drafted"
114
+ params[:print_job][:snap_shot] ||= false
115
+ params[:print_job][:print_sql] = set_resource_sql(resources,params)
116
+
117
+ # this is what we ultimately return
118
+ params
119
+ end
120
+
121
+ def base.set_resource_sql(resources,params)
122
+ return resources if resources.class == String && resources.downcase =~ /select/
123
+ raise PrintJobResourceError unless resources.respond_to?(:any?) and resources.any?
124
+ params[:print_job][:snap_shot] ? resources.to_yaml : (resources.class==Array ? array_to_arel(resources) : resources.to_sql)
125
+ end
126
+
127
+ def base.array_to_arel resources
128
+ arel_instance = Arel::Table.new(resources.first.class.table_name)
129
+ ar_rel = resources.first.class
130
+ ar_rel.where(arel_instance[:id].in(resources.map(&:id)).to_sql).to_sql
131
+ end
132
+
133
+ end
134
+
135
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :abstracted do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'oxen_printer/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "oxen_printer"
8
+ spec.version = OxenPrinter::VERSION
9
+ spec.authors = ["Walther H Diechmann"]
10
+ spec.email = ["walther@diechmann.net"]
11
+ spec.summary = %q{oxen_printer provides printer and print_job management.}
12
+ spec.description = %q{oxen_printer manages printers and print_jobs - as a front end to CUPS printers.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "oxen_job"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: oxen_printer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Walther H Diechmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: oxen_job
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: oxen_printer manages printers and print_jobs - as a front end to CUPS
56
+ printers.
57
+ email:
58
+ - walther@diechmann.net
59
+ executables:
60
+ - rails
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - app/controllers/oxen/print_jobs_controller.rb
70
+ - app/controllers/oxen/printers_controller.rb
71
+ - app/jobs/background_printer_job.rb
72
+ - app/models/ox_print_job.rb
73
+ - app/models/ox_printable.rb
74
+ - app/models/ox_printer.rb
75
+ - app/policies/oxen/print_job_policy.rb
76
+ - app/views/oxen/print_jobs/_form.html.haml
77
+ - app/views/oxen/print_jobs/_print_job.html.haml
78
+ - app/views/oxen/print_jobs/_print_jobs.html.haml
79
+ - app/views/oxen/print_jobs/_printer_print_job.html.haml
80
+ - app/views/oxen/print_jobs/_printer_print_jobs.html.haml
81
+ - app/views/oxen/print_jobs/_show.html.haml
82
+ - app/views/oxen/printers/_account_printer.html.haml
83
+ - app/views/oxen/printers/_account_printers.html.haml
84
+ - app/views/oxen/printers/_form.html.haml
85
+ - app/views/oxen/printers/_new.html.haml
86
+ - app/views/oxen/printers/_printer.html.haml
87
+ - app/views/oxen/printers/_printers.html.haml
88
+ - app/views/oxen/printers/_user_printer.html.haml
89
+ - app/views/oxen/printers/_user_printers.html.haml
90
+ - app/views/oxen/printers/create.html.haml
91
+ - bin/rails
92
+ - config/locales/da.yml
93
+ - config/routes.rb
94
+ - lib/action_printer.rb
95
+ - lib/c4_label_print_provider.rb
96
+ - lib/generators/printer/install_generator.rb
97
+ - lib/generators/printer/printer_generator.rb
98
+ - lib/generators/printer/templates/print_job.rb
99
+ - lib/generators/printer/templates/printable.rb
100
+ - lib/generators/printer/templates/printer.rb
101
+ - lib/java_pdf/LICENSE
102
+ - lib/java_pdf/LICENSE-LGPL-2.1.txt
103
+ - lib/java_pdf/LICENSE-W3C-TEST
104
+ - lib/java_pdf/README
105
+ - lib/java_pdf/about.jar
106
+ - lib/java_pdf/barbecue-1.5-beta1.jar
107
+ - lib/java_pdf/barcodeprinter.jar
108
+ - lib/java_pdf/browser.jar
109
+ - lib/java_pdf/core-renderer-minimal.jar
110
+ - lib/java_pdf/core-renderer.jar
111
+ - lib/java_pdf/docbook.jar
112
+ - lib/java_pdf/iText-2.0.8.jar
113
+ - lib/java_pdf/itext-paulo-155.jar
114
+ - lib/java_pdf/lib/LICENSE
115
+ - lib/java_pdf/lib/LICENSE-LGPL-2.1.txt
116
+ - lib/java_pdf/lib/LICENSE-W3C-TEST
117
+ - lib/java_pdf/lib/README
118
+ - lib/java_pdf/lib/core-renderer-minimal.jar
119
+ - lib/java_pdf/lib/core-renderer.jar
120
+ - lib/java_pdf/lib/iText-2.0.8.jar
121
+ - lib/java_pdf/lib/itext-paulo-155.jar
122
+ - lib/java_pdf/lib/minium.jar
123
+ - lib/java_pdf/minium.jar
124
+ - lib/java_pdf/pd4ml_demo.jar
125
+ - lib/java_pdf/ss_css2.jar
126
+ - lib/java_pdf/svg.jar
127
+ - lib/oxen_printer.rb
128
+ - lib/oxen_printer/cab_printer.rb
129
+ - lib/oxen_printer/csv_printer.rb
130
+ - lib/oxen_printer/engine.rb
131
+ - lib/oxen_printer/html_printer.rb
132
+ - lib/oxen_printer/label_printer.rb
133
+ - lib/oxen_printer/pdf_printer.rb
134
+ - lib/oxen_printer/version.rb
135
+ - lib/print_drivers.rb
136
+ - lib/print_engine.rb
137
+ - lib/tasks/oxen_printer_tasks.rake
138
+ - oxen_printer.gemspec
139
+ homepage: ''
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: oxen_printer provides printer and print_job management.
163
+ test_files: []