escpos 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +30 -27
- data/examples/report.erb +1 -1
- data/examples/report.rb +2 -2
- data/lib/escpos/helpers.rb +1 -0
- data/lib/escpos/printer.rb +1 -0
- data/lib/escpos/version.rb +1 -1
- data/lib/escpos.rb +0 -3
- data/test/fixtures/report.erb +1 -1
- data/test/lib/escpos/printer_test.rb +4 -3
- data/test/lib/escpos/report_test.rb +5 -4
- data/test/results/test_report.txt +0 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f12f7b1678273bcd3b2c08172d70ef2adb7ef8d166a6dc008eee50986759b92e
|
4
|
+
data.tar.gz: 3623dd3bbd6a560545882e8c2449525bd03774244e3a6e9b45ac801850d82d65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 951c55a10e3c72f0f31e05d8abb63d351d2947d7b2f3419a06f028570d30177e15cec57689da7ac95ac024598f31c1dfd678903283c7dc1ce38082023cea1d1d
|
7
|
+
data.tar.gz: 1bceefc51522a00fe8dedfbc66aced270bda291ec5f2bb7da109964959792c9ee4777f740b294f2ad94eb0a5d169a4c56220520d6df599003e64bfc7d9aecf10
|
data/README.md
CHANGED
@@ -43,11 +43,12 @@ gem install escpos-image
|
|
43
43
|
![](https://github.com/escpos/escpos/blob/master/examples/IMG_20160610_204358_HDR.jpg)
|
44
44
|
![](https://github.com/escpos/escpos-image/blob/master/examples/IMG_20160610_232415_HDR.jpg)
|
45
45
|
|
46
|
-
##
|
46
|
+
## Basic usage
|
47
47
|
|
48
48
|
```ruby
|
49
49
|
@printer = Escpos::Printer.new
|
50
|
-
@printer
|
50
|
+
@printer << "Some text"
|
51
|
+
@printer << Escpos::Helpers.big "Big text"
|
51
52
|
|
52
53
|
@printer.to_escpos # returns ESC/POS data ready to be sent to printer
|
53
54
|
# on linux this can be piped directly to /dev/usb/lp0
|
@@ -55,63 +56,65 @@ gem install escpos-image
|
|
55
56
|
# with serial port printer it can be sent directly to the serial port
|
56
57
|
|
57
58
|
@printer.to_base64 # returns base64 encoded ESC/POS data
|
59
|
+
```
|
58
60
|
|
59
|
-
|
61
|
+
## Report class usage
|
60
62
|
|
63
|
+
```ruby
|
61
64
|
# my_report.rb:
|
62
65
|
class MyReport < Escpos::Report
|
63
66
|
def item(text)
|
64
67
|
@count ||= 0
|
65
68
|
@count += 1
|
66
|
-
|
69
|
+
bold "#{@count}. #{text}"
|
67
70
|
end
|
68
71
|
|
69
72
|
def order
|
70
73
|
options[:order]
|
71
74
|
end
|
72
75
|
end
|
73
|
-
|
74
76
|
```
|
75
77
|
|
76
78
|
```erb
|
77
79
|
<% # my_report.erb: %>
|
78
|
-
Order number
|
80
|
+
<%= big "Order number #{order[:number]}" %>
|
79
81
|
<%= item "First item" %>
|
80
82
|
<%= item "Second item" %>
|
81
83
|
<%= item "Third item" %>
|
82
84
|
```
|
83
85
|
|
84
86
|
```ruby
|
85
|
-
# usage:
|
86
|
-
|
87
87
|
report = MyReport.new 'path/to/my_report.erb', {
|
88
88
|
order: { number: 123 }
|
89
89
|
}
|
90
|
-
@printer
|
90
|
+
@printer << report.render
|
91
91
|
@printer.cut!
|
92
|
+
|
92
93
|
# @printer.to_escpos or @printer.to_base64 contains resulting ESC/POS data
|
93
94
|
```
|
94
95
|
|
95
96
|
## Available helper methods
|
96
97
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
98
|
+
| Method name | Description |
|
99
|
+
| --- | --- |
|
100
|
+
| **text** | Normal text formatting |
|
101
|
+
| **encode** | Encode text for the printer |
|
102
|
+
| **encoding, set_encoding, set_printer_encoding** | Set printer encoding |
|
103
|
+
| **double_height** | Double height text |
|
104
|
+
| **quad_text, big, title, header, double_width_double_height, double_height_double_width** | Double width & Double height text |
|
105
|
+
| **double_width** |Double width text |
|
106
|
+
| **underline, u** | Underlined text |
|
107
|
+
| **underline2, u2** | Stronger underlined text |
|
108
|
+
| **bold, b** | Bold text |
|
109
|
+
| **left** | Align to left |
|
110
|
+
| **right** | Align to right |
|
111
|
+
| **center** | Align to center |
|
112
|
+
| **invert, inverted** | Color inverted text |
|
113
|
+
| **black, default_color, color_black, black_color** | Default Color (Usually black) |
|
114
|
+
| **red, alt_color, alternative_color, color_red, red_color** | Alternative Color (Usually Red) |
|
115
|
+
| **barcode** | Print barcode |
|
116
|
+
| **partial_cut** | Partially cut the paper (may not be available on all devices) |
|
117
|
+
| **cut** | Fully cut the paper (may not be available on all devices) |
|
115
118
|
|
116
119
|
## Contributing
|
117
120
|
|
data/examples/report.erb
CHANGED
data/examples/report.rb
CHANGED
@@ -4,7 +4,7 @@ class MyReport < Escpos::Report
|
|
4
4
|
def item(text)
|
5
5
|
@count ||= 0
|
6
6
|
@count += 1
|
7
|
-
|
7
|
+
bold "#{@count}. #{text}"
|
8
8
|
end
|
9
9
|
|
10
10
|
def order
|
@@ -15,7 +15,7 @@ end
|
|
15
15
|
report = MyReport.new File.join(__dir__, 'report.erb'), {
|
16
16
|
order: { number: 123 }
|
17
17
|
}
|
18
|
-
@printer
|
18
|
+
@printer << report.render
|
19
19
|
@printer.cut!
|
20
20
|
|
21
21
|
# @printer.to_escpos or @printer.to_base64 contains resulting ESC/POS data
|
data/lib/escpos/helpers.rb
CHANGED
data/lib/escpos/printer.rb
CHANGED
data/lib/escpos/version.rb
CHANGED
data/lib/escpos.rb
CHANGED
@@ -108,9 +108,6 @@ module Escpos
|
|
108
108
|
BARCODE_ITF = [ 0x1d, 0x6b, 0x05 ] # Barcode type ITF
|
109
109
|
BARCODE_NW7 = [ 0x1d, 0x6b, 0x06 ] # Barcode type NW7
|
110
110
|
|
111
|
-
# Images
|
112
|
-
IMAGE = [ 0x1d, 0x76, 0x30, 0x00 ] # Start image pixel data
|
113
|
-
|
114
111
|
# Transforms an array of codes into a string
|
115
112
|
def sequence(*arr_sequence)
|
116
113
|
arr_sequence.flatten.pack('U*')
|
data/test/fixtures/report.erb
CHANGED
@@ -9,10 +9,11 @@ class PrinterTest < Minitest::Test
|
|
9
9
|
require 'erb'
|
10
10
|
template = ERB.new(File.open(File.join(__dir__, '../../fixtures/styles.erb')).read)
|
11
11
|
result = template.result(Class.new { include Escpos::Helpers }.new.instance_eval { binding })
|
12
|
-
@printer
|
12
|
+
@printer << result
|
13
13
|
@printer.cut!
|
14
|
-
|
15
|
-
|
14
|
+
file = File.join(__dir__, "../../results/#{__method__}.txt")
|
15
|
+
#IO.binwrite file, @printer.to_escpos
|
16
|
+
assert_equal IO.binread(file), @printer.to_escpos
|
16
17
|
end
|
17
18
|
|
18
19
|
end
|
@@ -11,7 +11,7 @@ class TestReport < Minitest::Test
|
|
11
11
|
def item(text)
|
12
12
|
@count ||= 0
|
13
13
|
@count += 1
|
14
|
-
|
14
|
+
bold "#{@count}. #{text}"
|
15
15
|
end
|
16
16
|
def order
|
17
17
|
options[:order]
|
@@ -21,10 +21,11 @@ class TestReport < Minitest::Test
|
|
21
21
|
order: { number: 123 }
|
22
22
|
}
|
23
23
|
|
24
|
-
@printer
|
24
|
+
@printer << report.render
|
25
25
|
@printer.cut!
|
26
|
-
|
27
|
-
|
26
|
+
file = File.join(__dir__, "../../results/#{__method__}.txt")
|
27
|
+
#IO.binwrite file, @printer.to_escpos
|
28
|
+
assert_equal IO.binread(file), @printer.to_escpos
|
28
29
|
end
|
29
30
|
|
30
31
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: escpos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Svoboda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|