escper 1.0.9 → 1.1.0
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.
- data/lib/escper.rb +3 -1
- data/lib/escper/printer.rb +8 -19
- data/lib/escper/version.rb +1 -1
- metadata +1 -1
data/lib/escper.rb
CHANGED
@@ -6,9 +6,11 @@ Dir[File.expand_path("#{dir}/escper/*.rb")].uniq.each do |file|
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module Escper
|
9
|
-
mattr_accessor :codepage_file
|
9
|
+
mattr_accessor :codepage_file, :use_safe_device_path, :safe_device_path
|
10
10
|
|
11
11
|
@@codepage_file = File.join(File.dirname(__FILE__), 'escper', 'codepages.yml')
|
12
|
+
@@use_safe_device_path = false
|
13
|
+
@@safe_device_path = File.join('/','tmp')
|
12
14
|
|
13
15
|
def self.setup
|
14
16
|
yield self
|
data/lib/escper/printer.rb
CHANGED
@@ -30,7 +30,7 @@ module Escper
|
|
30
30
|
|
31
31
|
codepage = printer[:codepage]
|
32
32
|
codepage ||= 0
|
33
|
-
output_text = merge_texts(text, raw_text_insertations, codepage)
|
33
|
+
output_text = Printer.merge_texts(text, raw_text_insertations, codepage)
|
34
34
|
|
35
35
|
ActiveRecord::Base.logger.info "[PRINTING] Printing on #{ printer[:name] } @ #{ printer[:device].inspect }."
|
36
36
|
bytes_written = nil
|
@@ -87,9 +87,12 @@ module Escper
|
|
87
87
|
name = p.name
|
88
88
|
path = p.path
|
89
89
|
codepage = p.codepage
|
90
|
-
|
91
|
-
|
90
|
+
|
91
|
+
if Escper.use_safe_device_path == true
|
92
|
+
sanitized_path = path.gsub(/[\/\s'"\&\^\$\#\!;\*]/,'_').gsub(/[^\w\/\.\-@]/,'')
|
93
|
+
path = File.join(Escper.safe_device_path, "#{sanitized_path}.salor")
|
92
94
|
end
|
95
|
+
|
93
96
|
ActiveRecord::Base.logger.info "[PRINTING] Trying to open #{ name } @ #{ path } ..."
|
94
97
|
pid = p.id ? p.id : i
|
95
98
|
begin
|
@@ -119,25 +122,11 @@ module Escper
|
|
119
122
|
end
|
120
123
|
end
|
121
124
|
unless @open_printers.has_key? p.id
|
122
|
-
|
123
|
-
path = File.join(Rails.root, 'tmp')
|
124
|
-
else
|
125
|
-
path = File.join('/', 'var', 'lib', 'salor-hospitality', SalorHospitality::Application::SH_DEBIAN_SITEID)
|
126
|
-
end
|
127
|
-
printer = File.open(File.join(path, "#{ p.id }-#{ name }-fallback-busy.salor"), 'wb')
|
128
|
-
@open_printers.merge! pid => { :name => name, :path => path, :copies => p.copies, :device => printer, :codepage => codepage }
|
129
|
-
ActiveRecord::Base.logger.info "[PRINTING] Failed to open as either SerialPort or USB File and resource IS busy. This should not have happened. Created #{ printer.inspect } instead."
|
125
|
+
ActiveRecord::Base.logger.info "[PRINTING] Failed to open as either SerialPort or USB File and resource IS busy. This should not have happened."
|
130
126
|
end
|
131
127
|
next
|
132
128
|
rescue Exception => e
|
133
|
-
|
134
|
-
path = File.join(Rails.root, 'tmp')
|
135
|
-
else
|
136
|
-
path = File.join('/', 'var', 'lib', 'salor-hospitality', SalorHospitality::Application::SH_DEBIAN_SITEID)
|
137
|
-
end
|
138
|
-
printer = File.open(File.join(path, "#{ p.id }-#{ name }-fallback-notbusy.salor"), 'wb')
|
139
|
-
@open_printers.merge! pid => { :name => name, :path => path, :copies => p.copies, :device => printer, :codepage => codepage }
|
140
|
-
ActiveRecord::Base.logger.info "[PRINTING] Failed to open as either SerialPort or USB File and resource is NOT busy. Created #{ printer.inspect } instead."
|
129
|
+
ActiveRecord::Base.logger.info "[PRINTING] Failed to open as either SerialPort or USB File and resource is NOT busy."
|
141
130
|
end
|
142
131
|
end
|
143
132
|
end
|
data/lib/escper/version.rb
CHANGED