squib 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -1,40 +1,44 @@
1
- module Squib
2
- # Squib's command-line options
3
- module Commands
4
-
5
- # Generate a new Squib project into a fresh directory.
6
- #
7
- # Provides conventions for using Git (you are using version control, right??).
8
- # Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget.
9
- #
10
- #
11
- # @example
12
- # squib new foo-blasters
13
- # cd foo-blasters
14
- # ruby deck.rb
15
- # git commit -am "Starting my cool new game using Squib!"
16
- #
17
- # @api public
18
- class New
19
-
20
- # :nodoc:
21
- # @api private
22
- def process(args)
23
- raise ArgumentError.new('Please specify a path.') if args.empty?
24
-
25
- new_project_path = File.expand_path(args.join(" "), Dir.pwd)
26
- template_path = File.expand_path('../project_template', File.dirname(__FILE__))
27
-
28
- FileUtils.mkdir_p new_project_path
29
- if !Dir["#{new_project_path}/**/*"].empty?
30
- $stderr.puts "#{new_project_path} exists and is not empty. Doing nothing and quitting."
31
- else
32
- Dir.chdir(new_project_path) do
33
- FileUtils.cp_r template_path + '/.', new_project_path
34
- end
35
- end
36
- end
37
-
38
- end
39
- end
1
+ require 'fileutils'
2
+
3
+ module Squib
4
+ # Squib's command-line options
5
+ module Commands
6
+
7
+ # Generate a new Squib project into a fresh directory.
8
+ #
9
+ # Provides conventions for using Git (you are using version control, right??).
10
+ # Also provides some basic layout and config files to start from, along with templates for instructions and other notes you don't want to forget.
11
+ #
12
+ #
13
+ # @example
14
+ # squib new foo-blasters
15
+ # cd foo-blasters
16
+ # ruby deck.rb
17
+ # git init
18
+ # git add .
19
+ # git commit -m "Starting my cool new game using Squib!"
20
+ #
21
+ # @api public
22
+ class New
23
+
24
+ # :nodoc:
25
+ # @api private
26
+ def process(args)
27
+ raise ArgumentError.new('Please specify a path.') if args.empty?
28
+
29
+ new_project_path = File.expand_path(args.join(" "), Dir.pwd)
30
+ template_path = File.expand_path('../project_template', File.dirname(__FILE__))
31
+
32
+ FileUtils.mkdir_p new_project_path
33
+ if !Dir["#{new_project_path}/**/*"].empty?
34
+ $stderr.puts "#{new_project_path} exists and is not empty. Doing nothing and quitting."
35
+ else
36
+ Dir.chdir(new_project_path) do
37
+ FileUtils.cp_r template_path + '/.', new_project_path
38
+ end
39
+ end
40
+ end
41
+
42
+ end
43
+ end
40
44
  end
