squib 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +29 -29
  3. data/.travis.yml +6 -6
  4. data/.yardopts +7 -5
  5. data/Gemfile +2 -2
  6. data/LICENSE.txt +22 -22
  7. data/README.md +245 -92
  8. data/Rakefile +11 -11
  9. data/bin/squib +18 -18
  10. data/lib/squib.rb +31 -18
  11. data/lib/squib/api/background.rb +18 -16
  12. data/lib/squib/api/data.rb +52 -52
  13. data/lib/squib/api/image.rb +66 -48
  14. data/lib/squib/api/save.rb +43 -37
  15. data/lib/squib/api/settings.rb +38 -35
  16. data/lib/squib/api/shapes.rb +116 -106
  17. data/lib/squib/api/text.rb +50 -45
  18. data/lib/squib/api/units.rb +16 -16
  19. data/lib/squib/card.rb +42 -36
  20. data/lib/squib/commands/new.rb +43 -39
  21. data/lib/squib/constants.rb +104 -39
  22. data/lib/squib/deck.rb +116 -113
  23. data/lib/squib/graphics/background.rb +13 -12
  24. data/lib/squib/graphics/image.rb +47 -28
  25. data/lib/squib/graphics/save_doc.rb +54 -50
  26. data/lib/squib/graphics/save_images.rb +32 -10
  27. data/lib/squib/graphics/shapes.rb +59 -55
  28. data/lib/squib/graphics/text.rb +113 -107
  29. data/lib/squib/input_helpers.rb +193 -139
  30. data/lib/squib/progress.rb +38 -0
  31. data/lib/squib/project_template/.gitignore +4 -3
  32. data/lib/squib/project_template/ABOUT.md +19 -19
  33. data/lib/squib/project_template/Gemfile +2 -2
  34. data/lib/squib/project_template/PNP NOTES.md +3 -3
  35. data/lib/squib/project_template/config.yml +20 -2
  36. data/lib/squib/project_template/deck.rb +5 -5
  37. data/lib/squib/version.rb +6 -6
  38. data/samples/ball.png +0 -0
  39. data/samples/basic.rb +19 -19
  40. data/samples/colors.rb +15 -16
  41. data/samples/custom-config.yml +6 -1
  42. data/samples/custom-layout.yml +39 -34
  43. data/samples/custom_config.rb +18 -5
  44. data/samples/customconfig-imgdir/shiny-purse2.png +0 -0
  45. data/samples/customconfig-imgdir/spanner2.svg +91 -0
  46. data/samples/draw_shapes.rb +18 -18
  47. data/samples/excel.rb +19 -19
  48. data/samples/grit.png +0 -0
  49. data/samples/hello_world.rb +6 -6
  50. data/samples/load_images.rb +29 -19
  51. data/samples/offset.svg +71 -0
  52. data/samples/portrait-landscape.rb +23 -0
  53. data/samples/ranges.rb +55 -47
  54. data/samples/save_pdf.rb +14 -14
  55. data/samples/shiny-purse.png +0 -0
  56. data/samples/spanner.svg +91 -91
  57. data/samples/text_options.rb +60 -58
  58. data/samples/tgc_proofs.rb +19 -19
  59. data/samples/units.rb +12 -12
  60. data/samples/use_layout.rb +28 -28
  61. data/spec/api/api_text_spec.rb +42 -36
  62. data/spec/commands/new_spec.rb +47 -47
  63. data/spec/data/multi-extends-single-entry.yml +13 -0
  64. data/spec/data/multi-level-extends.yml +10 -0
  65. data/spec/data/no-extends.yml +5 -0
  66. data/spec/data/single-extends.yml +7 -0
  67. data/spec/data/single-level-multi-extends.yml +12 -0
  68. data/spec/deck_spec.rb +147 -49
  69. data/spec/input_helpers_spec.rb +117 -0
  70. data/spec/samples_run_spec.rb +19 -14
  71. data/spec/spec_helper.rb +3 -0
  72. data/squib.gemspec +46 -42
  73. metadata +78 -4
  74. data/API.md +0 -59
