sprues: rename "template" to "sprue"

Also:
  * Move stuff around to a builtin/ folder
  * Separate out classes to follow my one-class-per-file convention
  * Samples are renamed to the underscore convention

I just like the word "sprue", and it's more descriptive than our original choice of "template". If I had to start Squib all over again, I would probably name it "Sprue" :P
This commit is contained in:
Andy Meneely
2017-07-17 14:48:43 -04:00
parent 36dc7ce4eb
commit 0d076b1e85
35 changed files with 127 additions and 285 deletions
+15 -16
View File
@@ -1,13 +1,12 @@
require_relative '../template'
require_relative '../args/card_range'
require_relative '../args/hand_special'
require_relative '../args/output_file'
require_relative '../args/save_batch'
require_relative '../args/sheet'
require_relative '../args/template_file'
require_relative '../args/output_file'
require_relative '../args/showcase_special'
require_relative '../args/sprue_file'
require_relative '../graphics/save_pdf'
require_relative '../graphics/save_templated_sheet'
require_relative '../graphics/save_sprue'
module Squib
class Deck
@@ -23,15 +22,15 @@ module Squib
def save_pdf(opts = {})
range = Args::CardRange.new(opts[:range], deck_size: size)
sheet = Args::Sheet.new(custom_colors, { file: 'output.pdf' }).load!(opts, expand_by: size, layout: layout, dpi: dpi)
tmpl_file = Args::TemplateFile.new.load!(opts, expand_by: size)
sprue_file = Args::SprueFile.new.load!(opts, expand_by: size)
if tmpl_file.template_file.nil?
if sprue_file.sprue.nil?
Graphics::SavePDF.new(self).render_pdf(range, sheet)
else
tmpl = Template.load tmpl_file.template_file, dpi
Graphics::SaveTemplatedSheetPDF.new(self, tmpl, sheet).render_sheet(
range
)
tmpl = Sprue.load sprue_file.sprue, dpi
Graphics::SaveSpruePDF.
new(self, tmpl, sheet).
render_sheet(range)
end
end
@@ -52,15 +51,15 @@ module Squib
range = Args::CardRange.new(opts[:range], deck_size: size)
batch = Args::SaveBatch.new.load!(opts, expand_by: size, layout: layout, dpi: dpi)
sheet = Args::Sheet.new(custom_colors, { margin: 0 }, size).load!(opts, expand_by: size, layout: layout, dpi: dpi)
tmpl_file = Args::TemplateFile.new.load!(opts, expand_by: size)
sprue_file = Args::SprueFile.new.load!(opts, expand_by: size)
if tmpl_file.template_file.nil?
if sprue_file.sprue.nil?
render_sheet(range, batch, sheet)
else
tmpl = Template.load tmpl_file.template_file, dpi
Graphics::SaveTemplatedSheetPNG.new(self, tmpl, batch).render_sheet(
range
)
tmpl = Sprue.load sprue_file.sprue, dpi
Graphics::SaveSpruePNG.
new(self, tmpl, batch).
render_sheet(range)
end
end
@@ -3,8 +3,7 @@ require_relative 'arg_loader'
module Squib
# @api private
module Args
# Template file argument loader
class TemplateFile
class SprueFile
include ArgLoader
def initialize(dsl_method_default = {})
@@ -13,7 +12,7 @@ module Squib
def self.parameters
{
template_file: nil
sprue: nil
}
end
@@ -38,7 +37,7 @@ module Squib
private
def builtin(file)
"#{File.dirname(__FILE__)}/../sheet_templates/#{file}"
"#{File.dirname(__FILE__)}/../builtin/sprues/#{file}"
end
end
end
@@ -12,7 +12,7 @@ module Squib
# +save_templated_sheet+
#
# @api public
class MakeTemplate
class MakeSprue
# :nodoc:
# @api private
def process(args)
@@ -1,7 +1,7 @@
module Squib
module Graphics
# Helper class to generate templated sheet.
class SaveTemplatedSheet
class SaveSprue
def initialize(deck, tmpl, outfile)
@deck = deck
@tmpl = tmpl
@@ -184,7 +184,7 @@ module Squib
end
# Templated sheet renderer in PDF format.
class SaveTemplatedSheetPDF < SaveTemplatedSheet
class SaveSpruePDF < SaveSprue
def init_cc
ratio = 72.0 / @deck.dpi
@@ -210,7 +210,7 @@ module Squib
end
# Templated sheet renderer in PDF format.
class SaveTemplatedSheetPNG < SaveTemplatedSheet
class SaveSpruePNG < SaveSprue
def init_cc
surface = Cairo::ImageSurface.new @tmpl.sheet_width, @tmpl.sheet_height
Cairo::Context.new(surface)
-42
View File
@@ -1,42 +0,0 @@
---
sheet_width: 210mm
sheet_height: 297mm
card_width: 59.0mm
card_height: 92.0mm
cards:
- x: 16.5mm
y: 10.0mm
- x: 75.5mm
y: 10.0mm
- x: 134.5mm
y: 10.0mm
- x: 16.5mm
y: 102.0mm
- x: 75.5mm
y: 102.0mm
- x: 134.5mm
y: 102.0mm
- x: 16.5mm
y: 194.0mm
- x: 75.5mm
y: 194.0mm
- x: 134.5mm
y: 194.0mm
crop_line:
lines:
- type: :vertical
position: 16.5mm
- type: :vertical
position: 75.5mm
- type: :vertical
position: 134.5mm
- type: :vertical
position: 193.5mm
- type: :horizontal
position: 10.0mm
- type: :horizontal
position: 102.0mm
- type: :horizontal
position: 194.0mm
- type: :horizontal
position: 286.0mm
@@ -1,40 +0,0 @@
---
sheet_width: 297mm
sheet_height: 210mm
card_width: 63.0mm
card_height: 88.0mm
cards:
- x: 22.5mm
y: 10.0mm
- x: 85.5mm
y: 10.0mm
- x: 148.5mm
y: 10.0mm
- x: 211.5mm
y: 10.0mm
- x: 22.5mm
y: 98.0mm
- x: 85.5mm
y: 98.0mm
- x: 148.5mm
y: 98.0mm
- x: 211.5mm
y: 98.0mm
crop_line:
lines:
- type: :vertical
position: 22.5mm
- type: :vertical
position: 85.5mm
- type: :vertical
position: 148.5mm
- type: :vertical
position: 211.5mm
- type: :vertical
position: 274.5mm
- type: :horizontal
position: 10.0mm
- type: :horizontal
position: 98.0mm
- type: :horizontal
position: 186.0mm
@@ -1,42 +0,0 @@
---
sheet_width: 210mm
sheet_height: 297mm
card_width: 63.0mm
card_height: 88.0mm
cards:
- x: 10.5mm
y: 10.0mm
- x: 73.5mm
y: 10.0mm
- x: 136.5mm
y: 10.0mm
- x: 10.5mm
y: 98.0mm
- x: 73.5mm
y: 98.0mm
- x: 136.5mm
y: 98.0mm
- x: 10.5mm
y: 186.0mm
- x: 73.5mm
y: 186.0mm
- x: 136.5mm
y: 186.0mm
crop_line:
lines:
- type: :vertical
position: 10.5mm
- type: :vertical
position: 73.5mm
- type: :vertical
position: 136.5mm
- type: :vertical
position: 199.5mm
- type: :horizontal
position: 10.0mm
- type: :horizontal
position: 98.0mm
- type: :horizontal
position: 186.0mm
- type: :horizontal
position: 274.0mm
-42
View File
@@ -1,42 +0,0 @@
---
sheet_width: 210mm
sheet_height: 297mm
card_width: 56.0mm
card_height: 87.0mm
cards:
- x: 21.0mm
y: 10.0mm
- x: 77.0mm
y: 10.0mm
- x: 133.0mm
y: 10.0mm
- x: 21.0mm
y: 97.0mm
- x: 77.0mm
y: 97.0mm
- x: 133.0mm
y: 97.0mm
- x: 21.0mm
y: 184.0mm
- x: 77.0mm
y: 184.0mm
- x: 133.0mm
y: 184.0mm
crop_line:
lines:
- type: :vertical
position: 21.0mm
- type: :vertical
position: 77.0mm
- type: :vertical
position: 133.0mm
- type: :vertical
position: 189.0mm
- type: :horizontal
position: 10.0mm
- type: :horizontal
position: 97.0mm
- type: :horizontal
position: 184.0mm
- type: :horizontal
position: 271.0mm
+28
View File
@@ -0,0 +1,28 @@
module Squib
module Sprues
class CropLine
attr_reader :x1, :y1, :x2, :y2
def initialize(type, position, sheet_width, sheet_height, dpi)
method = "parse_#{type}"
send method, position, sheet_width, sheet_height, dpi
end
def parse_horizontal(position, sheet_width, _, dpi)
position = Args::UnitConversion.parse(position, dpi)
@x1 = 0
@y1 = position
@x2 = sheet_width
@y2 = position
end
def parse_vertical(position, _, sheet_height, dpi)
position = Args::UnitConversion.parse(position, dpi)
@x1 = position
@y1 = 0
@x2 = position
@y2 = sheet_height
end
end
end
end
+35
View File
@@ -0,0 +1,35 @@
module Squib
module Sprues
class CropLineDash
VALIDATION_REGEX = /%r{
^(\d*[.])?\d+(in|cm|mm)
\s+
(\d*[.])?\d+(in|cm|mm)$
}x/
attr_reader :pattern
def initialize(value, dpi)
if value == :solid
@pattern = nil
elsif value == :dotted
@pattern = [
Args::UnitConversion.parse('0.2mm', dpi),
Args::UnitConversion.parse('0.5mm', dpi)
]
elsif value == :dashed
@pattern = [
Args::UnitConversion.parse('2mm', dpi),
Args::UnitConversion.parse('2mm', dpi)
]
elsif value.is_a? String
@pattern = value.split(' ').map do |val|
Args::UnitConversion.parse val, dpi
end
else
raise ArgumentError, 'Unsupported dash style'
end
end
end
end
end
@@ -1,44 +1,12 @@
require 'yaml'
require 'classy_hash'
require_relative 'args/color_validator'
require_relative 'args/unit_conversion'
require_relative '../args/color_validator'
require_relative '../args/unit_conversion'
require_relative 'crop_line'
require_relative 'crop_line_dash'
module Squib
# Crop line dash definition
class CropLineDash
VALIDATION_REGEX = /%r{
^(\d*[.])?\d+(in|cm|mm)
\s+
(\d*[.])?\d+(in|cm|mm)$
}x/
attr_reader :pattern
def initialize(value, dpi)
if value == :solid
@pattern = nil
elsif value == :dotted
@pattern = [
Args::UnitConversion.parse('0.2mm', dpi),
Args::UnitConversion.parse('0.5mm', dpi)
]
elsif value == :dashed
@pattern = [
Args::UnitConversion.parse('2mm', dpi),
Args::UnitConversion.parse('2mm', dpi)
]
elsif value.is_a? String
@pattern = value.split(' ').map do |val|
Args::UnitConversion.parse val, dpi
end
else
raise ArgumentError, 'Unsupported dash style'
end
end
end
# Template file
class Template
class Sprue
include Args::ColorValidator
# Defaults are set for poker sized deck on a A4 sheet, with no cards
@@ -85,7 +53,7 @@ module Squib
# Create a new template file
warn_unrecognized(yaml)
Template.new new_hash, dpi
Sprue.new new_hash, dpi
end
def sheet_width
@@ -181,7 +149,7 @@ module Squib
'crop_line' => {
'style' => [
ClassyHash::G.enum(:solid, :dotted, :dashed),
CropLineDash::VALIDATION_REGEX
Sprues::CropLineDash::VALIDATION_REGEX
],
'width' => UNIT_REGEX,
'color' => [String, Symbol],
@@ -214,7 +182,7 @@ module Squib
# Return path for built-in sheet templates
def self.builtin(file)
"#{File.dirname(__FILE__)}/sheet_templates/#{file}"
"#{File.dirname(__FILE__)}/../builtin/sprues/#{file}"
end
# Parse crop line definitions from template.
@@ -223,8 +191,8 @@ module Squib
new_line['width'] = Args::UnitConversion.parse(new_line['width'], @dpi)
new_line['color'] = colorify new_line['color']
new_line['style_desc'] = new_line['style']
new_line['style'] = CropLineDash.new(new_line['style'], @dpi)
new_line['line'] = CropLine.new(
new_line['style'] = Sprues::CropLineDash.new(new_line['style'], @dpi)
new_line['line'] = Sprues::CropLine.new(
new_line['type'], new_line['position'], sheet_width, sheet_height, @dpi
)
new_line
@@ -271,30 +239,4 @@ module Squib
end
end
end
# Crop line definition
class CropLine
attr_reader :x1, :y1, :x2, :y2
def initialize(type, position, sheet_width, sheet_height, dpi)
method = "parse_#{type}"
send method, position, sheet_width, sheet_height, dpi
end
def parse_horizontal(position, sheet_width, _, dpi)
position = Args::UnitConversion.parse(position, dpi)
@x1 = 0
@y1 = position
@x2 = sheet_width
@y2 = position
end
def parse_vertical(position, _, sheet_height, dpi)
position = Args::UnitConversion.parse(position, dpi)
@x1 = position
@y1 = 0
@x2 = position
@y2 = sheet_height
end
end
end