prawn-label_sheet 0.1.0 → 0.2.0
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/dependabot.yml +7 -0
- data/.github/workflows/gem-push.yml +43 -0
- data/.rubocop.yml +3 -10
- data/.travis.yml +7 -6
- data/.yardopts +1 -0
- data/README.md +2 -1
- data/lib/prawn/label_sheet/configuration.rb +19 -18
- data/lib/prawn/label_sheet/version.rb +2 -1
- data/lib/prawn/label_sheet.rb +26 -31
- data/prawn-label_sheet.gemspec +5 -5
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d593ea89fd930b39f95de418c4164fbbf9fbf11308d9e6fe24d8d2febebeecf
|
4
|
+
data.tar.gz: 3fd4bf13ada22220777b107b3abb5bd4b8a60291c75f9d9617c1921727419f09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9755747c24dd0e22f744dea0e6483d4580712cf2741cf50d5a852b0bee75b52a47394d8644ffba65a9387cfed105b4951bb96c026d2967f4a66c8dea8377b243
|
7
|
+
data.tar.gz: 2189f582469ee7cb745ded23d3eecf865ffc1a2ab16c8ca6efb8b96f2d1db15a06a6d28a449d8abae41a6b1d054024378c0dd1e8ea9ee87adb4929f92daf09e1
|
@@ -0,0 +1,43 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
tags: [ 'v*.*.*' ]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
permissions:
|
12
|
+
contents: read
|
13
|
+
packages: write
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v3
|
17
|
+
- name: Set up Ruby 2.7
|
18
|
+
uses: actions/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: 2.7.x
|
21
|
+
|
22
|
+
- name: Publish to GPR
|
23
|
+
run: |
|
24
|
+
mkdir -p $HOME/.gem
|
25
|
+
touch $HOME/.gem/credentials
|
26
|
+
chmod 0600 $HOME/.gem/credentials
|
27
|
+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
28
|
+
gem build *.gemspec
|
29
|
+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem
|
30
|
+
env:
|
31
|
+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
|
32
|
+
OWNER: ${{ github.repository_owner }}
|
33
|
+
|
34
|
+
- name: Publish to RubyGems
|
35
|
+
run: |
|
36
|
+
mkdir -p $HOME/.gem
|
37
|
+
touch $HOME/.gem/credentials
|
38
|
+
chmod 0600 $HOME/.gem/credentials
|
39
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
40
|
+
gem build *.gemspec
|
41
|
+
gem push *.gem
|
42
|
+
env:
|
43
|
+
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
|
data/.rubocop.yml
CHANGED
@@ -2,11 +2,11 @@ inherit_gem:
|
|
2
2
|
relaxed-rubocop: .rubocop.yml
|
3
3
|
|
4
4
|
AllCops:
|
5
|
-
TargetRubyVersion: 2.
|
5
|
+
TargetRubyVersion: 2.7
|
6
6
|
|
7
|
-
Layout/
|
7
|
+
Layout/ArgumentAlignment:
|
8
8
|
EnforcedStyle: with_fixed_indentation
|
9
|
-
Layout/
|
9
|
+
Layout/ParameterAlignment:
|
10
10
|
EnforcedStyle: with_fixed_indentation
|
11
11
|
Layout/MultilineMethodCallIndentation:
|
12
12
|
EnforcedStyle: indented
|
@@ -16,10 +16,3 @@ Layout/MultilineOperationIndentation:
|
|
16
16
|
Metrics/BlockLength:
|
17
17
|
Exclude:
|
18
18
|
- example/**/*.rb
|
19
|
-
|
20
|
-
Style/TrivialAccessors:
|
21
|
-
Exclude:
|
22
|
-
- lib/prawn/label_sheet/configuration.rb
|
23
|
-
Style/Documentation:
|
24
|
-
Exclude:
|
25
|
-
- lib/prawn/label_sheet/configuration.rb
|
data/.travis.yml
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
---
|
2
|
-
|
2
|
+
os: linux
|
3
3
|
language: ruby
|
4
4
|
cache: bundler
|
5
5
|
rvm:
|
6
|
-
- 2.4
|
7
|
-
- 2.5.3
|
8
|
-
- 2.6
|
9
6
|
- 2.7
|
7
|
+
- 3.0
|
8
|
+
- 3.1
|
10
9
|
- ruby-head
|
11
|
-
|
10
|
+
jobs:
|
12
11
|
allow_failures:
|
13
12
|
- rvm: ruby-head
|
14
13
|
fast_finish: true
|
15
|
-
before_install:
|
14
|
+
before_install:
|
15
|
+
- gem update --system
|
16
|
+
- gem install bundler
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-m markdown - LICENSE.txt
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Prawn::LabelSheet
|
2
2
|
|
3
|
+
[](https://rubygems.org/gems/prawn-label_sheet)
|
3
4
|
[](https://app.codacy.com/manual/t.crouch/prawn-label_sheet?utm_source=github.com&utm_medium=referral&utm_content=tcrouch/prawn-label_sheet&utm_campaign=Badge_Grade_Dashboard)
|
4
5
|
[](http://inch-ci.org/github/tcrouch/prawn-label_sheet)
|
5
|
-
|
6
|
+
[](http://rubydoc.info/github/tcrouch/prawn-label_sheet)
|
6
7
|
|
7
8
|
Generate sets of labels or stickers using Prawn PDF.
|
8
9
|
|
@@ -6,6 +6,8 @@ module Prawn
|
|
6
6
|
class LabelSheet
|
7
7
|
# config options
|
8
8
|
class Configuration
|
9
|
+
# Default layout key
|
10
|
+
# @return [String] the default key
|
9
11
|
attr_accessor :default_layout
|
10
12
|
attr_writer :layouts
|
11
13
|
|
@@ -13,31 +15,30 @@ module Prawn
|
|
13
15
|
@default_layout = 'Avery7160'
|
14
16
|
end
|
15
17
|
|
16
|
-
#
|
18
|
+
# Layout definitions
|
19
|
+
#
|
20
|
+
# @return [{String => Hash}]
|
17
21
|
def layouts
|
18
22
|
@layouts ||= YAML.load_file(File.expand_path('layouts.yml', __dir__))
|
19
23
|
end
|
20
24
|
end
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
# @return [Prawn::LabelSheet::Configuration]
|
25
|
-
def self.config
|
26
|
-
@config ||= Configuration.new
|
27
|
-
end
|
26
|
+
class << self
|
27
|
+
attr_writer :config
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
# Current configuration
|
30
|
+
#
|
31
|
+
# @return [Prawn::LabelSheet::Configuration]
|
32
|
+
def config
|
33
|
+
@config ||= Configuration.new
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
36
|
+
# Modify configuration
|
37
|
+
#
|
38
|
+
# @yieldparam config [Prawn::LabelSheet::Configuration]
|
39
|
+
def configure
|
40
|
+
yield config
|
41
|
+
end
|
41
42
|
end
|
42
43
|
end
|
43
44
|
end
|
data/lib/prawn/label_sheet.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'prawn'
|
4
|
-
require 'polyfill'
|
5
4
|
require 'prawn/label_sheet/version'
|
6
5
|
require 'prawn/label_sheet/configuration'
|
7
6
|
|
@@ -15,37 +14,34 @@ module Prawn
|
|
15
14
|
class Error < StandardError; end
|
16
15
|
|
17
16
|
# Override Prawn::View#document
|
18
|
-
|
19
|
-
attr_reader :
|
20
|
-
|
21
|
-
using Polyfill(Hash: %w[#transform_keys])
|
17
|
+
attr_reader :document
|
18
|
+
attr_reader :layout
|
22
19
|
|
23
20
|
# Render and persist a set of label sheets
|
24
21
|
#
|
25
|
-
# @param
|
22
|
+
# @param filename [String] Name of output file
|
23
|
+
# @param labels (see #initialize)
|
26
24
|
# @param options (see #initialize)
|
25
|
+
# @yieldparam (see #initialize)
|
27
26
|
def self.generate(filename, labels, **options, &block)
|
28
|
-
pdf = new(labels, options, &block)
|
27
|
+
pdf = new(labels, **options, &block)
|
29
28
|
pdf.document.render_file(filename)
|
30
29
|
end
|
31
30
|
|
32
31
|
# @param labels [Enumerable] collection of labels
|
33
32
|
# @option options [String] :layout
|
34
|
-
# @option options [Proc, Integer] :break_on
|
33
|
+
# @option options [Proc, Integer, String] :break_on
|
35
34
|
# @option options [Prawn::Document] :document
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@
|
40
|
-
@document
|
41
|
-
# @document.on_page_create { self.instance_variable_set :@count, 0 }
|
35
|
+
# @yieldparam doc (see #make_label)
|
36
|
+
# @yieldparam item (see #make_label)
|
37
|
+
def initialize(labels, **options, &block)
|
38
|
+
@layout = setup_layout(options[:layout]).merge(info: options[:info])
|
39
|
+
@document = setup_document(options[:document], @layout)
|
42
40
|
|
43
41
|
@count = 0
|
44
42
|
@break_on = options[:break_on]
|
45
43
|
|
46
|
-
labels.each
|
47
|
-
make_label(label, options) { |pdf, item| yield pdf, item }
|
48
|
-
end
|
44
|
+
labels.each { |label| make_label(label, options, &block) }
|
49
45
|
end
|
50
46
|
|
51
47
|
# Generate individual label
|
@@ -57,9 +53,7 @@ module Prawn
|
|
57
53
|
def make_label(item, _options)
|
58
54
|
break_page if break_page?(item)
|
59
55
|
|
60
|
-
@document.grid(*gridref).bounding_box
|
61
|
-
yield @document, item
|
62
|
-
end
|
56
|
+
@document.grid(*gridref).bounding_box { yield @document, item }
|
63
57
|
@count += 1
|
64
58
|
end
|
65
59
|
|
@@ -70,7 +64,7 @@ module Prawn
|
|
70
64
|
# @param item [Proc, #[]]
|
71
65
|
# @return [Boolean]
|
72
66
|
def break_page?(item)
|
73
|
-
return unless @break_on
|
67
|
+
return false unless @break_on
|
74
68
|
|
75
69
|
val = @break_on.is_a?(Proc) ? @break_on.call(item) : item[@break_on]
|
76
70
|
return false if @last_val == val
|
@@ -99,21 +93,20 @@ module Prawn
|
|
99
93
|
r.divmod(@document.grid.columns)
|
100
94
|
end
|
101
95
|
|
96
|
+
# Extract definition & provide defaults for required keys
|
97
|
+
#
|
102
98
|
# @param layout_def [String, #to_h] layout definition or identifier
|
103
99
|
# @return [Hash]
|
104
|
-
# rubocop:disable Style/RescueModifier
|
105
100
|
def setup_layout(layout_def)
|
106
101
|
defs = resolve_layout(layout_def).slice(
|
107
102
|
'page_size', 'columns', 'rows',
|
108
103
|
'top_margin', 'bottom_margin',
|
109
104
|
'left_margin', 'right_margin',
|
110
105
|
'column_gutter', 'row_gutter'
|
111
|
-
)
|
112
|
-
|
113
|
-
|
114
|
-
}.merge!(defs.transform_keys { |key| key.to_sym rescue key })
|
106
|
+
).transform_keys(&:to_sym)
|
107
|
+
|
108
|
+
{ page_size: 'A4', top_margin: 40, left_margin: 20 }.merge!(defs)
|
115
109
|
end
|
116
|
-
# rubocop:enable Style/RescueModifier
|
117
110
|
|
118
111
|
# Lookup layout definition
|
119
112
|
#
|
@@ -127,11 +120,13 @@ module Prawn
|
|
127
120
|
end
|
128
121
|
|
129
122
|
# @param doc [Prawn::Document, nil]
|
123
|
+
# @param layout [Hash]
|
130
124
|
# @return [Prawn::Document]
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
|
125
|
+
def setup_document(doc, layout)
|
126
|
+
doc&.start_new_page(layout)
|
127
|
+
doc ||= Document.new layout
|
128
|
+
doc.define_grid layout
|
129
|
+
doc
|
135
130
|
end
|
136
131
|
|
137
132
|
# @return [Prawn::LabelSheet::Configuration]
|
data/prawn-label_sheet.gemspec
CHANGED
@@ -27,14 +27,14 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.bindir = 'exe'
|
28
28
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
29
|
spec.require_paths = ['lib']
|
30
|
-
spec.required_ruby_version = ">= 2.
|
30
|
+
spec.required_ruby_version = ">= 2.7.0"
|
31
31
|
|
32
|
-
spec.add_dependency '
|
32
|
+
spec.add_dependency 'matrix'
|
33
33
|
spec.add_dependency 'prawn'
|
34
34
|
|
35
35
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
36
|
-
spec.add_development_dependency 'rake', '~>
|
37
|
-
spec.add_development_dependency 'relaxed-rubocop', '~> 2.
|
36
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
37
|
+
spec.add_development_dependency 'relaxed-rubocop', '~> 2.5'
|
38
38
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
39
|
-
spec.add_development_dependency 'rubocop', '~>
|
39
|
+
spec.add_development_dependency 'rubocop', '~> 1.8'
|
40
40
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-label_sheet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Crouch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-10-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: matrix
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: prawn
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,28 +58,28 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '13.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '13.0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: relaxed-rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
75
|
+
version: '2.5'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '2.
|
82
|
+
version: '2.5'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: rspec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
103
|
+
version: '1.8'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
110
|
+
version: '1.8'
|
111
111
|
description: 'Generate sets of labels or stickers programmatically using Prawn PDF.
|
112
112
|
|
113
113
|
'
|
@@ -117,10 +117,13 @@ executables: []
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
+
- ".github/dependabot.yml"
|
121
|
+
- ".github/workflows/gem-push.yml"
|
120
122
|
- ".gitignore"
|
121
123
|
- ".rspec"
|
122
124
|
- ".rubocop.yml"
|
123
125
|
- ".travis.yml"
|
126
|
+
- ".yardopts"
|
124
127
|
- Gemfile
|
125
128
|
- LICENSE.txt
|
126
129
|
- README.md
|
@@ -144,15 +147,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
147
|
requirements:
|
145
148
|
- - ">="
|
146
149
|
- !ruby/object:Gem::Version
|
147
|
-
version: 2.
|
150
|
+
version: 2.7.0
|
148
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
152
|
requirements:
|
150
153
|
- - ">="
|
151
154
|
- !ruby/object:Gem::Version
|
152
155
|
version: '0'
|
153
156
|
requirements: []
|
154
|
-
|
155
|
-
rubygems_version: 2.7.6
|
157
|
+
rubygems_version: 3.1.6
|
156
158
|
signing_key:
|
157
159
|
specification_version: 4
|
158
160
|
summary: Generate PDF sets of labels & stickers.
|