laser-cutter 0.4.1 → 0.4.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/Gemfile +0 -1
- data/bin/laser-cutter +1 -0
- data/laser-cutter.gemspec +1 -1
- data/lib/laser-cutter/configuration.rb +10 -13
- data/lib/laser-cutter/renderer/box_renderer.rb +44 -23
- data/lib/laser-cutter/version.rb +1 -1
- data/spec/configuration_spec.rb +13 -4
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 32ce72abddaaccd285d8dbcbf03b9a7644bf0a91
|
|
4
|
+
data.tar.gz: df1bfc141e15b055e054dd70cbf921460f663ce2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14f27fcf968d47af5505d7430022c02b6b69c33aec68102822ad5b80bb6915e44783509e94e4e169b8ee5af840fdc1173116138b239ac184cb52521d99e5ab13
|
|
7
|
+
data.tar.gz: 90c95f1f44c2ae2f0f15ae978faf130e2a3a62316bf405a719ef70fd26354695f0e905eedf9f440d2d3d591a5ec48ad8cf839c4302ee4fca1c449c217516498a
|
data/Gemfile
CHANGED
data/bin/laser-cutter
CHANGED
|
@@ -62,6 +62,7 @@ EOF
|
|
|
62
62
|
opts.separator ""
|
|
63
63
|
opts.on("-A", "--list-all-page-sizes", "Print all available page sizes with dimensions and exit") { |v| options.list_all_page_sizes = true }
|
|
64
64
|
opts.on("-v", "--[no-]verbose", "Run verbosely") { |v| options.verbose = v }
|
|
65
|
+
opts.on("-m", "--[no-]metadata", "Print to the PDF metadata") { |value| options.metadata = value }
|
|
65
66
|
opts.separator ""
|
|
66
67
|
opts.on("--examples", "Show detailed usage examples") { puts opts; puts examples.yellow; exit }
|
|
67
68
|
opts.on("--help", "Show this message") { puts opts; exit }
|
data/laser-cutter.gemspec
CHANGED
|
@@ -6,11 +6,14 @@ module Laser
|
|
|
6
6
|
module Cutter
|
|
7
7
|
class MissingOption < RuntimeError
|
|
8
8
|
end
|
|
9
|
+
class ZeroValueNotAllowed < MissingOption
|
|
10
|
+
end
|
|
9
11
|
class Configuration < Hashie::Mash
|
|
10
12
|
DEFAULTS = {
|
|
11
13
|
units: 'mm',
|
|
12
14
|
page_size: 'LETTER',
|
|
13
|
-
page_layout: 'portrait'
|
|
15
|
+
page_layout: 'portrait',
|
|
16
|
+
metadata: true
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
UNIT_SPECIFIC_DEFAULTS = {
|
|
@@ -52,18 +55,12 @@ module Laser
|
|
|
52
55
|
|
|
53
56
|
def validate!
|
|
54
57
|
missing = []
|
|
55
|
-
REQUIRED.each
|
|
56
|
-
|
|
57
|
-
end
|
|
58
|
-
unless missing.empty?
|
|
59
|
-
raise MissingOption.new("#{missing.join(', ')} #{missing.size > 1 ? 'are' : 'is'} required, but missing.")
|
|
60
|
-
end
|
|
58
|
+
REQUIRED.each { |k| missing << k if self[k].nil? }
|
|
59
|
+
raise MissingOption.new("#{missing.join(', ')} #{missing.size > 1 ? 'are' : 'is'} required, but missing.") unless missing.empty?
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
end
|
|
66
|
-
end
|
|
61
|
+
zeros = []
|
|
62
|
+
NON_ZERO.each { |k| zeros << k if self[k] == 0 }
|
|
63
|
+
raise ZeroValueNotAllowed.new("#{zeros.join(', ')} #{zeros.size > 1 ? 'are' : 'is'} required, but is zero.") unless zeros.empty?
|
|
67
64
|
end
|
|
68
65
|
|
|
69
66
|
def page_size_values
|
|
@@ -91,7 +88,7 @@ module Laser
|
|
|
91
88
|
return if (self.units.eql?(new_units) || !UNIT_SPECIFIC_DEFAULTS.keys.include?(new_units))
|
|
92
89
|
k = (self.units == 'in') ? 25.4 : 0.039370079
|
|
93
90
|
FLOATS.each do |field|
|
|
94
|
-
self.send("#{field}=".to_sym, self.send(field.to_sym) * k)
|
|
91
|
+
self.send("#{field}=".to_sym, (self.send(field.to_sym) * k).round(5))
|
|
95
92
|
end
|
|
96
93
|
self.units = new_units
|
|
97
94
|
end
|
|
@@ -5,6 +5,7 @@ module Laser
|
|
|
5
5
|
module Renderer
|
|
6
6
|
class BoxRenderer < AbstractRenderer
|
|
7
7
|
alias_method :box, :subject
|
|
8
|
+
|
|
8
9
|
def initialize(options = {})
|
|
9
10
|
self.options = options
|
|
10
11
|
self.subject = Laser::Cutter::Box.new(options)
|
|
@@ -16,41 +17,61 @@ module Laser
|
|
|
16
17
|
:page_layout => options.page_layout.to_sym)
|
|
17
18
|
header = <<-EOF
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
Credits to Prawn
|
|
21
|
-
and BoxMaker
|
|
22
|
-
|
|
20
|
+
Made with Laser Cutter Ruby Gem (v#{Laser::Cutter::VERSION})
|
|
21
|
+
Credits to Prawn for ruby PDF generation,
|
|
22
|
+
and BoxMaker for inspiration.
|
|
23
|
+
|
|
24
|
+
Online: http://makeabox.io/
|
|
23
25
|
https://github.com/kigster/laser-cutter
|
|
24
|
-
Generated at #{Time.new}.
|
|
25
26
|
EOF
|
|
26
27
|
|
|
27
28
|
renderer = self
|
|
28
29
|
|
|
30
|
+
meta_color = "406080"
|
|
31
|
+
meta_top = 150
|
|
32
|
+
metadata = renderer.options.to_hash
|
|
33
|
+
metadata.delete_if { |k| %w(verbose metadata open).include?(k) }
|
|
29
34
|
pdf.instance_eval do
|
|
30
35
|
self.line_width = renderer.options.stroke.send(renderer.options.units.to_sym)
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
if renderer.options.metadata
|
|
37
|
+
float do
|
|
38
|
+
bounding_box([0, meta_top], :width => 140, :height => 150) do
|
|
39
|
+
stroke_color meta_color
|
|
40
|
+
stroke_bounds
|
|
41
|
+
indent 10 do
|
|
42
|
+
font('Helvetica', :size => 6) do
|
|
43
|
+
text header, :color => meta_color
|
|
44
|
+
end
|
|
39
45
|
end
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
float do
|
|
47
|
+
bounding_box([0, 100], :width => 140, :height => 100) do
|
|
48
|
+
stroke_color meta_color
|
|
49
|
+
stroke_bounds
|
|
50
|
+
float do
|
|
51
|
+
bounding_box([0, 100], :width => 70, :height => 100) do
|
|
52
|
+
indent 10 do
|
|
53
|
+
font('Helvetica', :size => 6) do
|
|
54
|
+
out = JSON.pretty_generate(metadata).gsub(/[\{\}",]/, '').gsub(/:.*\n/x, "\n")
|
|
55
|
+
text out, :color => meta_color, align: :right
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
float do
|
|
61
|
+
bounding_box([60, 100], :width => 70, :height => 100) do
|
|
62
|
+
indent 10 do
|
|
63
|
+
font('Helvetica', :size => 6) do
|
|
64
|
+
out = JSON.pretty_generate(metadata).gsub(/[\{\}",]/, '').gsub(/\n?.*:/x, "\n:")
|
|
65
|
+
text out, :color => meta_color
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
49
71
|
end
|
|
50
72
|
end
|
|
51
73
|
end
|
|
52
74
|
end
|
|
53
|
-
|
|
54
75
|
stroke_color "000000"
|
|
55
76
|
renderer.box.notches.each do |notch|
|
|
56
77
|
LineRenderer.new(notch, renderer.options).render(self)
|
data/lib/laser-cutter/version.rb
CHANGED
data/spec/configuration_spec.rb
CHANGED
|
@@ -16,11 +16,20 @@ module Laser
|
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
context '#validate' do
|
|
19
|
+
context 'missing options' do
|
|
19
20
|
let(:opts) { {"height" => "23"} }
|
|
20
21
|
it 'should be able to validate missing options' do
|
|
21
22
|
expect(config.height).to eql(23.0)
|
|
22
23
|
expect { config.validate! }.to raise_error(Laser::Cutter::MissingOption)
|
|
23
24
|
end
|
|
25
|
+
end
|
|
26
|
+
context 'zero options' do
|
|
27
|
+
let(:opts) { {"size" => "2.0x0.0x2/0.125/0.5", "inches" => true, 'file' => '/tmp/a'} }
|
|
28
|
+
it 'should be able to validate missing options' do
|
|
29
|
+
expect(config.height).to eql(0.0)
|
|
30
|
+
expect { config.validate! }.to raise_error(Laser::Cutter::ZeroValueNotAllowed)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
24
33
|
end
|
|
25
34
|
context '#list_page_sizes' do
|
|
26
35
|
context 'formatting of output' do
|
|
@@ -48,14 +57,14 @@ module Laser
|
|
|
48
57
|
|
|
49
58
|
context "#change_units" do
|
|
50
59
|
context "from inches" do
|
|
51
|
-
let(:opts) { {"size" => "2.0x3x2/0.125/0.5", 'padding' => '4.
|
|
60
|
+
let(:opts) { {"size" => "2.0x3x2/0.125/0.5", 'padding' => '4.2', "units" => 'in'} }
|
|
52
61
|
it "should convert to mm" do
|
|
53
62
|
expect(config.width).to eql(2.0)
|
|
54
63
|
config.change_units('in')
|
|
55
64
|
expect(config.width).to eql(2.0)
|
|
56
65
|
config.change_units('mm')
|
|
57
66
|
expect(config.width).to eql(50.8)
|
|
58
|
-
expect(config.padding).to eql(
|
|
67
|
+
expect(config.padding).to eql(106.68)
|
|
59
68
|
expect(config.units).to eql('mm')
|
|
60
69
|
end
|
|
61
70
|
end
|
|
@@ -66,8 +75,8 @@ module Laser
|
|
|
66
75
|
config.change_units('mm')
|
|
67
76
|
expect(config.width).to eql(20.0)
|
|
68
77
|
config.change_units('in')
|
|
69
|
-
expect(config.width).to be_within(0.
|
|
70
|
-
expect(config.margin).to be_within(0.
|
|
78
|
+
expect(config.width).to be_within(0.00001).of(0.787401575)
|
|
79
|
+
expect(config.margin).to be_within(0.00001).of(0.393700787)
|
|
71
80
|
expect(config.units).to eql('in')
|
|
72
81
|
end
|
|
73
82
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: laser-cutter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Konstantin Gredeskoul
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-09-
|
|
11
|
+
date: 2014-09-28 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: prawn
|
|
@@ -108,6 +108,20 @@ dependencies:
|
|
|
108
108
|
- - ">="
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
110
|
version: '0'
|
|
111
|
+
- !ruby/object:Gem::Dependency
|
|
112
|
+
name: codeclimate-test-reporter
|
|
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'
|
|
111
125
|
description: Similar to the older BoxMaker, this ruby gem generates PDFs that can
|
|
112
126
|
be used as a basis for cutting boxes on a typical laser cutter. The intention was
|
|
113
127
|
to create an extensible, well tested, and modern ruby gem for generating PDF templates
|