squib 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +162 -133
  3. data/Gemfile +4 -4
  4. data/README.md +630 -550
  5. data/RELEASE TODO.md +18 -18
  6. data/Rakefile +99 -99
  7. data/lib/squib.rb +32 -32
  8. data/lib/squib/api/background.rb +20 -19
  9. data/lib/squib/api/data.rb +100 -99
  10. data/lib/squib/api/image.rb +90 -76
  11. data/lib/squib/api/save.rb +149 -103
  12. data/lib/squib/api/settings.rb +35 -37
  13. data/lib/squib/api/shapes.rb +230 -228
  14. data/lib/squib/api/text.rb +65 -66
  15. data/lib/squib/api/text_embed.rb +96 -66
  16. data/lib/squib/args/arg_loader.rb +138 -0
  17. data/lib/squib/args/box.rb +55 -0
  18. data/lib/squib/args/card_range.rb +32 -0
  19. data/lib/squib/args/color_validator.rb +12 -0
  20. data/lib/squib/args/coords.rb +33 -0
  21. data/lib/squib/args/dir_validator.rb +16 -0
  22. data/lib/squib/args/draw.rb +92 -0
  23. data/lib/squib/args/embed_adjust.rb +25 -0
  24. data/lib/squib/args/embed_key.rb +17 -0
  25. data/lib/squib/args/hand_special.rb +37 -0
  26. data/lib/squib/args/input_file.rb +37 -0
  27. data/lib/squib/args/paint.rb +44 -0
  28. data/lib/squib/args/paragraph.rb +115 -0
  29. data/lib/squib/args/save_batch.rb +60 -0
  30. data/lib/squib/args/scale_box.rb +53 -0
  31. data/lib/squib/args/sheet.rb +72 -0
  32. data/lib/squib/args/showcase_special.rb +38 -0
  33. data/lib/squib/args/svg_special.rb +37 -0
  34. data/lib/squib/args/transform.rb +25 -0
  35. data/lib/squib/args/typographer.rb +117 -117
  36. data/lib/squib/card.rb +67 -67
  37. data/lib/squib/conf.rb +117 -111
  38. data/lib/squib/constants.rb +178 -178
  39. data/lib/squib/deck.rb +113 -111
  40. data/lib/squib/graphics/cairo_context_wrapper.rb +99 -53
  41. data/lib/squib/graphics/gradient_regex.rb +46 -46
  42. data/lib/squib/graphics/hand.rb +42 -43
  43. data/lib/squib/graphics/image.rb +76 -73
  44. data/lib/squib/graphics/save_doc.rb +103 -137
  45. data/lib/squib/graphics/save_images.rb +33 -33
  46. data/lib/squib/graphics/shapes.rb +119 -152
  47. data/lib/squib/graphics/showcase.rb +85 -88
  48. data/lib/squib/graphics/text.rb +176 -216
  49. data/lib/squib/layout_parser.rb +91 -89
  50. data/lib/squib/layouts/economy.yml +85 -0
  51. data/lib/squib/layouts/fantasy.yml +101 -0
  52. data/lib/squib/layouts/hand.yml +62 -46
  53. data/lib/squib/layouts/playing-card.yml +35 -18
  54. data/lib/squib/project_template/config.yml +45 -40
  55. data/lib/squib/version.rb +10 -10
  56. data/samples/color_shortcuts.rb +6 -0
  57. data/samples/csv_import.rb +18 -18
  58. data/samples/custom-config.yml +5 -5
  59. data/samples/custom_config.rb +18 -18
  60. data/samples/draw_shapes.rb +45 -35
  61. data/samples/embed_text.rb +88 -90
  62. data/samples/hand.rb +24 -24
  63. data/samples/layouts.rb +62 -61
  64. data/samples/layouts_builtin.rb +51 -0
  65. data/samples/load_images.rb +78 -64
  66. data/samples/ranges.rb +64 -53
  67. data/samples/sample.csv +2 -2
  68. data/samples/text_options.rb +102 -94
  69. data/spec/api/api_data_spec.rb +57 -50
  70. data/spec/api/api_settings_spec.rb +37 -17
  71. data/spec/args/box_spec.rb +127 -0
  72. data/spec/args/draw_spec.rb +95 -0
  73. data/spec/args/embed_key_spec.rb +13 -0
  74. data/spec/args/input_file_spec.rb +21 -0
  75. data/spec/args/paint_spec.rb +22 -0
  76. data/spec/args/paragraph_spec.rb +153 -0
  77. data/spec/args/range_spec.rb +36 -0
  78. data/spec/args/save_batch_spec.rb +51 -0
  79. data/spec/args/scale_box_spec.rb +71 -0
  80. data/spec/args/sheet_spec.rb +58 -0
  81. data/spec/args/showcase_special_spec.rb +15 -0
  82. data/spec/data/samples/autoscale_font.rb.txt +84 -87
  83. data/spec/data/samples/basic.rb.txt +209 -203
  84. data/spec/data/samples/cairo_access.rb.txt +2 -2
  85. data/spec/data/samples/config_text_markup.rb.txt +72 -75
  86. data/spec/data/samples/csv_import.rb.txt +76 -80
  87. data/spec/data/samples/custom_config.rb.txt +48 -49
  88. data/spec/data/samples/draw_shapes.rb.txt +100 -42
  89. data/spec/data/samples/embed_text.rb.txt +283 -295
  90. data/spec/data/samples/excel.rb.txt +162 -171
  91. data/spec/data/samples/gradients.rb.txt +79 -67
  92. data/spec/data/samples/hand.rb.txt +538 -514
  93. data/spec/data/samples/hello_world.rb.txt +36 -38
  94. data/spec/data/samples/load_images.rb.txt +41 -5
  95. data/spec/data/samples/portrait-landscape.rb.txt +49 -51
  96. data/spec/data/samples/ranges.rb.txt +460 -429
  97. data/spec/data/samples/saves.rb.txt +801 -785
  98. data/spec/data/samples/showcase.rb.txt +5910 -5906
  99. data/spec/data/samples/text_options.rb.txt +1125 -981
  100. data/spec/data/samples/tgc_proofs.rb.txt +81 -79
  101. data/spec/data/samples/units.rb.txt +18 -12
  102. data/spec/data/xlsx/with_macros.xlsm +0 -0
  103. data/spec/graphics/cairo_context_wrapper_spec.rb +84 -75
  104. data/spec/graphics/graphics_images_spec.rb +94 -85
  105. data/spec/graphics/graphics_save_doc_spec.rb +67 -65
  106. data/spec/samples/expected/hand.png +0 -0
  107. data/spec/samples/expected/hand_pretty.png +0 -0
  108. data/spec/samples/expected/layout_00.png +0 -0
  109. data/spec/samples/expected/load_images_00.png +0 -0
  110. data/spec/samples/expected/ranges_00.png +0 -0
  111. data/spec/samples/expected/shape_00.png +0 -0
  112. data/spec/samples/expected/showcase.png +0 -0
  113. data/spec/samples/expected/showcase2.png +0 -0
  114. data/spec/samples/expected/showcase_individual_00.png +0 -0
  115. data/spec/samples/expected/showcase_individual_01.png +0 -0
  116. data/spec/samples/expected/showcase_individual_02.png +0 -0
  117. data/spec/samples/expected/showcase_individual_03.png +0 -0
  118. data/spec/samples/expected/text_00.png +0 -0
  119. data/spec/samples/expected/text_01.png +0 -0
  120. data/spec/samples/expected/text_02.png +0 -0
  121. data/spec/samples/samples_regression_spec.rb +82 -82
  122. data/spec/spec_helper.rb +3 -2
  123. data/squib.gemspec +48 -48
  124. data/squib.sublime-project +42 -36
  125. metadata +61 -33
  126. data/lib/squib/input_helpers.rb +0 -238
  127. data/spec/api/api_image_spec.rb +0 -38
  128. data/spec/api/api_text_spec.rb +0 -37
  129. data/spec/graphics/graphics_shapes_spec.rb +0 -85
  130. data/spec/graphics/graphics_text_spec.rb +0 -164
  131. data/spec/input_helpers_spec.rb +0 -238
  132. data/spec/samples/expected/embed_multi_00.png +0 -0
  133. data/spec/samples/expected/embed_multi_01.png +0 -0
  134. data/spec/samples/expected/embed_multi_02.png +0 -0
  135. data/spec/samples/expected/ranges_01.png +0 -0
  136. data/spec/samples/expected/ranges_02.png +0 -0
