labrat 1.2.1 → 1.2.3
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 +4 -4
- data/.github/workflows/main.yml +27 -0
- data/.github/workflows/ruby.yml +38 -0
- data/.rubocop.yml +177 -2
- data/Gemfile +11 -5
- data/Gemfile.lock +108 -70
- data/README.org +52 -39
- data/Rakefile +1 -1
- data/bin/labrat +0 -1
- data/labrat.gemspec +5 -13
- data/lib/config_files/labeldb.yml +17 -0
- data/lib/labrat/arg_parser.rb +202 -96
- data/lib/labrat/config.rb +32 -12
- data/lib/labrat/hash.rb +2 -8
- data/lib/labrat/label.rb +28 -12
- data/lib/labrat/label_db.rb +2 -2
- data/lib/labrat/options.rb +48 -22
- data/lib/labrat/read_files.rb +3 -2
- data/lib/labrat/version.rb +1 -1
- data/lib/labrat.rb +1 -0
- data/texlabels/sample.pdf +0 -0
- data/texlabels/sample.tex +9 -5
- metadata +17 -116
- data/texlabels/sample.synctex.gz +0 -0
data/lib/labrat/label.rb
CHANGED
@@ -40,13 +40,22 @@ module Labrat
|
|
40
40
|
bpm = ops.right_page_margin
|
41
41
|
end
|
42
42
|
out_file = File.expand_path(ops.out_file)
|
43
|
-
Prawn::Document.generate(
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
Prawn::Document.generate(
|
44
|
+
out_file,
|
45
|
+
page_size: [ops.page_width, ops.page_height],
|
46
|
+
left_margin: lpm,
|
47
|
+
right_margin: rpm,
|
48
|
+
top_margin: tpm,
|
49
|
+
bottom_margin: bpm,
|
50
|
+
page_layout: layout,
|
51
|
+
) do |pdf|
|
47
52
|
# Define a grid with each grid box to be used for a single label.
|
48
|
-
pdf.define_grid(
|
49
|
-
|
53
|
+
pdf.define_grid(
|
54
|
+
rows: ops.rows,
|
55
|
+
columns: ops.columns,
|
56
|
+
row_gutter: ops.row_gap,
|
57
|
+
column_gutter: ops.column_gap,
|
58
|
+
)
|
50
59
|
if ops.verbose
|
51
60
|
warn "Page dimensions:"
|
52
61
|
warn " [pg_wd, pg_ht] = [#{ops.page_width.round(2)}pt,#{ops.page_height.round(2)}pt]"
|
@@ -62,7 +71,7 @@ module Labrat
|
|
62
71
|
if ops.label != ops.raw_label
|
63
72
|
lab_text += "\n(#{ops.label})"
|
64
73
|
end
|
65
|
-
self.texts = (1..(ops.rows * ops.columns)).map {|n| "#{n}\n#{lab_text}"}
|
74
|
+
self.texts = (1..(ops.rows * ops.columns)).map { |n| "#{n}\n#{lab_text}" }
|
66
75
|
ops.font_name = 'Helvetica'
|
67
76
|
ops.font_style = 'bold'
|
68
77
|
ops.font_size = 11
|
@@ -82,9 +91,15 @@ module Labrat
|
|
82
91
|
box_x = ops.left_pad + ops.delta_x
|
83
92
|
box_y = ops.bottom_pad + box_ht + ops.delta_y
|
84
93
|
pdf.font ops.font_name, style: ops.font_style, size: ops.font_size.to_f
|
85
|
-
pdf.text_box(
|
86
|
-
|
87
|
-
|
94
|
+
pdf.text_box(
|
95
|
+
text,
|
96
|
+
width: box_wd,
|
97
|
+
height: box_ht,
|
98
|
+
align: ops.h_align,
|
99
|
+
valign: ops.v_align,
|
100
|
+
overflow: :truncate,
|
101
|
+
at: [box_x, box_y],
|
102
|
+
)
|
88
103
|
if ops.verbose && !lab_dims_reported
|
89
104
|
warn "Label text box dimensions:"
|
90
105
|
warn " [box_wd, box_ht] = [#{box_wd.round(2)}pt,#{box_ht.round(2)}pt]"
|
@@ -94,7 +109,7 @@ module Labrat
|
|
94
109
|
lab_dims_reported = true
|
95
110
|
end
|
96
111
|
if ops.verbose
|
97
|
-
warn "Label
|
112
|
+
warn "Label ##{(k % lpp) + 1} on page #{page_num(k)} at row #{row + 1}, column #{col + 1}:"
|
98
113
|
warn '-------------------'
|
99
114
|
warn text
|
100
115
|
warn '-------------------'
|
@@ -149,8 +164,9 @@ module Labrat
|
|
149
164
|
# Should we emit a new page at this point?
|
150
165
|
def needs_new_page?(k, last_k)
|
151
166
|
return false if k == last_k
|
167
|
+
|
152
168
|
r, c = row_col(k + 1)
|
153
|
-
|
169
|
+
r + 1 == ops.rows && c + 1 == ops.columns
|
154
170
|
end
|
155
171
|
|
156
172
|
# Would we just be printing blank labels?
|
data/lib/labrat/label_db.rb
CHANGED
@@ -10,8 +10,8 @@ module Labrat
|
|
10
10
|
# Read in the Labrat database of label settings, merging system and user
|
11
11
|
# databases.
|
12
12
|
def self.read(dir_prefix: '')
|
13
|
-
|
14
|
-
|
13
|
+
reader = FatConfig::Reader.new('labrat', root_prefix: dir_prefix)
|
14
|
+
self.db = reader.read('labeldb')
|
15
15
|
end
|
16
16
|
|
17
17
|
# Return a hash of config settings for the label named by labname.
|
data/lib/labrat/options.rb
CHANGED
@@ -6,18 +6,44 @@ module Labrat
|
|
6
6
|
# and perhaps environment. An Options instance can be handed off to the
|
7
7
|
# label-printing objects to inform its formatting, printing, etc.
|
8
8
|
class Options
|
9
|
-
attr_accessor :label,
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
9
|
+
attr_accessor :label,
|
10
|
+
:raw_label,
|
11
|
+
:page_width,
|
12
|
+
:page_height,
|
13
|
+
:left_page_margin,
|
14
|
+
:right_page_margin,
|
15
|
+
:top_page_margin,
|
16
|
+
:bottom_page_margin,
|
17
|
+
:rows,
|
18
|
+
:columns,
|
19
|
+
:row_gap,
|
20
|
+
:column_gap,
|
21
|
+
:landscape,
|
22
|
+
:start_label,
|
23
|
+
:grid,
|
24
|
+
:h_align,
|
25
|
+
:v_align,
|
26
|
+
:left_pad,
|
27
|
+
:right_pad,
|
28
|
+
:top_pad,
|
29
|
+
:bottom_pad,
|
30
|
+
:delta_x,
|
31
|
+
:delta_y,
|
32
|
+
:font_name,
|
33
|
+
:font_style,
|
34
|
+
:font_size,
|
35
|
+
:in_file,
|
36
|
+
:nl_sep,
|
37
|
+
:label_sep,
|
38
|
+
:copies,
|
39
|
+
:printer,
|
40
|
+
:out_file,
|
41
|
+
:print_command,
|
42
|
+
:view_command,
|
43
|
+
:view,
|
44
|
+
:template,
|
45
|
+
:verbose,
|
46
|
+
:msg
|
21
47
|
|
22
48
|
# Initialize with an optional hash of default values for the attributes.
|
23
49
|
def initialize(**init)
|
@@ -73,15 +99,15 @@ module Labrat
|
|
73
99
|
default_config.report("Default settings") if verbose
|
74
100
|
|
75
101
|
# Config files
|
76
|
-
|
77
|
-
file_config.
|
102
|
+
config_reader = FatConfig::Reader.new('labrat', xdg: true)
|
103
|
+
file_config = config_reader.read('labrat', verbose: verbose)
|
78
104
|
file_options = Labrat::ArgParser.new.parse(file_config, prior: default_config, verbose: verbose)
|
79
105
|
|
80
106
|
# Command-line
|
81
107
|
if verbose
|
82
|
-
warn "
|
108
|
+
warn "\nCommand-line:"
|
83
109
|
args.each do |arg|
|
84
|
-
warn arg
|
110
|
+
warn arg
|
85
111
|
end
|
86
112
|
warn ""
|
87
113
|
end
|
@@ -98,27 +124,27 @@ module Labrat
|
|
98
124
|
# Allow hash-like assignment to attributes. This allows an Options object
|
99
125
|
# to be used, for example, in the OptionParser#parse :into parameter.
|
100
126
|
def []=(att, val)
|
101
|
-
att = att.to_s.
|
102
|
-
send("#{att}=", val)
|
127
|
+
att = att.to_s.tr('-', '_')
|
128
|
+
send(:"#{att}=", val)
|
103
129
|
end
|
104
130
|
|
105
131
|
# Allow hash-like access to attributes. This allows an Options object
|
106
132
|
# to be used, for example, in the OptionParser#parse :into parameter.
|
107
133
|
def [](att)
|
108
|
-
att = att.to_s.
|
134
|
+
att = att.to_s.tr('-', '_')
|
109
135
|
send(att.to_s)
|
110
136
|
end
|
111
137
|
|
112
138
|
# For testing, return an Array of the attributes as symbols.
|
113
139
|
def self.attrs
|
114
140
|
instance_methods(false).grep(/\A[a-z_]+=\Z/)
|
115
|
-
.map { |a| a.to_s.
|
141
|
+
.map { |a| a.to_s.delete_suffix('=').to_sym }
|
116
142
|
end
|
117
143
|
|
118
144
|
# For testing, return an Array of the flags-form of the attributes, i.e.,
|
119
145
|
# with the underscores, _, replaced with hyphens.
|
120
146
|
def self.flags
|
121
|
-
attrs.map { |a| a.
|
147
|
+
attrs.map { |a| a.tr('_', '-') }
|
122
148
|
end
|
123
149
|
|
124
150
|
# Return a hash of the values in this Options object. This is the
|
@@ -174,7 +200,7 @@ module Labrat
|
|
174
200
|
# an Options object.
|
175
201
|
def merge!(hsh)
|
176
202
|
# Convert any separator hyphens in the hash keys to underscores
|
177
|
-
hsh = hsh.to_hash.transform_keys { |key| key.to_s.
|
203
|
+
hsh = hsh.to_hash.transform_keys { |key| key.to_s.tr('-', '_').to_sym }
|
178
204
|
new_hash = to_hash.merge(hsh)
|
179
205
|
new_hash.each_pair do |k, val|
|
180
206
|
setter = "#{k}=".to_sym
|
data/lib/labrat/read_files.rb
CHANGED
@@ -9,6 +9,7 @@ module Labrat
|
|
9
9
|
unless File.readable?(fname)
|
10
10
|
raise "Cannot open label file '#{ofname}' for reading"
|
11
11
|
end
|
12
|
+
|
12
13
|
File.open(fname)
|
13
14
|
else
|
14
15
|
$stdin
|
@@ -17,9 +18,9 @@ module Labrat
|
|
17
18
|
texts = []
|
18
19
|
label = nil
|
19
20
|
file.each do |line|
|
20
|
-
next if
|
21
|
+
next if /\A\s*#/.match?(line)
|
21
22
|
|
22
|
-
if
|
23
|
+
if /\A\s*\z/.match?(line)
|
23
24
|
# At blank line record any accumulated label into texts, but remove
|
24
25
|
# the nlsep from the end.
|
25
26
|
if label
|
data/lib/labrat/version.rb
CHANGED
data/lib/labrat.rb
CHANGED
data/texlabels/sample.pdf
CHANGED
Binary file
|
data/texlabels/sample.tex
CHANGED
@@ -1,17 +1,21 @@
|
|
1
1
|
\documentclass{article}
|
2
2
|
|
3
3
|
\usepackage{geometry}
|
4
|
-
\geometry{paperwidth=25mm,paperheight=87mm,landscape}
|
4
|
+
\geometry{paperwidth=25mm,paperheight=87mm,landscape,left=1mm,right=1mm,top=1mm,bottom=1mm}
|
5
5
|
\renewcommand*\familydefault{\sfdefault}
|
6
6
|
\usepackage{tgheros}
|
7
|
+
\usepackage{beton}
|
7
8
|
|
8
9
|
\begin{document}
|
9
|
-
\vfill
|
10
|
+
\vfill\hbox{}
|
10
11
|
\begin{center}
|
12
|
+
% \footnotesize
|
13
|
+
\large
|
11
14
|
\textbf{ABCDEFGHIJKLMNOPQRSTUVWXYZ}\\
|
12
15
|
$\int_0^x e^{-t\pi} dx$\\
|
13
|
-
0123456789abcdefghijklmnopqrstuvwxyz\\
|
14
|
-
\textbf{0123456789abcdefghijklmnopqrstuvwxyz}
|
16
|
+
% 0123456789abcdefghijklmnopqrstuvwxyz\\
|
17
|
+
% \textbf{0123456789abcdefghijklmnopqrstuvwxyz}\\
|
18
|
+
% $c^2 - a^2 + b^2$\\
|
15
19
|
\end{center}
|
16
|
-
\vfill
|
20
|
+
\vfill\hbox{}
|
17
21
|
\end{document}
|
metadata
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: labrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel E. Doherty
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-03-20 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
13
|
+
name: activesupport
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
@@ -25,33 +24,19 @@ dependencies:
|
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '0'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '2.0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '2.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activesupport
|
27
|
+
name: fat_config
|
43
28
|
requirement: !ruby/object:Gem::Requirement
|
44
29
|
requirements:
|
45
30
|
- - ">="
|
46
31
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
32
|
+
version: 0.4.2
|
48
33
|
type: :runtime
|
49
34
|
prerelease: false
|
50
35
|
version_requirements: !ruby/object:Gem::Requirement
|
51
36
|
requirements:
|
52
37
|
- - ">="
|
53
38
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
39
|
+
version: 0.4.2
|
55
40
|
- !ruby/object:Gem::Dependency
|
56
41
|
name: fat_core
|
57
42
|
requirement: !ruby/object:Gem::Requirement
|
@@ -67,97 +52,13 @@ dependencies:
|
|
67
52
|
- !ruby/object:Gem::Version
|
68
53
|
version: '0'
|
69
54
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: pry
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: simplecov
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - ">="
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - ">="
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: debug
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - ">="
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 1.0.0
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - ">="
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 1.0.0
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: rubocop-performance
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - ">="
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - ">="
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0'
|
153
|
-
- !ruby/object:Gem::Dependency
|
154
|
-
name: rubocop-shopify
|
55
|
+
name: matrix
|
155
56
|
requirement: !ruby/object:Gem::Requirement
|
156
57
|
requirements:
|
157
58
|
- - ">="
|
158
59
|
- !ruby/object:Gem::Version
|
159
60
|
version: '0'
|
160
|
-
type: :
|
61
|
+
type: :runtime
|
161
62
|
prerelease: false
|
162
63
|
version_requirements: !ruby/object:Gem::Requirement
|
163
64
|
requirements:
|
@@ -165,19 +66,19 @@ dependencies:
|
|
165
66
|
- !ruby/object:Gem::Version
|
166
67
|
version: '0'
|
167
68
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
69
|
+
name: prawn
|
169
70
|
requirement: !ruby/object:Gem::Requirement
|
170
71
|
requirements:
|
171
|
-
- - "
|
72
|
+
- - "~>"
|
172
73
|
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :
|
74
|
+
version: '2.0'
|
75
|
+
type: :runtime
|
175
76
|
prerelease: false
|
176
77
|
version_requirements: !ruby/object:Gem::Requirement
|
177
78
|
requirements:
|
178
|
-
- - "
|
79
|
+
- - "~>"
|
179
80
|
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
81
|
+
version: '2.0'
|
181
82
|
description: |2+
|
182
83
|
|
183
84
|
Labrat is a linux command-line program for quickly printing labels. Labrat uses
|
@@ -202,6 +103,8 @@ extensions: []
|
|
202
103
|
extra_rdoc_files: []
|
203
104
|
files:
|
204
105
|
- ".envrc"
|
106
|
+
- ".github/workflows/main.yml"
|
107
|
+
- ".github/workflows/ruby.yml"
|
205
108
|
- ".gitignore"
|
206
109
|
- ".rspec"
|
207
110
|
- ".rubocop.yml"
|
@@ -238,7 +141,6 @@ files:
|
|
238
141
|
- lib/lisp/labrat.el
|
239
142
|
- texlabels/sample.dvi
|
240
143
|
- texlabels/sample.pdf
|
241
|
-
- texlabels/sample.synctex.gz
|
242
144
|
- texlabels/sample.tex
|
243
145
|
homepage: http://github.com/ddoherty03/labrat
|
244
146
|
licenses: []
|
@@ -261,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
163
|
- !ruby/object:Gem::Version
|
262
164
|
version: '0'
|
263
165
|
requirements: []
|
264
|
-
rubygems_version: 3.
|
265
|
-
signing_key:
|
166
|
+
rubygems_version: 3.6.3
|
266
167
|
specification_version: 4
|
267
168
|
summary: Command-line and Emacs label print software.
|
268
169
|
test_files: []
|
data/texlabels/sample.synctex.gz
DELETED
Binary file
|