shoes-core 4.0.0.pre7 → 4.0.0.pre8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/shoes/arc.rb +10 -13
  3. data/lib/shoes/arrow.rb +1 -11
  4. data/lib/shoes/background.rb +0 -3
  5. data/lib/shoes/border.rb +0 -3
  6. data/lib/shoes/button.rb +4 -1
  7. data/lib/shoes/check_button.rb +0 -1
  8. data/lib/shoes/common/art_element.rb +21 -0
  9. data/lib/shoes/common/background_element.rb +10 -0
  10. data/lib/shoes/common/clickable.rb +2 -0
  11. data/lib/shoes/common/rotate.rb +1 -2
  12. data/lib/shoes/common/ui_element.rb +10 -1
  13. data/lib/shoes/core/version.rb +1 -1
  14. data/lib/shoes/download.rb +47 -29
  15. data/lib/shoes/dsl.rb +99 -40
  16. data/lib/shoes/font.rb +0 -4
  17. data/lib/shoes/http_request.rb +91 -0
  18. data/lib/shoes/image.rb +0 -1
  19. data/lib/shoes/input_box.rb +0 -1
  20. data/lib/shoes/internal_app.rb +1 -1
  21. data/lib/shoes/line.rb +25 -11
  22. data/lib/shoes/link.rb +10 -4
  23. data/lib/shoes/list_box.rb +0 -1
  24. data/lib/shoes/mock/app.rb +6 -0
  25. data/lib/shoes/mock/clickable.rb +3 -0
  26. data/lib/shoes/mock/font.rb +0 -4
  27. data/lib/shoes/oval.rb +3 -13
  28. data/lib/shoes/progress.rb +0 -1
  29. data/lib/shoes/rect.rb +1 -11
  30. data/lib/shoes/shape.rb +16 -8
  31. data/lib/shoes/slot.rb +2 -1
  32. data/lib/shoes/star.rb +8 -11
  33. data/lib/shoes/text_block.rb +0 -1
  34. data/lib/shoes/ui/picker.rb +29 -8
  35. data/lib/shoes/version.rb +1 -1
  36. metadata +8 -231
  37. data/Guardfile +0 -5
  38. data/Rakefile +0 -1
  39. data/bin/shoes-stub +0 -62
  40. data/ext/install/Rakefile +0 -39
  41. data/ext/install/shoes.bat +0 -17
  42. data/lib/rubygems_plugin.rb +0 -24
  43. data/shoes-core.gemspec +0 -22
  44. data/spec/shoes/animation_spec.rb +0 -71
  45. data/spec/shoes/app_spec.rb +0 -454
  46. data/spec/shoes/arc_spec.rb +0 -52
  47. data/spec/shoes/arrow_spec.rb +0 -28
  48. data/spec/shoes/background_spec.rb +0 -47
  49. data/spec/shoes/border_spec.rb +0 -46
  50. data/spec/shoes/builtin_methods_spec.rb +0 -122
  51. data/spec/shoes/button_spec.rb +0 -55
  52. data/spec/shoes/check_spec.rb +0 -36
  53. data/spec/shoes/color_spec.rb +0 -429
  54. data/spec/shoes/common/attachable_spec.rb +0 -32
  55. data/spec/shoes/common/inspect_spec.rb +0 -26
  56. data/spec/shoes/common/remove_spec.rb +0 -37
  57. data/spec/shoes/common/rotate_spec.rb +0 -13
  58. data/spec/shoes/common/style_normalizer_spec.rb +0 -28
  59. data/spec/shoes/common/style_spec.rb +0 -197
  60. data/spec/shoes/common/translate_spec.rb +0 -27
  61. data/spec/shoes/configuration_spec.rb +0 -51
  62. data/spec/shoes/constants_spec.rb +0 -39
  63. data/spec/shoes/dialog_spec.rb +0 -169
  64. data/spec/shoes/dimension_spec.rb +0 -451
  65. data/spec/shoes/dimensions_spec.rb +0 -868
  66. data/spec/shoes/download_spec.rb +0 -198
  67. data/spec/shoes/flow_spec.rb +0 -132
  68. data/spec/shoes/font_spec.rb +0 -36
  69. data/spec/shoes/framework_learning_spec.rb +0 -31
  70. data/spec/shoes/gradient_spec.rb +0 -31
  71. data/spec/shoes/helpers/fake_absolute_element.rb +0 -31
  72. data/spec/shoes/helpers/fake_element.rb +0 -25
  73. data/spec/shoes/helpers/inspect_helpers.rb +0 -5
  74. data/spec/shoes/helpers/sample17_helper.rb +0 -65
  75. data/spec/shoes/image_spec.rb +0 -69
  76. data/spec/shoes/images/shoe.jpg +0 -0
  77. data/spec/shoes/input_box_spec.rb +0 -80
  78. data/spec/shoes/integration_spec.rb +0 -19
  79. data/spec/shoes/internal_app_spec.rb +0 -148
  80. data/spec/shoes/keypress_spec.rb +0 -11
  81. data/spec/shoes/keyrelease_spec.rb +0 -11
  82. data/spec/shoes/line_spec.rb +0 -120
  83. data/spec/shoes/link_spec.rb +0 -149
  84. data/spec/shoes/list_box_spec.rb +0 -87
  85. data/spec/shoes/logger/ruby_spec.rb +0 -8
  86. data/spec/shoes/logger_spec.rb +0 -45
  87. data/spec/shoes/oval_spec.rb +0 -25
  88. data/spec/shoes/packager_spec.rb +0 -25
  89. data/spec/shoes/point_spec.rb +0 -99
  90. data/spec/shoes/progress_spec.rb +0 -54
  91. data/spec/shoes/radio_spec.rb +0 -32
  92. data/spec/shoes/rect_spec.rb +0 -40
  93. data/spec/shoes/renamed_delegate_spec.rb +0 -69
  94. data/spec/shoes/shape_spec.rb +0 -119
  95. data/spec/shoes/shared_examples/button.rb +0 -6
  96. data/spec/shoes/shared_examples/changeable.rb +0 -26
  97. data/spec/shoes/shared_examples/clickable.rb +0 -5
  98. data/spec/shoes/shared_examples/common_methods.rb +0 -35
  99. data/spec/shoes/shared_examples/dimensions.rb +0 -32
  100. data/spec/shoes/shared_examples/dsl.rb +0 -44
  101. data/spec/shoes/shared_examples/dsl/animate.rb +0 -29
  102. data/spec/shoes/shared_examples/dsl/arc.rb +0 -45
  103. data/spec/shoes/shared_examples/dsl/background.rb +0 -26
  104. data/spec/shoes/shared_examples/dsl/border.rb +0 -10
  105. data/spec/shoes/shared_examples/dsl/button.rb +0 -5
  106. data/spec/shoes/shared_examples/dsl/cap.rb +0 -6
  107. data/spec/shoes/shared_examples/dsl/check.rb +0 -11
  108. data/spec/shoes/shared_examples/dsl/edit_box.rb +0 -8
  109. data/spec/shoes/shared_examples/dsl/edit_line.rb +0 -8
  110. data/spec/shoes/shared_examples/dsl/editable_element.rb +0 -29
  111. data/spec/shoes/shared_examples/dsl/fill.rb +0 -27
  112. data/spec/shoes/shared_examples/dsl/flow.rb +0 -15
  113. data/spec/shoes/shared_examples/dsl/gradient.rb +0 -62
  114. data/spec/shoes/shared_examples/dsl/image.rb +0 -21
  115. data/spec/shoes/shared_examples/dsl/line.rb +0 -9
  116. data/spec/shoes/shared_examples/dsl/nofill.rb +0 -6
  117. data/spec/shoes/shared_examples/dsl/nostroke.rb +0 -6
  118. data/spec/shoes/shared_examples/dsl/oval.rb +0 -88
  119. data/spec/shoes/shared_examples/dsl/pattern.rb +0 -34
  120. data/spec/shoes/shared_examples/dsl/progress.rb +0 -7
  121. data/spec/shoes/shared_examples/dsl/rect.rb +0 -92
  122. data/spec/shoes/shared_examples/dsl/rgb.rb +0 -28
  123. data/spec/shoes/shared_examples/dsl/shape.rb +0 -61
  124. data/spec/shoes/shared_examples/dsl/star.rb +0 -110
  125. data/spec/shoes/shared_examples/dsl/stroke.rb +0 -30
  126. data/spec/shoes/shared_examples/dsl/strokewidth.rb +0 -19
  127. data/spec/shoes/shared_examples/dsl/style.rb +0 -32
  128. data/spec/shoes/shared_examples/dsl/text_elements.rb +0 -84
  129. data/spec/shoes/shared_examples/dsl/video.rb +0 -5
  130. data/spec/shoes/shared_examples/dsl_app_context.rb +0 -11
  131. data/spec/shoes/shared_examples/hover.rb +0 -78
  132. data/spec/shoes/shared_examples/parent.rb +0 -6
  133. data/spec/shoes/shared_examples/scroll.rb +0 -41
  134. data/spec/shoes/shared_examples/shared_element_method.rb +0 -60
  135. data/spec/shoes/shared_examples/slot.rb +0 -441
  136. data/spec/shoes/shared_examples/state.rb +0 -26
  137. data/spec/shoes/shared_examples/style.rb +0 -77
  138. data/spec/shoes/slot_spec.rb +0 -176
  139. data/spec/shoes/sound_spec.rb +0 -16
  140. data/spec/shoes/span_spec.rb +0 -112
  141. data/spec/shoes/spec_helper.rb +0 -24
  142. data/spec/shoes/stack_spec.rb +0 -79
  143. data/spec/shoes/star_spec.rb +0 -49
  144. data/spec/shoes/text_block_dimensions_spec.rb +0 -77
  145. data/spec/shoes/text_block_spec.rb +0 -314
  146. data/spec/shoes/text_spec.rb +0 -22
  147. data/spec/shoes/ui/picker_spec.rb +0 -69
  148. data/spec/shoes/url_spec.rb +0 -67
  149. data/spec/shoes/widget_spec.rb +0 -78
  150. data/spec/shoes_spec.rb +0 -41
  151. data/spec/spec_helper.rb +0 -27
