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.
@@ -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
@@ -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
- if @mode != 'local' and SalorHospitality::Application::SH_DEBIAN_SITEID != 'none'
91
- path = File.join('/', 'var', 'lib', 'salor-hospitality', SalorHospitality::Application::SH_DEBIAN_SITEID, 'public', 'uploads', "#{path}.salor")
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
- if SalorHospitality::Application::SH_DEBIAN_SITEID == 'none'
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
- if SalorHospitality::Application::SH_DEBIAN_SITEID == 'none'
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
@@ -1,3 +1,3 @@
1
1
  module Escper
2
- VERSION = "1.0.9"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: escper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: