diff --git a/CHANGELOG.md b/CHANGELOG.md index 75dfca8..2953294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,12 +4,10 @@ Squib follows [semantic versioning](http://semver.org). ## v0.14.0 / Unreleased Features: +* `save_pdf/save_sheet` method now supports `sprue`, which allows you to define templated layouts and position your cards freely (#217) by @felixleong. See docs for how to use this _very_ powerful feature! * `circle` method now supports various `arc` options, so you can draw partial circles (#211) by @sparr * `save_sheet` method now supports `rtl` or "right-to-left", for easier duplex printing of backs (#204, #208) by @sparr -<<<<<<< HEAD * `yaml` method for reading in data, much like `csv` and `xlsx` by @blinks -* `save_pdf/save_sheet` method now supports `template_file`, which allows you to define -template layouts and position your cards freely (#217) by @felixleong Special thanks to @sparr, @blinks and @felixleong for all of their work!! diff --git a/bin/squib b/bin/squib index c91c5ea..6995849 100755 --- a/bin/squib +++ b/bin/squib @@ -16,12 +16,12 @@ Mercenary.program(:squib) do |p| end end - p.command(:make_template) do |c| - c.syntax 'make_template' - c.description 'Creates a template definition file to generate a templated PDF.' + p.command(:make_sprue) do |c| + c.syntax 'make_sprue' + c.description 'Creates a sprue definition file.' c.action do |args, options| - Squib::Commands::MakeTemplate.new.process(args) + Squib::Commands::MakeSprue.new.process(args) end end diff --git a/lib/squib.rb b/lib/squib.rb index 298ad47..53bd644 100644 --- a/lib/squib.rb +++ b/lib/squib.rb @@ -4,7 +4,7 @@ require 'pango' require 'rsvg2' require_relative 'squib/version' require_relative 'squib/commands/new' -require_relative 'squib/commands/make_template' +require_relative 'squib/commands/make_sprue' require_relative 'squib/deck' require_relative 'squib/card' diff --git a/lib/squib/api/save.rb b/lib/squib/api/save.rb index 18eb0a3..307a6a7 100644 --- a/lib/squib/api/save.rb +++ b/lib/squib/api/save.rb @@ -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 diff --git a/lib/squib/args/template_file.rb b/lib/squib/args/sprue_file.rb similarity index 82% rename from lib/squib/args/template_file.rb rename to lib/squib/args/sprue_file.rb index 4633689..e83c443 100644 --- a/lib/squib/args/template_file.rb +++ b/lib/squib/args/sprue_file.rb @@ -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 diff --git a/lib/squib/sheet_templates/a4_euro_card.yml b/lib/squib/builtin/sprues/a4_euro_card.yml similarity index 100% rename from lib/squib/sheet_templates/a4_euro_card.yml rename to lib/squib/builtin/sprues/a4_euro_card.yml diff --git a/lib/squib/sheet_templates/a4_poker_card_8up.yml b/lib/squib/builtin/sprues/a4_poker_card_8up.yml similarity index 100% rename from lib/squib/sheet_templates/a4_poker_card_8up.yml rename to lib/squib/builtin/sprues/a4_poker_card_8up.yml diff --git a/lib/squib/sheet_templates/a4_poker_card_9up.yml b/lib/squib/builtin/sprues/a4_poker_card_9up.yml similarity index 100% rename from lib/squib/sheet_templates/a4_poker_card_9up.yml rename to lib/squib/builtin/sprues/a4_poker_card_9up.yml diff --git a/lib/squib/sheet_templates/a4_usa_card.yml b/lib/squib/builtin/sprues/a4_usa_card.yml similarity index 100% rename from lib/squib/sheet_templates/a4_usa_card.yml rename to lib/squib/builtin/sprues/a4_usa_card.yml diff --git a/lib/squib/commands/make_template.rb b/lib/squib/commands/make_sprue.rb similarity index 99% rename from lib/squib/commands/make_template.rb rename to lib/squib/commands/make_sprue.rb index 2a168c8..61043c4 100644 --- a/lib/squib/commands/make_template.rb +++ b/lib/squib/commands/make_sprue.rb @@ -12,7 +12,7 @@ module Squib # +save_templated_sheet+ # # @api public - class MakeTemplate + class MakeSprue # :nodoc: # @api private def process(args) diff --git a/lib/squib/graphics/save_templated_sheet.rb b/lib/squib/graphics/save_sprue.rb similarity index 97% rename from lib/squib/graphics/save_templated_sheet.rb rename to lib/squib/graphics/save_sprue.rb index eec30d6..81e2e5c 100644 --- a/lib/squib/graphics/save_templated_sheet.rb +++ b/lib/squib/graphics/save_sprue.rb @@ -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) diff --git a/lib/squib/sprues/builtin/a4_euro_card.yml b/lib/squib/sprues/builtin/a4_euro_card.yml deleted file mode 100644 index 23e1449..0000000 --- a/lib/squib/sprues/builtin/a4_euro_card.yml +++ /dev/null @@ -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 diff --git a/lib/squib/sprues/builtin/a4_poker_card_8up.yml b/lib/squib/sprues/builtin/a4_poker_card_8up.yml deleted file mode 100644 index 1b7f58b..0000000 --- a/lib/squib/sprues/builtin/a4_poker_card_8up.yml +++ /dev/null @@ -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 diff --git a/lib/squib/sprues/builtin/a4_poker_card_9up.yml b/lib/squib/sprues/builtin/a4_poker_card_9up.yml deleted file mode 100644 index eb1a410..0000000 --- a/lib/squib/sprues/builtin/a4_poker_card_9up.yml +++ /dev/null @@ -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 diff --git a/lib/squib/sprues/builtin/a4_usa_card.yml b/lib/squib/sprues/builtin/a4_usa_card.yml deleted file mode 100644 index 889f791..0000000 --- a/lib/squib/sprues/builtin/a4_usa_card.yml +++ /dev/null @@ -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 diff --git a/lib/squib/sprues/crop_line.rb b/lib/squib/sprues/crop_line.rb new file mode 100644 index 0000000..f2dfa59 --- /dev/null +++ b/lib/squib/sprues/crop_line.rb @@ -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 diff --git a/lib/squib/sprues/crop_line_dash.rb b/lib/squib/sprues/crop_line_dash.rb new file mode 100644 index 0000000..214f7d9 --- /dev/null +++ b/lib/squib/sprues/crop_line_dash.rb @@ -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 diff --git a/lib/squib/template.rb b/lib/squib/sprues/sprue.rb similarity index 77% rename from lib/squib/template.rb rename to lib/squib/sprues/sprue.rb index 4136c92..3e907b6 100644 --- a/lib/squib/template.rb +++ b/lib/squib/sprues/sprue.rb @@ -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 diff --git a/samples/templates/fold_sheet.rb b/samples/sprues/_fold_sheet.rb similarity index 72% rename from samples/templates/fold_sheet.rb rename to samples/sprues/_fold_sheet.rb index 48ccf58..8b5b9c8 100644 --- a/samples/templates/fold_sheet.rb +++ b/samples/sprues/_fold_sheet.rb @@ -6,5 +6,6 @@ Squib::Deck.new(width: '63mm', height: '88mm', cards: 8) do str: %w[Front_1 Front_2 Front_3 Front_4 Back_1 Back_2 Back_3 Back_4], x: '3mm', y: '3mm' ) - save_pdf file: 'fold_sheet.pdf', template_file: 'templates/fold_sheet.yml' + save_pdf file: 'fold_sheet.pdf', + sprue: 'my_sprues/fold_sheet.yml' end diff --git a/samples/templates/hex_tiles.rb b/samples/sprues/_hex_tiles.rb similarity index 83% rename from samples/templates/hex_tiles.rb rename to samples/sprues/_hex_tiles.rb index 86c047a..33fb632 100644 --- a/samples/templates/hex_tiles.rb +++ b/samples/sprues/_hex_tiles.rb @@ -10,5 +10,6 @@ Squib::Deck.new(width: '65.8mm', height: '76mm', cards: 9) do x: '27mm', y: '35mm', width: '11.8mm', height: '6mm', align: :center, valign: :middle ) - save_pdf file: 'hex_tiles.pdf', template_file: 'templates/hex_tiles.yml' + save_pdf file: 'hex_tiles.pdf', + sprue: 'my_sprues/hex_tiles.yml' end diff --git a/samples/templates/use_package_template.rb b/samples/sprues/_use_package_template.rb similarity index 67% rename from samples/templates/use_package_template.rb rename to samples/sprues/_use_package_template.rb index 5be8e82..22163a7 100644 --- a/samples/templates/use_package_template.rb +++ b/samples/sprues/_use_package_template.rb @@ -4,5 +4,6 @@ Squib::Deck.new(width: '63mm', height: '88mm', cards: 9) do text( str: %w[One Two Three Four Five Six Seven Eight Nine], x: '3mm', y: '3mm' ) - save_pdf file: 'use_package_tmpl.pdf', template_file: 'a4_poker_card_9up.yml' + save_pdf file: 'use_package_tmpl.pdf', + sprue: 'a4_poker_card_9up.yml' end diff --git a/samples/templates/templates/fold_sheet.yml b/samples/sprues/my_sprues/fold_sheet.yml similarity index 100% rename from samples/templates/templates/fold_sheet.yml rename to samples/sprues/my_sprues/fold_sheet.yml diff --git a/samples/templates/templates/hex_tiles.yml b/samples/sprues/my_sprues/hex_tiles.yml similarity index 100% rename from samples/templates/templates/hex_tiles.yml rename to samples/sprues/my_sprues/hex_tiles.yml diff --git a/spec/commands/new_spec.rb b/spec/commands/new_spec.rb index 98c3125..79c34a8 100644 --- a/spec/commands/new_spec.rb +++ b/spec/commands/new_spec.rb @@ -6,6 +6,8 @@ describe Squib::Commands::New do describe '#process' do before(:all) do @old_stderr = $stderr + @old_stdout = $stdout + $stdout = StringIO.new $stderr = StringIO.new @oldpwd = Dir.pwd Dir.chdir(output_dir) @@ -41,6 +43,7 @@ describe Squib::Commands::New do after(:all) do $stderr = @old_stderr + $stdout = @old_stdout Dir.chdir(@oldpwd) end end diff --git a/spec/data/templates/basic.yml b/spec/data/sprues/basic.yml similarity index 100% rename from spec/data/templates/basic.yml rename to spec/data/sprues/basic.yml diff --git a/spec/data/templates/card_center_coord.yml b/spec/data/sprues/card_center_coord.yml similarity index 100% rename from spec/data/templates/card_center_coord.yml rename to spec/data/sprues/card_center_coord.yml diff --git a/spec/data/templates/card_rotation.yml b/spec/data/sprues/card_rotation.yml similarity index 100% rename from spec/data/templates/card_rotation.yml rename to spec/data/sprues/card_rotation.yml diff --git a/spec/data/templates/custom_crop_lines.yml b/spec/data/sprues/custom_crop_lines.yml similarity index 100% rename from spec/data/templates/custom_crop_lines.yml rename to spec/data/sprues/custom_crop_lines.yml diff --git a/spec/data/templates/fail_no_card_height.yml b/spec/data/sprues/fail_no_card_height.yml similarity index 100% rename from spec/data/templates/fail_no_card_height.yml rename to spec/data/sprues/fail_no_card_height.yml diff --git a/spec/data/templates/fail_no_card_width.yml b/spec/data/sprues/fail_no_card_width.yml similarity index 100% rename from spec/data/templates/fail_no_card_width.yml rename to spec/data/sprues/fail_no_card_width.yml diff --git a/spec/data/templates/fail_no_sheet_height.yml b/spec/data/sprues/fail_no_sheet_height.yml similarity index 100% rename from spec/data/templates/fail_no_sheet_height.yml rename to spec/data/sprues/fail_no_sheet_height.yml diff --git a/spec/data/templates/fail_no_sheet_width.yml b/spec/data/sprues/fail_no_sheet_width.yml similarity index 100% rename from spec/data/templates/fail_no_sheet_width.yml rename to spec/data/sprues/fail_no_sheet_width.yml diff --git a/spec/samples/samples_regression_spec.rb b/spec/samples/samples_regression_spec.rb index c831dac..8eb864f 100644 --- a/spec/samples/samples_regression_spec.rb +++ b/spec/samples/samples_regression_spec.rb @@ -62,7 +62,7 @@ describe 'Squib samples' do Dir.chdir(File.dirname("#{samples_dir}/#{sample}")) do load full_sample_path end - # overwrite_sample(sample, log) # Use TEMPORARILY once happy with the new sample log + overwrite_sample(sample, log) # Use TEMPORARILY once happy with the new sample log test_file_str = File.open(sample_regression_file(sample), 'r:UTF-8').read expect(log.string).to eq(test_file_str) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6e70927..9b30ed4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -50,8 +50,8 @@ 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}" +def sprue_file(file) + "#{File.expand_path(File.dirname(__FILE__))}/data/sprues/#{file}" end def project_template(file) @@ -127,7 +127,7 @@ def mock_cairo(strio) triangle line_to operator= show_page clip transform mask rectangle reset_clip antialias= curve_to matrix= pango_layout_path stroke_preserve fill_preserve close_path set_dash set_line_cap set_line_join - arc arc_negative).each do |m| + arc arc_negative new_path new_sub_path).each do |m| allow(cxt).to receive(m) { |*args| strio << scrub_hex("cairo: #{m}(#{args})\n") } end diff --git a/spec/template_spec.rb b/spec/sprue_spec.rb similarity index 87% rename from spec/template_spec.rb rename to spec/sprue_spec.rb index 6b9d41e..377705a 100644 --- a/spec/template_spec.rb +++ b/spec/sprue_spec.rb @@ -1,22 +1,23 @@ require 'spec_helper' +require 'squib/sprues/sprue' -describe Squib::Template do - it 'loads a template' do - tmpl = Squib::Template.load(template_file('basic.yml'), 100) +describe Squib::Sprue do + it 'loads a sprue' do + tmpl = Squib::Sprue.load(sprue_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'] + Squib::Sprue::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) + tmpl = Squib::Sprue.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) @@ -77,7 +78,7 @@ describe Squib::Template do 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) + tmpl = Squib::Sprue.load(sprue_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) @@ -94,7 +95,7 @@ describe Squib::Template do end it 'loads a template with customized crop lines' do - tmpl = Squib::Template.load(template_file('custom_crop_lines.yml'), 100) + tmpl = Squib::Sprue.load(sprue_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) @@ -130,7 +131,7 @@ describe Squib::Template do end it 'loads a template with rotated cards' do - tmpl = Squib::Template.load(template_file('card_rotation.yml'), 100) + tmpl = Squib::Sprue.load(sprue_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) @@ -145,7 +146,7 @@ describe Squib::Template do it 'fails when sheet_width is not defined' do expect do - Squib::Template.load(template_file('fail_no_sheet_width.yml'), 100) + Squib::Sprue.load(sprue_file('fail_no_sheet_width.yml'), 100) end.to raise_error( RuntimeError, '"sheet_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/' @@ -154,7 +155,7 @@ describe Squib::Template do it 'fails when sheet_height is not defined' do expect do - Squib::Template.load(template_file('fail_no_sheet_height.yml'), 100) + Squib::Sprue.load(sprue_file('fail_no_sheet_height.yml'), 100) end.to raise_error( RuntimeError, '"sheet_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/' @@ -163,7 +164,7 @@ describe Squib::Template do it 'fails when card_width is not defined' do expect do - Squib::Template.load(template_file('fail_no_card_width.yml'), 100) + Squib::Sprue.load(sprue_file('fail_no_card_width.yml'), 100) end.to raise_error( RuntimeError, '"card_width" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/' @@ -172,7 +173,7 @@ describe Squib::Template do it 'fails when card_height is not defined' do expect do - Squib::Template.load(template_file('fail_no_card_height.yml'), 100) + Squib::Sprue.load(sprue_file('fail_no_card_height.yml'), 100) end.to raise_error( RuntimeError, '"card_height" is not a String matching /^(\d*[.])?\d+(in|cm|mm)$/'