outwood_labels 0.1.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 +7 -0
- data/.github/workflows/gem-push.yml +43 -0
- data/.github/workflows/ruby.yml +31 -0
- data/.gitignore +14 -0
- data/.rspec +3 -0
- data/.rubocop.yml +12 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +45 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +10 -0
- data/exe/outwood_labels +9 -0
- data/lib/outwood_labels/callable.rb +16 -0
- data/lib/outwood_labels/cli.rb +66 -0
- data/lib/outwood_labels/csv_loader.rb +28 -0
- data/lib/outwood_labels/file_namer.rb +21 -0
- data/lib/outwood_labels/generate.rb +37 -0
- data/lib/outwood_labels/options.rb +66 -0
- data/lib/outwood_labels/options_validator.rb +43 -0
- data/lib/outwood_labels/template/base.rb +34 -0
- data/lib/outwood_labels/template/email_password.rb +89 -0
- data/lib/outwood_labels/template/email_password_initial.rb +22 -0
- data/lib/outwood_labels/template.rb +10 -0
- data/lib/outwood_labels/version.rb +5 -0
- data/lib/outwood_labels.rb +41 -0
- data/outwood_labels.gemspec +32 -0
- metadata +126 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 909ec8c91f83b4f1346d461fa33e5d8ba0cc28d63373f3671506f1d82b43f0de
|
|
4
|
+
data.tar.gz: 265635a5dcf6036e7240ff927bf6b558d314337b4bf213bfba58dbd22352e59a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b979ddd2229525efbc24082b85b89041d8c3498303092186cd61f19e76a3ece3d7bb6ca7c6b6d7361e6cef6857540892fe7ec57c05722c06da6ccf9e92f953cb
|
|
7
|
+
data.tar.gz: faf363585a21f7e609a0b9a8738afc49fa07bf8168ba6d5b965ae8ba144a99e525669ee74e50837cfb8632b62137b8c927d2756fc13bd2146374aaf09dd81f69
|
|
@@ -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.6
|
|
18
|
+
uses: actions/setup-ruby@v1
|
|
19
|
+
with:
|
|
20
|
+
ruby-version: 2.6.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}}"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
|
2
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
|
3
|
+
|
|
4
|
+
name: Ruby
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ "main" ]
|
|
9
|
+
pull_request:
|
|
10
|
+
branches: [ "main" ]
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
test:
|
|
17
|
+
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
strategy:
|
|
20
|
+
matrix:
|
|
21
|
+
ruby-version: ['2.7', '3.0', '3.1']
|
|
22
|
+
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v3
|
|
25
|
+
- name: Set up Ruby
|
|
26
|
+
uses: ruby/setup-ruby@v1
|
|
27
|
+
with:
|
|
28
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
29
|
+
bundler-cache: true
|
|
30
|
+
- name: Run tests
|
|
31
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
inherit_from:
|
|
2
|
+
- https://relaxed.ruby.style/rubocop.yml
|
|
3
|
+
|
|
4
|
+
AllCops:
|
|
5
|
+
TargetRubyVersion: 2.7
|
|
6
|
+
|
|
7
|
+
Layout/ArgumentAlignment:
|
|
8
|
+
EnforcedStyle: with_fixed_indentation
|
|
9
|
+
Layout/MultilineMethodCallIndentation:
|
|
10
|
+
EnforcedStyle: indented
|
|
11
|
+
Layout/MultilineOperationIndentation:
|
|
12
|
+
EnforcedStyle: indented
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-2022 Outwood Grange Academies Trust
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# OutwoodLabels
|
|
2
|
+
|
|
3
|
+
Generate stickers from CSV data.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'outwood_labels'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
```shell
|
|
16
|
+
$ bundle
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it yourself as:
|
|
20
|
+
|
|
21
|
+
```shell
|
|
22
|
+
$ gem install outwood_labels
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```shell
|
|
28
|
+
$ outwood_labels infile.csv
|
|
29
|
+
|
|
30
|
+
$ cat infile.csv | outwood_labels -o outfile.csv
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Development
|
|
34
|
+
|
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
36
|
+
|
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
38
|
+
|
|
39
|
+
## Contributing
|
|
40
|
+
|
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/outwood/outwood_labels.
|
|
42
|
+
|
|
43
|
+
## License
|
|
44
|
+
|
|
45
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "outwood_labels"
|
|
6
|
+
|
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
9
|
+
|
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
11
|
+
# require "pry"
|
|
12
|
+
# Pry.start
|
|
13
|
+
|
|
14
|
+
require "irb"
|
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/outwood_labels
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'outwood_labels/options'
|
|
4
|
+
require 'outwood_labels/file_namer'
|
|
5
|
+
require 'outwood_labels/csv_loader'
|
|
6
|
+
require 'csv'
|
|
7
|
+
|
|
8
|
+
module OutwoodLabels
|
|
9
|
+
class CLI
|
|
10
|
+
STATUS_SUCCESS = 0
|
|
11
|
+
STATUS_ERROR = 1
|
|
12
|
+
|
|
13
|
+
def initialize
|
|
14
|
+
@options = {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# @return [Integer] status
|
|
18
|
+
def run(args = ARGV, input = ARGF)
|
|
19
|
+
@options = Options.call(args)
|
|
20
|
+
|
|
21
|
+
option_actions || write_csv(input)
|
|
22
|
+
|
|
23
|
+
STATUS_SUCCESS
|
|
24
|
+
rescue OutwoodLabels::Error,
|
|
25
|
+
OutwoodLabels::OptionArgumentError,
|
|
26
|
+
OptionParser::InvalidOption,
|
|
27
|
+
OptionParser::MissingArgument => e
|
|
28
|
+
warn e.message
|
|
29
|
+
STATUS_ERROR
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
private
|
|
33
|
+
|
|
34
|
+
def write_csv(input)
|
|
35
|
+
output = @options[:output_path] || FileNamer.call("labels")
|
|
36
|
+
template = OutwoodLabels[@options[:style]]
|
|
37
|
+
|
|
38
|
+
data = CsvLoader.call(input.to_io, template, @options.fetch(:headers, true))
|
|
39
|
+
template ||= detect_template(data)
|
|
40
|
+
Generate.call(data, output, template, @options)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def detect_template(data)
|
|
44
|
+
template = OutwoodLabels.infer_template(data.headers)
|
|
45
|
+
raise Error, "No template found" unless template
|
|
46
|
+
|
|
47
|
+
warn "Inferred template: #{template.name}"
|
|
48
|
+
template
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def option_actions
|
|
52
|
+
return false if (Options::EXIT_ACTIONS & @options.keys).empty?
|
|
53
|
+
|
|
54
|
+
list_styles if @options[:list]
|
|
55
|
+
puts OutwoodLabels::VERSION.to_s if @options[:version]
|
|
56
|
+
true
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def list_styles
|
|
60
|
+
OutwoodLabels.default_mapping.reverse_each do |k, v|
|
|
61
|
+
puts "#{k}:"
|
|
62
|
+
puts v.columns.join(',').prepend(' ')
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OutwoodLabels
|
|
4
|
+
class CsvLoader
|
|
5
|
+
include Callable
|
|
6
|
+
|
|
7
|
+
# @param [IO]
|
|
8
|
+
# @param template [Template::Base]
|
|
9
|
+
# @param has_headers [Boolean]
|
|
10
|
+
def initialize(io, template, has_headers)
|
|
11
|
+
@io = io
|
|
12
|
+
@template = template
|
|
13
|
+
@has_headers = has_headers
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @return [CSV]
|
|
17
|
+
# @raise [Error] when no template or headers are given
|
|
18
|
+
def call
|
|
19
|
+
raise Error, "Missing template" unless @template || @has_headers
|
|
20
|
+
|
|
21
|
+
return CSV.new(@io, headers: @template.headers) unless @has_headers
|
|
22
|
+
|
|
23
|
+
data = CSV.new @io, headers: true, return_headers: true
|
|
24
|
+
data.shift
|
|
25
|
+
data
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OutwoodLabels
|
|
4
|
+
class FileNamer
|
|
5
|
+
include Callable
|
|
6
|
+
|
|
7
|
+
# @param root [String]
|
|
8
|
+
def initialize(root)
|
|
9
|
+
@root = root
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @return [String]
|
|
13
|
+
def call
|
|
14
|
+
return "#{@root}.pdf" unless File.exist?("#{@root}.pdf")
|
|
15
|
+
|
|
16
|
+
base_name = "#{@root}-1"
|
|
17
|
+
base_name = base_name.next while File.exist?("#{base_name}.pdf")
|
|
18
|
+
"#{base_name}.pdf"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'csv'
|
|
4
|
+
require 'prawn/label_sheet'
|
|
5
|
+
|
|
6
|
+
module OutwoodLabels
|
|
7
|
+
class Generate
|
|
8
|
+
include Callable
|
|
9
|
+
|
|
10
|
+
# @param data [CSV]
|
|
11
|
+
# @param outfile [String]
|
|
12
|
+
# @param template [OutwoodLabels::Template::Base]
|
|
13
|
+
def initialize(data, outfile, template, config = {})
|
|
14
|
+
@config = config
|
|
15
|
+
@data = data
|
|
16
|
+
@outfile = outfile
|
|
17
|
+
@template = template
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Generate PDF and write to disk
|
|
21
|
+
# @raise [Error] when required columns are missing
|
|
22
|
+
def call
|
|
23
|
+
check_header if @template
|
|
24
|
+
config = @config.merge({ layout: @template.layout })
|
|
25
|
+
labels = Prawn::LabelSheet.new @data, **config, &@template.method(:evaluate)
|
|
26
|
+
labels.document.render_file(@outfile)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def check_header
|
|
32
|
+
return if @template.valid_for?(@data.headers)
|
|
33
|
+
|
|
34
|
+
raise Error, "Required columns: #{@template.columns.join(',')}"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'optparse'
|
|
4
|
+
require 'outwood_labels/options_validator'
|
|
5
|
+
|
|
6
|
+
module OutwoodLabels
|
|
7
|
+
class OptionArgumentError < StandardError; end
|
|
8
|
+
|
|
9
|
+
class Options
|
|
10
|
+
include Callable
|
|
11
|
+
|
|
12
|
+
EXIT_ACTIONS = %i[version list].freeze
|
|
13
|
+
|
|
14
|
+
# @param cli_args [<String>]
|
|
15
|
+
def initialize(cli_args)
|
|
16
|
+
@args = cli_args
|
|
17
|
+
@options = {}
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# @return [{String => Object}]
|
|
21
|
+
def call
|
|
22
|
+
define_options.parse!(@args)
|
|
23
|
+
OptionsValidator.call(@options)
|
|
24
|
+
|
|
25
|
+
@options
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
private
|
|
29
|
+
|
|
30
|
+
def define_options
|
|
31
|
+
OptionParser.new do |opts|
|
|
32
|
+
opts.banner = "Usage: #{$PROGRAM_NAME} [OPTIONS]"
|
|
33
|
+
opts.separator ''
|
|
34
|
+
opts.separator 'OPTIONS'
|
|
35
|
+
|
|
36
|
+
opts.on('-o', '--out FILE', 'Output file') do |opt|
|
|
37
|
+
@options[:output_path] = opt
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
opts.on('--[no-]headers', 'Expect a header row') do |opt|
|
|
41
|
+
@options[:headers] = opt
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
opts.on('-b', '--break BREAK', 'Break column') do |opt|
|
|
45
|
+
@options[:break_on] = opt
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
opts.on('-s', '--style NAME', 'Label template') do |opt|
|
|
49
|
+
@options[:style] = opt
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
opts.on('-d', '--debug') do |opt|
|
|
53
|
+
@options[:debug] = opt
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
opts.on('--list', 'List templates') do |opt|
|
|
57
|
+
@options[:list] = opt
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
opts.on('--version') do |opt|
|
|
61
|
+
@options[:version] = opt
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OutwoodLabels
|
|
4
|
+
class OptionsValidator
|
|
5
|
+
include Callable
|
|
6
|
+
|
|
7
|
+
# @param opts [{Symbol => Object}]
|
|
8
|
+
def initialize(opts)
|
|
9
|
+
@options = opts
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# @raise [OptionArgumentError] on errors
|
|
13
|
+
# @return [Boolean]
|
|
14
|
+
def call
|
|
15
|
+
validate_compatibility
|
|
16
|
+
validate_values
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def validate_values
|
|
23
|
+
return true unless @options.key?(:style) && !OutwoodLabels[@options[:style]]
|
|
24
|
+
|
|
25
|
+
raise OptionArgumentError, 'Unknown style'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def validate_compatibility
|
|
29
|
+
if !@options.fetch(:headers, true) && !@options[:style]
|
|
30
|
+
raise OptionArgumentError, 'Style must be specified'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
return true if exclusive_options.size <= 1
|
|
34
|
+
|
|
35
|
+
raise OptionArgumentError, 'Incompatible options: ' \
|
|
36
|
+
"#{exclusive_options.join(', ')}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def exclusive_options
|
|
40
|
+
@exclusive_options ||= @options.keys & Options::EXIT_ACTIONS
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OutwoodLabels
|
|
4
|
+
module Template
|
|
5
|
+
class Base
|
|
6
|
+
include Callable
|
|
7
|
+
|
|
8
|
+
class << self
|
|
9
|
+
attr_reader :columns, :name, :layout
|
|
10
|
+
|
|
11
|
+
# @param name [String] template name
|
|
12
|
+
def template_name(name)
|
|
13
|
+
@name = name
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @param columns [Array<String>] required column names
|
|
17
|
+
def accept_columns(*columns)
|
|
18
|
+
@columns = columns
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @param layout [String] label page layout
|
|
22
|
+
def page_layout(layout)
|
|
23
|
+
@layout = layout
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# @param columns [Array<String>] verify required columns are present
|
|
27
|
+
# @return [Boolean] true when columns are present
|
|
28
|
+
def valid_for?(columns)
|
|
29
|
+
(@columns - columns).empty?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OutwoodLabels
|
|
4
|
+
module Template
|
|
5
|
+
class EmailPassword < Base
|
|
6
|
+
PADDING = 6
|
|
7
|
+
|
|
8
|
+
template_name 'email-password'
|
|
9
|
+
page_layout 'Avery7160'
|
|
10
|
+
accept_columns(
|
|
11
|
+
'admin',
|
|
12
|
+
'lastname',
|
|
13
|
+
'firstname',
|
|
14
|
+
'vmg',
|
|
15
|
+
'email',
|
|
16
|
+
'password'
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
def self.password_label
|
|
20
|
+
"Password"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @param data [#[]] data object
|
|
24
|
+
# @param pdf [Prawn::Document]
|
|
25
|
+
def self.evaluate(pdf, data)
|
|
26
|
+
b = pdf.bounds
|
|
27
|
+
full_width = b.width - (PADDING * 2)
|
|
28
|
+
col1 = (full_width / 3).floor - 1
|
|
29
|
+
col2 = (col1 * 2) - 1
|
|
30
|
+
|
|
31
|
+
pdf.font 'Helvetica'
|
|
32
|
+
|
|
33
|
+
pdf.move_down (PADDING * 2).round
|
|
34
|
+
pdf.indent(PADDING) do
|
|
35
|
+
pdf.text_box "#{data['firstname']} #{data['lastname']}",
|
|
36
|
+
at: [b.left, pdf.cursor],
|
|
37
|
+
width: full_width, height: 12,
|
|
38
|
+
overflow: :truncate
|
|
39
|
+
end
|
|
40
|
+
pdf.move_down 12
|
|
41
|
+
pdf.stroke_horizontal_rule
|
|
42
|
+
pdf.move_down 6
|
|
43
|
+
pdf.indent(PADDING) do
|
|
44
|
+
pdf.font "Helvetica", size: 7 do
|
|
45
|
+
pdf.text_box "Admin no.",
|
|
46
|
+
at: [b.left, pdf.cursor],
|
|
47
|
+
width: col1, height: 8
|
|
48
|
+
pdf.text_box "Group",
|
|
49
|
+
at: [b.right - col2, pdf.cursor],
|
|
50
|
+
width: col2, height: 8
|
|
51
|
+
end
|
|
52
|
+
pdf.move_down 9
|
|
53
|
+
pdf.text_box (data["admin"] || ""),
|
|
54
|
+
at: [b.left, pdf.cursor],
|
|
55
|
+
width: col1, height: 10,
|
|
56
|
+
overflow: :shrink_to_fit
|
|
57
|
+
pdf.text_box (data["vmg"] || ""),
|
|
58
|
+
at: [b.right - col2, pdf.cursor],
|
|
59
|
+
width: col2, height: 10,
|
|
60
|
+
overflow: :shrink_to_fit
|
|
61
|
+
pdf.move_down 16
|
|
62
|
+
pdf.font_size 7 do
|
|
63
|
+
pdf.text_box "Email",
|
|
64
|
+
at: [b.left, pdf.cursor],
|
|
65
|
+
width: full_width, height: 8
|
|
66
|
+
end
|
|
67
|
+
pdf.move_down 9
|
|
68
|
+
pdf.text_box (data["email"] || ""),
|
|
69
|
+
at: [b.left, pdf.cursor],
|
|
70
|
+
width: full_width, height: 12,
|
|
71
|
+
overflow: :shrink_to_fit
|
|
72
|
+
pdf.move_down 16
|
|
73
|
+
pdf.font_size 7 do
|
|
74
|
+
pdf.text_box password_label,
|
|
75
|
+
at: [b.left, pdf.cursor],
|
|
76
|
+
width: full_width, height: 8
|
|
77
|
+
end
|
|
78
|
+
pdf.move_down 9
|
|
79
|
+
pdf.font "Courier" do
|
|
80
|
+
pdf.text_box (data["password"] || ""),
|
|
81
|
+
at: [b.left, pdf.cursor],
|
|
82
|
+
width: full_width, height: 12,
|
|
83
|
+
overflow: :shrink_to_fit
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OutwoodLabels
|
|
4
|
+
module Template
|
|
5
|
+
class EmailPasswordInitial < EmailPassword
|
|
6
|
+
template_name 'email-initial-password'
|
|
7
|
+
page_layout 'Avery7160'
|
|
8
|
+
accept_columns(
|
|
9
|
+
'admin',
|
|
10
|
+
'lastname',
|
|
11
|
+
'firstname',
|
|
12
|
+
'vmg',
|
|
13
|
+
'email',
|
|
14
|
+
'password'
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
def self.password_label
|
|
18
|
+
"Initial password"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'logger'
|
|
4
|
+
require 'outwood_labels/callable'
|
|
5
|
+
require 'outwood_labels/generate'
|
|
6
|
+
require 'outwood_labels/template'
|
|
7
|
+
require 'outwood_labels/version'
|
|
8
|
+
|
|
9
|
+
module OutwoodLabels
|
|
10
|
+
class Error < StandardError; end
|
|
11
|
+
|
|
12
|
+
@templates = {}
|
|
13
|
+
|
|
14
|
+
# @param klass [Class] template class to add
|
|
15
|
+
def self.register(klass)
|
|
16
|
+
default_mapping[klass.name] = klass
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# @param name [String] name of a template
|
|
20
|
+
def self.[](name)
|
|
21
|
+
default_mapping[name]
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# @param columns [Array<String>] list of column names
|
|
25
|
+
# @return [Template::Base, nil]
|
|
26
|
+
def self.infer_template(columns = [])
|
|
27
|
+
default_mapping.each_value.reverse_each do |t|
|
|
28
|
+
return t if t.valid_for? columns
|
|
29
|
+
end
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [{String => Template::Base}]
|
|
34
|
+
def self.default_mapping
|
|
35
|
+
@templates
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Register in ascending preference order
|
|
39
|
+
register(Template::EmailPasswordInitial)
|
|
40
|
+
register(Template::EmailPassword)
|
|
41
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
+
require "outwood_labels/version"
|
|
6
|
+
|
|
7
|
+
Gem::Specification.new do |spec|
|
|
8
|
+
spec.name = "outwood_labels"
|
|
9
|
+
spec.version = OutwoodLabels::VERSION
|
|
10
|
+
spec.authors = ["Tom Crouch"]
|
|
11
|
+
spec.email = ["t.crouch@outwood.com"]
|
|
12
|
+
|
|
13
|
+
spec.summary = "Sticker generator"
|
|
14
|
+
spec.homepage = "https://github.com/outwood/outwood_labels"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
21
|
+
end
|
|
22
|
+
spec.bindir = "exe"
|
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
24
|
+
spec.require_paths = ["lib"]
|
|
25
|
+
|
|
26
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
27
|
+
|
|
28
|
+
spec.add_dependency "prawn-label_sheet", "~> 0.2"
|
|
29
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
|
30
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
|
32
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: outwood_labels
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Tom Crouch
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2022-10-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: prawn-label_sheet
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0.2'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0.2'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '2.0'
|
|
34
|
+
type: :development
|
|
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: rake
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '13.0'
|
|
48
|
+
type: :development
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '13.0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rspec
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - "~>"
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '3.0'
|
|
62
|
+
type: :development
|
|
63
|
+
prerelease: false
|
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - "~>"
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '3.0'
|
|
69
|
+
description:
|
|
70
|
+
email:
|
|
71
|
+
- t.crouch@outwood.com
|
|
72
|
+
executables:
|
|
73
|
+
- outwood_labels
|
|
74
|
+
extensions: []
|
|
75
|
+
extra_rdoc_files: []
|
|
76
|
+
files:
|
|
77
|
+
- ".github/workflows/gem-push.yml"
|
|
78
|
+
- ".github/workflows/ruby.yml"
|
|
79
|
+
- ".gitignore"
|
|
80
|
+
- ".rspec"
|
|
81
|
+
- ".rubocop.yml"
|
|
82
|
+
- Gemfile
|
|
83
|
+
- LICENSE.txt
|
|
84
|
+
- README.md
|
|
85
|
+
- Rakefile
|
|
86
|
+
- bin/console
|
|
87
|
+
- bin/setup
|
|
88
|
+
- exe/outwood_labels
|
|
89
|
+
- lib/outwood_labels.rb
|
|
90
|
+
- lib/outwood_labels/callable.rb
|
|
91
|
+
- lib/outwood_labels/cli.rb
|
|
92
|
+
- lib/outwood_labels/csv_loader.rb
|
|
93
|
+
- lib/outwood_labels/file_namer.rb
|
|
94
|
+
- lib/outwood_labels/generate.rb
|
|
95
|
+
- lib/outwood_labels/options.rb
|
|
96
|
+
- lib/outwood_labels/options_validator.rb
|
|
97
|
+
- lib/outwood_labels/template.rb
|
|
98
|
+
- lib/outwood_labels/template/base.rb
|
|
99
|
+
- lib/outwood_labels/template/email_password.rb
|
|
100
|
+
- lib/outwood_labels/template/email_password_initial.rb
|
|
101
|
+
- lib/outwood_labels/version.rb
|
|
102
|
+
- outwood_labels.gemspec
|
|
103
|
+
homepage: https://github.com/outwood/outwood_labels
|
|
104
|
+
licenses:
|
|
105
|
+
- MIT
|
|
106
|
+
metadata: {}
|
|
107
|
+
post_install_message:
|
|
108
|
+
rdoc_options: []
|
|
109
|
+
require_paths:
|
|
110
|
+
- lib
|
|
111
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
|
+
requirements:
|
|
113
|
+
- - ">="
|
|
114
|
+
- !ruby/object:Gem::Version
|
|
115
|
+
version: 2.7.0
|
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
|
+
requirements:
|
|
118
|
+
- - ">="
|
|
119
|
+
- !ruby/object:Gem::Version
|
|
120
|
+
version: '0'
|
|
121
|
+
requirements: []
|
|
122
|
+
rubygems_version: 3.0.3.1
|
|
123
|
+
signing_key:
|
|
124
|
+
specification_version: 4
|
|
125
|
+
summary: Sticker generator
|
|
126
|
+
test_files: []
|