data/Rakefile CHANGED
@@ -1,11 +1,11 @@
1
- require 'bundler/gem_tasks'
2
- require 'rspec/core/rake_task'
3
- require 'yard'
4
-
5
- RSpec::Core::RakeTask.new(:spec)
6
- task :default => [:install, :spec]
7
-
8
- YARD::Rake::YardocTask.new(:doc) do |t|
9
- t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional
10
- #t.options = ['--any', '--extra', '--opts'] # optional
11
- end
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'yard'
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+ task :default => [:install, :spec]
7
+
8
+ YARD::Rake::YardocTask.new(:doc) do |t|
9
+ t.files = ['lib/**/*.rb', 'samples/**/*.rb'] # optional
10
+ #t.options = ['--any', '--extra', '--opts'] # optional
11
+ end
data/bin/squib CHANGED
@@ -1,19 +1,19 @@
1
- #!/usr/bin/env ruby
2
- require 'squib'
3
- require 'mercenary'
4
-
5
- Mercenary.program(:squib) do |p|
6
- p.version Squib::VERSION
7
- p.description "A Ruby DSL for prototyping card games"
8
- p.syntax "squib <subcommand> [options]"
9
-
10
- p.command(:new) do |c|
11
- c.syntax "new PATH"
12
- c.description "Creates a new Squib project scaffolding in PATH. Must be a new directory or already empty."
13
-
14
- c.action do |args, options|
15
- Squib::Commands::New.new.process(args)
16
- end
17
- end
18
-
1
+ #!/usr/bin/env ruby
2
+ require 'squib'
3
+ require 'mercenary'
4
+
5
+ Mercenary.program(:squib) do |p|
6
+ p.version Squib::VERSION
7
+ p.description "A Ruby DSL for prototyping card games"
8
+ p.syntax "squib <subcommand> [options]"
9
+
10
+ p.command(:new) do |c|
11
+ c.syntax "new PATH"
12
+ c.description "Creates a new Squib project scaffolding in PATH. Must be a new directory or already empty."
13
+
14
+ c.action do |args, options|
15
+ Squib::Commands::New.new.process(args)
16
+ end
17
+ end
18
+
19
19
  end
@@ -1,19 +1,32 @@
1
- require 'logger'
2
- require 'cairo'
3
- require 'pango'
4
- require 'rsvg2'
5
- require 'squib/version'
6
- require 'squib/commands/new'
7
- require 'squib/deck'
8
- require 'squib/card'
9
-
10
- module Squib
11
-
12
- # :nodoc:
13
- # @api private
14
- def logger
15
- @logger ||= Logger.new(STDOUT)
16
- end
17
- module_function :logger
18
-
1
+ require 'logger'
2
+ require 'cairo'
3
+ require 'pango'
4
+ require 'rsvg2'
5
+ require 'squib/version'
6
+ require 'squib/commands/new'
7
+ require 'squib/deck'
8
+ require 'squib/card'
9
+
10
+ module Squib
11
+
12
+ # Access the internal logger that Squib uses. By default, Squib configure the logger to the WARN level
13
+ # Use this to suppress or increase output levels.
14
+ # @example
15
+ # Squib.logger.level = Logger::DEBUG #show waaaay more information than you probably need, unless you're a dev
16
+ # Squib.logger.level = Logger::ERROR #basically turns it off
17
+ #
18
+ # @return [Logger] the ruby logger
19
+ # @api public
20
+ def logger
21
+ if @logger.nil?
22
+ @logger = Logger.new(STDOUT);
23
+ @logger.level = Logger::WARN;
24
+ @logger.formatter = proc do |severity, datetime, progname, msg|
25
+ "#{severity} #{progname}: #{msg}\n"
26
+ end
27
+ end
28
+ @logger
29
+ end
30
+ module_function :logger
31
+
19
32
  end
@@ -1,17 +1,19 @@
1
- module Squib
2
- class Deck
3
- # Fills the background with the given color
4
- # @example
5
- # background color: :white
6
- #
7
- # @option range [Enumerable] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
8
- # @option color [String] (:black) the color the font will render to. See {file:API.md#label-Specifying+Colors Specifying Colors}
9
- # @return [nil] nothing
10
- # @api public
11
- def background(opts = {})
12
- opts = needs(opts,[:range, :color])
13
- opts[:range].each { |i| @cards[i].background(opts[:color]) }
14
- end
15
-
16
- end
1
+ module Squib
2
+ class Deck
3
+ # Fills the background with the given color
4
+ # @example
5
+ # background color: :white
6
+ #
7
+ # Options support Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
8
+ #
9
+ # @option opts range [Enumerable] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
10
+ # @option opts color [String] (:black) the color the font will render to. See {file:README.md#Specifying_Colors Specifying Colors}.
11
+ # @return [nil] nothing
12
+ # @api public
13
+ def background(opts = {})
14
+ opts = needs(opts,[:range, :color])
15
+ opts[:range].each { |i| @cards[i].background(opts[:color][i]) }
16
+ end
17
+
18
+ end
17
19
  end
@@ -1,52 +1,52 @@
1
- require 'roo'
2
-
3
- module Squib
4
-
5
- # Pulls Excel data from `.xlsx` files into a column-based hash
6
- #
7
- # Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row.
8
- # See the example `samples/excel.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples)
9
- #
10
- # @example
11
- # # Excel file looks like this:
12
- # # | h1 | h2 |
13
- # # ------------
14
- # # | 1 | 2 |
15
- # # | 3 | 4 |
16
- # data = xlsx file: 'data.xlsx', sheet: 0
17
- # {'h1' => [1,3], 'h2' => [2,4]}
18
- #
19
- # @option opts file [String] the file to open. Must end in `.xlsx`. Opens relative to the current directory.
20
- # @option opts sheet [Integer] (0) The zero-based index of the sheet from which to read.
21
- # @return [Hash] a hash of arrays based on columns in the spreadsheet
22
- # @api public
23
- def xlsx(opts = {})
24
- opts = Squib::SYSTEM_DEFAULTS.merge(opts)
25
- opts = Squib::InputHelpers.fileify(opts)
26
- s = Roo::Excelx.new(opts[:file])
27
- s.default_sheet = s.sheets[opts[:sheet]]
28
- data = {}
29
- s.first_column.upto(s.last_column) do |col|
30
- header = s.cell(s.first_row,col).to_s
31
- data[header] = []
32
- (s.first_row+1).upto(s.last_row) do |row|
33
- cell = s.cell(row,col)
34
- # Roo hack for avoiding unnecessary .0's on whole integers
35
- cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, "General"]
36
- data[header] << cell
37
- end#row
38
- end#col
39
- data
40
- end#xlsx
41
- module_function :xlsx
42
-
43
- class Deck
44
-
45
- # Convenience call for Squib.xlsx
46
- def xlsx(opts = {})
47
- Squib.xlsx(opts)
48
- end
49
-
50
- end
51
- end
52
-
1
+ require 'roo'
2
+
3
+ module Squib
4
+
5
+ # Pulls Excel data from `.xlsx` files into a column-based hash
6
+ #
7
+ # Pulls the data into a Hash of arrays based on the columns. First row is assumed to be the header row.
8
+ # See the example `samples/excel.rb` in the [source repository](https://github.com/andymeneely/squib/tree/master/samples)
9
+ #
10
+ # @example
11
+ # # Excel file looks like this:
12
+ # # | h1 | h2 |
13
+ # # ------------
14
+ # # | 1 | 2 |
15
+ # # | 3 | 4 |
16
+ # data = xlsx file: 'data.xlsx', sheet: 0
17
+ # {'h1' => [1,3], 'h2' => [2,4]}
18
+ #
19
+ # @option opts file [String] the file to open. Must end in `.xlsx`. Opens relative to the current directory.
20
+ # @option opts sheet [Integer] (0) The zero-based index of the sheet from which to read.
21
+ # @return [Hash] a hash of arrays based on columns in the spreadsheet
22
+ # @api public
23
+ def xlsx(opts = {})
24
+ opts = Squib::SYSTEM_DEFAULTS.merge(opts)
25
+ opts = Squib::InputHelpers.fileify(opts)
26
+ s = Roo::Excelx.new(opts[:file])
27
+ s.default_sheet = s.sheets[opts[:sheet]]
28
+ data = {}
29
+ s.first_column.upto(s.last_column) do |col|
30
+ header = s.cell(s.first_row,col).to_s
31
+ data[header] = []
32
+ (s.first_row+1).upto(s.last_row) do |row|
33
+ cell = s.cell(row,col)
34
+ # Roo hack for avoiding unnecessary .0's on whole integers
35
+ cell = s.excelx_value(row,col) if s.excelx_type(row,col) == [:numeric_or_formula, "General"]
36
+ data[header] << cell
37
+ end#row
38
+ end#col
39
+ data
40
+ end#xlsx
41
+ module_function :xlsx
42
+
43
+ class Deck
44
+
45
+ # Convenience call for Squib.xlsx
46
+ def xlsx(opts = {})
47
+ Squib.xlsx(opts)
48
+ end
49
+
50
+ end
51
+ end
52
+
@@ -1,49 +1,67 @@
1
- module Squib
2
- class Deck
3
-
4
- # Renders a png file at the given location.
5
- #
6
- # See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
7
- # Note: scaling not currently supported for PNGs.
8
- # @example
9
- # png file: 'img.png', x: 50, y: 50
10
- #
11
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
12
- # @option opts file [String, Array] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. See {file:API.md#Specifying+Files Specifying Files}
13
- # @option opts x [Integer] (0) the x-coordinate to place
14
- # @option opts y [Integer] (0) the y-coordinate to place
15
- # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:API.md#label-Custom+Layouts Custom Layouts}
16
- # @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image
17
- # @return [nil] Returns nil
18
- # @api public
19
- def png(opts = {})
20
- opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout])
21
- opts[:range].each do |i|
22
- @cards[i].png(opts[:file][i], opts[:x], opts[:y], opts[:alpha])
23
- end
24
- end
25
-
26
- # Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height.
27
- #
28
- # See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
29
- # @example
30
- # svg 1..2, 'icon.svg', '#stone', x: 50, y:50
31
- #
32
- # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
33
- # @option opts file [String, Array] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. See {file:API.md#Specifying+Files Specifying Files}
34
- # @option opts x [Integer] (0) the x-coordinate to place
35
- # @option opts y [Integer] (0) the y-coordinate to place
36
- # @option opts width [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document.
37
- # @option opts height [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document.
38
- # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:API.md#label-Custom+Layouts Custom Layouts}
39
- # @return [nil] Returns nil
40
- # @api public
41
- def svg(opts = {})
42
- p = needs(opts,[:range, :files, :svgid, :x, :y, :width, :height, :layout])
43
- p[:range].each do |i|
44
- @cards[i].svg(p[:file][i], p[:id], p[:x], p[:y], p[:width], p[:height])
45
- end
46
- end
47
-
48
- end
1
+ module Squib
2
+ class Deck
3
+
4
+ # Renders a png file at the given location.
5
+ #
6
+ # See {file:samples/image.rb samples/image.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
7
+ # Note: scaling not currently supported for PNGs.
8
+ # @example
9
+ # png file: 'img.png', x: 50, y: 50
10
+ #
11
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
12
+ # @option opts file [String] ((empty)) file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
13
+ # @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
14
+ # @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
15
+ # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
16
+ # @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
17
+ # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
18
+ # @return [nil] Returns nil
19
+ # @api public
20
+ def png(opts = {})
21
+ opts = needs(opts, [:range, :files, :x, :y, :alpha, :layout, :blend])
22
+ Dir.chdir(@img_dir) do
23
+ @progress_bar.start("Loading PNG(s)", opts[:range].size) do |bar|
24
+ opts[:range].each do |i|
25
+ @cards[i].png(opts[:file][i], opts[:x][i], opts[:y][i], opts[:alpha][i], opts[:blend][i])
26
+ bar.increment
27
+ end
28
+ end
29
+ end
30
+ end
31
+
32
+ # Renders an entire svg file at the given location. Uses the SVG-specified units and DPI to determine the pixel width and height.
33
+ #
34
+ # See {file:samples/load-images.rb samples/load-images.rb} and {file:samples/tgc-overlay.rb samples/tgc-overlay.rb} as examples.
35
+ # @example
36
+ # svg 1..2, 'icon.svg', '#stone', x: 50, y:50
37
+ #
38
+ # @option opts range [Enumerable, :all] (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
39
+ # @option opts file [String] ('') file(s) to read in. If it's a single file, then it's use for every card in range. If the parameter is an Array of files, then each file is looked up for each card. If any of them are nil or '', nothing is done. See {file:README.md#Specifying_Files Specifying Files}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
40
+ # @option opts id [String] (nil) if set, then only render the SVG element with the given id. Prefix '#' is optional. Note: the x-y coordinates are still relative to the SVG document's page. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
41
+ # @option opts force_id [Boolean] (false) if set, then this svg will not be rendered at all if the id is empty or nil. If not set, the entire SVG is rendered. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
42
+ # @option opts x [Integer] (0) the x-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
43
+ # @option opts y [Integer] (0) the y-coordinate to place. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
44
+ # @option opts width [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
45
+ # @option opts height [Integer] (:native) the pixel width that the image should scale to. SVG scaling is done with vectors, so the scaling should be smooth. When set to `:native`, uses the DPI and units of the loaded SVG document. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
46
+ # @option opts layout [String, Symbol] (nil) entry in the layout to use as defaults for this command. See {file:README.md#Custom_Layouts Custom Layouts}. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
47
+ # @option opts alpha [Decimal] (1.0) the alpha-transparency percentage used to blend this image. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
48
+ # @option opts blend [:none, :multiply, :screen, :overlay, :darken, :lighten, :color_dodge, :color_burn, :hard_light, :soft_light, :difference, :exclusion, :hsl_hue, :hsl_saturation, :hsl_color, :hsl_luminosity] (:none) the composite blend operator used when applying this image. See Blend Modes at http://cairographics.org/operators. Supports Arrays, see {file:README.md#Arrays_and_Singleton_Expansion Arrays and Singleon Expansion}
49
+ # @return [nil] Returns nil
50
+ # @api public
51
+ def svg(opts = {})
52
+ p = needs(opts,[:range, :files, :svgid, :force_svgid, :x, :y, :width, :height, :layout, :alpha, :blend])
53
+ Dir.chdir(@img_dir) do
54
+ @progress_bar.start("Loading SVG(s)", p[:range].size) do |bar|
55
+ p[:range].each do |i|
56
+ unless p[:force_id][i] && p[:id][i].to_s.empty?
57
+ @cards[i].svg(p[:file][i], p[:id][i], p[:x][i], p[:y][i],
58
+ p[:width][i], p[:height][i], p[:alpha][i], p[:blend][i])
59
+ end
60
+ bar.increment
61
+ end
62
+ end
63
+ end
64
+ end
65
+
66
+ end
49
67
  end
