usps_flags 0.3.10 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +2 -2
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/usps_flags/config.rb +18 -69
- data/lib/usps_flags/core/trident.rb +1 -1
- data/lib/usps_flags/core/trident_spec.rb +1 -1
- data/lib/usps_flags/generate.rb +8 -8
- data/lib/usps_flags/helpers.rb +3 -3
- data/lib/usps_flags.rb +29 -30
- data/spec/spec_helper.rb +1 -1
- data/spec/usps_flags/config_spec.rb +11 -11
- data/spec/usps_flags/generate_spec.rb +2 -2
- data/usps_flags.gemspec +1 -1
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 912c06bbc43cfe66768f59b678da12adaecd9964
|
4
|
+
data.tar.gz: 44107e8638acf16858899949fc6b29198844f742
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb93a2912820cc42b41a03d1c1deab2fb3caec1a2ccec47c9a0e2ab38e3e930ba1afbcf0510e22d1c6b6a032cdf2619bd4a6cebf413587938ad45a1d0c6b6688
|
7
|
+
data.tar.gz: bf314db590a8cd310e92155ba5dba21a5bde8773c21ab37faf1d0c6428144a3e554a01dcd392e9b84b15a2269593e9c5143b96b3feb93ddc72a5136dff22f084
|
checksums.yaml.gz.sig
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
B�wA[�zs���R1p����q�Ң^�������M�����̡��l����d*���>n
|
2
|
+
����RK�ՖBӴPm�b}E�|m�*Ԫ���YI�f��Iw2���f/L P����j���jsI��8�!Z/xU�}%kJ7��-C�!Q�XQ}�=_f튧�Ɓx���;큒���c<�\X6>qo�L�Q�'.��^˻\g�Ib��g�GN�:l,��ܧ�Lӈc
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/usps_flags/config.rb
CHANGED
@@ -8,35 +8,27 @@ class USPSFlags::Config
|
|
8
8
|
BASE_HOIST ||= BASE_FLY*2/3
|
9
9
|
FRACTION_SCALE ||= 85
|
10
10
|
|
11
|
-
|
12
|
-
@@use_larger_tridents = true
|
13
|
-
@@reset = false
|
11
|
+
attr_accessor :flags_dir, :clear, :use_larger_tridents
|
14
12
|
|
15
13
|
# Configuration constructor
|
16
14
|
#
|
17
15
|
# @param [String] flag_dir The path to the flags directory.
|
18
16
|
# @param [Boolean] use_larger_tridents Whether to use the larger trident configuration.
|
19
|
-
# @param [Boolean]
|
17
|
+
# @param [Boolean] clear Whether to clear out the specified flags_dir.
|
20
18
|
def initialize
|
21
|
-
|
19
|
+
get_defaults
|
22
20
|
yield self if block_given?
|
23
|
-
set_class_variables
|
24
|
-
set_flags_dir(reset: @reset)
|
25
21
|
end
|
26
22
|
|
27
|
-
attr_accessor :flags_dir
|
28
|
-
attr_accessor :reset
|
29
|
-
attr_accessor :use_larger_tridents
|
30
|
-
|
31
23
|
# Base configuration values for trident insignia.
|
32
24
|
#
|
33
25
|
# All other values are derived from these, or directly from the constant sizes.
|
34
26
|
#
|
35
27
|
# @return [Hash] RThe configuration values for tridents.
|
36
|
-
def
|
28
|
+
def trident
|
37
29
|
point_height = USPSFlags::Config::BASE_FLY/48*17/8
|
38
30
|
bar_width = USPSFlags::Config::BASE_FLY/48
|
39
|
-
bar_width = bar_width*5/4 if
|
31
|
+
bar_width = bar_width*5/4 if USPSFlags.configuration.use_larger_tridents
|
40
32
|
{
|
41
33
|
height: trident_heights,
|
42
34
|
|
@@ -57,8 +49,8 @@ class USPSFlags::Config
|
|
57
49
|
hash_width: USPSFlags::Config::BASE_FLY*3/32,
|
58
50
|
|
59
51
|
delta_height: USPSFlags::Config::BASE_FLY*2/15,
|
60
|
-
delta_gap_height:
|
61
|
-
delta_gap_width:
|
52
|
+
delta_gap_height: USPSFlags.configuration.use_larger_tridents ? USPSFlags::Config::BASE_FLY*14/256 : USPSFlags::Config::BASE_FLY*17/256,
|
53
|
+
delta_gap_width: USPSFlags.configuration.use_larger_tridents ? bar_width*5/4 : bar_width*7/4,
|
62
54
|
delta_width: USPSFlags::Config::BASE_FLY*43/768,
|
63
55
|
delta_from_bottom: USPSFlags::Config::BASE_HOIST*11/64,
|
64
56
|
delta_gap_scale: 0.40,
|
@@ -72,7 +64,7 @@ class USPSFlags::Config
|
|
72
64
|
# Height values for trident insignia.
|
73
65
|
#
|
74
66
|
# @return [Hash] The height values for tridents.
|
75
|
-
def
|
67
|
+
def trident_heights
|
76
68
|
{
|
77
69
|
s: USPSFlags::Config::BASE_HOIST/2,
|
78
70
|
d: USPSFlags::Config::BASE_HOIST*5/8,
|
@@ -81,68 +73,25 @@ class USPSFlags::Config
|
|
81
73
|
}
|
82
74
|
end
|
83
75
|
|
84
|
-
# Accessor for the directory for storing generated flags.
|
85
|
-
#
|
86
|
-
# @return [String] The current path to the flags directory.
|
87
|
-
def self.flags_dir
|
88
|
-
@@flags_dir || if defined?(::Rails)
|
89
|
-
"#{::Rails.root}/app/assets/images/usps-flags"
|
90
|
-
else
|
91
|
-
"#{File.dirname(__dir__)}/output"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
76
|
# Alias for the directory to store generated log files.
|
96
77
|
#
|
97
78
|
# @return [String] The current path to the logs directory.
|
98
|
-
def
|
99
|
-
|
79
|
+
def log_path
|
80
|
+
if defined?(::Rails)
|
100
81
|
"#{::Rails.root}/log"
|
101
82
|
else
|
102
|
-
"#{
|
83
|
+
"#{USPSFlags.configuration.flags_dir}/log"
|
103
84
|
end
|
104
|
-
::FileUtils.mkdir_p(log_path)
|
105
|
-
log_path
|
106
|
-
end
|
107
|
-
|
108
|
-
# Accessor for the boolean of whether to use the larger or smaller trident width.
|
109
|
-
#
|
110
|
-
# @return [Boolean] Returns the current setting.
|
111
|
-
def self.use_larger_tridents
|
112
|
-
# Smaller: 1/2 in width on 24in x 16in field
|
113
|
-
# Larger: 5/8 in width on 24in x 16in field
|
114
|
-
@@use_larger_tridents
|
115
|
-
end
|
116
|
-
|
117
|
-
# Accessor for the boolean of whether to clear the flags_dir.
|
118
|
-
#
|
119
|
-
# @return [Boolean] Returns the current setting.
|
120
|
-
def self.reset
|
121
|
-
@@reset
|
122
85
|
end
|
123
86
|
|
124
87
|
private
|
125
|
-
def
|
126
|
-
@flags_dir =
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
def set_class_variables
|
132
|
-
@@flags_dir = @flags_dir
|
133
|
-
@@use_larger_tridents = @use_larger_tridents
|
134
|
-
@@reset = @reset
|
135
|
-
end
|
136
|
-
|
137
|
-
def set_flags_dir(reset: false)
|
138
|
-
return false if @@flags_dir.nil? || @@flags_dir.empty?
|
139
|
-
::FileUtils.rm_rf(@@flags_dir) if reset
|
140
|
-
[
|
141
|
-
"#{@@flags_dir}/SVG/insignia",
|
142
|
-
"#{@@flags_dir}/PNG/insignia",
|
143
|
-
"#{@@flags_dir}/ZIP"
|
144
|
-
].each do |dir|
|
145
|
-
::FileUtils.mkdir_p(dir)
|
88
|
+
def get_defaults
|
89
|
+
@flags_dir = if defined?(::Rails)
|
90
|
+
"#{::Rails.root}/app/assets/images/usps-flags"
|
91
|
+
else
|
92
|
+
"#{File.dirname(__dir__)}/output"
|
146
93
|
end
|
94
|
+
@use_larger_tridents = true
|
95
|
+
@clear = false
|
147
96
|
end
|
148
97
|
end
|
@@ -41,7 +41,7 @@ class USPSFlags::Core::Trident
|
|
41
41
|
|
42
42
|
private
|
43
43
|
def load_config
|
44
|
-
@trident_config = USPSFlags
|
44
|
+
@trident_config = USPSFlags.configuration.trident
|
45
45
|
@main_spike_overhang = @trident_config[:bar_width] / 2
|
46
46
|
@side_spike_overhang = @trident_config[:bar_width] / 2
|
47
47
|
@top_point = ((USPSFlags::Config::BASE_HOIST - @trident_config[:height][@type]) / 2)
|
data/lib/usps_flags/generate.rb
CHANGED
@@ -103,15 +103,15 @@ class USPSFlags::Generate
|
|
103
103
|
private
|
104
104
|
def remove_static_files
|
105
105
|
["SVG", "PNG", "ZIP"].each do |dir|
|
106
|
-
dir_path = "#{USPSFlags
|
106
|
+
dir_path = "#{USPSFlags.configuration.flags_dir}/#{dir}"
|
107
107
|
::FileUtils.rm_rf(::Dir.glob("#{dir_path}/*")) if ::Dir.exist?(dir_path)
|
108
108
|
end
|
109
|
-
["SVG/insignia", "PNG/insignia"].each { |dir| ::FileUtils.mkdir_p("#{USPSFlags
|
109
|
+
["SVG/insignia", "PNG/insignia"].each { |dir| ::FileUtils.mkdir_p("#{USPSFlags.configuration.flags_dir}/#{dir}") }
|
110
110
|
USPSFlags::Helpers.log "\n - Cleared previous files.\n"
|
111
111
|
end
|
112
112
|
|
113
113
|
def set_file_paths
|
114
|
-
@svg_file = "#{USPSFlags
|
114
|
+
@svg_file = "#{USPSFlags.configuration.flags_dir}/SVG/#{@flag}.svg"
|
115
115
|
@png_file = @svg_file.gsub("/SVG/", "/PNG/").gsub(".svg", ".png")
|
116
116
|
@svg_ins_file = @svg_file.gsub("/SVG/", "/SVG/insignia/")
|
117
117
|
@png_ins_file = @svg_file.gsub("/SVG/", "/PNG/insignia/").gsub(".svg", ".png")
|
@@ -122,20 +122,20 @@ class USPSFlags::Generate
|
|
122
122
|
puts "\nSVGs generate a single file.",
|
123
123
|
"PNGs generate full-res, 1500w, 1000w, 500w, and thumbnail files.",
|
124
124
|
"Corresponding rank insignia (including smaller sizes) are also generated, as appropriate."
|
125
|
-
USPSFlags::Helpers.log "\nGeneration location: #{USPSFlags
|
125
|
+
USPSFlags::Helpers.log "\nGeneration location: #{USPSFlags.configuration.flags_dir}\n"
|
126
126
|
USPSFlags::Helpers.log "\n#{Time.now.strftime('%Y%m%d.%H%M%S%z')} – Generating static files...\n\n"
|
127
127
|
USPSFlags::Helpers.log "Flag | SVG | PNG | Run time\n".rjust(USPSFlags::Helpers.max_flag_name_length+31),
|
128
128
|
"\n".rjust(USPSFlags::Helpers.max_flag_name_length+32, "-")
|
129
129
|
end
|
130
130
|
|
131
131
|
def generate_zip(type)
|
132
|
-
raise USPSFlags::Errors::ZipGenerationError, "Flags directory not found." unless ::Dir.exist?("#{USPSFlags
|
132
|
+
raise USPSFlags::Errors::ZipGenerationError, "Flags directory not found." unless ::Dir.exist?("#{USPSFlags.configuration.flags_dir}/ZIP")
|
133
133
|
|
134
|
-
zip = "#{USPSFlags
|
134
|
+
zip = "#{USPSFlags.configuration.flags_dir}/ZIP/USPS_Flags.#{type}.zip"
|
135
135
|
::File.delete(zip) if ::File.exist?(zip)
|
136
136
|
|
137
137
|
::Zip::File.open(zip, Zip::File::CREATE) do |z|
|
138
|
-
::Dir.glob("#{USPSFlags
|
138
|
+
::Dir.glob("#{USPSFlags.configuration.flags_dir}/#{type.upcase}/**/*").each do |f|
|
139
139
|
add_to_zip(z, f)
|
140
140
|
end
|
141
141
|
end
|
@@ -200,7 +200,7 @@ class USPSFlags::Generate
|
|
200
200
|
def generate_reduced_size_pngs
|
201
201
|
USPSFlags::Helpers.png_sizes.keys.each do |size|
|
202
202
|
size, size_key = USPSFlags::Helpers.size_and_key(size: size, flag: @flag)
|
203
|
-
@sized_png_file = "#{USPSFlags
|
203
|
+
@sized_png_file = "#{USPSFlags.configuration.flags_dir}/PNG/#{@flag}.#{size_key}.png"
|
204
204
|
@sized_png_ins_file = @sized_png_file.gsub("/PNG/", "/PNG/insignia/")
|
205
205
|
|
206
206
|
generate_smaller_png(size, size_key)
|
data/lib/usps_flags/helpers.rb
CHANGED
@@ -29,7 +29,7 @@ class USPSFlags::Helpers
|
|
29
29
|
# @param [String] size_key Size suffix to attach to the file name.
|
30
30
|
def resize_png(png_file, file: nil, outfile: nil, size:, size_key:)
|
31
31
|
raise USPSFlags::Errors::PNGConversionError if outfile.nil? && file.nil?
|
32
|
-
output_file_name = outfile || "#{USPSFlags
|
32
|
+
output_file_name = outfile || "#{USPSFlags.configuration.flags_dir}/PNG/#{file}.#{size_key}.png"
|
33
33
|
MiniMagick::Tool::Convert.new do |convert|
|
34
34
|
convert << "-background" << "none"
|
35
35
|
convert << "-format" << "png"
|
@@ -93,10 +93,10 @@ class USPSFlags::Helpers
|
|
93
93
|
# This should never need to be called directly.
|
94
94
|
# @private
|
95
95
|
def log(*messages)
|
96
|
-
::FileUtils.mkdir_p(USPSFlags
|
96
|
+
::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
|
97
97
|
outputs = [STDOUT]
|
98
98
|
|
99
|
-
log_file = File.open("#{USPSFlags
|
99
|
+
log_file = File.open("#{USPSFlags.configuration.log_path}/flag.log", 'a')
|
100
100
|
outputs << log_file
|
101
101
|
|
102
102
|
messages.each do |message|
|
data/lib/usps_flags.rb
CHANGED
@@ -29,6 +29,33 @@ class USPSFlags
|
|
29
29
|
require "usps_flags/helpers/#{d}"
|
30
30
|
end
|
31
31
|
|
32
|
+
class << self
|
33
|
+
attr_accessor :configuration
|
34
|
+
end
|
35
|
+
|
36
|
+
# Configuration accessor.
|
37
|
+
def self.configuration
|
38
|
+
@configuration ||= USPSFlags::Config.new
|
39
|
+
end
|
40
|
+
|
41
|
+
# Configuration constructor.
|
42
|
+
def self.configure
|
43
|
+
yield(configuration)
|
44
|
+
self.ensure_directories
|
45
|
+
@configuration
|
46
|
+
end
|
47
|
+
|
48
|
+
# Ensures the directory structure exists.
|
49
|
+
#
|
50
|
+
# @private
|
51
|
+
def self.ensure_directories
|
52
|
+
::FileUtils.rm_rf(@configuration.flags_dir) if @configuration.clear
|
53
|
+
::FileUtils.mkdir_p("#{@configuration.flags_dir}/PNG/insignia")
|
54
|
+
::FileUtils.mkdir_p("#{@configuration.flags_dir}/SVG/insignia")
|
55
|
+
::FileUtils.mkdir_p("#{@configuration.flags_dir}/ZIP")
|
56
|
+
::FileUtils.mkdir_p(USPSFlags.configuration.log_path)
|
57
|
+
end
|
58
|
+
|
32
59
|
# Constructor for individual flags.
|
33
60
|
#
|
34
61
|
# @example Generate insignia at default scale for Lt/C
|
@@ -53,43 +80,15 @@ class USPSFlags
|
|
53
80
|
yield self if block_given?
|
54
81
|
end
|
55
82
|
|
56
|
-
# Constructor
|
83
|
+
# Constructor accessors.
|
57
84
|
#
|
58
85
|
# @param [String] type The type of flag to generate.
|
59
|
-
# @return [String]
|
60
|
-
attr_accessor :type
|
61
|
-
|
62
|
-
# Constructor accessor for the SVG file output path.
|
63
|
-
#
|
64
86
|
# @param [String] svg_file The SVG file output path.
|
65
|
-
# @return [String] Returns the current (or updated) SVG file output path.
|
66
|
-
attr_accessor :svg_file
|
67
|
-
|
68
|
-
# Constructor accessor for the PNG file output path.
|
69
|
-
#
|
70
87
|
# @param [String] png_file The PNG file output path.
|
71
|
-
# @return [String] Returns the current (or updated) PNG file output path.
|
72
|
-
attr_accessor :png_file
|
73
|
-
|
74
|
-
# Constructor accessor for the image scale divisor factor.
|
75
|
-
#
|
76
|
-
# Available options are Float between 0 and 1, or Integer above 1.
|
77
|
-
#
|
78
88
|
# @param [Integer, Float] scale The scale divisor factor.
|
79
|
-
# @return [Integer, Float] Returns the current (or updated) scaling factor.
|
80
|
-
attr_accessor :scale
|
81
|
-
|
82
|
-
# Constructor accessor for whether to generate the flag field (including any border).
|
83
|
-
#
|
84
89
|
# @param [Boolean] field The field setting.
|
85
|
-
# @return [Boolean] Returns the current (or updated) setting.
|
86
|
-
attr_accessor :field
|
87
|
-
|
88
|
-
# Constructor accessor for whether to trim the generated PNG file of excess transparency.
|
89
|
-
#
|
90
90
|
# @param [Boolean] trim The trim setting.
|
91
|
-
|
92
|
-
attr_accessor :trim
|
91
|
+
attr_accessor :type, :svg_file, :png_file, :scale, :field, :trim
|
93
92
|
|
94
93
|
# Generates the constructed file as SVG.
|
95
94
|
#
|
data/spec/spec_helper.rb
CHANGED
@@ -3,38 +3,38 @@ require 'spec_helper'
|
|
3
3
|
describe USPSFlags::Config do
|
4
4
|
describe "class variable accessors" do
|
5
5
|
it "should return the current flags directory" do
|
6
|
-
expect(USPSFlags
|
6
|
+
expect(USPSFlags.configuration.flags_dir).to eql($tmp_flags_dir)
|
7
7
|
end
|
8
8
|
|
9
9
|
it "should return the current flags directory" do
|
10
10
|
default_log_path = $tmp_flags_dir + "/log"
|
11
|
-
expect(USPSFlags
|
11
|
+
expect(USPSFlags.configuration.log_path).to eql(default_log_path)
|
12
12
|
end
|
13
13
|
|
14
14
|
it "should return a Boolean from use_larger_tridents" do
|
15
|
-
expect([true, false]).to include(USPSFlags
|
15
|
+
expect([true, false]).to include(USPSFlags.configuration.use_larger_tridents)
|
16
16
|
end
|
17
17
|
|
18
|
-
it "should return a Boolean from
|
19
|
-
expect([true, false]).to include(USPSFlags
|
18
|
+
it "should return a Boolean from clear" do
|
19
|
+
expect([true, false]).to include(USPSFlags.configuration.clear)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
describe "trident" do
|
24
24
|
it "should return a Hash from trident" do
|
25
|
-
expect(USPSFlags
|
25
|
+
expect(USPSFlags.configuration.trident).to be_a(Hash)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
29
|
describe "configuration constructor" do
|
30
30
|
it "should return a properly constructed configuration" do
|
31
|
-
|
31
|
+
USPSFlags.configure do |config|
|
32
32
|
config.flags_dir = $tmp_flags_dir
|
33
33
|
end
|
34
34
|
|
35
|
-
expect(
|
36
|
-
expect(
|
37
|
-
expect(
|
35
|
+
expect(USPSFlags.configuration.flags_dir).to eql($tmp_flags_dir)
|
36
|
+
expect(USPSFlags.configuration.clear).to eql(false)
|
37
|
+
expect(USPSFlags.configuration.use_larger_tridents).to eql(true)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
@@ -52,7 +52,7 @@ describe USPSFlags::Config do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should use the default Rails log directory" do
|
55
|
-
expect(
|
55
|
+
expect(@config.log_path).to eql("tmp/rails_app/log")
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
@@ -176,7 +176,7 @@ describe USPSFlags::Generate do
|
|
176
176
|
end
|
177
177
|
|
178
178
|
it "should not raise an error while generating all static files" do
|
179
|
-
png_dir = "#{USPSFlags
|
179
|
+
png_dir = "#{USPSFlags.configuration.flags_dir}/PNG"
|
180
180
|
::FileUtils.cp("spec/assets/1LT.thumb.png", "#{png_dir}/insignia/1LT.thumb.png")
|
181
181
|
::FileUtils.cp("spec/assets/LT.png", "#{png_dir}/insignia/LT.png")
|
182
182
|
::FileUtils.cp("spec/assets/FLT.png", "#{png_dir}/FLT.png")
|
@@ -223,7 +223,7 @@ describe USPSFlags::Generate do
|
|
223
223
|
Generated PNG Zip
|
224
224
|
LOG
|
225
225
|
|
226
|
-
log_contents = ::File.read("#{USPSFlags
|
226
|
+
log_contents = ::File.read("#{USPSFlags.configuration.log_path}/flag.log")
|
227
227
|
|
228
228
|
expect(log_contents).to match(Regexp.new(correct_log_pattern))
|
229
229
|
end
|
data/usps_flags.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'usps_flags'
|
3
|
-
s.version = '0.3.
|
3
|
+
s.version = '0.3.11'
|
4
4
|
s.date = '2017-11-08'
|
5
5
|
s.summary = 'Flag generator for United States Power Squadrons'
|
6
6
|
s.description = 'A flag image (PNG, SVG) generator for United States Power Squadrons.'
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|