@@ -1,40 +1,105 @@
1
- module Squib
2
- # Squib's defaults for when arguments are not specified in the command nor layouts.
3
- #
4
- # @api public
5
- SYSTEM_DEFAULTS = {
6
- :range => :all,
7
- :color => :black,
8
- :str => '',
9
- :fill_color => '#0000',
10
- :stroke_color => :black,
11
- :stroke_width => 2.0,
12
- :font => :use_set,
13
- :default_font => 'Arial 36',
14
- :sheet => 0,
15
- :x => 0,
16
- :y => 0,
17
- :x1 => 100,
18
- :y1 => 100,
19
- :x2 => 150,
20
- :y2 => 150,
21
- :x3 => 100,
22
- :y3 => 150,
23
- :x_radius => 0,
24
- :y_radius => 0,
25
- :align => :left,
26
- :valign => :top,
27
- :justify => false,
28
- :ellipsize => :end,
29
- :width => :native,
30
- :height => :native,
31
- :alpha => 1.0,
32
- :format => :png,
33
- :dir => "_output",
34
- :prefix => "card_",
35
- :margin => 75,
36
- :gap => 0,
37
- :trim => 0
38
- }
39
-
1
+ module Squib
2
+ # Squib's defaults for when arguments are not specified in the command nor layouts.
3
+ #
4
+ # @api public
5
+ SYSTEM_DEFAULTS = {
6
+ :align => :left,
7
+ :alpha => 1.0,
8
+ :blend => :none,
9
+ :color => :black,
10
+ :default_font => 'Arial 36',
11
+ :dir => "_output",
12
+ :ellipsize => :end,
13
+ :fill_color => '#0000',
14
+ :force_id => false,
15
+ :font => :use_set,
16
+ :format => :png,
17
+ :gap => 0,
18
+ :height => :native,
19
+ :hint => :off,
20
+ :img_dir => '.',
21
+ :justify => false,
22
+ :margin => 75,
23
+ :markup => false,
24
+ :prefix => "card_",
25
+ :progress_bar => false,
26
+ :range => :all,
27
+ :rotate => false,
28
+ :sheet => 0,
29
+ :spacing => 0,
30
+ :str => '',
31
+ :stroke_color => :black,
32
+ :stroke_width => 2.0,
33
+ :trim => 0,
34
+ :valign => :top,
35
+ :width => :native,
36
+ :wrap => true,
37
+ :x => 0,
38
+ :x1 => 100,
39
+ :x2 => 150,
40
+ :x3 => 100,
41
+ :x_radius => 0,
42
+ :y => 0,
43
+ :y1 => 100,
44
+ :y2 => 150,
45
+ :y3 => 150,
46
+ :y_radius => 0,
47
+ }
48
+
49
+ # Squib's configuration defaults
50
+ #
51
+ # @api public
52
+ CONFIG_DEFAULTS = {
53
+ 'custom_colors' => {},
54
+ 'dpi' => 300,
55
+ 'hint' => :none,
56
+ 'progress_bar' => false,
57
+ 'img_dir' => '.',
58
+ }
59
+
60
+ # These are parameters that are intended to be "expanded" across
61
+ # range if they are singletons.
62
+ #
63
+ # For example, using a different font for each card, using one `text`
64
+ #
65
+ # key: the internal name of the param (e.g. :files)
66
+ # value: the user-facing API key (e.g. file: 'abc.png')
67
+ #
68
+ # @api private
69
+ EXPANDING_PARAMS = {
70
+ :align => :align,
71
+ :alpha => :alpha,
72
+ :blend => :blend,
73
+ :circle_radius => :radius,
74
+ :color => :color,
75
+ :ellipsize => :ellipsize,
76
+ :files => :file,
77
+ :fill_color => :fill_color,
78
+ :force_svgid => :force_id,
79
+ :font => :font,
80
+ :height => :height,
81
+ :hint => :hint,
82
+ :justify => :justify,
83
+ :layout => :layout,
84
+ :markup => :markup,
85
+ :rect_radius => :radius,
86
+ :spacing => :spacing,
87
+ :str => :str,
88
+ :stroke_color => :stroke_color,
89
+ :stroke_width => :stroke_width,
90
+ :svgid => :id,
91
+ :valign => :valign,
92
+ :width => :width,
93
+ :wrap => :wrap,
94
+ :x => :x,
95
+ :x1 => :x1,
96
+ :x2 => :x2,
97
+ :x3 => :x3,
98
+ :x_radius => :x_radius,
99
+ :y => :y,
100
+ :y1 => :y1,
101
+ :y2 => :y2,
102
+ :y2 => :y3,
103
+ :y_radius => :y_radius,
104
+ }
40
105
  end
