under-os-ui 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +26 -0
  3. data/lib/assets/fontawesome-webfont.ttf +0 -0
  4. data/lib/assets/under-os.css +115 -0
  5. data/lib/core/kernel.rb +16 -0
  6. data/lib/under-os-ui.rb +6 -0
  7. data/lib/under_os/app.rb +26 -0
  8. data/lib/under_os/config.rb +25 -0
  9. data/lib/under_os/history.rb +53 -0
  10. data/lib/under_os/page.rb +178 -0
  11. data/lib/under_os/page/builder.rb +96 -0
  12. data/lib/under_os/page/layout.rb +43 -0
  13. data/lib/under_os/page/matcher.rb +128 -0
  14. data/lib/under_os/page/stylesheet.rb +67 -0
  15. data/lib/under_os/parser.rb +24 -0
  16. data/lib/under_os/parser/css.rb +37 -0
  17. data/lib/under_os/parser/html.rb +97 -0
  18. data/lib/under_os/ui.rb +3 -0
  19. data/lib/under_os/ui/alert.rb +52 -0
  20. data/lib/under_os/ui/button.rb +42 -0
  21. data/lib/under_os/ui/collection.rb +65 -0
  22. data/lib/under_os/ui/collection/cell.rb +21 -0
  23. data/lib/under_os/ui/collection/delegate.rb +70 -0
  24. data/lib/under_os/ui/collection/item.rb +32 -0
  25. data/lib/under_os/ui/collection/layout.rb +43 -0
  26. data/lib/under_os/ui/collection/styles.rb +15 -0
  27. data/lib/under_os/ui/div.rb +3 -0
  28. data/lib/under_os/ui/form.rb +60 -0
  29. data/lib/under_os/ui/icon.rb +61 -0
  30. data/lib/under_os/ui/icon/awesome.rb +376 -0
  31. data/lib/under_os/ui/icon/engine.rb +9 -0
  32. data/lib/under_os/ui/image.rb +31 -0
  33. data/lib/under_os/ui/input.rb +140 -0
  34. data/lib/under_os/ui/label.rb +21 -0
  35. data/lib/under_os/ui/locker.rb +42 -0
  36. data/lib/under_os/ui/navbar.rb +123 -0
  37. data/lib/under_os/ui/progress.rb +17 -0
  38. data/lib/under_os/ui/scroll.rb +102 -0
  39. data/lib/under_os/ui/select.rb +95 -0
  40. data/lib/under_os/ui/sidebar.rb +45 -0
  41. data/lib/under_os/ui/slider.rb +37 -0
  42. data/lib/under_os/ui/spinner.rb +23 -0
  43. data/lib/under_os/ui/style.rb +21 -0
  44. data/lib/under_os/ui/style/fonts.rb +56 -0
  45. data/lib/under_os/ui/style/margins.rb +164 -0
  46. data/lib/under_os/ui/style/outlining.rb +170 -0
  47. data/lib/under_os/ui/style/positioning.rb +183 -0
  48. data/lib/under_os/ui/switch.rb +26 -0
  49. data/lib/under_os/ui/textarea.rb +19 -0
  50. data/lib/under_os/ui/utils/animation.rb +101 -0
  51. data/lib/under_os/ui/utils/commons.rb +70 -0
  52. data/lib/under_os/ui/utils/dimensions.rb +37 -0
  53. data/lib/under_os/ui/utils/events.rb +210 -0
  54. data/lib/under_os/ui/utils/manipulation.rb +44 -0
  55. data/lib/under_os/ui/utils/position.rb +21 -0
  56. data/lib/under_os/ui/utils/size.rb +21 -0
  57. data/lib/under_os/ui/utils/styles.rb +89 -0
  58. data/lib/under_os/ui/utils/traversing.rb +44 -0
  59. data/lib/under_os/ui/utils/wrap.rb +77 -0
  60. data/lib/under_os/ui/view.rb +31 -0
  61. data/spec/assets/app.css +13 -0
  62. data/spec/assets/test.css +7 -0
  63. data/spec/assets/test.html +3 -0
  64. data/spec/assets/test.png +0 -0
  65. data/spec/assets/test_page.rb +2 -0
  66. data/spec/under_os/page/builder_spec.rb +128 -0
  67. data/spec/under_os/page/layout_spec.rb +18 -0
  68. data/spec/under_os/page/matcher_spec.rb +260 -0
  69. data/spec/under_os/page/stylesheet_spec.rb +83 -0
  70. data/spec/under_os/page_spec.rb +5 -0
  71. data/spec/under_os/parser/css_spec.rb +77 -0
  72. data/spec/under_os/parser/html_spec.rb +152 -0
  73. data/spec/under_os/parser_spec.rb +16 -0
  74. data/spec/under_os/ui/button_spec.rb +50 -0
  75. data/spec/under_os/ui/collection_spec.rb +19 -0
  76. data/spec/under_os/ui/div_spec.rb +24 -0
  77. data/spec/under_os/ui/form_spec.rb +156 -0
  78. data/spec/under_os/ui/icon_spec.rb +57 -0
  79. data/spec/under_os/ui/image_spec.rb +39 -0
  80. data/spec/under_os/ui/input_spec.rb +109 -0
  81. data/spec/under_os/ui/label_spec.rb +22 -0
  82. data/spec/under_os/ui/locker_spec.rb +31 -0
  83. data/spec/under_os/ui/progress_spec.rb +31 -0
  84. data/spec/under_os/ui/scroll_spec.rb +75 -0
  85. data/spec/under_os/ui/select_spec.rb +135 -0
  86. data/spec/under_os/ui/sidebar_spec.rb +35 -0
  87. data/spec/under_os/ui/slider_spec.rb +69 -0
  88. data/spec/under_os/ui/spinner_spec.rb +57 -0
  89. data/spec/under_os/ui/style/fonts_spec.rb +111 -0
  90. data/spec/under_os/ui/style/margins_spec.rb +106 -0
  91. data/spec/under_os/ui/style/outlining_spec.rb +101 -0
  92. data/spec/under_os/ui/style/positioning_spec.rb +69 -0
  93. data/spec/under_os/ui/style_spec.rb +19 -0
  94. data/spec/under_os/ui/switch_spec.rb +60 -0
  95. data/spec/under_os/ui/textarea_spec.rb +34 -0
  96. data/spec/under_os/ui/utils/commons_spec.rb +81 -0
  97. data/spec/under_os/ui/utils/events_spec.rb +87 -0
  98. data/spec/under_os/ui/utils/manipulation_spec.rb +130 -0
  99. data/spec/under_os/ui/utils/styles_spec.rb +140 -0
  100. data/spec/under_os/ui/utils/traversing_spec.rb +124 -0
  101. data/spec/under_os/ui/utils/wrap_spec.rb +69 -0
  102. data/spec/under_os/ui/view_spec.rb +39 -0
  103. data/under-os-ui.gemspec +23 -0
  104. metadata +216 -0
