printr 0.1.4 → 0.1.5
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/.gitignore +2 -0
- data/lib/printr.rb +24 -13
- data/printr.gemspec +1 -1
- metadata +3 -3
data/lib/printr.rb
CHANGED
@@ -45,7 +45,7 @@ module Printr
|
|
45
45
|
def self.open_printers
|
46
46
|
@@conf.each do |key,value|
|
47
47
|
key = key.to_sym
|
48
|
-
puts "[Printr] Trying to open #{key}..."
|
48
|
+
puts "[Printr] Trying to open #{key} at path: #{value}..."
|
49
49
|
begin
|
50
50
|
@@printrs[key] = SerialPort.new(value,9600)
|
51
51
|
puts "[Printr] Success for SerialPort: #{ @printrs[key].inspect }"
|
@@ -56,14 +56,10 @@ module Printr
|
|
56
56
|
next if @@printrs[key]
|
57
57
|
# Try to open it as USB
|
58
58
|
begin
|
59
|
-
@@printrs[key] =
|
59
|
+
@@printrs[key] = "ECHO"
|
60
|
+
puts "[Printr] opened as usb"
|
60
61
|
rescue Errno::EBUSY
|
61
|
-
@@
|
62
|
-
if @@printrs[k] and @@printrs[k].class == File then
|
63
|
-
@@printrs[key] = @@printrs[k]
|
64
|
-
puts "[Printr] Reused."
|
65
|
-
end
|
66
|
-
end
|
62
|
+
@@printrs[key] = "ECHO"
|
67
63
|
rescue Exception => e
|
68
64
|
@@printrs[key] = File.open("#{RAILS_ROOT}/tmp/dummy-#{key}.txt","a")
|
69
65
|
puts "[Printr] Failed to open as either SerialPort or USB File. Created Dummy #{ @printrs[key].inspect } instead."
|
@@ -119,12 +115,21 @@ module Printr
|
|
119
115
|
text = sanitize(text)
|
120
116
|
if text.nil? then
|
121
117
|
puts "[Printr] Sanitize nillified the text..."
|
118
|
+
end
|
119
|
+
puts "[Printr] Going ahead with printing of: " + text.to_s
|
122
120
|
t = Printr.printrs[key].class
|
123
121
|
if Printr.printrs[key].class == File then
|
124
122
|
Printr.printrs[key].write text
|
125
123
|
Printr.printrs[key].flush
|
126
|
-
elsif Printr.printrs[key].class == SerialPort
|
124
|
+
elsif Printr.printrs[key].class == SerialPort then
|
127
125
|
Printr.printrs[key].write text
|
126
|
+
elsif Printr.printrs[key] == 'ECHO' then
|
127
|
+
puts "[Printr] Printing to device..." + Printr.conf[key]
|
128
|
+
File.open(Printr.conf[key],'w:ISO8859-15') do |f|
|
129
|
+
f.write Printr.codes[:header]
|
130
|
+
f.write text
|
131
|
+
f.write Printr.codes[:footer]
|
132
|
+
end
|
128
133
|
else
|
129
134
|
puts "Could not find #{key} #{Printr.printrs[key].class}"
|
130
135
|
end
|
@@ -144,11 +149,17 @@ module Printr
|
|
144
149
|
end
|
145
150
|
end
|
146
151
|
def sanitize(text)
|
147
|
-
i = 0
|
148
152
|
begin
|
149
|
-
|
150
|
-
|
151
|
-
|
153
|
+
i = 0
|
154
|
+
if Printr.sanitize_tokens.length > 1 then
|
155
|
+
begin
|
156
|
+
text.gsub!(Printr.sanitize_tokens[i],Printr.sanitize_tokens[i+1])
|
157
|
+
i += 2
|
158
|
+
end while i < Printr.sanitize_tokens.length
|
159
|
+
end
|
160
|
+
rescue Exception => e
|
161
|
+
puts "[Printr] Error in sanittize"
|
162
|
+
end
|
152
163
|
return text
|
153
164
|
end
|
154
165
|
def template(name,bndng)
|
data/printr.gemspec
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 5
|
9
|
+
version: 0.1.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Michael Franzl
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-19 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|