shoes-dsl 4.0.0.pre2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG +84 -0
  3. data/Gemfile +24 -0
  4. data/Guardfile +11 -0
  5. data/LICENSE +31 -0
  6. data/README.md +201 -0
  7. data/ext/install/Rakefile +29 -0
  8. data/ext/install/shoes.bat +9 -0
  9. data/fonts/Coolvetica.ttf +0 -0
  10. data/fonts/Lacuna.ttf +0 -0
  11. data/lib/shoes/animation.rb +56 -0
  12. data/lib/shoes/app.rb +131 -0
  13. data/lib/shoes/arc.rb +25 -0
  14. data/lib/shoes/background.rb +24 -0
  15. data/lib/shoes/border.rb +24 -0
  16. data/lib/shoes/builtin_methods.rb +77 -0
  17. data/lib/shoes/button.rb +30 -0
  18. data/lib/shoes/check_button.rb +44 -0
  19. data/lib/shoes/color.rb +385 -0
  20. data/lib/shoes/common/background_element.rb +9 -0
  21. data/lib/shoes/common/changeable.rb +34 -0
  22. data/lib/shoes/common/clickable.rb +24 -0
  23. data/lib/shoes/common/inspect.rb +14 -0
  24. data/lib/shoes/common/positioning.rb +30 -0
  25. data/lib/shoes/common/registration.rb +33 -0
  26. data/lib/shoes/common/remove.rb +10 -0
  27. data/lib/shoes/common/state.rb +18 -0
  28. data/lib/shoes/common/style.rb +152 -0
  29. data/lib/shoes/common/style_normalizer.rb +16 -0
  30. data/lib/shoes/common/ui_element.rb +11 -0
  31. data/lib/shoes/common/visibility.rb +40 -0
  32. data/lib/shoes/configuration.rb +96 -0
  33. data/lib/shoes/dialog.rb +27 -0
  34. data/lib/shoes/dimension.rb +239 -0
  35. data/lib/shoes/dimensions.rb +209 -0
  36. data/lib/shoes/download.rb +121 -0
  37. data/lib/shoes/dsl.rb +591 -0
  38. data/lib/shoes/font.rb +49 -0
  39. data/lib/shoes/gradient.rb +31 -0
  40. data/lib/shoes/image.rb +29 -0
  41. data/lib/shoes/image_pattern.rb +12 -0
  42. data/lib/shoes/input_box.rb +60 -0
  43. data/lib/shoes/internal_app.rb +219 -0
  44. data/lib/shoes/key_event.rb +17 -0
  45. data/lib/shoes/line.rb +87 -0
  46. data/lib/shoes/link.rb +59 -0
  47. data/lib/shoes/link_hover.rb +5 -0
  48. data/lib/shoes/list_box.rb +50 -0
  49. data/lib/shoes/logger.rb +66 -0
  50. data/lib/shoes/logger/ruby.rb +18 -0
  51. data/lib/shoes/mock.rb +31 -0
  52. data/lib/shoes/mock/animation.rb +8 -0
  53. data/lib/shoes/mock/app.rb +47 -0
  54. data/lib/shoes/mock/arc.rb +9 -0
  55. data/lib/shoes/mock/background.rb +10 -0
  56. data/lib/shoes/mock/border.rb +7 -0
  57. data/lib/shoes/mock/button.rb +10 -0
  58. data/lib/shoes/mock/check.rb +25 -0
  59. data/lib/shoes/mock/clickable.rb +8 -0
  60. data/lib/shoes/mock/common_methods.rb +12 -0
  61. data/lib/shoes/mock/dialog.rb +13 -0
  62. data/lib/shoes/mock/download.rb +18 -0
  63. data/lib/shoes/mock/font.rb +17 -0
  64. data/lib/shoes/mock/image.rb +13 -0
  65. data/lib/shoes/mock/image_pattern.rb +9 -0
  66. data/lib/shoes/mock/input_box.rb +30 -0
  67. data/lib/shoes/mock/keypress.rb +10 -0
  68. data/lib/shoes/mock/keyrelease.rb +10 -0
  69. data/lib/shoes/mock/line.rb +14 -0
  70. data/lib/shoes/mock/link.rb +12 -0
  71. data/lib/shoes/mock/list_box.rb +19 -0
  72. data/lib/shoes/mock/oval.rb +12 -0
  73. data/lib/shoes/mock/progress.rb +10 -0
  74. data/lib/shoes/mock/radio.rb +27 -0
  75. data/lib/shoes/mock/rect.rb +14 -0
  76. data/lib/shoes/mock/shape.rb +20 -0
  77. data/lib/shoes/mock/slot.rb +16 -0
  78. data/lib/shoes/mock/sound.rb +8 -0
  79. data/lib/shoes/mock/star.rb +14 -0
  80. data/lib/shoes/mock/text_block.rb +36 -0
  81. data/lib/shoes/mock/timer.rb +8 -0
  82. data/lib/shoes/not_implemented_error.rb +4 -0
  83. data/lib/shoes/oval.rb +20 -0
  84. data/lib/shoes/point.rb +54 -0
  85. data/lib/shoes/progress.rb +25 -0
  86. data/lib/shoes/radio.rb +16 -0
  87. data/lib/shoes/rect.rb +21 -0
  88. data/lib/shoes/renamed_delegate.rb +15 -0
  89. data/lib/shoes/shape.rb +158 -0
  90. data/lib/shoes/slot.rb +271 -0
  91. data/lib/shoes/slot_contents.rb +50 -0
  92. data/lib/shoes/sound.rb +18 -0
  93. data/lib/shoes/span.rb +16 -0
  94. data/lib/shoes/star.rb +45 -0
  95. data/lib/shoes/text.rb +24 -0
  96. data/lib/shoes/text_block.rb +143 -0
  97. data/lib/shoes/text_block_dimensions.rb +52 -0
  98. data/lib/shoes/timer.rb +12 -0
  99. data/lib/shoes/url.rb +44 -0
  100. data/lib/shoes/version.rb +3 -0
  101. data/lib/shoes/widget.rb +69 -0
  102. data/manifests/common.rb +34 -0
  103. data/manifests/shoes-dsl.rb +34 -0
  104. data/shoes-dsl.gemspec +19 -0
  105. data/spec/code_coverage.rb +14 -0
  106. data/spec/shoes/animation_spec.rb +65 -0
  107. data/spec/shoes/app_spec.rb +484 -0
  108. data/spec/shoes/arc_spec.rb +51 -0
  109. data/spec/shoes/background_spec.rb +53 -0
  110. data/spec/shoes/border_spec.rb +47 -0
  111. data/spec/shoes/builtin_methods_spec.rb +110 -0
  112. data/spec/shoes/button_spec.rb +44 -0
  113. data/spec/shoes/check_spec.rb +35 -0
  114. data/spec/shoes/cli_spec.rb +15 -0
  115. data/spec/shoes/color_spec.rb +408 -0
  116. data/spec/shoes/common/inspect_spec.rb +26 -0
  117. data/spec/shoes/common/remove_spec.rb +38 -0
  118. data/spec/shoes/common/style_normalizer_spec.rb +28 -0
  119. data/spec/shoes/common/style_spec.rb +147 -0
  120. data/spec/shoes/configuration_spec.rb +36 -0
  121. data/spec/shoes/constants_spec.rb +38 -0
  122. data/spec/shoes/dialog_spec.rb +163 -0
  123. data/spec/shoes/dimension_spec.rb +407 -0
  124. data/spec/shoes/dimensions_spec.rb +837 -0
  125. data/spec/shoes/download_spec.rb +142 -0
  126. data/spec/shoes/flow_spec.rb +133 -0
  127. data/spec/shoes/font_spec.rb +37 -0
  128. data/spec/shoes/framework_learning_spec.rb +30 -0
  129. data/spec/shoes/gradient_spec.rb +32 -0
  130. data/spec/shoes/helpers/fake_element.rb +17 -0
  131. data/spec/shoes/helpers/inspect_helpers.rb +5 -0
  132. data/spec/shoes/helpers/sample17_helper.rb +66 -0
  133. data/spec/shoes/image_spec.rb +49 -0
  134. data/spec/shoes/images/shoe.jpg +0 -0
  135. data/spec/shoes/input_box_spec.rb +80 -0
  136. data/spec/shoes/integration_spec.rb +20 -0
  137. data/spec/shoes/internal_app_spec.rb +141 -0
  138. data/spec/shoes/keypress_spec.rb +11 -0
  139. data/spec/shoes/keyrelease_spec.rb +12 -0
  140. data/spec/shoes/line_spec.rb +49 -0
  141. data/spec/shoes/link_spec.rb +105 -0
  142. data/spec/shoes/list_box_spec.rb +74 -0
  143. data/spec/shoes/logger/ruby_spec.rb +8 -0
  144. data/spec/shoes/logger_spec.rb +45 -0
  145. data/spec/shoes/oval_spec.rb +24 -0
  146. data/spec/shoes/point_spec.rb +71 -0
  147. data/spec/shoes/progress_spec.rb +54 -0
  148. data/spec/shoes/radio_spec.rb +32 -0
  149. data/spec/shoes/rect_spec.rb +39 -0
  150. data/spec/shoes/renamed_delegate_spec.rb +70 -0
  151. data/spec/shoes/shape_spec.rb +95 -0
  152. data/spec/shoes/shared_examples/button.rb +6 -0
  153. data/spec/shoes/shared_examples/changeable.rb +26 -0
  154. data/spec/shoes/shared_examples/clickable.rb +5 -0
  155. data/spec/shoes/shared_examples/common_methods.rb +35 -0
  156. data/spec/shoes/shared_examples/dimensions.rb +32 -0
  157. data/spec/shoes/shared_examples/dsl.rb +44 -0
  158. data/spec/shoes/shared_examples/dsl/animate.rb +29 -0
  159. data/spec/shoes/shared_examples/dsl/arc.rb +45 -0
  160. data/spec/shoes/shared_examples/dsl/background.rb +26 -0
  161. data/spec/shoes/shared_examples/dsl/border.rb +10 -0
  162. data/spec/shoes/shared_examples/dsl/button.rb +5 -0
  163. data/spec/shoes/shared_examples/dsl/cap.rb +6 -0
  164. data/spec/shoes/shared_examples/dsl/check.rb +11 -0
  165. data/spec/shoes/shared_examples/dsl/edit_box.rb +8 -0
  166. data/spec/shoes/shared_examples/dsl/edit_line.rb +8 -0
  167. data/spec/shoes/shared_examples/dsl/editable_element.rb +29 -0
  168. data/spec/shoes/shared_examples/dsl/fill.rb +27 -0
  169. data/spec/shoes/shared_examples/dsl/flow.rb +15 -0
  170. data/spec/shoes/shared_examples/dsl/gradient.rb +62 -0
  171. data/spec/shoes/shared_examples/dsl/image.rb +21 -0
  172. data/spec/shoes/shared_examples/dsl/line.rb +9 -0
  173. data/spec/shoes/shared_examples/dsl/nofill.rb +6 -0
  174. data/spec/shoes/shared_examples/dsl/nostroke.rb +6 -0
  175. data/spec/shoes/shared_examples/dsl/oval.rb +88 -0
  176. data/spec/shoes/shared_examples/dsl/pattern.rb +34 -0
  177. data/spec/shoes/shared_examples/dsl/progress.rb +7 -0
  178. data/spec/shoes/shared_examples/dsl/rect.rb +92 -0
  179. data/spec/shoes/shared_examples/dsl/rgb.rb +26 -0
  180. data/spec/shoes/shared_examples/dsl/shape.rb +21 -0
  181. data/spec/shoes/shared_examples/dsl/star.rb +48 -0
  182. data/spec/shoes/shared_examples/dsl/stroke.rb +30 -0
  183. data/spec/shoes/shared_examples/dsl/strokewidth.rb +19 -0
  184. data/spec/shoes/shared_examples/dsl/style.rb +32 -0
  185. data/spec/shoes/shared_examples/dsl/text_elements.rb +81 -0
  186. data/spec/shoes/shared_examples/dsl/video.rb +5 -0
  187. data/spec/shoes/shared_examples/dsl_app_context.rb +8 -0
  188. data/spec/shoes/shared_examples/hover_leave.rb +11 -0
  189. data/spec/shoes/shared_examples/parent.rb +6 -0
  190. data/spec/shoes/shared_examples/scroll.rb +41 -0
  191. data/spec/shoes/shared_examples/shared_element_method.rb +60 -0
  192. data/spec/shoes/shared_examples/slot.rb +331 -0
  193. data/spec/shoes/shared_examples/state.rb +19 -0
  194. data/spec/shoes/shared_examples/style.rb +82 -0
  195. data/spec/shoes/slot_spec.rb +130 -0
  196. data/spec/shoes/sound_spec.rb +15 -0
  197. data/spec/shoes/span_spec.rb +112 -0
  198. data/spec/shoes/spec_helper.rb +24 -0
  199. data/spec/shoes/stack_spec.rb +79 -0
  200. data/spec/shoes/star_spec.rb +31 -0
  201. data/spec/shoes/text_block_dimensions_spec.rb +75 -0
  202. data/spec/shoes/text_block_spec.rb +270 -0
  203. data/spec/shoes/url_spec.rb +68 -0
  204. data/spec/shoes/widget_spec.rb +70 -0
  205. data/spec/shoes_spec.rb +44 -0
  206. data/spec/spec_helper.rb +18 -0
  207. data/static/Shoes.icns +0 -0
  208. data/static/shoes-icon.png +0 -0
  209. metadata +354 -0