@@ -1,114 +1,117 @@
1
- require 'yaml'
2
- require 'pp'
3
- require 'squib/card'
4
- require 'squib/input_helpers'
5
- require 'squib/constants'
6
-
7
- # The project module
8
- #
9
- # @api public
10
- module Squib
11
-
12
- # The main interface to Squib. Provides a front-end porcelain whereas the Card class interacts with the graphics plumbing.
13
- #
14
- # @api public
15
- class Deck
16
- include Enumerable
17
- include Squib::InputHelpers
18
-
19
- # :nodoc:
20
- # @api private
21
- attr_reader :width, :height
22
-
23
- # :nodoc:
24
- # @api private
25
- attr_reader :cards
26
-
27
- # :nodoc:
28
- # @api private
29
- attr_reader :text_hint
30
-
31
- # Squib's constructor that sets the immutable properties.
32
- #
33
- # This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods.
34
- # The documented methods in Deck are the ones intended for use by most users.
35
- # If your game requires multiple different sizes or orientations, I recommend using multiple `Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that's not recommended.
36
- # @example
37
- # require 'squib'
38
- # Squib::Deck.new do
39
- # text str: 'Hello, World!'
40
- # end
41
- #
42
- # @param width: [Integer] the width of each card in pixels
43
- # @param height: [Integer] the height of each card in pixels
44
- # @param cards: [Integer] the number of cards in the deck
45
- # @param dpi: [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
46
- # @param config: [String] the file used for global settings of this deck
47
- # @param block [Block] the main body of the script.
48
- # @api public
49
- def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
50
- @width=width; @height=height
51
- @dpi = dpi
52
- @font = Squib::SYSTEM_DEFAULTS[:default_font]
53
- @cards = []
54
- cards.times{ @cards << Squib::Card.new(self, width, height) }
55
- load_config(config)
56
- load_layout(layout)
57
- if block_given?
58
- instance_eval(&block)
59
- end
60
- end
61
-
62
- # Directly accesses the array of cards in the deck
63
- #
64
- # @api private
65
- def [](key)
66
- @cards[key]
67
- end
68
-
69
- # Iterates over each card in the deck
70
- #
71
- # @api private
72
- def each(&block)
73
- @cards.each { |card| block.call(card) }
74
- end
75
-
76
- # Load the configuration file, if exists, overriding hardcoded defaults
77
- # @api private
78
- def load_config(file)
79
- if File.exists? file
80
- if config = YAML.load_file(file)
81
- @dpi = config['dpi'].to_i
82
- end
83
- end
84
- end
85
-
86
- # Load the layout configuration file, if exists
87
- # @api private
88
- def load_layout(file)
89
- return if file.nil?
90
- prelayout = YAML.load_file(file)
91
- @layout = {}
92
- prelayout.each do |key, value|
93
- if value.key? "extends"
94
- @layout[key] = prelayout[value["extends"]].merge prelayout[key]
95
- else
96
- @layout[key] = value
97
- end
98
- end
99
- end
100
-
101
- ##################
102
- ### PUBLIC API ###
103
- ##################
104
- require 'squib/api/background'
105
- require 'squib/api/data'
106
- require 'squib/api/image'
107
- require 'squib/api/save'
108
- require 'squib/api/settings'
109
- require 'squib/api/shapes'
110
- require 'squib/api/text'
111
- require 'squib/api/units'
112
-
113
- end
1
+ require 'yaml'
2
+ require 'pp'
3
+ require 'squib'
4
+ require 'squib/card'
5
+ require 'squib/progress'
6
+ require 'squib/input_helpers'
7
+ require 'squib/constants'
8
+
9
+ # The project module
10
+ #
11
+ # @api public
12
+ module Squib
13
+
14
+ # The main interface to Squib. Provides a front-end porcelain whereas the Card class interacts with the graphics plumbing.
15
+ #
16
+ # @api public
17
+ class Deck
18
+ include Enumerable
19
+ include Squib::InputHelpers
20
+
21
+ # :nodoc:
22
+ # @api private
23
+ attr_reader :width, :height
24
+
25
+ # :nodoc:
26
+ # @api private
27
+ attr_reader :cards
28
+
29
+ # :nodoc:
30
+ # @api private
31
+ attr_reader :text_hint
32
+
33
+ # :nodoc:
34
+ # @api private
35
+ attr_reader :layout, :config
36
+
37
+ # Squib's constructor that sets the immutable properties.
38
+ #
39
+ # This is the starting point for Squib. In providing a block to the constructor, you have access to all of Deck's instance methods.
40
+ # The documented methods in Deck are the ones intended for use by most users.
41
+ # If your game requires multiple different sizes or orientations, I recommend using multiple `Squib::Deck`s in your `deck.rb`. You can modify the internals of `Squib::Deck` (e.g. `@cards`), but that's not recommended.
42
+ # @example
43
+ # require 'squib'
44
+ # Squib::Deck.new do
45
+ # text str: 'Hello, World!'
46
+ # end
47
+ #
48
+ # @param width: [Integer] the width of each card in pixels
49
+ # @param height: [Integer] the height of each card in pixels
50
+ # @param cards: [Integer] the number of cards in the deck
51
+ # @param dpi: [Integer] the pixels per inch when rendering out to PDF or calculating using inches.
52
+ # @param config: [String] the Yaml file used for global settings of this deck
53
+ # @param layout: [String] the Yaml file used for layouts.
54
+ # @param block [Block] the main body of the script.
55
+ # @api public
56
+ def initialize(width: 825, height: 1125, cards: 1, dpi: 300, config: 'config.yml', layout: nil, &block)
57
+ @width=width; @height=height
58
+ @dpi = dpi
59
+ @font = Squib::SYSTEM_DEFAULTS[:default_font]
60
+ @cards = []
61
+ @custom_colors = {}
62
+ @img_dir = '.'
63
+ @progress_bar = Squib::Progress.new(false)
64
+ cards.times{ @cards << Squib::Card.new(self, width, height) }
65
+ load_config(config)
66
+ @layout = YAML.load_file(layout) unless layout.nil?
67
+ if block_given?
68
+ instance_eval(&block)
69
+ end
70
+ end
71
+
72
+ # Directly accesses the array of cards in the deck
73
+ #
74
+ # @api private
75
+ def [](key)
76
+ @cards[key]
77
+ end
78
+
79
+ # Iterates over each card in the deck
80
+ #
81
+ # @api private
82
+ def each(&block)
83
+ @cards.each { |card| block.call(card) }
84
+ end
85
+
86
+ # Shows a descriptive place of the location
87
+ def location(opts)
88
+ opts[:layout] || (" @ #{opts[:x]},#{opts[:y]}")
89
+ end
90
+
91
+ # Load the configuration file, if exists, overriding hardcoded defaults
92
+ # @api private
93
+ def load_config(file)
94
+ if File.exists?(file) && config = YAML.load_file(file)
95
+ config = Squib::CONFIG_DEFAULTS.merge(config)
96
+ @dpi = config['dpi'].to_i
97
+ @text_hint = config['text_hint']
98
+ @progress_bar.enabled = config['progress_bars']
99
+ @custom_colors = config['custom_colors']
100
+ @img_dir = config['img_dir']
101
+ end
102
+ end
103
+
104
+ ##################
105
+ ### PUBLIC API ###
106
+ ##################
107
+ require 'squib/api/background'
108
+ require 'squib/api/data'
109
+ require 'squib/api/image'
110
+ require 'squib/api/save'
111
+ require 'squib/api/settings'
112
+ require 'squib/api/shapes'
113
+ require 'squib/api/text'
114
+ require 'squib/api/units'
115
+
116
+ end
114
117
  end