esc-pos 0.0.8

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 39cd811bcfa44436c13c1e51bbf625eec659b81f
4
+ data.tar.gz: 6444c99af6e97045adb88096e2d3d5914e4ffec3
5
+ SHA512:
6
+ metadata.gz: 36114be7f8451a5d23133dc1fb8858cdf7917e6152cfda59d1aff416d5db8130baa85755bb10f0361e96a8ac15454da209018cc2b5644e3e5188fcffe94cbca1
7
+ data.tar.gz: f8ba862cfdec32c7d02c03d42466b0986a2755b9572a1c014a6e2f1cb99f71777965aa1cff208ce20775ce271d9194de9e8c704854964132c7f70d624a6a98b7
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in angus-remote.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 adrian-gomez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ esc-pos
2
+ ==============
3
+ Simple esc-pos template compiler.
4
+
5
+ Installing
6
+ ==============
7
+ Add this to your Gemfile:
8
+ ```ruby
9
+ gem 'esc-pos'
10
+ ```
11
+
12
+ Usage
13
+ ==============
14
+ ```ruby
15
+ specification = ESC_POS::Specifications::Epson::TM_U220.new
16
+ specification.render(template: 'payment_ticket')
17
+ ```
18
+
19
+ Templates
20
+ ==============
21
+
22
+ Contributing
23
+ ==============
24
+
25
+ - Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
26
+ - Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
27
+ - Fork the project.
28
+ - Start a feature/bugfix branch.
29
+ - Commit and push until you are happy with your contribution.
30
+ - Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
31
+ - Please try not to mess with the version, or history. If you want to have your own version, or is
32
+ otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
33
+
34
+ Copyright
35
+ ==============
36
+
37
+ Copyright © 2014 Adrian Gomez. See LICENSE.txt for further details.
@@ -0,0 +1,35 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'esc-pos/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+
8
+ spec.name = 'esc-pos'
9
+ spec.version = ESC_POS::VERSION
10
+ spec.authors = ['Adrian Gomez']
11
+ spec.date = '2014-06-05'
12
+ spec.summary = 'Helpers to aid in the generation of ESC/POS templates.'
13
+ spec.description = <<-DESCRIPTION
14
+ Provides helpers to generate ESC/POS templates without having to write the hex commands
15
+ manually.
16
+ DESCRIPTION
17
+ spec.email = 'adrian_g171@hotmail.com'
18
+ spec.extra_rdoc_files = %w[LICENSE README.md]
19
+ spec.files = %w[
20
+ Gemfile
21
+ LICENSE
22
+ README.md
23
+ esc-pos.gemspec
24
+ lib/esc-pos.rb
25
+ lib/esc-pos/settings.rb
26
+ lib/esc-pos/version.rb
27
+ lib/esc-pos/specifications/base.rb
28
+ lib/esc-pos/specifications/epson.rb
29
+ lib/esc-pos/specifications/epson/tm_u220.rb
30
+ ]
31
+ spec.homepage = 'https://github.com/adrian-gomez/esc-pos'
32
+ spec.licenses = %w[MIT]
33
+ spec.require_paths = %w[lib]
34
+
35
+ end
@@ -0,0 +1,4 @@
1
+ require_relative 'esc-pos/settings'
2
+ require_relative 'esc-pos/specifications/base'
3
+ require_relative 'esc-pos/specifications/epson'
4
+ require_relative 'esc-pos/specifications/epson/tm_u220'
@@ -0,0 +1,17 @@
1
+ module ESC_POS
2
+ module Settings
3
+
4
+ def self.add_option(name, default_value)
5
+ define_singleton_method(name) do
6
+ instance_variable_get("@#{name}") || default_value
7
+ end
8
+
9
+ define_singleton_method("#{name}=") do |value|
10
+ instance_variable_set("@#{name}", value)
11
+ end
12
+ end
13
+
14
+ add_option(:templates_path, 'views/esc_pos')
15
+
16
+ end
17
+ end
@@ -0,0 +1,88 @@
1
+ require 'erb'
2
+
3
+ module ESC_POS
4
+ module Specifications
5
+
6
+ class Base
7
+
8
+ def self.specifications
9
+ @@specifications ||= {}
10
+ end
11
+
12
+ def self.set(name, value)
13
+ specifications[name] = value
14
+ end
15
+
16
+ def initialize
17
+ raise NoMethodError, 'This is just a base class, use it to create custom specifications.'
18
+ end
19
+
20
+ def text(txt, options = {})
21
+ font = options.fetch(:font, :font_b)
22
+ color = options.fetch(:color, :color_black)
23
+
24
+ formatted_text = ''
25
+ formatted_text << set_font(font)
26
+ formatted_text << set_alignment(options[:align_type]) if options[:align_type]
27
+ formatted_text << set_color(color)
28
+ formatted_text << txt if txt
29
+ end
30
+
31
+ def reset_printer
32
+ "#{get_value(:esc_code)}#{get_value(:reset_printer_code)}"
33
+ end
34
+
35
+ def feed_lines(lines)
36
+ return '' if lines == 1
37
+
38
+ "#{get_value(:esc_code)}\x64" << (lines - 1).chr
39
+ end
40
+
41
+ def render(options = {})
42
+ template_filename = options.fetch(:template, self.class.to_s.underscore)
43
+
44
+ template = File.read(File.join(Settings.templates_path, "#{template_filename}.esc_pos.erb"))
45
+ erb = ERB.new(template, 0, '%<>-')
46
+ erb.result(binding)
47
+ end
48
+
49
+ def set_font(font)
50
+ "#{get_value(:esc_code)}#{get_value(:font_selector_code)}#{get_value(font)}"
51
+ end
52
+
53
+ def set_alignment(alignment)
54
+ "#{get_value(:esc_code)}#{get_value(:alignment_selector_code)}#{get_value(alignment)}"
55
+ end
56
+
57
+ def set_color(color)
58
+ "#{get_value(:esc_code)}#{get_value(:color_selector_code)}#{get_value(color)}"
59
+ end
60
+
61
+ def split_line(char = '-')
62
+ text(char * get_value(:width), :font => :font_b)
63
+ end
64
+
65
+ def go_to_cut
66
+ feed_lines(get_value(:lines_to_cut_line))
67
+ end
68
+
69
+ def go_to_cut_and_cut(spaces_after = 0)
70
+ "#{get_value(:gs_code)}V#{65.chr}#{spaces_after}\r"
71
+ end
72
+
73
+ def cut_paper(partial_cut = false)
74
+ if partial_cut
75
+ "#{get_value(:esc_code)}m"
76
+ else
77
+ "#{get_value(:esc_code)}i"
78
+ end
79
+ end
80
+
81
+ def get_value(key)
82
+ self.class.specifications[key]
83
+ end
84
+
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,34 @@
1
+ require_relative 'base'
2
+
3
+ module ESC_POS
4
+ module Specifications
5
+
6
+ class Epson < Base
7
+
8
+ set :esc_code, "\x1B"
9
+ set :gs_code, "\x1D"
10
+ set :fs_code, "\x1C"
11
+
12
+ set :reset_printer_code, '@'
13
+ set :font_selector_code, 'M'
14
+ set :alignment_selector_code, 'a'
15
+ set :color_selector_code, 'r'
16
+
17
+ set :width, 42
18
+ set :lines_to_cut_line, 7
19
+ set :spaces_to_end_page, 0
20
+
21
+ set :font_a, 0
22
+ set :font_b, 1
23
+
24
+ set :color_black, 0
25
+ set :color_red, 1
26
+
27
+ set :align_left, 0
28
+ set :align_center, 1
29
+ set :align_right, 2
30
+
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,16 @@
1
+ require_relative '../epson'
2
+
3
+ module ESC_POS
4
+ module Specifications
5
+ class Epson
6
+
7
+ class TM_U220 < Base
8
+
9
+ set :width, 40
10
+ set :spaces_to_end_page, 5
11
+
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ module ESC_POS
2
+
3
+ VERSION = '0.0.8'
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: esc-pos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.8
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Gomez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |2
14
+ Provides helpers to generate ESC/POS templates without having to write the hex commands
15
+ manually.
16
+ email: adrian_g171@hotmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - LICENSE
21
+ - README.md
22
+ files:
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - esc-pos.gemspec
27
+ - lib/esc-pos.rb
28
+ - lib/esc-pos/settings.rb
29
+ - lib/esc-pos/specifications/base.rb
30
+ - lib/esc-pos/specifications/epson.rb
31
+ - lib/esc-pos/specifications/epson/tm_u220.rb
32
+ - lib/esc-pos/version.rb
33
+ homepage: https://github.com/adrian-gomez/esc-pos
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 2.2.2
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Helpers to aid in the generation of ESC/POS templates.
57
+ test_files: []