Browse Source

add suffix option

closes #268
dev
Andy Meneely 5 years ago
parent
commit
cd3bf1b3f2
  1. 1
      CHANGELOG.md
  2. 7
      docs/dsl/save_png.rst
  3. 5
      docs/dsl/save_sheet.rst
  4. 5
      lib/squib/args/save_batch.rb
  5. 3
      lib/squib/args/sheet.rb
  6. 2
      lib/squib/dsl/save_png.rb
  7. 2
      lib/squib/dsl/save_sheet.rb
  8. 6
      lib/squib/graphics/save_images.rb
  9. 4
      samples/saves/_save_filenames.rb
  10. 1
      samples/saves/_saves.rb
  11. BIN
      samples/saves/save_sheet_rtl_00_expected.png
  12. BIN
      samples/saves/save_sheet_rtl_00_with_suffix_expected.png
  13. 2
      spec/data/samples/saves/_saves.rb.txt

1
CHANGELOG.md

@ -8,6 +8,7 @@ Features:
* Shorthands for `x`, `y`, `width`, and `height`! The words `x: 'middle'` and `x: 'middle + 1in'` will get interpreted. See the docs for details.
* Autoscaling text! `ellipsize: :autoscale` will now downscale your `font_size` if the text ellipsized. Thanks @Qgel! (#288, #111).
* Option checking!! Completely reworked the way we handle arguments in Squib internally (no external behavioral differences). Now, when you give an option to Squib that is not expected. Since every DSL method "knows" what options it takes, that also means we have EVERY option properly documented (missed a few...) AND we have an automated test that will tell us if we forget to document it.
* `save_png` and `save_sheet` now have a `suffix` option which defaults to `''`. So now you can customize the filenames with `prefix`, `count_format`, and `suffix`.
Compatibility:
* When saving PNGs with sprues, outputs start counting at zero - which is more consistent with the rest of Squib.

7
docs/dsl/save_png.rst

@ -14,13 +14,18 @@ dir
prefix
default ``'card_'``
the prefix of the file name to be printed.
the prefix of all the filenames saved
count_format
default: ``'%02d'``
the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for ``Kernel::sprintf`` for specifics)
suffix
default: ``''``
the suffix of all the filenames saved, just before the `.png` extension.
rotate
default: ``false``

5
docs/dsl/save_sheet.rst

@ -36,6 +36,11 @@ count_format
the format string used for formatting the card count (e.g. padding zeros). Uses a Ruby format string (see the Ruby doc for ``Kernel::sprintf`` for specifics)
suffix
default: ``''``
the suffix of all the filenames saved, just before the `.png` extension.
dir
default: ``'_output'``

5
lib/squib/args/save_batch.rb

@ -20,6 +20,7 @@ module Squib::Args
dir: '_output',
prefix: 'card_',
rotate: false,
suffix: '',
trim_radius: 0,
trim: 0,
}
@ -53,11 +54,11 @@ module Squib::Args
end
def full_filename(i)
"#{dir[i]}/#{prefix[i]}#{count_format[i] % i}.png"
"#{dir[i]}/#{prefix[i]}#{count_format[i] % i}#{suffix[i]}.png"
end
def summary
"#{dir[0]}/#{prefix[0]}_*"
"#{dir[0]}/#{prefix[0]}_*#{suffix[0]}"
end
end

3
lib/squib/args/sheet.rb

@ -35,6 +35,7 @@ module Squib::Args
height: 2550,
margin: 75,
prefix: 'sheet_',
suffix: '',
rows: :infinite,
columns: 5,
trim_radius: 0,
@ -95,7 +96,7 @@ module Squib::Args
if i.nil?
"#{dir}/#{file}"
else
"#{dir}/#{prefix}#{count_format % i}.png"
"#{dir}/#{prefix}#{count_format % i}#{suffix}.png"
end
end

2
lib/squib/dsl/save_png.rb

@ -22,7 +22,7 @@ module Squib
def self.accepted_params
%i(
range
dir prefix count_format
dir prefix suffix count_format
rotate trim trim_radius
)
end

2
lib/squib/dsl/save_sheet.rb

@ -29,7 +29,7 @@ module Squib
%i(
range sprue
columns rows rtl
prefix count_format dir
dir prefix count_format suffix
margin gap trim trim_radius
)
end

6
lib/squib/graphics/save_images.rb

@ -10,7 +10,7 @@ module Squib
else
@cairo_surface
end
write_png(surface, index, batch.dir, batch.prefix, batch.count_format)
write_png(surface, index, batch)
end
# :nodoc:
@ -44,8 +44,8 @@ module Squib
return new_cc.target
end
def write_png(surface, i, dir, prefix, count_format)
surface.write_to_png("#{dir}/#{prefix}#{count_format % i}.png")
def write_png(surface, i, b)
surface.write_to_png("#{b.dir}/#{b.prefix}#{b.count_format % i}#{b.suffix}.png")
end
end

4
samples/saves/_save_filenames.rb

@ -16,6 +16,10 @@ Squib::Deck.new(width: 50, height: 50, cards: 2) do
# bar.png
save_png prefix: ['foo', 'bar'], count_format: ''
# foo_00_bar.png
# foo_01_bar.png
save_png prefix: 'foo_', suffix: '_bar'
# thief.png
# thug.png
data = csv data: "filename\nthief\nthug"

1
samples/saves/_saves.rb

@ -45,6 +45,7 @@ Squib::Deck.new(width: 825, height: 1125, cards: 16) do
# Sheets can arrange left-to-right and right-to-left
save_sheet prefix: 'save_sheet_rtl_',
suffix: '_with_suffix',
range: 0..1, rtl: true,
columns: 2, rows: 1,
margin: 75, gap: 5, trim: 37

BIN
samples/saves/save_sheet_rtl_00_expected.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

BIN
samples/saves/save_sheet_rtl_00_with_suffix_expected.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

2
spec/data/samples/saves/_saves.rb.txt

@ -1791,7 +1791,7 @@ cairo: set_source([MockDouble, -37, -37])
cairo: paint([])
cairo: set_source([MockDouble, 662, 75])
cairo: paint([])
surface: write_to_png(["_output/save_sheet_rtl_00.png"])
surface: write_to_png(["_output/save_sheet_rtl_00_with_suffix.png"])
surface: finish([])
surface: finish([])
surface: finish([])

Loading…
Cancel
Save