Squash @felixleong's pdf-template feature.
I will be making revisions based on this, but this is all of his hard work. Thank you!!! Conflicts: squib.gemspec
This commit is contained in:
committed by
Andy Meneely
parent
c6aa3983c4
commit
25bf0d7a67
@@ -0,0 +1,7 @@
|
||||
sheet_width: 8.5in
|
||||
sheet_height: 11in
|
||||
card_width: 2.5in
|
||||
card_height: 3.5in
|
||||
cards:
|
||||
- x: 0.5in
|
||||
y: 1in
|
||||
@@ -0,0 +1,22 @@
|
||||
sheet_width: 8.5in
|
||||
sheet_height: 11in
|
||||
card_width: 2in
|
||||
card_height: 3in
|
||||
position_reference: :center
|
||||
cards:
|
||||
- x: 1.25in
|
||||
y: 2.5in
|
||||
- x: 3.25in
|
||||
y: 2.5in
|
||||
- x: 5.25in
|
||||
y: 2.5in
|
||||
- x: 7.25in
|
||||
y: 2.5in
|
||||
- x: 1.25in
|
||||
y: 5.5in
|
||||
- x: 3.25in
|
||||
y: 5.5in
|
||||
- x: 5.25in
|
||||
y: 5.5in
|
||||
- x: 7.25in
|
||||
y: 5.5in
|
||||
@@ -0,0 +1,23 @@
|
||||
sheet_width: 8.5in
|
||||
sheet_height: 11in
|
||||
card_width: 2.5in
|
||||
card_height: 3.5in
|
||||
rotate: :clockwise
|
||||
cards:
|
||||
- x: 0.5in
|
||||
y: 1in
|
||||
- x: 3.0in
|
||||
y: 1in
|
||||
rotate: :counterclockwise
|
||||
- x: 3.5in
|
||||
y: 1in
|
||||
rotate: :turnaround
|
||||
- x: 0.5in
|
||||
y: 4.5in
|
||||
rotate: 1
|
||||
- x: 3.0in
|
||||
y: 4.5in
|
||||
rotate: 60deg
|
||||
- x: 3.5in
|
||||
y: 4.5in
|
||||
rotate: 1.25rad
|
||||
@@ -0,0 +1,28 @@
|
||||
sheet_width: 8.5in
|
||||
sheet_height: 11in
|
||||
card_width: 2in
|
||||
card_height: 3in
|
||||
crop_line:
|
||||
style: :dashed
|
||||
width: 0.1in
|
||||
color: :pink
|
||||
overlay: :overlay_on_cards
|
||||
lines:
|
||||
- type: :horizontal
|
||||
position: 1in
|
||||
- type: :horizontal
|
||||
position: 2in
|
||||
width: 0.2in
|
||||
- type: :horizontal
|
||||
position: 3in
|
||||
style: :dotted
|
||||
- type: :horizontal
|
||||
position: 4in
|
||||
color: "#ff0000"
|
||||
- type: :horizontal
|
||||
position: 5in
|
||||
width: 0.3in
|
||||
style: :solid
|
||||
color: :blue
|
||||
- type: :vertical
|
||||
position: 6in
|
||||
@@ -0,0 +1,6 @@
|
||||
sheet_width: 8.5in
|
||||
sheet_height: 11in
|
||||
card_width: 2.5in
|
||||
cards:
|
||||
- x: 0.5in
|
||||
y: 1in
|
||||
@@ -0,0 +1,6 @@
|
||||
sheet_width: 8.5in
|
||||
sheet_height: 11in
|
||||
card_height: 3.5in
|
||||
cards:
|
||||
- x: 0.5in
|
||||
y: 1in
|
||||
@@ -0,0 +1,6 @@
|
||||
sheet_width: 8.5in
|
||||
card_width: 2.5in
|
||||
card_height: 3.5in
|
||||
cards:
|
||||
- x: 0.5in
|
||||
y: 1in
|
||||
@@ -0,0 +1,6 @@
|
||||
sheet_height: 11in
|
||||
card_width: 2.5in
|
||||
card_height: 3.5in
|
||||
cards:
|
||||
- x: 0.5in
|
||||
y: 1in
|
||||
@@ -50,6 +50,10 @@ def yaml_file(file)
|
||||
"#{File.expand_path(File.dirname(__FILE__))}/data/yaml/#{file}"
|
||||
end
|
||||
|
||||
def template_file(file)
|
||||
"#{File.expand_path(File.dirname(__FILE__))}/data/templates/#{file}"
|
||||
end
|
||||
|
||||
def project_template(file)
|
||||
"#{File.expand_path(File.dirname(__FILE__))}/../lib/squib/project_template/#{file}"
|
||||
end
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Squib::Template do
|
||||
it 'loads a template' do
|
||||
tmpl = Squib::Template.load(template_file('basic.yml'), 100)
|
||||
expect(tmpl.sheet_width).to eq(850)
|
||||
expect(tmpl.sheet_height).to eq(1100)
|
||||
expect(tmpl.card_width).to eq(250)
|
||||
expect(tmpl.card_height).to eq(350)
|
||||
expect(tmpl.dpi).to eq(100)
|
||||
expect(tmpl.crop_line_overlay).to eq(
|
||||
Squib::Template::DEFAULTS['crop_line']['overlay']
|
||||
)
|
||||
expect(tmpl.crop_lines).to eq([])
|
||||
expect(tmpl.cards).to eq([{ 'x' => 50, 'y' => 100, 'rotate' => 0 }])
|
||||
end
|
||||
|
||||
it 'loads from the default templates if none exists' do
|
||||
tmpl = Squib::Template.load('a4_poker_card_9up.yml', 100)
|
||||
expect(tmpl.sheet_width).to eq(826.7716527)
|
||||
expect(tmpl.sheet_height).to eq(1169.2913373899999)
|
||||
expect(tmpl.card_width).to eq(248.03149580999997)
|
||||
expect(tmpl.card_height).to eq(346.45669256)
|
||||
expect(tmpl.dpi).to eq(100)
|
||||
|
||||
expect(tmpl.crop_lines.length).to eq(8)
|
||||
expect(tmpl.crop_lines.map { |line| line['type'] }).to eq(
|
||||
%i[
|
||||
vertical vertical vertical vertical
|
||||
horizontal horizontal horizontal horizontal
|
||||
]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].x1 }).to eq(
|
||||
[
|
||||
41.338582635, 289.370078445, 537.401574255, 785.433070065,
|
||||
0, 0, 0, 0
|
||||
]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].x2 }).to eq(
|
||||
[
|
||||
41.338582635, 289.370078445, 537.401574255, 785.433070065,
|
||||
826.7716527, 826.7716527, 826.7716527, 826.7716527
|
||||
]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].y1 }).to eq(
|
||||
[
|
||||
0, 0, 0, 0,
|
||||
39.3700787, 385.82677126, 732.28346382, 1078.74015638
|
||||
]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].y2 }).to eq(
|
||||
[
|
||||
1169.2913373899999, 1169.2913373899999, 1169.2913373899999,
|
||||
1169.2913373899999,
|
||||
39.3700787, 385.82677126, 732.28346382, 1078.74015638
|
||||
]
|
||||
)
|
||||
|
||||
expect(tmpl.cards.length).to eq(9)
|
||||
expect(tmpl.cards.map { |card| card['x'] }).to eq(
|
||||
[41.338582635, 289.370078445, 537.401574255] * 3
|
||||
)
|
||||
expect(tmpl.cards.map { |card| card['y'] }).to eq(
|
||||
[
|
||||
39.3700787, 39.3700787, 39.3700787,
|
||||
385.82677126, 385.82677126, 385.82677126,
|
||||
732.28346382, 732.28346382, 732.28346382
|
||||
]
|
||||
)
|
||||
|
||||
expect(tmpl.margin).to eq(
|
||||
left: 40.3543306675,
|
||||
right: 786.4173220325,
|
||||
top: 38.3858267325,
|
||||
bottom: 1079.7244083475
|
||||
)
|
||||
end
|
||||
|
||||
it 'loads a template with the coordinates specifying the middle of cards' do
|
||||
tmpl = Squib::Template.load(template_file('card_center_coord.yml'), 100)
|
||||
expect(tmpl.sheet_width).to eq(850)
|
||||
expect(tmpl.sheet_height).to eq(1100)
|
||||
expect(tmpl.card_width).to eq(200)
|
||||
expect(tmpl.card_height).to eq(300)
|
||||
expect(tmpl.dpi).to eq(100)
|
||||
|
||||
expect(tmpl.cards.length).to eq(8)
|
||||
expect(tmpl.cards.map { |card| card['x'] }).to eq(
|
||||
[25.0, 225.0, 425.0, 625.0] * 2
|
||||
)
|
||||
expect(tmpl.cards.map { |card| card['y'] }).to eq(
|
||||
[100.0, 100.0, 100.0, 100.0, 400.0, 400.0, 400.0, 400.0]
|
||||
)
|
||||
end
|
||||
|
||||
it 'loads a template with customized crop lines' do
|
||||
tmpl = Squib::Template.load(template_file('custom_crop_lines.yml'), 100)
|
||||
expect(tmpl.sheet_width).to eq(850)
|
||||
expect(tmpl.sheet_height).to eq(1100)
|
||||
expect(tmpl.card_width).to eq(200)
|
||||
expect(tmpl.card_height).to eq(300)
|
||||
expect(tmpl.dpi).to eq(100)
|
||||
expect(tmpl.crop_line_overlay).to eq(:overlay_on_cards)
|
||||
|
||||
expect(tmpl.crop_lines.length).to eq(6)
|
||||
expect(tmpl.crop_lines.map { |line| line['type'] }).to eq(
|
||||
%i[horizontal horizontal horizontal horizontal horizontal vertical]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].x1 }).to eq(
|
||||
[0, 0, 0, 0, 0, 600]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].x2 }).to eq(
|
||||
[850, 850, 850, 850, 850, 600]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].y1 }).to eq(
|
||||
[100, 200, 300, 400, 500, 0]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['line'].y2 }).to eq(
|
||||
[100, 200, 300, 400, 500, 1100]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['style_desc'] }).to eq(
|
||||
%i[dashed dashed dotted dashed solid dashed]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['width'] }).to eq(
|
||||
[10, 20, 10, 10, 30, 10]
|
||||
)
|
||||
expect(tmpl.crop_lines.map { |line| line['color'] }).to eq(
|
||||
['pink', 'pink', 'pink', '#ff0000', 'blue', 'pink']
|
||||
)
|
||||
end
|
||||
|
||||
it 'loads a template with rotated cards' do
|
||||
tmpl = Squib::Template.load(template_file('card_rotation.yml'), 100)
|
||||
expect(tmpl.sheet_width).to eq(850)
|
||||
expect(tmpl.sheet_height).to eq(1100)
|
||||
expect(tmpl.card_width).to eq(250)
|
||||
expect(tmpl.card_height).to eq(350)
|
||||
expect(tmpl.dpi).to eq(100)
|
||||
|
||||
expect(tmpl.cards.length).to eq(6)
|
||||
expect(tmpl.cards.map { |card| card['rotate'] }).to eq(
|
||||
[0.5 * Math::PI, 1.5 * Math::PI, Math::PI, 1, Math::PI / 3, 1.25]
|
||||
)
|
||||
end
|
||||
|
||||
it 'fails when sheet_width is not defined' do
|
||||
expect do
|
||||
Squib::Template.load(template_file('fail_no_sheet_width.yml'), 100)
|
||||
end.to raise_error(
|
||||
RuntimeError,
|
||||
'"sheet_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
|
||||
)
|
||||
end
|
||||
|
||||
it 'fails when sheet_height is not defined' do
|
||||
expect do
|
||||
Squib::Template.load(template_file('fail_no_sheet_height.yml'), 100)
|
||||
end.to raise_error(
|
||||
RuntimeError,
|
||||
'"sheet_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
|
||||
)
|
||||
end
|
||||
|
||||
it 'fails when card_width is not defined' do
|
||||
expect do
|
||||
Squib::Template.load(template_file('fail_no_card_width.yml'), 100)
|
||||
end.to raise_error(
|
||||
RuntimeError,
|
||||
'"card_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
|
||||
)
|
||||
end
|
||||
|
||||
it 'fails when card_height is not defined' do
|
||||
expect do
|
||||
Squib::Template.load(template_file('fail_no_card_height.yml'), 100)
|
||||
end.to raise_error(
|
||||
RuntimeError,
|
||||
'"card_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user