@@ -1,38 +0,0 @@
1
- require 'spec_helper'
2
- require 'squib'
3
-
4
- describe Squib::Deck, 'images' do
5
-
6
- context '#png' do
7
- it 'calls Card#png, Dir, and progress bar' do
8
- card = instance_double(Squib::Card)
9
- progress = double(Squib::Progress)
10
- expect(card).to receive(:png).with('foo', 0, 1, :native, :native, 0.5, :overlay, 0.75, nil).once
11
- expect(Dir).to receive(:chdir).with('.').and_yield.once
12
- expect(progress).to receive(:start).and_yield(progress).once
13
- expect(progress).to receive(:increment).once
14
- Squib::Deck.new do
15
- @progress_bar = progress
16
- @cards = [card]
17
- png file: 'foo', x: 0, y: 1, alpha: 0.5, blend: :overlay, angle: 0.75
18
- end
19
- end
20
- end
21
-
22
- context '#svg' do
23
- it 'calls Card#svg, Dir, and progress bar' do
24
- card = instance_double(Squib::Card)
25
- progress = double(Squib::Progress)
26
- expect(card).to receive(:svg).with('foo', nil, '#bar', 0, 1, 20, 30, 0.5, :overlay, 0.75, nil).once
27
- expect(Dir).to receive(:chdir).with('.').and_yield.once
28
- expect(progress).to receive(:start).and_yield(progress).once
29
- expect(progress).to receive(:increment).once
30
- Squib::Deck.new do
31
- @progress_bar = progress
32
- @cards = [card]
33
- svg file: 'foo', id: 'bar', x: 0, y: 1, width: 20, height: 30, alpha: 0.5, blend: :overlay, angle: 0.75
34
- end
35
- end
36
- end
37
-
38
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
- require 'squib'
3
-
4
- describe Squib::Deck, '#text' do
5
-
6
- context 'fonts' do
7
- it "should use the default font when #text and #set_font don't specify" do
8
- card = instance_double(Squib::Card)
9
- expect(card).to receive(:text).with(anything, 'a', 'Arial 36', *([anything] * 17)).once
10
- Squib::Deck.new do
11
- @cards = [card]
12
- text str: 'a'
13
- end
14
- end
15
-
16
- it "should use the #set_font when #text doesn't specify" do
17
- card = instance_double(Squib::Card)
18
- expect(card).to receive(:text).with(anything, 'a', 'Times New Roman 16', *([anything] * 17)).once
19
- Squib::Deck.new do
20
- @cards = [card]
21
- set font: 'Times New Roman 16'
22
- text str: 'a'
23
- end
24
- end
25
-
26
- it 'should use the specified font no matter what' do
27
- card = instance_double(Squib::Card)
28
- expect(card).to receive(:text).with(anything, 'a', 'Arial 18', *([anything] * 17)).once
29
- Squib::Deck.new do
30
- @cards = [card]
31
- set font: 'Times New Roman 16'
32
- text str: 'a', font: 'Arial 18'
33
- end
34
- end
35
- end
36
-
37
- end
@@ -1,85 +0,0 @@
1
- require 'spec_helper'
2
- require 'squib'
3
-
4
- describe Squib::Card do
5
-
6
- let(:deck) { double(Squib::Deck) }
7
- let(:cxt) { double(Cairo::Context) }
8
-
9
- def expect_stroke(cxt, fill_color, stroke_color, stroke_width)
10
- expect(cxt).to receive(:set_source_color).with(stroke_color).once
11
- expect(cxt).to receive(:set_line_width).with(stroke_width).once
12
- expect(cxt).to receive(:stroke).once
13
- expect(cxt).to receive(:set_source_color).with(fill_color).once
14
- expect(cxt).to receive(:fill).once
15
- end
16
-
17
- before(:each) do
18
- allow(Cairo::Context).to receive(:new).and_return(cxt)
19
- allow(deck).to receive(:dir).and_return('_output')
20
- allow(deck).to receive(:count_format).and_return('%02d')
21
- allow(deck).to receive(:prefix).and_return('card_')
22
- allow(deck).to receive(:antialias).and_return('subpixel')
23
- allow(deck).to receive(:backend).and_return('memory')
24
- end
25
-
26
- context 'rect' do
27
- it 'make all the expected calls on a smoke test' do
28
- expect(cxt).to receive(:antialias=).with('subpixel')
29
- expect(cxt).to receive(:save).once
30
- expect(cxt).to receive(:rounded_rectangle).with(37, 38, 50, 100, 10, 15).twice
31
- expect_stroke(cxt, '#fff', '#f00', 2.0)
32
- expect(cxt).to receive(:restore).once
33
-
34
- card = Squib::Card.new(deck, 100, 150)
35
- # rect(x, y, width, height, x_radius, y_radius,
36
- # fill_color, stroke_color, stroke_width)
37
- card.rect(37, 38, 50, 100, 10, 15, '#fff', '#f00', 2.0)
38
- end
39
- end
40
-
41
- context 'circle' do
42
- it 'make all the expected calls on a smoke test' do
43
- expect(cxt).to receive(:antialias=).with('subpixel')
44
- expect(cxt).to receive(:save).once
45
- expect(cxt).to receive(:move_to).with(137, 38)
46
- expect(cxt).to receive(:circle).with(37, 38, 100).twice
47
- expect_stroke(cxt, '#fff', '#f00', 2.0)
48
- expect(cxt).to receive(:restore).once
49
-
50
- card = Squib::Card.new(deck, 100, 150)
51
- # circle(x, y, radius,
52
- # fill_color, stroke_color, stroke_width)
53
- card.circle(37, 38, 100, '#fff', '#f00', 2.0)
54
- end
55
- end
56
-
57
- context 'triangle' do
58
- it 'make all the expected calls on a smoke test' do
59
- expect(cxt).to receive(:antialias=).with('subpixel')
60
- expect(cxt).to receive(:save).once
61
- expect(cxt).to receive(:triangle).with(1, 2, 3, 4, 5, 6).twice
62
- expect_stroke(cxt, '#fff', '#f00', 2.0)
63
- expect(cxt).to receive(:restore).once
64
-
65
- card = Squib::Card.new(deck, 100, 150)
66
- card.triangle(1, 2, 3, 4, 5, 6, '#fff', '#f00', 2.0)
67
- end
68
- end
69
-
70
- context 'line' do
71
- it 'make all the expected calls on a smoke test' do
72
- expect(cxt).to receive(:antialias=).with('subpixel')
73
- expect(cxt).to receive(:save).once
74
- expect(cxt).to receive(:move_to).with(1, 2).once
75
- expect(cxt).to receive(:line_to).with(3, 4).once
76
- expect(cxt).to receive(:set_source_color).with('#fff').once
77
- expect(cxt).to receive(:set_line_width).with(2.0).once
78
- expect(cxt).to receive(:stroke).once
79
- expect(cxt).to receive(:restore).once
80
-
81
- card = Squib::Card.new(deck, 100, 150)
82
- card.line(1, 2, 3, 4, '#fff', 2.0)
83
- end
84
- end
85
- end
@@ -1,164 +0,0 @@
1
- require 'spec_helper'
2
- require 'squib'
3
-
4
- describe Squib::Card, '#text' do
5
-
6
- context 'typical inputs' do
7
- let(:deck) { double(Squib::Deck) }
8
- let(:context) { double(Cairo::Context) }
9
- let(:layout) { double(Pango::Layout) }
10
- let(:font_desc) { double(Pango::FontDescription) }
11
- let(:pango_cxt) { double(Pango::Context) }
12
-
13
- before(:each) do
14
- allow(Cairo::Context).to receive(:new).and_return(context)
15
- allow(deck).to receive(:dir).and_return('_output')
16
- allow(deck).to receive(:count_format).and_return('%02d')
17
- allow(deck).to receive(:prefix).and_return('card_')
18
- allow(deck).to receive(:antialias).and_return('best')
19
- allow(deck).to receive(:antialias).and_return('subpixel')
20
- allow(deck).to receive(:backend).and_return('memory')
21
- allow(layout).to receive(:context).and_return(pango_cxt)
22
- end
23
-
24
- it 'make all the expected calls on a smoke test' do
25
- extent = Pango::Rectangle.new(50,60,100,200)
26
- expect(Squib.logger).to receive(:debug).once
27
- expect(context).to receive(:antialias=).with('subpixel').once
28
- expect(context).to receive(:save).once
29
- expect(context).to receive(:set_source_color).once
30
- expect(context).to receive(:move_to).with(0, 0).twice
31
- expect(context).to receive(:rotate).with(0.0).once
32
- expect(context).to receive(:translate).with(10, 15).once
33
- expect(context).to receive(:create_pango_layout).once.and_return(layout)
34
- expect(Pango::FontDescription).to receive(:new).with('Sans 12').and_return(font_desc)
35
- expect(layout ).to receive(:font_description=).with(font_desc).once
36
- expect(layout ).to receive(:text=).with('foo').once
37
- expect(layout ).to receive(:width=).with(20 * Pango::SCALE).once
38
- expect(layout ).to receive(:height=).with(25 * Pango::SCALE).once
39
- expect(layout ).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_NONE).once
40
- expect(layout ).to receive(:alignment=).with(Pango::Layout::ALIGN_LEFT).once
41
- expect(pango_cxt).to receive(:font_options=).once
42
- expect(layout ).to receive(:justify=).with(false).once
43
- expect(layout ).to receive(:spacing=).with(1.0 * Pango::SCALE).once
44
- expect(context).to receive(:update_pango_layout).once
45
- expect(layout ).to receive(:height).once.and_return(25)
46
- expect(layout ).to receive(:extents).thrice.and_return([nil,extent])
47
- expect(context).to receive(:update_pango_layout).once
48
- expect(context).to receive(:show_pango_layout).once
49
- expect(context).to receive(:restore).once
50
-
51
- card = Squib::Card.new(deck, 100, 150)
52
- # text(str, font, font_size, color,
53
- # x, y, width, height,
54
- # markup, justify, wrap, ellipsize,
55
- # spacing, align, valign, hint, angle,
56
- # stroke_width, stroke_color)
57
- ret = card.text(Squib::TextEmbed.new,'foo', 'Sans 12', nil, '#abc',
58
- 10, 15, 20, 25,
59
- nil, false, false, false,
60
- 1.0, :left, :top, nil, 0.0, '#fff', 0)
61
- expect(ret).to eq({width: 0, height: 0})
62
- end
63
- end
64
-
65
- context 'convenience lookups' do
66
- let(:deck) { double(Squib::Deck) }
67
- let(:context) { double(Cairo::Context).as_null_object }
68
- let(:layout) { double(Pango::Layout).as_null_object }
69
- let(:extents) { double("extents") }
70
-
71
- before(:each) do
72
- allow(Cairo::Context).to receive(:new).and_return(context)
73
- expect(context).to receive(:create_pango_layout).once.and_return(layout)
74
- allow(deck).to receive(:dir).and_return('_output')
75
- allow(deck).to receive(:count_format).and_return('%02d')
76
- allow(deck).to receive(:prefix).and_return('card_')
77
- allow(deck).to receive(:antialias).and_return('subpixel')
78
- allow(deck).to receive(:backend).and_return('memory')
79
- end
80
-
81
- it 'aligns right with strings' do
82
- card = Squib::Card.new(deck, 100, 150)
83
- expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_RIGHT).once
84
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
85
- 10, 15, 20, 50,
86
- nil, false, false, false,
87
- 1.0, 'right', :top, nil, 0.0, '#fff', 0)
88
- end
89
-
90
- it 'aligns center with strings' do
91
- card = Squib::Card.new(deck, 100, 150)
92
- expect(layout).to receive(:alignment=).with(Pango::Layout::ALIGN_CENTER).once
93
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
94
- 10, 15, 20, 50,
95
- nil, false, false, false,
96
- 1.0, 'center', :top, nil, 0.0, '#fff', 0)
97
- end
98
-
99
- it 'sets wrap to char with string char' do
100
- card = Squib::Card.new(deck, 100, 150)
101
- expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_CHAR).once
102
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
103
- 10, 15, 20, 50,
104
- nil, false, 'char', false,
105
- 1.0, :left, :top, nil, 0.0, '#fff', 0)
106
- end
107
-
108
- it 'sets wrap to word with word string' do
109
- card = Squib::Card.new(deck, 100, 150)
110
- expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD).once
111
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
112
- 10, 15, 20, 50,
113
- nil, false, 'word', false,
114
- 1.0, :left, :top, nil, 0.0, '#fff', 0)
115
- end
116
-
117
- it 'sets wrap to word_char with symbol word_char' do
118
- card = Squib::Card.new(deck, 100, 150)
119
- expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
120
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
121
- 10, 15, 20, 50,
122
- nil, false, :word_char, false,
123
- 1.0, :left, :top, nil, 0.0, '#fff', 0)
124
- end
125
-
126
- it 'sets wrap to word_char with true' do
127
- card = Squib::Card.new(deck, 100, 150)
128
- expect(layout).to receive(:wrap=).with(Pango::Layout::WRAP_WORD_CHAR).once
129
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
130
- 10, 15, 20, 50,
131
- nil, false, true, false,
132
- 1.0, :left, :top, nil, 0.0, '#fff', 0)
133
- end
134
-
135
- it 'sets ellipsize to start properly' do
136
- card = Squib::Card.new(deck, 100, 150)
137
- expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_START).once
138
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
139
- 10, 15, 20, 50,
140
- nil, false, true, :start,
141
- 1.0, :left, :top, nil, 0.0, '#fff', 0)
142
- end
143
-
144
- it 'sets ellipsize to middle properly' do
145
- card = Squib::Card.new(deck, 100, 150)
146
- expect(layout).to receive(:ellipsize=).with(Pango::Layout::ELLIPSIZE_MIDDLE).once
147
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
148
- 10, 15, 20, 50,
149
- nil, false, true, 'middle',
150
- 1.0, :left, :top, nil, 0.0, '#fff', 0)
151
- end
152
-
153
- it 'implements stroke and fill when asked to' do
154
- card = Squib::Card.new(deck, 100, 150)
155
- expect(context).to receive(:set_line_width).with(3.0).once
156
- expect(context).to receive(:pango_layout_path).once
157
- card.text(Squib::TextEmbed.new, 'foo', 'Sans 12', nil, '#abc',
158
- 10, 15, 20, 50,
159
- nil, false, true, 'middle',
160
- 1.0, :left, :top, nil, 0.0, '#f00', 3.0)
161
- end
162
-
163
- end
164
- end
@@ -1,238 +0,0 @@
1
- require 'spec_helper'
2
- require 'squib'
3
- require 'squib/input_helpers'
4
-
5
- class DummyDeck
6
- include Squib::InputHelpers
7
- attr_accessor :layout, :cards, :custom_colors, :width, :height, :dpi
8
- end
9
-
10
- describe Squib::InputHelpers do
11
-
12
- before(:each) do
13
- @deck = DummyDeck.new
14
- @deck.layout = {
15
- 'blah' => {x: 25},
16
- 'apples' => {x: 35},
17
- 'oranges' => {y: 45},
18
- }
19
- @deck.cards = %w(a b)
20
- @deck.custom_colors = {}
21
- @deck.width = 100
22
- @deck.height = 200
23
- @deck.dpi = 300
24
- end
25
-
26
- context '#layoutify' do
27
- it 'warns on the logger when the layout does not exist' do
28
- expect(Squib.logger).to receive(:warn).with("Layout entry 'foo' does not exist.").twice
29
- expect(Squib.logger).to receive(:debug)
30
- expect(@deck.send(:layoutify, {layout: :foo})).to eq({layout: [:foo,:foo]})
31
- end
32
-
33
- it 'applies the layout in a normal situation' do
34
- expect(@deck.send(:layoutify, {layout: :blah})).to \
35
- eq({layout: [:blah, :blah], x: [25, 25]})
36
- end
37
-
38
- it 'applies two different layouts for two different situations' do
39
- expect(@deck.send(:layoutify, {layout: ['blah', 'apples']})).to \
40
- eq({layout: ['blah','apples'], x: [25, 35]})
41
- end
42
-
43
- it 'still has nils when not applied two different layouts differ in structure' do
44
- expect(@deck.send(:layoutify, {layout: ['apples', 'oranges']})).to \
45
- eq({layout: ['apples','oranges'], x: [35], y: [nil, 45]})
46
- #...this might behavior that is hard to debug for users. Trying to come up with a warning or something...
47
- end
48
-
49
- it 'also looks up based on strings' do
50
- expect(@deck.send(:layoutify, {layout: 'blah'})).to \
51
- eq({layout: ['blah','blah'], x: [25, 25]})
52
- end
53
-
54
- end
55
-
56
- context '#rangeify' do
57
- it 'must be within the card size range' do
58
- expect{@deck.send(:rangeify, {range: 2..3})}.to \
59
- raise_error(ArgumentError, '2..3 is outside of deck range of 0..1')
60
- end
61
-
62
- it 'cannot be nil' do
63
- expect{@deck.send(:rangeify, {range: nil})}.to \
64
- raise_error(RuntimeError, 'Range cannot be nil')
65
- end
66
-
67
- it 'defaults to a range of all cards if :all' do
68
- expect(@deck.send(:rangeify, {range: :all})).to eq({range: 0..1})
69
- end
70
- end
71
-
72
- context '#fileify' do
73
- it 'should throw an error if the file does not exist' do
74
- expect{@deck.send(:fileify, {file: 'nonexist.txt'}, true)}.to \
75
- raise_error(RuntimeError,"File #{File.expand_path('nonexist.txt')} does not exist!")
76
- end
77
- end
78
-
79
- context '#dirify' do
80
- it 'should raise an error if the directory does not exist' do
81
- expect{@deck.send(:dirify, {dir: 'nonexist'}, :dir, false)}.to \
82
- raise_error(RuntimeError,"'nonexist' does not exist!")
83
- end
84
-
85
- it 'should warn and make a directory creation is allowed' do
86
- opts = {dir: 'tocreate'}
87
- Dir.chdir(output_dir) do
88
- FileUtils.rm_rf('tocreate', secure: true)
89
- expect(Squib.logger).to receive(:warn).with("Dir 'tocreate' does not exist, creating it.").once
90
- expect(@deck.send(:dirify, opts, :dir, true)).to eq(opts)
91
- expect(Dir.exists? 'tocreate').to be true
92
- end
93
- end
94
-
95
- end
96
-
97
- context '#colorify' do
98
- it 'should pass through if nillable' do
99
- color = @deck.send(:colorify, {color: ['#fff']}, true)[:color]
100
- expect(color).to eq(['#fff'])
101
- end
102
-
103
- it 'pulls from custom colors in the config' do
104
- @deck.custom_colors['foo'] = '#abc'
105
- expect(@deck.send(:colorify, {color: [:foo]}, false)[:color][0].to_s).to \
106
- eq('#abc')
107
- end
108
-
109
- it 'pulls custom colors even when a string' do
110
- @deck.custom_colors['foo'] = '#abc'
111
- expect(@deck.send(:colorify, {color: ['foo']}, false)[:color][0].to_s).to \
112
- eq('#abc')
113
- end
114
- end
115
-
116
- context '#rotateify' do
117
- it 'computes a clockwise rotate properly' do
118
- opts = @deck.send(:rotateify, {rotate: :clockwise})
119
- expect(opts).to eq({ :angle => 0.5 * Math::PI,
120
- :rotate => :clockwise
121
- })
122
- end
123
-
124
- it 'computes a counter-clockwise rotate properly' do
125
- opts = @deck.send(:rotateify, {rotate: :counterclockwise})
126
- expect(opts).to eq({ :angle => 1.5 * Math::PI,
127
- :rotate => :counterclockwise
128
- })
129
- end
130
- end
131
-
132
- context '#convert_units' do
133
- it 'does not touch arrays integers' do
134
- args = {x: [156]}
135
- needed_params = [:x]
136
- opts = @deck.send(:convert_units, args, needed_params)
137
- expect(opts).to eq({ :x => [156] })
138
- end
139
-
140
- it 'does not touch arrays floats' do
141
- args = {x: [156.2]}
142
- needed_params = [:x]
143
- opts = @deck.send(:convert_units, args, needed_params)
144
- expect(opts).to eq({ :x => [156.2] })
145
- end
146
-
147
- it 'converts array of all inches' do
148
- args = {x: ['1in', '2in']}
149
- needed_params = [:x]
150
- opts = @deck.send(:convert_units, args, needed_params)
151
- expect(opts).to eq({:x => [300.0, 600.0] }) #assume 300dpi default
152
- end
153
-
154
- it 'converts array of some inches' do
155
- args = {x: [156, '2in']}
156
- needed_params = [:x]
157
- opts = @deck.send(:convert_units, args, needed_params)
158
- expect(opts).to eq({:x => [156.0, 600.0]}) #assume 300dpi default
159
- end
160
-
161
- it 'handles whitespace' do
162
- args = {x: ['1in ']}
163
- needed_params = [:x]
164
- opts = @deck.send(:convert_units, args, needed_params)
165
- expect(opts).to eq({:x => [300.0] }) #assume 300dpi default
166
- end
167
-
168
- it 'converts centimeters' do
169
- args = {x: ['2cm']}
170
- needed_params = [:x]
171
- opts = @deck.send(:convert_units, args, needed_params)
172
- expect(opts).to eq({:x => [236.2204722] }) #assume 300dpi default
173
- end
174
-
175
- it 'handles non-expading singletons' do
176
- args = {margin: '1in', trim: '1in', gap: '1in'}
177
- needed_params = [:margin, :trim, :gap]
178
- opts = @deck.send(:convert_units, args, needed_params)
179
- expect(opts).to eq({margin: 300, trim: 300, gap: 300}) #assume 300dpi default
180
- end
181
-
182
- end
183
-
184
- context '#rowify' do
185
- it 'does nothing on an integer' do
186
- opts = @deck.send(:rowify, {columns: 2, rows: 2})
187
- expect(opts).to eq({ columns: 2,
188
- rows: 2
189
- })
190
- end
191
-
192
- it 'computes properly on non-integer' do
193
- opts = @deck.send(:rowify, {columns: 1, rows: :infinite})
194
- expect(opts).to eq({ columns: 1,
195
- rows: 2
196
- })
197
- end
198
- end
199
-
200
- context '#faceify' do
201
- it 'is false on left' do
202
- opts = @deck.send(:faceify, {face: :left})
203
- expect(opts).to eq({ face: false })
204
- end
205
-
206
- it 'is true on right' do
207
- opts = @deck.send(:faceify, {face: 'Right'})
208
- expect(opts).to eq({ face: true })
209
- end
210
-
211
- it 'is false on anything else' do
212
- opts = @deck.send(:faceify, {face: 'flugelhorn'})
213
- expect(opts).to eq({ face: false })
214
- end
215
- end
216
-
217
- context '#formatify' do
218
- it 'sets format to nil when format is not set' do
219
- opts = @deck.send(:formatify, {foo: true})
220
- expect(opts).to eq({
221
- foo: true,
222
- format: [nil]
223
- })
224
- end
225
-
226
- it 'updates the format to array' do
227
- opts = @deck.send(:formatify, {format: :png})
228
- expect(opts).to eq({format: [:png]})
229
- end
230
-
231
- it 'updates the format to flattened array' do
232
- opts = @deck.send(:formatify, {format: [[:png]]})
233
- expect(opts).to eq({format: [:png]})
234
- end
235
-
236
- end
237
-
238
- end