@@ -0,0 +1,34 @@
1
+ describe UnderOs::UI::Textarea do
2
+ before do
3
+ @textarea = UnderOs::UI::Textarea.new
4
+ end
5
+
6
+ it "inherits fromthe UnderOs::UI::Input" do
7
+ (UnderOs::UI::Textarea < UnderOs::UI::Input).should == true
8
+ end
9
+
10
+ describe '#initialize' do
11
+ it "should spawn new textareas" do
12
+ @textarea.class.should == UnderOs::UI::Textarea
13
+ end
14
+
15
+ it "should wrap the UITextView class" do
16
+ @textarea._.class.should == UITextView
17
+ end
18
+
19
+ it "should assign correct tag name" do
20
+ @textarea.tagName.should == 'TEXTAREA'
21
+ end
22
+
23
+ it "should accept the 'value' option" do
24
+ textarea = UnderOs::UI::Textarea.new(value: 'boo hoo')
25
+ textarea.value.should == 'boo hoo'
26
+ end
27
+
28
+ it "should accept the 'keyboard' option" do
29
+ textarea = UnderOs::UI::Textarea.new(keyboard: 'email')
30
+ textarea.keyboard.should == :email
31
+ end
32
+ end
33
+
34
+ end
@@ -0,0 +1,81 @@
1
+ describe UnderOs::UI::Commons do
2
+ before do
3
+ @view = UnderOs::UI::View.new
4
+ end
5
+
6
+ describe '#id' do
7
+ it "should allow build views with ids" do
8
+ view = UnderOs::UI::View.new(id: 'my-id')
9
+ view.id.should == 'my-id'
10
+ end
11
+
12
+ it "should allow to change the id" do
13
+ view = UnderOs::UI::View.new(id: 'old-id')
14
+ view.id = 'new-id'
15
+ view.id.should == 'new-id'
16
+ end
17
+ end
18
+
19
+ describe '#data' do
20
+ it "should allow to specify the data hash with views constructor" do
21
+ view = UnderOs::UI::View.new(data: {my: 'data'})
22
+ view.data.should == {my: 'data'}
23
+ end
24
+
25
+ it "should allow to assign the new data" do
26
+ view = UnderOs::UI::View.new(data: {old: 'data'})
27
+ view.data = {new: 'data'}
28
+ view.data.should == {new: 'data'}
29
+ end
30
+ end
31
+
32
+ describe '#hidden' do
33
+ it "shoudl return 'false' for visible views" do
34
+ @view.hidden.should == false
35
+ end
36
+
37
+ it "should return 'true' for hidden views" do
38
+ @view._.hidden = true
39
+ @view.hidden.should == true
40
+ end
41
+ end
42
+
43
+ describe '#visible' do
44
+ it "should return 'true' if the element's visible" do
45
+ @view.visible.should == true
46
+ end
47
+
48
+ it "should return 'false' if the element's is hidden" do
49
+ @view._.hidden = true
50
+ @view.visible.should == false
51
+ end
52
+ end
53
+
54
+ describe '#hide' do
55
+ it "should hide elmements" do
56
+ @view.hide
57
+ @view.hidden.should == true
58
+ end
59
+ end
60
+
61
+ describe '#show' do
62
+ it "should show hidden elements" do
63
+ @view.hide
64
+ @view.show
65
+ @view.visible.should == true
66
+ end
67
+ end
68
+
69
+ describe '#toggle' do
70
+ it "should show an element if it's hidden" do
71
+ @view.hide
72
+ @view.toggle
73
+ @view.visible.should == true
74
+ end
75
+
76
+ it "should hide visible elements" do
77
+ @view.toggle
78
+ @view.hidden.should == true
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,87 @@
1
+ class MyView < UnderOs::UI::View
2
+ attr_reader :args
3
+
4
+ def handler_with_event(event)
5
+ @args = [event]
6
+ end
7
+
8
+ def handler_without_event
9
+ @args = []
10
+ end
11
+ end
12
+
13
+ describe UnderOs::UI::Events do
14
+ before do
15
+ @view = UnderOs::UI::View.new
16
+ end
17
+
18
+ describe "#on" do
19
+ before do
20
+ @tapped = false
21
+ @result = @view.on(:tap) { @tapped = true }
22
+
23
+ @view.emit(:tap)
24
+ end
25
+
26
+ it "binds the event listener" do
27
+ @tapped.should == true
28
+ end
29
+
30
+ it "returns the view object itself back" do
31
+ @result.should.be.same_as @view
32
+ end
33
+ end
34
+
35
+ describe "#off" do
36
+ before do
37
+ @tapped = false
38
+ @view.on(:tap) { @tapped = true }
39
+
40
+ @result = @view.off(:tap)
41
+
42
+ @view.emit(:tap)
43
+ end
44
+
45
+ it "un-binds the event listener" do
46
+ @tapped.should == false
47
+ end
48
+
49
+ it "returns the view object itself back" do
50
+ @result.should.be.same_as @view
51
+ end
52
+ end
53
+
54
+ describe "#emit" do
55
+ before do
56
+ @view.on(:tap) { |e| @event = e }
57
+ @view.emit(:tap, custom: 'param')
58
+ end
59
+
60
+ it "emits an UI::Event" do
61
+ @event.class.should == UnderOs::UI::Events::Event
62
+ end
63
+
64
+ it "sets the event target to the view" do
65
+ @event.target.should.be.same_as @view
66
+ end
67
+ end
68
+
69
+ describe "named event handlers" do
70
+ before do
71
+ @view = MyView.new
72
+ end
73
+
74
+ it "allows to bind a method by name with an event listener" do
75
+ @view.on :tap, :handler_with_event
76
+ @view.emit(:tap)
77
+ @view.args.size.should == 1
78
+ @view.args[0].class.should == UnderOs::UI::Events::Event
79
+ end
80
+
81
+ it "allows to bind a method by name without an event argument" do
82
+ @view.on :tap, :handler_without_event
83
+ @view.emit(:tap)
84
+ @view.args.size.should == 0
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,130 @@
1
+ describe UnderOs::UI::Manipulation do
2
+ before do
3
+ @v1 = UnderOs::UI::View.new
4
+ @v2 = UnderOs::UI::View.new
5
+ @v3 = UnderOs::UI::View.new
6
+ end
7
+
8
+ describe '#insert' do
9
+ it "should let insert views inside of each other" do
10
+ @v1.insert(@v2)
11
+ @v1.insert(@v3)
12
+
13
+ @v1.children.should == [@v2, @v3]
14
+ end
15
+
16
+ it "should let insert views on top of the subviews" do
17
+ @v1.insert(@v2)
18
+ @v1.insert(@v3, :top)
19
+
20
+ @v1.children.should == [@v3, @v2]
21
+ end
22
+
23
+ it "should return the view itself after each operation" do
24
+ @v1.insert(@v2).should == @v1
25
+ @v1.insert(@v3).should == @v1
26
+ end
27
+
28
+ it "should accept lists of items" do
29
+ @v1.insert([@v2, @v3])
30
+ @v1.children.should == [@v2, @v3]
31
+ end
32
+ end
33
+
34
+ describe '#append' do
35
+ it "should append other views into the current one" do
36
+ @v1.append(@v2)
37
+ @v1.append(@v3)
38
+
39
+ @v1.children.should == [@v2, @v3]
40
+ end
41
+
42
+ it "should allow to append several views as multiple arguments" do
43
+ @v1.append(@v2, @v3)
44
+
45
+ @v1.children.should == [@v2, @v3]
46
+ end
47
+
48
+ it "should return the view itself after each operation" do
49
+ @v1.append(@v2).should == @v1
50
+ @v1.append(@v3).should == @v1
51
+ end
52
+ end
53
+
54
+ describe '#prepend' do
55
+ it "should put all items on top" do
56
+ @v1.prepend(@v2)
57
+ @v1.prepend(@v3)
58
+
59
+ @v1.children.should == [@v3, @v2]
60
+ end
61
+
62
+ it "should accept several views as multiple arguments" do
63
+ @v1.prepend(@v2, @v3)
64
+
65
+ @v1.children.should == [@v3, @v2]
66
+ end
67
+
68
+ it "should return the view itself after each operation" do
69
+ @v1.prepend(@v2).should == @v1
70
+ @v1.prepend(@v3).should == @v1
71
+ end
72
+ end
73
+
74
+ describe '#insertTo' do
75
+ it "should allow to insert view into others" do
76
+ @v2.insertTo(@v1)
77
+ @v3.insertTo(@v1)
78
+
79
+ @v1.children.should == [@v2, @v3]
80
+ end
81
+
82
+ it "should allo to insert intems on top of the stack" do
83
+ @v1.insert(@v2)
84
+ @v3.insertTo(@v1, :top)
85
+
86
+ @v1.children.should == [@v3, @v2]
87
+ end
88
+
89
+ it "should return the view itself after each operation" do
90
+ @v2.insertTo(@v1).should == @v2
91
+ @v3.insertTo(@v1).should == @v3
92
+ end
93
+ end
94
+
95
+ describe '#remove' do
96
+ it "should allow to remove items from superviews" do
97
+ @v1.append(@v2, @v3)
98
+
99
+ @v2.remove
100
+
101
+ @v1.children.should == [@v3]
102
+ end
103
+
104
+ it "should not crash if there is no superviews" do
105
+ @v1.remove
106
+ @v2.remove
107
+ @v3.remove
108
+ true.should == true
109
+ end
110
+
111
+ it "should return the view iteslf back" do
112
+ @v1.remove.should == @v1
113
+ @v2.remove.should == @v2
114
+ @v3.remove.should == @v3
115
+ end
116
+ end
117
+
118
+ describe '#clear' do
119
+ before { @v1.append(@v2, @v3) }
120
+
121
+ it "should remove all the child elements" do
122
+ @v1.clear
123
+ @v1.children.should == []
124
+ end
125
+
126
+ it "should return itself back as a reference" do
127
+ @v1.clear.should.be.same_as @v1
128
+ end
129
+ end
130
+ end
@@ -0,0 +1,140 @@
1
+ describe UnderOs::UI::Styles do
2
+ before do
3
+ @view = UnderOs::UI::View.new
4
+ end
5
+
6
+ describe '#style' do
7
+ it "should return a style handler for the view" do
8
+ style = @view.style
9
+ style.class.should == UnderOs::UI::Style
10
+ style.view.should.be.same_as @view._
11
+ end
12
+
13
+ it "should cache the styles handler instance" do
14
+ @view.style.should.be.same_as @view.style
15
+ end
16
+
17
+ it "should allow to set the styles as a hash" do
18
+ @view.style = {top: 10, left: 20}
19
+ @view.style.top.should == 10
20
+ @view.style.left.should == 20
21
+ end
22
+ end
23
+
24
+ describe '#classNames' do
25
+ it "should return an empty list by default" do
26
+ @view.classNames.should == []
27
+ end
28
+
29
+ it "should allow to assign the lists" do
30
+ @view.classNames = ['one', 'two']
31
+ @view.classNames.should == ['one', 'two']
32
+ end
33
+
34
+ it "should remove dups on fly" do
35
+ @view.classNames = ['one', 'two', 'two', 'one']
36
+ @view.classNames.should == ['one', 'two']
37
+ end
38
+ end
39
+
40
+ describe '#className' do
41
+ it "should return an empty string by default" do
42
+ @view.className.should == ''
43
+ end
44
+
45
+ it "should allow to assign new class names" do
46
+ @view.className = 'one two'
47
+ @view.className.should == 'one two'
48
+ @view.classNames.should == ['one', 'two']
49
+ end
50
+ end
51
+
52
+ describe '#hasClass' do
53
+ it "should return 'true' if the view has the class" do
54
+ @view.className = 'boo hoo'
55
+ @view.hasClass('boo').should == true
56
+ end
57
+
58
+ it "should return false if the view has no class" do
59
+ @view.className = 'boo hoo'
60
+ @view.hasClass('foo').should == false
61
+ end
62
+ end
63
+
64
+ describe '#addClass' do
65
+ it "should add the class name if it's missing" do
66
+ @view.addClass 'boo'
67
+ @view.classNames.should == ['boo']
68
+ end
69
+
70
+ it "should not duplicat the class if it's already exists" do
71
+ @view.classNames = ['boo']
72
+ @view.addClass 'boo'
73
+ @view.classNames.should == ['boo']
74
+ end
75
+
76
+ it "should return the view itself back" do
77
+ @view.addClass('boo').should === @view
78
+ end
79
+ end
80
+
81
+ describe '#removeClass' do
82
+ it "should remove the class name if it was set" do
83
+ @view.classNames = ['boo']
84
+ @view.removeClass('boo')
85
+ @view.classNames.should == []
86
+ end
87
+
88
+ it "should return the view itself back" do
89
+ @view.removeClass('boo').should === @view
90
+ end
91
+ end
92
+
93
+ describe '#toggleClass' do
94
+ it "should add the class if it's missing" do
95
+ @view.toggleClass('test')
96
+ @view.classNames.should == ['test']
97
+ end
98
+
99
+ it "should remove the class if was set before" do
100
+ @view.classNames = ['test']
101
+ @view.toggleClass('test')
102
+ @view.classNames.should == []
103
+ end
104
+
105
+ it "should return the view itself back" do
106
+ @view.toggleClass('test').should === @view
107
+ end
108
+ end
109
+
110
+ describe '#radioClass' do
111
+ before do
112
+ @v1 = UnderOs::UI::View.new.insertTo(@view)
113
+ @v2 = UnderOs::UI::View.new.insertTo(@view)
114
+ @v3 = UnderOs::UI::View.new.insertTo(@view)
115
+ end
116
+
117
+ it "should set the class only on one element" do
118
+ @v2.radioClass('boo')
119
+
120
+ @v1.hasClass('boo').should == false
121
+ @v2.hasClass('boo').should == true
122
+ @v1.hasClass('boo').should == false
123
+ end
124
+
125
+ it "should automatically remove the class from any of the siblings" do
126
+ @v1.className = 'boo'
127
+ @v3.className = 'boo'
128
+
129
+ @v2.radioClass('boo')
130
+
131
+ @v1.hasClass('boo').should == false
132
+ @v2.hasClass('boo').should == true
133
+ @v1.hasClass('boo').should == false
134
+ end
135
+
136
+ it "should return the view itself back" do
137
+ @v2.radioClass('boo').should === @v2
138
+ end
139
+ end
140
+ end