under-os-ui 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,16 @@
1
+ describe UnderOs::Parser do
2
+
3
+ it "should parse .css files" do
4
+ UnderOs::Parser.parse('test.css').size.should.not == 0
5
+ end
6
+
7
+ it "should parse .html files" do
8
+ UnderOs::Parser.parse('test.html').size.should.not == 0
9
+ end
10
+
11
+ it "should not fail on non existing files" do
12
+ UnderOs::Parser.parse('non-existing.css').should == {}
13
+ UnderOs::Parser.parse('non-existing.html').should == []
14
+ end
15
+
16
+ end
@@ -0,0 +1,50 @@
1
+ describe "UnderOs::UI::Button" do
2
+ before do
3
+ @button = UnderOs::UI::Button.new(text: "Hello")
4
+ end
5
+
6
+ describe "constructor" do
7
+ it "builds an instance of the UnderOs::UI::Button" do
8
+ @button.class.should == UnderOs::UI::Button
9
+ end
10
+
11
+ it "wraps an UIButton instance" do
12
+ @button._.class.should == UIButton
13
+ end
14
+
15
+ it "assigns the BUTTON tag after it" do
16
+ @button.tagName.should == "BUTTON"
17
+ end
18
+ end
19
+
20
+ describe "#text" do
21
+ it "returns the button's label text" do
22
+ @button.text.should == "Hello"
23
+ end
24
+
25
+ it "allows to set a new value" do
26
+ @button.text = "New Label"
27
+ @button._.currentTitle.should == "New Label"
28
+ end
29
+ end
30
+
31
+ describe '#disabled' do
32
+ it "returns 'false' by default" do
33
+ @button.disabled.should == false
34
+ end
35
+
36
+ it "reads the value right of the ios entity" do
37
+ @button._.enabled = false
38
+ @button.disabled.should == true
39
+ end
40
+
41
+ it "allows to disable the inputs" do
42
+ @button.disabled = true
43
+ @button._.isEnabled.should == false
44
+ end
45
+
46
+ it "has a ruby-style alias" do
47
+ @button.disabled?.should == false
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,19 @@
1
+ describe UnderOs::UI::Collection do
2
+ describe '#initialize' do
3
+ before do
4
+ @collection = UnderOs::UI::Collection.new
5
+ end
6
+
7
+ it "makes instances of UI::Collection" do
8
+ @collection.class.should == UnderOs::UI::Collection
9
+ end
10
+
11
+ it "wraps the UICollectionView object" do
12
+ @collection._.class.should == UICollectionView
13
+ end
14
+
15
+ it "assigns the COLLECTION class" do
16
+ @collection.tagName.should == "COLLECTION"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ describe "UnderOs::UI::Div" do
2
+ before do
3
+ @div = UnderOs::UI::Div.new
4
+ end
5
+
6
+ describe "constructor" do
7
+ it "builds an UnderOs::UI::Div instance" do
8
+ @div.class.should == UnderOs::UI::Div
9
+ end
10
+
11
+ it "wraps a generic UIView element" do
12
+ @div._.class.should == UIView
13
+ end
14
+
15
+ it "has the DIV tag assigned to the element" do
16
+ @div.tagName.should == "DIV"
17
+ end
18
+
19
+ it "handles the usual options" do
20
+ div = UnderOs::UI::Div.new(id: 'my-div')
21
+ div.id.should == 'my-div'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,156 @@
1
+ describe "UnderOs::UI::Form" do
2
+ before do
3
+ @form = UnderOs::UI::Form.new
4
+ end
5
+
6
+ describe "constructor" do
7
+ it "makes the UnderOs::UI::Form instances" do
8
+ @form.class.should == UnderOs::UI::Form
9
+ end
10
+
11
+ it "assigns the FORM tag for the element" do
12
+ @form.tagName.should == "FORM"
13
+ end
14
+
15
+ it "takes the usual HTML params" do
16
+ form = UnderOs::UI::Form.new(id: 'my-form')
17
+ form.id.should == 'my-form'
18
+ end
19
+ end
20
+
21
+ describe '#elements' do
22
+ before do
23
+ @view = UnderOs::UI::View.new
24
+ @icon = UnderOs::UI::Icon.new
25
+ @input = UnderOs::UI::Input.new
26
+ @button = UnderOs::UI::Button.new
27
+
28
+ @form.append @view.append(@icon), @input, @button
29
+ end
30
+
31
+ it "returns inputs and buttons" do
32
+ @form.elements.should == [@icon, @input, @button]
33
+ end
34
+ end
35
+
36
+ describe "#inputs" do
37
+ it "returns an empty list when there is no input elements" do
38
+ @form.inputs.should == []
39
+ end
40
+
41
+ it "returns the list of the input elements only" do
42
+ v1 = UnderOs::UI::View.new
43
+ i1 = UnderOs::UI::Input.new
44
+ i2 = UnderOs::UI::Select.new
45
+ i3 = UnderOs::UI::Switch.new
46
+ i4 = UnderOs::UI::Textarea.new
47
+
48
+ @form.append v1.append(i1, i2), i3, i4
49
+
50
+ @form.inputs.should == [i1, i2, i3, i4]
51
+ end
52
+
53
+ class MyInput1 < UnderOs::UI::Input; end
54
+ class MyInput2 < MyInput1; end
55
+
56
+ it "handles subclasses of the inputs as well" do
57
+ i1 = MyInput1.new
58
+ i2 = MyInput2.new
59
+ i3 = UnderOs::UI::Input.new
60
+
61
+ @form.append i1, i2, i3
62
+
63
+ @form.inputs.should == [i1, i2, i3]
64
+ end
65
+ end
66
+
67
+ describe "#values" do
68
+ before do
69
+ @i1 = UnderOs::UI::Input.new(name: 'username', value: 'Nikolay')
70
+ @i2 = UnderOs::UI::Input.new(name: 'password', value: 'TheOsom')
71
+
72
+ @form.append @i1, @i2
73
+ end
74
+
75
+ it "returns a hash of the values" do
76
+ @form.values.should == {'username' => 'Nikolay', 'password' => 'TheOsom'}
77
+ end
78
+
79
+ it "skips inputs without names" do
80
+ @i2.name = nil
81
+ @form.values.should == {'username' => 'Nikolay'}
82
+ end
83
+
84
+ it "skips disabled inputs" do
85
+ @i1.disabled = true
86
+ @form.values.should == {'password' => 'TheOsom'}
87
+ end
88
+
89
+ it "handles nested hashes in the names" do
90
+ @i1.name = 'user[username]'
91
+ @i2.name = 'user[password]'
92
+
93
+ @form.values.should == {'user' => {'username' => 'Nikolay', 'password' => 'TheOsom'}}
94
+ end
95
+
96
+ it "handles the array names notation" do
97
+ @i1.name = 'fields[]'
98
+ @i2.name = 'fields[]'
99
+
100
+ @form.values.should == {'fields' => ['Nikolay', 'TheOsom']}
101
+ end
102
+
103
+ describe 'with a checkbox input' do
104
+ before do
105
+ @checkbox = UnderOs::UI::Switch.new(name: 'isawesome', value: 'true')
106
+ @form.append @checkbox
107
+ end
108
+
109
+ it "counts in checkboxes when they're switched on" do
110
+ @checkbox.checked = true
111
+ @form.values.should == {'username' => 'Nikolay', 'password' => 'TheOsom', 'isawesome' => 'true'}
112
+ end
113
+
114
+ it "skips the input if it's not ON" do
115
+ @checkbox.checked = false
116
+ @form.values.should == {'username' => 'Nikolay', 'password' => 'TheOsom'}
117
+ end
118
+ end
119
+ end
120
+
121
+ describe '#disable' do
122
+ before do
123
+ @icon = UnderOs::UI::Icon.new
124
+ @input = UnderOs::UI::Input.new
125
+ @button = UnderOs::UI::Button.new
126
+
127
+ @form.append @icon, @input, @button
128
+ end
129
+
130
+ it "disabled all the elements on the form" do
131
+ @form.disable
132
+
133
+ @icon.disabled.should == true
134
+ @input.disabled.should == true
135
+ @button.disabled.should == true
136
+ end
137
+ end
138
+
139
+ describe '#enable' do
140
+ before do
141
+ @icon = UnderOs::UI::Icon.new(disabled: true)
142
+ @input = UnderOs::UI::Input.new(disabled: true)
143
+ @button = UnderOs::UI::Button.new(disabled: true)
144
+
145
+ @form.append @icon, @input, @button
146
+ end
147
+
148
+ it "disabled all the elements on the form" do
149
+ @form.enable
150
+
151
+ @icon.disabled.should == false
152
+ @input.disabled.should == false
153
+ @button.disabled.should == false
154
+ end
155
+ end
156
+ end
@@ -0,0 +1,57 @@
1
+ describe "UnderOs::UI::Icon" do
2
+ before do
3
+ @icon = UnderOs::UI::Icon.new
4
+ end
5
+
6
+ describe '#initialize' do
7
+ it "builds the UnderOs::UI::Icon instances" do
8
+ @icon.class.should == UnderOs::UI::Icon
9
+ end
10
+
11
+ it "wraps an UIButton object" do
12
+ @icon._.class.should == UIButton
13
+ end
14
+
15
+ it "should assign correct tag name" do
16
+ @icon.tagName.should == 'ICON'
17
+ end
18
+
19
+ it "should allow to initialize the icon with type" do
20
+ icon = UnderOs::UI::Icon.new('ok')
21
+ icon.type.should == 'ok'
22
+ end
23
+
24
+ it "should set the default size of 20 pixels" do
25
+ icon = UnderOs::UI::Icon.new(type: 'ok')
26
+ icon.size.should == 20
27
+ end
28
+ end
29
+
30
+ describe '#type' do
31
+ it "should compile types into acutal UTF-8 keys" do
32
+ icon = UnderOs::UI::Icon.new(:ok)
33
+ icon._.currentTitle.should == "\xEF\x80\x8C"
34
+ end
35
+ end
36
+
37
+ describe '#disabled' do
38
+ it "returns 'false' by default" do
39
+ @icon.disabled.should == false
40
+ end
41
+
42
+ it "reads the value right of the ios entity" do
43
+ @icon._.enabled = false
44
+ @icon.disabled.should == true
45
+ end
46
+
47
+ it "allows to disable the inputs" do
48
+ @icon.disabled = true
49
+ @icon._.isEnabled.should == false
50
+ end
51
+
52
+ it "has a ruby-style alias" do
53
+ @icon.disabled?.should == false
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,39 @@
1
+ describe UnderOs::UI::Image do
2
+
3
+ describe '#initialize' do
4
+ before do
5
+ @image = UnderOs::UI::Image.new(src: 'test.png')
6
+ end
7
+
8
+ it "should say it has the 'IMG' tag name" do
9
+ @image.tagName.should == 'IMG'
10
+ end
11
+
12
+ it "should extract and assign the image source" do
13
+ @image._.image.class.should == UIImage
14
+ end
15
+ end
16
+
17
+
18
+ describe '#src' do
19
+ before do
20
+ @image = UnderOs::UI::Image.new
21
+ end
22
+
23
+ it "should be nil" do
24
+ @image.src.should == nil
25
+ end
26
+
27
+ it "should allow to specify the source as a file name" do
28
+ @image.src = 'test.png'
29
+ @image.src.class.should == UIImage
30
+ end
31
+
32
+ it "should allow to specify the source as an UIImage object" do
33
+ src = UIImage.imageNamed('test.png')
34
+ @image.src = src
35
+ @image.src.should == src
36
+ end
37
+ end
38
+
39
+ end
@@ -0,0 +1,109 @@
1
+ describe UnderOs::UI::Input do
2
+ before do
3
+ @input = UnderOs::UI::Input.new
4
+ end
5
+
6
+ describe '#initialize' do
7
+ it "should spawn new inputs" do
8
+ @input.class.should == UnderOs::UI::Input
9
+ end
10
+
11
+ it "should wrap the UITextField class" do
12
+ @input._.class.should == UITextField
13
+ end
14
+
15
+ it "should assign correct tag name" do
16
+ @input.tagName.should == 'INPUT'
17
+ end
18
+
19
+ it "should accept the 'name' option" do
20
+ input = UnderOs::UI::Input.new(name: 'some_name')
21
+ input.name.should == 'some_name'
22
+ end
23
+
24
+ it "should accept the 'value' option" do
25
+ input = UnderOs::UI::Input.new(value: 'boo hoo')
26
+ input.value.should == 'boo hoo'
27
+ end
28
+
29
+ it "should accept the 'placeholder' option" do
30
+ input = UnderOs::UI::Input.new(placeholder: 'enter here')
31
+ input.placeholder.should == 'enter here'
32
+ end
33
+
34
+ it "should accept the 'keyboard' option" do
35
+ input = UnderOs::UI::Input.new(keyboard: 'email')
36
+ input.keyboard.should == :email
37
+ end
38
+ end
39
+
40
+ describe '#type' do
41
+ # it "should handle the 'password' type correctly" do
42
+ # @input.type = 'password'
43
+ # @input._.secureTextEntry.should == true
44
+ # end
45
+
46
+ # it "should convert the input type back" do
47
+ # @input.type = 'password'
48
+ # @input.type.should == :password
49
+ # end
50
+
51
+ it "should return 'text' by default" do
52
+ @input.type.should == :text
53
+ end
54
+ end
55
+
56
+ describe '#name' do
57
+ it "should assign the name to an input field" do
58
+ @input.name = 'newname'
59
+ @input.name.should == 'newname'
60
+ end
61
+ end
62
+
63
+ describe '#value' do
64
+ it "should assign the value to the wrapped element" do
65
+ @input.value = 'new value'
66
+ @input._.text.should == 'new value'
67
+ end
68
+ end
69
+
70
+ describe '#placeholder' do
71
+ it "should assign the placeholder property on the wrapped element" do
72
+ @input.placeholder = 'tap here'
73
+ @input._.placeholder.should == 'tap here'
74
+ end
75
+ end
76
+
77
+ describe '#keyboard' do
78
+ it "should allow to assign keyboard types" do
79
+ @input.keyboard = :url
80
+ @input._.keyboardType.should == UIKeyboardTypeURL
81
+ end
82
+
83
+ it "should convert the keybaord types back to symbolic name in the getter" do
84
+ @input.keyboard = :email
85
+ @input.keyboard.should == :email
86
+ end
87
+ end
88
+
89
+ describe '#disabled' do
90
+ it "returns 'false' by default" do
91
+ @input.disabled.should == false
92
+ end
93
+
94
+ it "reads the value right of the ios entity" do
95
+ @input._.enabled = false
96
+ @input.disabled.should == true
97
+ end
98
+
99
+ it "allows to disable the inputs" do
100
+ @input.disabled = true
101
+ @input._.isEnabled.should == false
102
+ end
103
+
104
+ it "has a ruby-style alias" do
105
+ @input.disabled?.should == false
106
+ end
107
+ end
108
+
109
+ end