@@ -1,30 +0,0 @@
1
- shared_examples_for "stroke DSL method" do
2
- let(:color) { Shoes::COLORS.fetch :tomato }
3
-
4
- it "returns a color" do
5
- expect(dsl.stroke(color).class).to eq(Shoes::Color)
6
- end
7
-
8
- # This works differently on a container than on a normal element
9
- it "sets on receiver" do
10
- dsl.stroke color
11
- expect(dsl.style[:stroke]).to eq(color)
12
- end
13
-
14
- it "applies to subsequently created objects" do
15
- dsl.stroke color
16
- expect(Shoes::Rect).to receive(:new) do |*args|
17
- style = args[-2]
18
- expect(style[:stroke]).to eq(color)
19
- end
20
- dsl.rect(10, 10, 100, 100)
21
- end
22
-
23
- context "with hex string" do
24
- let(:color) { "#fff" }
25
-
26
- it "sets the color" do
27
- expect(dsl.stroke(color)).to eq(Shoes::COLORS[:white])
28
- end
29
- end
30
- end
@@ -1,19 +0,0 @@
1
- shared_examples_for "strokewidth DSL method" do
2
- it "returns a number" do
3
- expect(dsl.strokewidth(4)).to eq(4)
4
- end
5
-
6
- it "sets on receiver" do
7
- dsl.strokewidth 4
8
- expect(dsl.style[:strokewidth]).to eq(4)
9
- end
10
-
11
- it "applies to subsequently created objects" do
12
- dsl.strokewidth 6
13
- expect(Shoes::Rect).to receive(:new) do |*args|
14
- style = args[-2]
15
- expect(style[:strokewidth]).to eq(6)
16
- end
17
- dsl.rect(10, 10, 100, 100)
18
- end
19
- end
@@ -1,32 +0,0 @@
1
- shared_examples_for "style DSL method" do
2
- describe "setting new defaults for text block" do
3
- let(:stroke) { Shoes::COLORS[:chartreuse] }
4
- let(:size) { 42 }
5
- let(:fill) { Shoes::COLORS[:peru] }
6
- let(:font) { "SOME FONT" }
7
- let(:style) { {stroke: stroke, size: size, fill: fill, font: font} }
8
-
9
- %w(Banner Title Subtitle Tagline Caption Para Inscription).each do |text_block|
10
- describe text_block do
11
- let(:element) { dsl.public_send text_block.downcase, "Hello!" }
12
- let(:klass) { Shoes.const_get(text_block) }
13
-
14
- before :each do
15
- dsl.style klass, style
16
- end
17
-
18
- it "creates element with appropriate class" do
19
- expect(element.class).to eq(klass)
20
- end
21
-
22
- it "sets size" do
23
- expect(element.size).to eq(size)
24
- end
25
-
26
- it "sets font" do
27
- expect(element.font).to eq(font)
28
- end
29
- end
30
- end
31
- end
32
- end
@@ -1,84 +0,0 @@
1
- shared_examples_for "text element DSL methods" do
2
- it "should set banner font size to 48" do
3
- text_block = dsl.banner("hello!")
4
- expect(text_block.size).to eql 48
5
- end
6
-
7
- it "should set title font size to 34" do
8
- text_block = dsl.title("hello!")
9
- expect(text_block.size).to eql 34
10
- end
11
-
12
- it "should set subtitle font size to 26" do
13
- text_block = dsl.subtitle("hello!")
14
- expect(text_block.size).to eql 26
15
- end
16
-
17
- it "should set tagline font size to 18" do
18
- text_block = dsl.tagline("hello!")
19
- expect(text_block.size).to eql 18
20
- end
21
-
22
- it "should set caption font size to 14" do
23
- text_block = dsl.caption("hello!")
24
- expect(text_block.size).to eql 14
25
- end
26
-
27
- it "should set para font size to 12" do
28
- text_block = dsl.para("hello!")
29
- expect(text_block.size).to eql 12
30
- end
31
-
32
- it "should set inscription font size to 10" do
33
- text_block = dsl.inscription("hello!")
34
- expect(text_block.size).to eql 10
35
- end
36
-
37
- describe 'span' do
38
- let(:link_array) { [dsl.link('foo'), dsl.link('foo')] }
39
-
40
- it 'should parse the color' do
41
- span = dsl.span 'Hello', stroke: '#ccc'
42
- expect(span.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
43
- end
44
-
45
- it 'should handle a splatted array of links' do
46
- expect { dsl.span(*link_array) }.not_to raise_error
47
- end
48
-
49
- it 'should handle a splatted array of links and parse the color' do
50
- span = dsl.span(*link_array, stroke: '#ccc')
51
- expect(span.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
52
- end
53
-
54
- it 'should handle a splatted array of links with a block' do
55
- link = dsl.link('foo') { "Bar" }
56
- array = [link, link]
57
- expect { dsl.span(*array) }.not_to raise_error
58
- end
59
- end
60
-
61
- describe 'link' do
62
- it 'handles multiple texts' do
63
- link = dsl.link('one', 'two')
64
- expect(link.to_s).to eql('onetwo')
65
- end
66
-
67
- it 'handles trailing options' do
68
- link = dsl.link('one', 'two', stroke: '#ccc')
69
- expect(link.to_s).to eql('onetwo')
70
- expect(link.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
71
- end
72
- end
73
-
74
- describe 'para' do
75
- context "with nested text fragments with parameters" do
76
- Shoes::DSL::TEXT_STYLES.keys.each do |style|
77
- it "handles opts properly for #{style}" do
78
- para = dsl.para(dsl.send(style, style, stroke: '#ccc'))
79
- expect(para.text).to eq(style.to_s)
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,5 +0,0 @@
1
- shared_examples_for 'video DSL method' do
2
- it 'throws a Shoes::NotImplementedError' do
3
- expect { dsl.video }.to raise_error Shoes::NotImplementedError
4
- end
5
- end
@@ -1,11 +0,0 @@
1
- shared_context "dsl app" do
2
- let(:input_block) { proc {} }
3
- let(:input_opts) { Hash.new }
4
- let(:user_facing_app) { Shoes::App.new input_opts, &input_block }
5
- let(:app) { user_facing_app.instance_variable_get(:@__app__) }
6
- let(:parent) do
7
- Shoes::Flow.new app, app,
8
- width: Shoes::InternalApp::DEFAULT_OPTIONS[:width],
9
- height: Shoes::InternalApp::DEFAULT_OPTIONS[:height]
10
- end
11
- end
@@ -1,78 +0,0 @@
1
- shared_examples "object with hover" do
2
- let(:teal) { Shoes::COLORS[:teal] }
3
- let(:gold) { Shoes::COLORS[:gold] }
4
-
5
- let(:hover_class) { subject.hover_class }
6
-
7
- it "registers hover" do
8
- expect(subject).to receive(:add_mouse_hover_control)
9
- subject.hover {}
10
- end
11
-
12
- it "registers with leave" do
13
- expect(subject).to receive(:add_mouse_hover_control)
14
- subject.leave {}
15
- end
16
-
17
- it "marks itself as hovered" do
18
- subject.mouse_hovered
19
- expect(subject.hovered?).to eq(true)
20
- end
21
-
22
- it "marks itself not hovered after leaving" do
23
- subject.mouse_hovered
24
- expect(subject.hovered?).to eq(true)
25
-
26
- subject.mouse_left
27
- expect(subject.hovered?).to eq(false)
28
- end
29
-
30
- it "only calls hover block once" do
31
- count = 0
32
- subject.hover do
33
- count += 1
34
- end
35
-
36
- subject.mouse_hovered
37
- subject.mouse_hovered
38
-
39
- expect(count).to eq(1)
40
- end
41
-
42
- it "only calls leave block once after we're hovering" do
43
- count = 0
44
- subject.leave do
45
- count += 1
46
- end
47
-
48
- subject.mouse_hovered
49
- subject.mouse_left
50
- subject.mouse_left
51
-
52
- expect(count).to eq(1)
53
- end
54
-
55
- it "doesn't update styles on hover by default" do
56
- original_style = subject.style.dup
57
- subject.mouse_hovered
58
-
59
- expect(subject.style).to eq(original_style)
60
- end
61
-
62
- it "updates styles on hover" do
63
- user_facing_app.style(hover_class, stroke: teal)
64
-
65
- subject.mouse_hovered
66
- expect(subject.style[:stroke]).to eq(teal)
67
- end
68
-
69
- it "restores style after hover's done" do
70
- user_facing_app.style(hover_class, stroke: teal)
71
-
72
- subject.style[:stroke] = gold
73
- subject.mouse_hovered
74
- subject.mouse_left
75
-
76
- expect(subject.style[:stroke]).to eq(gold)
77
- end
78
- end
@@ -1,6 +0,0 @@
1
- # requires you to provide a let(:parent)
2
- shared_examples_for 'object with parent' do
3
- it 'has a getter for the parent' do
4
- expect(subject.parent).to eq parent
5
- end
6
- end
@@ -1,41 +0,0 @@
1
- shared_examples_for "scrollable slot" do
2
- its(:scroll) { should be_truthy }
3
- it "initializes scroll_top to 0" do
4
- expect(subject.scroll_top).to eq(0)
5
- end
6
- end
7
-
8
- shared_examples_for "scrollable slot with overflowing content" do
9
- it "retains the same height" do
10
- expect(subject.height).to eq(height)
11
- end
12
-
13
- it "has scroll_height larger than height" do
14
- expect(subject.scroll_height).to be > height
15
- end
16
-
17
- it "has scroll_max = (scroll_height - height)" do
18
- expect(subject.scroll_max).to eq(subject.scroll_height - subject.height)
19
- end
20
-
21
- it 'adjusts scroll_top' do
22
- expect(subject.scroll_top).to eq(new_position)
23
- end
24
- end
25
-
26
- shared_context "scroll" do
27
- let(:height) { 200 }
28
- let(:input_opts) { {left: 40, top: 20, width: 400, height: height} }
29
- let(:opts) { input_opts.merge(scroll: scroll) }
30
- end
31
-
32
- shared_context "overflowing content" do
33
- let(:new_position) { 300 }
34
-
35
- before :each do
36
- 200.times do
37
- Shoes::TextBlock.new(app, subject, "Fourteen fat chimichangas", size: 18)
38
- end
39
- subject.scroll_top = new_position
40
- end
41
- end
@@ -1,60 +0,0 @@
1
- require 'shoes/color'
2
-
3
- shared_examples_for "object with stroke" do
4
- let(:color) { Shoes::COLORS.fetch :tomato }
5
- let(:color2) { Shoes::COLORS.fetch :forestgreen }
6
- let(:gradient) { Shoes::Gradient.new(color, color2) }
7
-
8
- specify "returns a color" do
9
- c = subject.stroke = color
10
- expect(c.class).to eq(Shoes::Color)
11
- end
12
-
13
- specify "sets on receiver" do
14
- subject.stroke = color
15
- expect(subject.stroke).to eq(color)
16
- expect(subject.style[:stroke]).to eq(color)
17
- end
18
-
19
- specify "sets with a gradient" do
20
- subject.stroke = gradient
21
- expect(subject.stroke).to eq(gradient)
22
- expect(subject.style[:stroke]).to eq(gradient)
23
- end
24
-
25
- # Be sure the subject does *not* have the stroke set previously
26
- specify "defaults to black" do
27
- expect(subject.stroke).to eq(Shoes::COLORS.fetch(:black))
28
- end
29
-
30
- describe "strokewidth" do
31
- specify "defaults to 1" do
32
- expect(subject.strokewidth).to eq(1)
33
- end
34
-
35
- specify "sets" do
36
- subject.strokewidth = 2
37
- expect(subject.strokewidth).to eq(2)
38
- end
39
- end
40
- end
41
-
42
- shared_examples_for "object with fill" do
43
- let(:color) { Shoes::COLORS.fetch :honeydew }
44
-
45
- specify "returns a color" do
46
- c = subject.fill = color
47
- expect(c.class).to eq(Shoes::Color)
48
- end
49
-
50
- specify "sets on receiver" do
51
- subject.fill = color
52
- expect(subject.fill).to eq(color)
53
- expect(subject.style[:fill]).to eq(color)
54
- end
55
-
56
- # Be sure the subject does *not* have the stroke set previously
57
- specify "defaults to black" do
58
- expect(subject.fill).to eq(Shoes::COLORS.fetch(:black))
59
- end
60
- end
@@ -1,441 +0,0 @@
1
- shared_examples_for "Slot" do
2
- it "should be able to append" do
3
- expect(subject.contents).to be_empty
4
- our_subject = subject
5
- app.execute_block proc { our_subject.append { para "foo" } }
6
- expect(subject.contents.size).to eq(1)
7
- end
8
-
9
- it 'has a height of 0 as it is empty although it has a top' do
10
- subject.absolute_top = 100
11
- subject.contents_alignment
12
- expect(subject.height).to eq 0
13
- end
14
-
15
- it_behaves_like 'prepending'
16
- it_behaves_like 'clearing'
17
- it_behaves_like 'element one positioned with bottom and right'
18
- it_behaves_like 'growing although relatively positioned elements'
19
- it_behaves_like 'margin and positioning'
20
- it_behaves_like 'margin with a relative positioned child'
21
- end
22
-
23
- shared_context 'one slot child' do
24
- let(:ele_opts) { Hash.new }
25
- let(:element) { Shoes::FakeElement.new(nil, {height: 100, width: 50}.merge(ele_opts)) }
26
-
27
- before :each do
28
- subject.add_child element
29
- end
30
- end
31
-
32
- shared_context 'two slot children' do
33
- include_context 'one slot child'
34
- let(:element2) { Shoes::FakeElement.new nil, height: 200, width: 70 }
35
-
36
- before :each do
37
- subject.add_child element2
38
- end
39
- end
40
-
41
- shared_context 'hidden child' do
42
- let(:hidden_element) { Shoes::FakeElement.new nil, height: 200, width: 70 }
43
-
44
- before :each do
45
- subject.add_child hidden_element
46
- hidden_element.gui = double("hidden gui", update_visibility: nil)
47
- hidden_element.hide
48
- end
49
- end
50
-
51
- shared_context 'three slot children' do
52
- include_context 'two slot children'
53
- let(:element3) { Shoes::FakeElement.new(nil, height: 50, width: 20) }
54
-
55
- before :each do
56
- subject.add_child element3
57
- end
58
- end
59
-
60
- shared_context 'contents_alignment' do
61
- before :each do
62
- subject.contents_alignment
63
- end
64
- end
65
-
66
- shared_context 'element one with top and left' do
67
- let(:ele_top) { 22 }
68
- let(:ele_left) { 47 }
69
- let(:ele_opts) { {left: ele_left, top: ele_top} }
70
- end
71
-
72
- shared_context 'slot with set height and width' do
73
- let(:input_opts) { {width: 250, height: 300} }
74
- end
75
-
76
- shared_context 'slot with a top margin' do
77
- let(:margin_top) { 70 }
78
- let(:input_opts) { {margin_top: margin_top} }
79
- end
80
-
81
- shared_context 'slot with a left margin' do
82
- let(:margin_left) { 30 }
83
- let(:input_opts) { {margin_left: margin_left} }
84
- end
85
-
86
- shared_context 'element one with bottom and right' do
87
- let(:ele_bottom) { 24 }
88
- let(:ele_right) { 49 }
89
- let(:ele_opts) { {right: ele_right, bottom: ele_bottom} }
90
- end
91
-
92
- shared_examples_for 'positioning through :_position' do
93
- let(:element) { Shoes::FakeElement.new nil, height: 100, width: 50 }
94
-
95
- def add_child_and_align
96
- subject.add_child element
97
- subject.contents_alignment
98
- end
99
-
100
- it 'sends the child the :_position method to position it' do
101
- expect(element).to receive(:_position).and_call_original
102
- add_child_and_align
103
- end
104
-
105
- it 'does not send _position again if the position did not change' do
106
- add_child_and_align
107
- expect(element).not_to receive(:_position)
108
- subject.contents_alignment
109
- end
110
-
111
- it 'does not send _position if element does not need positioning' do
112
- allow(element).to receive(:takes_up_space?) { false }
113
- allow(element).to receive(:needs_positioning?) { false }
114
- expect(element).not_to receive(:_position)
115
- add_child_and_align
116
- end
117
-
118
- it 'sends _position even when element does not take up space' do
119
- allow(element).to receive(:takes_up_space?) { false }
120
- allow(element).to receive(:needs_positioning?) { true }
121
- expect(element).to receive(:_position).and_call_original
122
- add_child_and_align
123
- end
124
-
125
- it 'is resilient to exceptions during positioning' do
126
- allow(element).to receive(:contents_alignment).and_raise("O_o")
127
- allow(subject).to receive(:puts) # Quiet, you
128
- add_child_and_align
129
- end
130
-
131
- describe 'attached' do
132
- let(:attached_to) { double('attached slot', absolute_left: 101, absolute_top: 101) }
133
- let(:element) { Shoes::FakeElement.new nil }
134
-
135
- it "gets positioned where it's attached" do
136
- element.style[:attach] = attached_to
137
- expect(element).to receive(:_position).with(101, 101).at_least(1)
138
- add_child_and_align
139
- end
140
- end
141
-
142
- describe 'absolute dimensions' do
143
- let(:element) { Shoes::FakeAbsoluteElement.new }
144
-
145
- it 'positions element via _position' do
146
- expect(element).to receive(:_position).and_call_original
147
- add_child_and_align
148
- end
149
- end
150
- end
151
-
152
- shared_examples_for 'element one positioned with top and left' do
153
- it 'positions the element at its left value' do
154
- expect(element.absolute_left).to eq subject.absolute_left + ele_left
155
- end
156
-
157
- it 'positions the element at its top value' do
158
- expect(element.absolute_top).to eq subject.absolute_top + ele_top
159
- end
160
- end
161
-
162
- shared_examples_for 'element one positioned with bottom and right' do
163
- include_context 'one slot child'
164
- include_context 'contents_alignment'
165
- include_context 'element one with bottom and right'
166
- include_context 'slot with set height and width'
167
-
168
- it 'positions the element from its right' do
169
- expect(element.absolute_right).to eq(subject.absolute_right - ele_right - 1)
170
- end
171
-
172
- it 'positions the element from its bottom' do
173
- expect(element.absolute_bottom).to eq(subject.absolute_bottom - ele_bottom - 1)
174
- end
175
- end
176
-
177
- shared_examples_for 'positions the first element in the top left' do
178
- include_context 'one slot child'
179
- include_context 'contents_alignment'
180
- it 'positions a single object at the same top as self' do
181
- expect(element.absolute_top).to eq subject.element_top
182
- end
183
-
184
- it 'positions a single object at the same left as self' do
185
- expect(element.absolute_left).to eq subject.element_left
186
- end
187
-
188
- it 'has a slot height of the element height' do
189
- expect(subject.height).to eq element.height
190
- end
191
-
192
- describe 'top and left' do
193
- include_context 'element one with top and left'
194
- it_behaves_like 'element one positioned with top and left'
195
- end
196
- end
197
-
198
- shared_examples_for 'arranges elements underneath each other' do
199
- include_context 'two slot children'
200
- include_context 'contents_alignment'
201
-
202
- it 'positions an element beneath a previous element' do
203
- expect(element2.absolute_top).to eq element.absolute_bottom + 1
204
- end
205
-
206
- it 'still positions it at the start of the line (e.g. self.left)' do
207
- expect(element2.absolute_left).to eq subject.absolute_left
208
- end
209
-
210
- it 'has a stack height according to its contents' do
211
- expect(subject.height).to eq(element.height + element2.height)
212
- end
213
-
214
- it 'has an absolute_bottom of top + height' do
215
- expect(subject.absolute_bottom).to eq(subject.absolute_top + subject.height - 1)
216
- end
217
-
218
- describe 'element one with top and left' do
219
- include_context 'element one with top and left'
220
- it_behaves_like 'element one positioned with top and left'
221
-
222
- describe 'positions element2 disregarding element1' do
223
- it 'has the same absolute left as the slot' do
224
- expect(element2.absolute_left).to eq subject.absolute_left
225
- end
226
-
227
- it 'has the same absolute top as the slot' do
228
- expect(element2.absolute_top).to eq subject.absolute_top
229
- end
230
- end
231
- end
232
- end
233
-
234
- shared_examples_for 'set height and contents alignment' do
235
- include_context 'two slot children'
236
-
237
- it 'contents_alignment returns the height of the content' do
238
- expect(subject.contents_alignment).to eq(element.height + element2.height)
239
- end
240
-
241
- it 'still has the same height though' do
242
- old_height = subject.height
243
- subject.contents_alignment
244
- expect(subject.height).to eq old_height
245
- end
246
- end
247
-
248
- shared_examples_for 'taking care of margin' do
249
- include_context 'two slot children'
250
- include_context 'contents_alignment'
251
-
252
- it 'respects the left margin for the first element' do
253
- expect(element.absolute_left).to eq input_opts[:margin]
254
- end
255
-
256
- it 'respects the left margin for the second element' do
257
- expect(element2.absolute_left).to eq input_opts[:margin]
258
- end
259
-
260
- it 'respects the top margin for the first element' do
261
- expect(element.absolute_top).to eq input_opts[:margin]
262
- end
263
- end
264
-
265
- shared_examples_for 'growing although relatively positioned elements' do
266
- include_context 'one slot child'
267
- include_context 'contents_alignment'
268
-
269
- describe 'positioned at the very beginning' do
270
- let(:ele_opts) { {top: 0} }
271
-
272
- it 'grows the slot height' do
273
- expect(subject.height).to eq element.height
274
- end
275
- end
276
-
277
- describe 'positioned with a good offset' do
278
- let(:ele_opts) { {top: 70} }
279
-
280
- it 'grows the height even further' do
281
- expect(subject.height).to eq element.height + 70
282
- end
283
- end
284
-
285
- describe 'positioning with hidden elements' do
286
- include_context 'hidden child'
287
-
288
- it 'grows only to height of first child' do
289
- subject.contents_alignment
290
- expect(subject.height).to eq element.height
291
- end
292
- end
293
- end
294
-
295
- shared_examples_for 'prepending' do
296
- include_context 'two slot children'
297
- let(:prepend1) { Shoes::FakeElement.new(nil, width: 100) }
298
- let(:prepend2) { Shoes::FakeElement.new(nil, width: 100) }
299
-
300
- describe 'one element' do
301
- before :each do
302
- subject.prepend do
303
- subject.add_child prepend1
304
- end
305
- end
306
-
307
- it 'as the first' do
308
- expect(subject.contents.first).to eq prepend1
309
- end
310
-
311
- it 'has a total of 3 elements then' do
312
- expect(subject.contents.size).to eq(3)
313
- end
314
- end
315
-
316
- describe 'two elements' do
317
- before :each do
318
- subject.prepend do
319
- subject.add_child prepend1
320
- subject.add_child prepend2
321
- end
322
- end
323
-
324
- it 'has prepend1 as the first child' do
325
- expect(subject.contents.first).to eq prepend1
326
- end
327
-
328
- it 'has prepend2 as the second child' do
329
- expect(subject.contents[1]).to eq prepend2
330
- end
331
-
332
- it 'has a total of 4 children' do
333
- expect(subject.contents.size).to eq(4)
334
- end
335
- end
336
-
337
- describe 'two times' do
338
- before :each do
339
- subject.prepend { subject.add_child prepend1 }
340
- subject.prepend { subject.add_child prepend2 }
341
- end
342
-
343
- it 'has the last prepended element as the first' do
344
- expect(subject.contents.first).to eq prepend2
345
- end
346
-
347
- it 'has the first prepended element as the second' do
348
- expect(subject.contents[1]).to eq prepend1
349
- end
350
-
351
- it 'has a total of 4 children' do
352
- expect(subject.contents.size).to eq(4)
353
- end
354
- end
355
- end
356
-
357
- shared_examples_for 'clearing' do
358
- include_context 'two slot children'
359
-
360
- describe '#clear' do
361
- it 'removes all contents' do
362
- subject.clear
363
- expect(subject.contents).to be_empty
364
- end
365
- end
366
-
367
- describe 'Element#remove' do
368
- it 'removes the element' do
369
- element.parent = subject
370
- element.remove
371
- expect(subject.contents).not_to include element
372
- end
373
- end
374
- end
375
-
376
- shared_examples_for 'margin with a relative positioned child' do
377
- include_context 'one slot child'
378
- include_context 'element one with top and left'
379
- include_context 'contents_alignment'
380
-
381
- describe 'margin top' do
382
- include_context 'slot with a top margin'
383
-
384
- it 'positions the first element taking the top margin into account' do
385
- expect(element.absolute_top).to eq ele_top + margin_top
386
- end
387
-
388
- it 'still keeps the left value intact (only margin_top)' do
389
- expect(element.absolute_left).to eq ele_left
390
- end
391
- end
392
-
393
- describe 'left margin' do
394
- include_context 'slot with a left margin'
395
-
396
- it 'positions the element to take the left margin into account' do
397
- expect(element.absolute_left).to eq ele_left + margin_left
398
- end
399
-
400
- it 'keeps the top margin intact' do
401
- expect(element.absolute_top).to eq ele_top
402
- end
403
- end
404
- end
405
-
406
- shared_examples_for 'margin and positioning' do
407
- include_context 'one slot child'
408
- include_context 'contents_alignment'
409
-
410
- describe 'margin top' do
411
- include_context 'slot with a top margin'
412
-
413
- it 'positions the element after margin_top' do
414
- expect(element.absolute_top).to eq margin_top
415
- end
416
-
417
- it 'leaves the left value as zero' do
418
- expect(element.absolute_left).to eq 0
419
- end
420
-
421
- it 'sets the slot element_height to the height of the child + adjustment' do
422
- expect(subject.element_height).to eq element.height
423
- end
424
-
425
- it 'sets the slot total height to element height + margin' do
426
- expect(subject.height).to eq element.height + margin_top
427
- end
428
- end
429
-
430
- describe 'margin left' do
431
- include_context 'slot with a left margin'
432
-
433
- it 'positions the element after margin_left' do
434
- expect(element.absolute_left).to eq margin_left
435
- end
436
-
437
- it 'leaves the top value as zero' do
438
- expect(element.absolute_top).to eq 0
439
- end
440
- end
441
- end