@@ -0,0 +1,81 @@
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
+ it 'should parse the color' do
39
+ span = dsl.span 'Hello', stroke: '#ccc'
40
+ expect(span.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
41
+ end
42
+
43
+ it 'should handle a splatted array of links' do
44
+ expect{dsl.span *[dsl.link('foo'), dsl.link('foo')]}.not_to raise_error
45
+ end
46
+
47
+ it 'should handle a splatted array of links and parse the color' do
48
+ span = dsl.span *[dsl.link('foo'), dsl.link('foo')], stroke: '#ccc'
49
+ expect(span.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
50
+ end
51
+
52
+ it 'should handle a splatted array of links with a block' do
53
+ link = dsl.link('foo') { "Bar" }
54
+ expect{dsl.span *[link, link]}.not_to raise_error
55
+ end
56
+ end
57
+
58
+ describe 'link' do
59
+ it 'handles multiple texts' do
60
+ link = dsl.link('one', 'two')
61
+ expect(link.to_s).to eql('onetwo')
62
+ end
63
+
64
+ it 'handles trailing options' do
65
+ link = dsl.link('one', 'two', stroke: '#ccc')
66
+ expect(link.to_s).to eql('onetwo')
67
+ expect(link.style[:stroke]).to eq Shoes::Color.new 204, 204, 204
68
+ end
69
+ end
70
+
71
+ describe 'para' do
72
+ context "with nested text fragments with parameters" do
73
+ Shoes::DSL::TEXT_STYLES.keys.each do |style|
74
+ it "handles opts properly for #{style}" do
75
+ para = dsl.para(dsl.send(style, style, stroke: '#ccc'))
76
+ expect(para.text).to eq(style.to_s)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,5 @@
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
@@ -0,0 +1,8 @@
1
+ shared_context "dsl app" do
2
+ let(:input_block) { Proc.new {} }
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) { Shoes::Flow.new app, app }
7
+ end
8
+
@@ -0,0 +1,11 @@
1
+ shared_examples "hover and leave events" do
2
+ let(:proc) {Proc.new do end}
3
+
4
+ it 'can execute hover without raising an error' do
5
+ expect{subject.hover proc}.not_to raise_error
6
+ end
7
+
8
+ it 'can execute leave without raising an error' do
9
+ expect{subject.leave proc}.not_to raise_error
10
+ end
11
+ end
@@ -0,0 +1,6 @@
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
@@ -0,0 +1,41 @@
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
@@ -0,0 +1,60 @@
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
@@ -0,0 +1,331 @@
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.new { 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
+ end
20
+
21
+ shared_context 'one slot child' do
22
+ let(:ele_opts) {Hash.new}
23
+ let(:element) {Shoes::FakeElement.new(nil, {height: 100,width: 50}.merge(ele_opts))}
24
+
25
+ before :each do
26
+ subject.add_child element
27
+ end
28
+ end
29
+
30
+ shared_context 'two slot children' do
31
+ include_context 'one slot child'
32
+ let(:element2) {Shoes::FakeElement.new nil, height: 200, width: 70}
33
+
34
+ before :each do
35
+ subject.add_child element2
36
+ end
37
+ end
38
+
39
+ shared_context 'hidden child' do
40
+ let(:hidden_element) {Shoes::FakeElement.new nil, height: 200, width: 70}
41
+
42
+ before :each do
43
+ subject.add_child hidden_element
44
+ hidden_element.gui = double("hidden gui", update_visibility: nil)
45
+ hidden_element.hide
46
+ end
47
+ end
48
+
49
+ shared_context 'three slot children' do
50
+ include_context 'two slot children'
51
+ let(:element3) {Shoes::FakeElement.new(nil, height: 50, width: 20)}
52
+
53
+ before :each do
54
+ subject.add_child element3
55
+ end
56
+ end
57
+
58
+ shared_context 'contents_alignment' do
59
+ before :each do
60
+ subject.contents_alignment
61
+ end
62
+ end
63
+
64
+ shared_context 'element one with top and left' do
65
+ let(:ele_top) {22}
66
+ let(:ele_left) {47}
67
+ let(:ele_opts) {{left: ele_left, top: ele_top}}
68
+ end
69
+
70
+ shared_context 'slot with set height and width' do
71
+ let(:input_opts) {{width: 250, height: 300}}
72
+ end
73
+
74
+ shared_context 'element one with bottom and right' do
75
+ let(:ele_bottom) {24}
76
+ let(:ele_right) {49}
77
+ let(:ele_opts) {{right: ele_right, bottom: ele_bottom}}
78
+ end
79
+
80
+ shared_examples_for 'positioning through :_position' do
81
+
82
+ let(:element) {Shoes::FakeElement.new nil, height: 100, width: 50}
83
+
84
+ def add_child_and_align
85
+ subject.add_child element
86
+ subject.contents_alignment
87
+ end
88
+
89
+ it 'sends the child the :_position method to position it' do
90
+ expect(element).to receive(:_position).and_call_original
91
+ add_child_and_align
92
+ end
93
+
94
+ it 'does not send _position again if the position did not change' do
95
+ add_child_and_align
96
+ expect(element).not_to receive(:_position)
97
+ subject.contents_alignment
98
+ end
99
+
100
+ it 'does not position an element if it does not need positioning' do
101
+ my_element = element
102
+ allow(my_element).to receive_messages needs_to_be_positioned?: false
103
+ expect(my_element).not_to receive :_position
104
+ subject.add_child my_element
105
+ subject.contents_alignment
106
+ end
107
+ end
108
+
109
+ shared_examples_for 'element one positioned with top and left' do
110
+ it 'positions the element at its left value' do
111
+ expect(element.absolute_left).to eq subject.absolute_left + ele_left
112
+ end
113
+
114
+ it 'positions the element at its top value' do
115
+ expect(element.absolute_top).to eq subject.absolute_top + ele_top
116
+ end
117
+ end
118
+
119
+ shared_examples_for 'element one positioned with bottom and right' do
120
+ include_context 'one slot child'
121
+ include_context 'contents_alignment'
122
+ include_context 'element one with bottom and right'
123
+ include_context 'slot with set height and width'
124
+
125
+ it 'positions the element from its right' do
126
+ expect(element.absolute_right).to eq (subject.absolute_right - ele_right - 1)
127
+ end
128
+
129
+ it 'positions the element from its bottom' do
130
+ expect(element.absolute_bottom).to eq (subject.absolute_bottom - ele_bottom - 1)
131
+ end
132
+ end
133
+
134
+ shared_examples_for 'positions the first element in the top left' do
135
+ include_context 'one slot child'
136
+ include_context 'contents_alignment'
137
+ it 'positions a single object at the same top as self' do
138
+ expect(element.absolute_top).to eq subject.element_top
139
+ end
140
+
141
+ it 'positions a single object at the same left as self' do
142
+ expect(element.absolute_left).to eq subject.element_left
143
+ end
144
+
145
+ it 'has a slot height of the element height' do
146
+ expect(subject.height).to eq element.height
147
+ end
148
+
149
+ describe 'top and left' do
150
+ include_context 'element one with top and left'
151
+ it_behaves_like 'element one positioned with top and left'
152
+ end
153
+ end
154
+
155
+ shared_examples_for 'arranges elements underneath each other' do
156
+ include_context 'two slot children'
157
+ include_context 'contents_alignment'
158
+
159
+ it 'positions an element beneath a previous element' do
160
+ expect(element2.absolute_top).to eq element.absolute_bottom + 1
161
+ end
162
+
163
+ it 'still positions it at the start of the line (e.g. self.left)' do
164
+ expect(element2.absolute_left).to eq subject.absolute_left
165
+ end
166
+
167
+ it 'has a stack height according to its contents' do
168
+ expect(subject.height).to eq (element.height + element2.height)
169
+ end
170
+
171
+ it 'has an absolute_bottom of top + height' do
172
+ expect(subject.absolute_bottom).to eq (subject.absolute_top + subject.height - 1)
173
+ end
174
+
175
+ describe 'element one with top and left' do
176
+ include_context 'element one with top and left'
177
+ it_behaves_like 'element one positioned with top and left'
178
+
179
+ describe 'positions element2 disregarding element1' do
180
+ it 'has the same absolute left as the slot' do
181
+ expect(element2.absolute_left).to eq subject.absolute_left
182
+ end
183
+
184
+ it 'has the same absolute top as the slot' do
185
+ expect(element2.absolute_top).to eq subject.absolute_top
186
+ end
187
+ end
188
+ end
189
+ end
190
+
191
+ shared_examples_for 'set height and contents alignment' do
192
+ include_context 'two slot children'
193
+
194
+ it 'contents_alignment returns the height of the content' do
195
+ expect(subject.contents_alignment).to eq (element.height + element2.height)
196
+ end
197
+
198
+ it 'still has the same height though' do
199
+ old_height = subject.height
200
+ subject.contents_alignment
201
+ expect(subject.height).to eq old_height
202
+ end
203
+ end
204
+
205
+ shared_examples_for 'taking care of margin' do
206
+ include_context 'two slot children'
207
+ include_context 'contents_alignment'
208
+
209
+ it 'respects the left margin for the first element' do
210
+ expect(element.absolute_left).to eq input_opts[:margin]
211
+ end
212
+
213
+ it 'respects the left margin for the second element' do
214
+ expect(element2.absolute_left).to eq input_opts[:margin]
215
+ end
216
+
217
+ it 'respects the top margin for the first element' do
218
+ expect(element.absolute_top).to eq input_opts[:margin]
219
+ end
220
+ end
221
+
222
+ shared_examples_for 'growing although relatively positioned elements' do
223
+ include_context 'one slot child'
224
+ include_context 'contents_alignment'
225
+
226
+ describe 'positioned at the very beginning' do
227
+ let(:ele_opts) {{top: 0}}
228
+
229
+ it 'grows the slot height' do
230
+ expect(subject.height).to eq element.height
231
+ end
232
+ end
233
+
234
+ describe 'positioned with a good offset' do
235
+ let(:ele_opts) {{top: 70}}
236
+
237
+ it 'grows the height even further' do
238
+ expect(subject.height).to eq element.height + 70
239
+ end
240
+ end
241
+
242
+ describe 'positioning with hidden elements' do
243
+ include_context 'hidden child'
244
+
245
+ it 'grows only to height of first child' do
246
+ subject.contents_alignment
247
+ expect(subject.height).to eq element.height
248
+ end
249
+ end
250
+ end
251
+
252
+ shared_examples_for 'prepending' do
253
+ include_context 'two slot children'
254
+ let(:prepend1) {double 'prepend1'}
255
+ let(:prepend2) {double 'prepend2'}
256
+
257
+ describe 'one element' do
258
+ before :each do
259
+ subject.prepend do
260
+ subject.add_child prepend1
261
+ end
262
+ end
263
+
264
+ it 'as the first' do
265
+ expect(subject.contents.first).to eq prepend1
266
+ end
267
+
268
+ it 'has a total of 3 elements then' do
269
+ expect(subject.contents.size).to eq(3)
270
+ end
271
+ end
272
+
273
+ describe 'two elements' do
274
+ before :each do
275
+ subject.prepend do
276
+ subject.add_child prepend1
277
+ subject.add_child prepend2
278
+ end
279
+ end
280
+
281
+ it 'has prepend1 as the first child' do
282
+ expect(subject.contents.first).to eq prepend1
283
+ end
284
+
285
+ it 'has prepend2 as the second child' do
286
+ expect(subject.contents[1]).to eq prepend2
287
+ end
288
+
289
+ it 'has a total of 4 children' do
290
+ expect(subject.contents.size).to eq(4)
291
+ end
292
+ end
293
+
294
+ describe 'two times' do
295
+ before :each do
296
+ subject.prepend { subject.add_child prepend1 }
297
+ subject.prepend {subject.add_child prepend2 }
298
+ end
299
+
300
+ it 'has the last prepended element as the first' do
301
+ expect(subject.contents.first).to eq prepend2
302
+ end
303
+
304
+ it 'has the first prepended element as the second' do
305
+ expect(subject.contents[1]).to eq prepend1
306
+ end
307
+
308
+ it 'has a total of 4 children' do
309
+ expect(subject.contents.size).to eq(4)
310
+ end
311
+ end
312
+ end
313
+
314
+ shared_examples_for 'clearing' do
315
+ include_context 'two slot children'
316
+
317
+ describe '#clear' do
318
+ it 'removes all contents' do
319
+ subject.clear
320
+ expect(subject.contents).to be_empty
321
+ end
322
+ end
323
+
324
+ describe 'Element#remove' do
325
+ it 'removees the element' do
326
+ element.parent = subject
327
+ element.remove
328
+ expect(subject.contents).not_to include element
329
+ end
330
+ end
331
+ end