@@ -1,37 +1,43 @@
1
- module Squib
2
- class Deck
3
-
4
- # Saves the given range of cards to either PNG or PDF
5
- #
6
- # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
7
- # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
8
- # @option opts [Symbol] format (:png) the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]`
9
- # @option opts [String] prefix (card_) the prefix of the file name to be printed
10
- # @return self
11
- # @api public
12
- def save(opts = {})
13
- opts = needs(opts, [:range, :creatable_dir, :formats, :prefix])
14
- save_png(opts) if opts[:format].include? :png
15
- save_pdf(opts) if opts[:format].include? :pdf
16
- self
17
- end
18
-
19
- # Saves the given range of cards to a PNG
20
- #
21
- # @example
22
- # save range: 1..8, dir: '_pnp', prefix: 'bw_'
23
- #
24
- # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:API.md#label-Specifying+Ranges Specifying Ranges}
25
- # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
26
- # @option opts [String] prefix (card_) the prefix of the file name to be printed.
27
- # @return [nil] Returns nothing
28
- # @api public
29
- def save_png(opts = {})
30
- opts = needs(opts,[:range, :creatable_dir, :prefix])
31
- opts[:range].each do |i|
32
- @cards[i].save_png(i, opts[:dir], opts[:prefix])
33
- end
34
- end
35
-
36
- end
37
- end
1
+ module Squib
2
+ class Deck
3
+
4
+ # Saves the given range of cards to either PNG or PDF
5
+ #
6
+ # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
7
+ # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
8
+ # @option opts [Symbol] format (:png) the format that this will be rendered too. Options `:pdf, :png`. Array of both is allowed: `[:pdf, :png]`
9
+ # @option opts [String] prefix (card_) the prefix of the file name to be printed
10
+ # @option opts [Boolean] rotate (false) PNG saving only. If true, the saved cards will be rotated 90 degrees clockwise. Intended to rendering landscape instead of portrait.
11
+ # @return self
12
+ # @api public
13
+ def save(opts = {})
14
+ opts = needs(opts, [:range, :creatable_dir, :formats, :prefix, :rotate])
15
+ save_png(opts) if opts[:format].include? :png
16
+ save_pdf(opts) if opts[:format].include? :pdf
17
+ self
18
+ end
19
+
20
+ # Saves the given range of cards to a PNG
21
+ #
22
+ # @example
23
+ # save range: 1..8, dir: '_pnp', prefix: 'bw_'
24
+ #
25
+ # @option opts [Enumerable] range (:all) the range of cards over which this will be rendered. See {file:README.md#Specifying_Ranges Specifying Ranges}
26
+ # @option opts [String] dir (_output) the directory for the output to be sent to. Will be created if it doesn't exist.
27
+ # @option opts [String] prefix (card_) the prefix of the file name to be printed.
28
+ # @option opts [Boolean, :clockwise, :counterclockwise] rotate (false) if true, the saved cards will be rotated 90 degrees clockwise. Or, rotate by the number of radians. Intended to rendering landscape instead of portrait.
29
+ # @return [nil] Returns nothing
30
+ # @api public
31
+ def save_png(opts = {})
32
+ opts = needs(opts,[:range, :creatable_dir, :prefix, :rotate])
33
+ @progress_bar.start("Saving PNGs to #{opts[:dir]}/#{opts[:prefix]}*", @cards.size) do |bar|
34
+ opts[:range].each do |i|
35
+ @cards[i].save_png(i, opts[:dir], opts[:prefix], opts[:rotate], opts[:angle])
36
+ bar.increment
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+ end
43
+