escpos 0.0.8 → 0.0.9

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8a5a4ab7452b36d984ed17128e3a9b452b54108db7e173b4c0b1dfe4c10dc684
4
- data.tar.gz: 67f724b2193209f7f4a6cc317f9eae6bfd4b33f346af87c65d48064fdc064926
3
+ metadata.gz: f12f7b1678273bcd3b2c08172d70ef2adb7ef8d166a6dc008eee50986759b92e
4
+ data.tar.gz: 3623dd3bbd6a560545882e8c2449525bd03774244e3a6e9b45ac801850d82d65
5
5
  SHA512:
6
- metadata.gz: 7c188461fafe8f0a15a5291fa9d59b1958e1830a314cc75122cd90f840e010dd2a31d6d82546e114c8cda8a5806ae1b2761ecad5cfcceaf6be10129a76e9ccf7
7
- data.tar.gz: 47fbf1a5a6ae7e064de78f31a74832b7ee8fcb6f72ad67311a5cb3f7590ce547f4a4c3fbb30557cdf972e523ce0aaca85ed1d8eea600077edeea073c1704784b
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
- ## Usage
46
+ ## Basic usage
47
47
 
48
48
  ```ruby
49
49
  @printer = Escpos::Printer.new
50
- @printer.write "Some text"
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
- # using report class
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
- quad_text "#{@count}. #{text}"
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 <%= 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.write report.render
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
- - **text**: Normal text formatting
98
- - **encode**: Encode text for the printer
99
- - **encoding, set_encoding, set_printer_encoding**: Set printer encoding
100
- - **double_height**: Double height text
101
- - **quad_text, big, title, header, double_width_double_height, double_height_double_width**: Double width & Double height text
102
- - **double_width**: Double width text
103
- - **underline, u**: Underlined text
104
- - **underline2, u2**: Stronger underlined text
105
- - **bold, b**: Bold text
106
- - **left**: Align to left
107
- - **right**: Align to right
108
- - **center**: Align to center
109
- - **invert, inverted**: Color inverted text
110
- - **black, default_color, color_black, black_color**: Default Color (Usually black)
111
- - **red, alt_color, alternative_color, color_red, red_color**: Alternative Color (Usually Red)
112
- - **barcode**: Print barcode
113
- - **partial_cut**: Partially cut the paper (may not be available on all devices)
114
- - **cut**: Fully cut the paper (may not be available on all devices)
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
@@ -1,4 +1,4 @@
1
- Order number <%= order[:number] %>
1
+ <%= big "Order number #{order[:number]}" %>
2
2
 
3
3
  <%= item "First item" %>
4
4
  <%= item "Second item" %>
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
- quad_text "#{@count}. #{text}"
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.write report.render
18
+ @printer << report.render
19
19
  @printer.cut!
20
20
 
21
21
  # @printer.to_escpos or @printer.to_base64 contains resulting ESC/POS data
@@ -1,5 +1,6 @@
1
1
  module Escpos
2
2
  module Helpers
3
+ extend self
3
4
 
4
5
  # Encodes UTF-8 string to encoding acceptable for the printer
5
6
  # The printer must be set to that encoding
@@ -13,6 +13,7 @@ module Escpos
13
13
  escpos_data = data.respond_to?(:to_escpos) ? data.to_escpos : data
14
14
  @data << escpos_data.force_encoding("ASCII-8BIT")
15
15
  end
16
+ alias :<< :write
16
17
 
17
18
  def partial_cut!
18
19
  @data << Escpos.sequence(PAPER_PARTIAL_CUT)
@@ -1,3 +1,3 @@
1
1
  module Escpos
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
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*')
@@ -1,4 +1,4 @@
1
- Order number <%= order[:number] %>
1
+ <%= big "Order number #{order[:number]}" %>
2
2
 
3
3
  <%= item "First item" %>
4
4
  <%= item "Second item" %>
@@ -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.write result
12
+ @printer << result
13
13
  @printer.cut!
14
- #pp @printer.to_base64
15
- assert_equal @printer.to_base64, 'G0BVbmZvcm1hdHRlZCB0ZXh0CgobdBYKClVURi04IHRvIElTTy04ODU5LTIgdGV4dDogKOy56Pi+/eHt6fr5KQoKGyEATm9ybWFsIHRleHQbIQAKChshEERvdWJsZSBoZWlnaHQgdGV4dBshAAoKGyEgRG91YmxlIHdpZHRoIHRleHQbIQAKChshMFF1YWQgYXJlYSB0ZXh0GyEACgobLQFVbmRlcmxpbmVkIHRleHQbLQAKChstAlVuZGVybGluZWQgdGV4dCAoMikbLQAKChtFAUJvbGQgdGV4dBtFAAoKG2EATGVmdCBhbGlnbmVkIHRleHQbYQAKChthAlJpZ2h0IGFsaWduZWQgdGV4dBthAAoKG2EBQ2VudGVyZWQgdGV4dBthAAoKG2EAG2EACgodQgFJbnZlcnRlZCBjb2xvciB0ZXh0HUIACgodSAAddwMdaDIdawI4NTk0NDA0MDAwNTcyCgoKCgodVgA='
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
- quad_text "#{@count}. #{text}"
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.write report.render
24
+ @printer << report.render
25
25
  @printer.cut!
26
- #pp @printer.to_base64
27
- assert_equal @printer.to_base64, 'G0BPcmRlciBudW1iZXIgMTIzCgobITAxLiBGaXJzdCBpdGVtGyEAChshMDIuIFNlY29uZCBpdGVtGyEAChshMDMuIFRoaXJkIGl0ZW0bIQAKCgoKCh1WAA=='
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.8
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-21 00:00:00.000000000 Z
11
+ date: 2019-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler