under-os 0.0.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/Gemfile +2 -0
  4. data/Gemfile.lock +16 -0
  5. data/README.md +70 -0
  6. data/Rakefile +24 -0
  7. data/app/config.rb +4 -0
  8. data/app/layouts/alerts.html +8 -0
  9. data/app/layouts/calculator.html +26 -0
  10. data/app/layouts/collections.html +7 -0
  11. data/app/layouts/home.html +14 -0
  12. data/app/layouts/http.html +8 -0
  13. data/app/layouts/inputs.html +44 -0
  14. data/app/layouts/lockers.html +6 -0
  15. data/app/layouts/navbar.html +9 -0
  16. data/app/layouts/scrolls.html +42 -0
  17. data/app/layouts/sidebars.html +17 -0
  18. data/app/pages/alerts_page.rb +14 -0
  19. data/app/pages/calculator_page.rb +36 -0
  20. data/app/pages/collections_page.rb +9 -0
  21. data/app/pages/home_page.rb +11 -0
  22. data/app/pages/http_page.rb +33 -0
  23. data/app/pages/inputs_page.rb +9 -0
  24. data/app/pages/lockers_page.rb +16 -0
  25. data/app/pages/navbar_page.rb +19 -0
  26. data/app/pages/scrolls_page.rb +5 -0
  27. data/app/pages/sidebars_page.rb +42 -0
  28. data/app/pages/stuff_page.rb +35 -0
  29. data/app/styles/application.css +25 -0
  30. data/app/styles/calculator.css +37 -0
  31. data/app/styles/collections.css +19 -0
  32. data/app/styles/home.css +0 -0
  33. data/app/styles/http.css +24 -0
  34. data/app/styles/inputs.css +47 -0
  35. data/app/styles/scrolls.css +67 -0
  36. data/app/styles/sidebars.css +19 -0
  37. data/lib/assets/fontawesome-webfont.ttf +0 -0
  38. data/lib/assets/under-os.css +115 -0
  39. data/lib/under-os.rb +9 -1
  40. data/lib/under_os/app.rb +33 -0
  41. data/lib/under_os/color.rb +176 -0
  42. data/lib/under_os/config.rb +28 -1
  43. data/lib/under_os/core/kernel.rb +16 -0
  44. data/lib/under_os/core/numeric.rb +23 -0
  45. data/lib/under_os/core/string.rb +40 -0
  46. data/lib/under_os/delegate.rb +3 -2
  47. data/lib/under_os/events.rb +85 -0
  48. data/lib/under_os/file.rb +110 -0
  49. data/lib/under_os/history.rb +50 -0
  50. data/lib/under_os/http/receiver.rb +44 -0
  51. data/lib/under_os/http/request.rb +89 -0
  52. data/lib/under_os/http/response.rb +24 -0
  53. data/lib/under_os/http/session.rb +49 -0
  54. data/lib/under_os/http.rb +5 -0
  55. data/lib/under_os/page/builder.rb +96 -0
  56. data/lib/under_os/page/layout.rb +43 -0
  57. data/lib/under_os/page/matcher.rb +83 -0
  58. data/lib/under_os/page/stylesheet.rb +67 -0
  59. data/lib/under_os/page.rb +153 -0
  60. data/lib/under_os/parser/css.rb +37 -0
  61. data/lib/under_os/parser/html.rb +97 -0
  62. data/lib/under_os/parser.rb +24 -0
  63. data/lib/under_os/point.rb +47 -0
  64. data/lib/under_os/screen.rb +9 -0
  65. data/lib/under_os/timer.rb +65 -0
  66. data/lib/under_os/ui/alert.rb +52 -0
  67. data/lib/under_os/ui/button.rb +22 -0
  68. data/lib/under_os/ui/collection/cell.rb +21 -0
  69. data/lib/under_os/ui/collection/delegate.rb +68 -0
  70. data/lib/under_os/ui/collection/item.rb +32 -0
  71. data/lib/under_os/ui/collection/layout.rb +43 -0
  72. data/lib/under_os/ui/collection/styles.rb +15 -0
  73. data/lib/under_os/ui/collection.rb +63 -0
  74. data/lib/under_os/ui/icon/awesome.rb +376 -0
  75. data/lib/under_os/ui/icon/engine.rb +10 -0
  76. data/lib/under_os/ui/icon.rb +42 -0
  77. data/lib/under_os/ui/image.rb +30 -0
  78. data/lib/under_os/ui/input.rb +41 -0
  79. data/lib/under_os/ui/label.rb +21 -0
  80. data/lib/under_os/ui/locker.rb +42 -0
  81. data/lib/under_os/ui/navbar.rb +115 -0
  82. data/lib/under_os/ui/progress.rb +17 -0
  83. data/lib/under_os/ui/scroll.rb +41 -0
  84. data/lib/under_os/ui/select.rb +98 -0
  85. data/lib/under_os/ui/sidebar.rb +45 -0
  86. data/lib/under_os/ui/slider.rb +49 -0
  87. data/lib/under_os/ui/spinner.rb +23 -0
  88. data/lib/under_os/ui/style/fonts.rb +60 -0
  89. data/lib/under_os/ui/style/margins.rb +160 -0
  90. data/lib/under_os/ui/style/outlining.rb +98 -0
  91. data/lib/under_os/ui/style/positioning.rb +169 -0
  92. data/lib/under_os/ui/style.rb +21 -0
  93. data/lib/under_os/ui/switch.rb +29 -0
  94. data/lib/under_os/ui/textarea.rb +14 -0
  95. data/lib/under_os/ui/utils/animation.rb +99 -0
  96. data/lib/under_os/ui/utils/commons.rb +70 -0
  97. data/lib/under_os/ui/utils/dimensions.rb +37 -0
  98. data/lib/under_os/ui/utils/editable.rb +43 -0
  99. data/lib/under_os/ui/utils/events.rb +75 -0
  100. data/lib/under_os/ui/utils/manipulation.rb +44 -0
  101. data/lib/under_os/ui/utils/position.rb +21 -0
  102. data/lib/under_os/ui/utils/size.rb +21 -0
  103. data/lib/under_os/ui/utils/styles.rb +89 -0
  104. data/lib/under_os/ui/utils/traversing.rb +44 -0
  105. data/lib/under_os/ui/utils/wrap.rb +77 -0
  106. data/lib/under_os/ui/view.rb +31 -0
  107. data/lib/under_os/ui.rb +3 -0
  108. data/lib/under_os.rb +2 -2
  109. data/resources/Default-568h@2x.png +0 -0
  110. data/resources/test.png +0 -0
  111. data/spec/assets/app.css +13 -0
  112. data/spec/assets/test.css +7 -0
  113. data/spec/assets/test.html +3 -0
  114. data/spec/assets/test_page.rb +2 -0
  115. data/spec/lib/core/numeric_spec.rb +37 -0
  116. data/spec/lib/core/string_spec.rb +87 -0
  117. data/spec/lib/under_os/color_spec.rb +133 -0
  118. data/spec/lib/under_os/events_spec.rb +71 -0
  119. data/spec/lib/under_os/file_spec.rb +98 -0
  120. data/spec/lib/under_os/page/builder_spec.rb +128 -0
  121. data/spec/lib/under_os/page/layout_spec.rb +18 -0
  122. data/spec/lib/under_os/page/matcher_spec.rb +154 -0
  123. data/spec/lib/under_os/page/stylesheet_spec.rb +83 -0
  124. data/spec/lib/under_os/page_spec.rb +5 -0
  125. data/spec/lib/under_os/parser/css_spec.rb +77 -0
  126. data/spec/lib/under_os/parser/html_spec.rb +152 -0
  127. data/spec/lib/under_os/parser_spec.rb +16 -0
  128. data/spec/lib/under_os/point_spec.rb +54 -0
  129. data/spec/lib/under_os/screen_spec.rb +11 -0
  130. data/spec/lib/under_os/timer_spec.rb +93 -0
  131. data/spec/lib/under_os/ui/button_spec.rb +5 -0
  132. data/spec/lib/under_os/ui/collection_spec.rb +19 -0
  133. data/spec/lib/under_os/ui/icon_spec.rb +26 -0
  134. data/spec/lib/under_os/ui/image_spec.rb +39 -0
  135. data/spec/lib/under_os/ui/input_spec.rb +77 -0
  136. data/spec/lib/under_os/ui/label_spec.rb +22 -0
  137. data/spec/lib/under_os/ui/locker_spec.rb +31 -0
  138. data/spec/lib/under_os/ui/progress_spec.rb +31 -0
  139. data/spec/lib/under_os/ui/scroll_spec.rb +40 -0
  140. data/spec/lib/under_os/ui/select_spec.rb +131 -0
  141. data/spec/lib/under_os/ui/sidebar_spec.rb +35 -0
  142. data/spec/lib/under_os/ui/slider_spec.rb +65 -0
  143. data/spec/lib/under_os/ui/spinner_spec.rb +57 -0
  144. data/spec/lib/under_os/ui/style/fonts_spec.rb +73 -0
  145. data/spec/lib/under_os/ui/style/margins_spec.rb +106 -0
  146. data/spec/lib/under_os/ui/style/outlining_spec.rb +69 -0
  147. data/spec/lib/under_os/ui/style/positioning_spec.rb +69 -0
  148. data/spec/lib/under_os/ui/style_spec.rb +19 -0
  149. data/spec/lib/under_os/ui/switch_spec.rb +56 -0
  150. data/spec/lib/under_os/ui/textarea_spec.rb +30 -0
  151. data/spec/lib/under_os/ui/utils/commons_spec.rb +81 -0
  152. data/spec/lib/under_os/ui/utils/manipulation_spec.rb +130 -0
  153. data/spec/lib/under_os/ui/utils/styles_spec.rb +140 -0
  154. data/spec/lib/under_os/ui/utils/traversing_spec.rb +124 -0
  155. data/spec/lib/under_os/ui/utils/wrap_spec.rb +69 -0
  156. data/spec/lib/under_os/ui/view_spec.rb +39 -0
  157. data/under-os.gemspec +32 -0
  158. metadata +225 -11
  159. data/lib/under_os/application.rb +0 -16
  160. data/lib/under_os/window.rb +0 -5
@@ -0,0 +1,98 @@
1
+ describe UnderOs::File do
2
+ before do
3
+ @existing_path = NSBundle.mainBundle.pathForResource("under-os.css", ofType:nil)
4
+ end
5
+
6
+ describe '.exists?' do
7
+ it "returns true for existing files" do
8
+ UnderOs::File.exists?(@existing_path).should == true
9
+ end
10
+
11
+ it "returns false for non existing files" do
12
+ UnderOs::File.exists?("non-existing.file").should == false
13
+ end
14
+ end
15
+
16
+ describe '.size' do
17
+ it "returns file size" do
18
+ UnderOs::File.size(@existing_path).should > 0
19
+ end
20
+
21
+ it "raises an error when exessing a non-existing file" do
22
+ -> {
23
+ UnderOs::File.size("non-existing.file")
24
+ }.should.raise(StandardError)
25
+ end
26
+ end
27
+
28
+ describe '.read' do
29
+ it "reads files content" do
30
+ content = UnderOs::File.read(@existing_path)
31
+ content.class.should == String
32
+ content.size.should > 0
33
+ end
34
+
35
+ it "raises an error when read a non-existing file" do
36
+ -> {
37
+ UnderOs::File.read("non-existing.file")
38
+ }.should.raise(StandardError)
39
+ end
40
+ end
41
+
42
+ describe '.write' do
43
+ before do
44
+ UnderOs::File.delete('test.txt')
45
+ @result = UnderOs::File.write('test.txt', 'stuff')
46
+ end
47
+
48
+ it "creates new files" do
49
+ UnderOs::File.exists?('test.txt').should == true
50
+ end
51
+
52
+ it "writes stuff into files" do
53
+ UnderOs::File.read('test.txt').should == 'stuff'
54
+ end
55
+
56
+ it "overwrites existing files" do
57
+ UnderOs::File.write('test.txt', 'new stuff')
58
+ UnderOs::File.read('test.txt').should == 'new stuff'
59
+ end
60
+
61
+ it "returns a new File object" do
62
+ @result.class.should == UnderOs::File
63
+ end
64
+ end
65
+
66
+ describe '.size' do
67
+ it "returns the file size" do
68
+ UnderOs::File.write('test.txt', '12345')
69
+ UnderOs::File.size('test.txt').should == 5
70
+ end
71
+ end
72
+
73
+ describe '.delete' do
74
+ before do
75
+ UnderOs::File.write('test.txt', 'stuff')
76
+ end
77
+
78
+ it "deletes files" do
79
+ UnderOs::File.delete('test.txt')
80
+ UnderOs::File.exists?('test.txt').should == false
81
+ end
82
+ end
83
+
84
+ describe '.tmp' do
85
+ before do
86
+ @file = UnderOs::File.tmp("test.txt")
87
+ end
88
+
89
+ it "creates a new File instance" do
90
+ @file.class.should == UnderOs::File
91
+ end
92
+
93
+ it "should locate it in the tmp directory" do
94
+ @file.path.to_s.should == "#{NSTemporaryDirectory()}test.txt"
95
+ end
96
+ end
97
+
98
+ end
@@ -0,0 +1,128 @@
1
+ describe UnderOs::Page::Builder do
2
+ def build(html)
3
+ UnderOs::Page::Builder.views_from(html)
4
+ end
5
+
6
+ describe 'generic build' do
7
+ before do
8
+ @result = build("<view id='my-view'></view>")
9
+ end
10
+
11
+ it "should return an array" do
12
+ @result.class.should == Array
13
+ end
14
+
15
+ it "should build just one item" do
16
+ @result.size.should == 1
17
+ end
18
+
19
+ it "should build an UnderOs::UI::View instance" do
20
+ @result[0].class.should == UnderOs::UI::View
21
+ end
22
+
23
+ it "should assign the element properties" do
24
+ @result[0].id.should == 'my-view'
25
+ end
26
+ end
27
+
28
+ describe 'types building' do
29
+ it "should build buttons" do
30
+ button = build(%Q{<button class="my-button">Some text</button>})[0]
31
+ button.class.should == UnderOs::UI::Button
32
+ button.classNames.should == ['my-button']
33
+ button.text.should == 'Some text'
34
+ end
35
+
36
+ it "should build labels" do
37
+ label = build(%Q{<label>The Text</label>})[0]
38
+ label.class.should == UnderOs::UI::Label
39
+ label.text.should == 'The Text'
40
+ end
41
+
42
+ it "should build images" do
43
+ image = build(%Q{<img src="test.png">})[0]
44
+ image.class.should == UnderOs::UI::Image
45
+ image.src.class.should == UIImage
46
+ end
47
+
48
+ it "should build icons" do
49
+ icon = build(%Q{<icon type="ok" />})[0]
50
+ icon.class.should == UnderOs::UI::Icon
51
+ icon.type.should == 'ok'
52
+ end
53
+ end
54
+
55
+ describe 'nested build' do
56
+ before do
57
+ @result = build(%Q{
58
+ <page id="level1">
59
+ <view id="level2">
60
+ <label>A</label>
61
+ <button>B</button>
62
+ </view>
63
+ </page>
64
+ })[0]
65
+ end
66
+
67
+ it "should still assign the top level element attributes" do
68
+ @result.id.should == 'level1'
69
+ end
70
+
71
+ it "should build the second level elements" do
72
+ level2 = @result.children
73
+ level2.size.should == 1
74
+ level2[0].id.should == 'level2'
75
+ end
76
+
77
+ it "should build the third level of the elements" do
78
+ level3 = @result.children[0].children
79
+ level3.size.should == 2
80
+ level3.map(&:class).should == [UnderOs::UI::Label, UnderOs::UI::Button]
81
+ level3.map(&:text).should == ['A', 'B']
82
+ end
83
+ end
84
+
85
+ describe 'selectboxes build' do
86
+ before do
87
+ @result = build(%Q{
88
+ <select>
89
+ <option value="1">One</option>
90
+ <option value="2">Two</option>
91
+ <option>Three</option>
92
+ </select>
93
+ })[0]
94
+ end
95
+
96
+ it "should allow to build a select box" do
97
+ @result.class.should == UnderOs::UI::Select
98
+ end
99
+
100
+ it "should recognize options" do
101
+ @result.options.should == {
102
+ '1' => 'One',
103
+ '2' => 'Two',
104
+ 'Three' => 'Three'
105
+ }
106
+ end
107
+
108
+ it "should allow to build multi-select boxes" do
109
+ select = build(%Q{
110
+ <select>
111
+ <optgroup>
112
+ <option value="1">One</option>
113
+ </optgroup>
114
+ <optgroup>
115
+ <option value="2">Two</option>
116
+ </optgroup>
117
+ <optgroup>
118
+ <option value="3">Three</option>
119
+ </optgroup>
120
+ </select>
121
+ })[0]
122
+
123
+ select.optgroups.should == [
124
+ {'1' => 'One'}, {'2' => 'Two'}, {'3' => 'Three'}
125
+ ]
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,18 @@
1
+ describe UnderOs::Page::Layout do
2
+ before do
3
+ @page = TestPage.new
4
+ @layout = UnderOs::Page::Layout.new(@page)
5
+ end
6
+
7
+ it "should pickup the elements from the layout.html file" do
8
+ @page.view.should.not == nil
9
+ children = @page.view.children
10
+ children.size.should == 1
11
+ children[0].class.should == UnderOs::UI::Button
12
+ children[0].text.should == 'Say Hello'
13
+ end
14
+
15
+ it "should pickup the page title from the test layout" do
16
+ @page.title.should == 'Hello World'
17
+ end
18
+ end
@@ -0,0 +1,154 @@
1
+ describe UnderOs::Page::StylesMatcher do
2
+ before do
3
+ @view = UnderOs::UI::View.new
4
+ @view1 = UnderOs::UI::View.new
5
+ @view2 = UnderOs::UI::View.new
6
+ @matcher = UnderOs::Page::StylesMatcher.new('smth')
7
+ end
8
+
9
+ describe '.new' do
10
+ it "should cache instances" do
11
+ @i1 = UnderOs::Page::StylesMatcher.new('.one')
12
+ @i2 = UnderOs::Page::StylesMatcher.new('.one')
13
+ @i3 = UnderOs::Page::StylesMatcher.new('.two')
14
+
15
+ @i1.should.be.same_as @i2
16
+ @i1.should.not == @i3
17
+ end
18
+ end
19
+
20
+ describe '#match' do
21
+ it "should return 'true' for views with score > 0" do
22
+ def @matcher.score_for(view); 1 end
23
+ @matcher.match(@view).should == true
24
+ end
25
+
26
+ it "should return 'false' for views with score == 0" do
27
+ def @matcher.score_for(view); 0 end
28
+ @matcher.match(@view).should == false
29
+ end
30
+ end
31
+
32
+ describe '#score_for' do
33
+ def score_for(view, css_rule)
34
+ UnderOs::Page::StylesMatcher.new(css_rule).score_for(view)
35
+ end
36
+
37
+ describe 'tags matching' do
38
+ it "should add score for tag match" do
39
+ score_for(@view, 'view').should == 1
40
+ end
41
+
42
+ it "should not add score for not matching tags" do
43
+ score_for(@view, 'button').should == 0
44
+ end
45
+
46
+ it "should not add score if the id is wrong" do
47
+ score_for(@view, 'view#some-id').should == 0
48
+ end
49
+
50
+ it "should not add score if the css-rule is wrong" do
51
+ score_for(@view, 'view.some-class').should == 0
52
+ end
53
+ end
54
+
55
+ describe 'IDs matching' do
56
+ it "should add score for IDs matches" do
57
+ @view.id = 'my-id'
58
+ score_for(@view, '#my-id').should == 1
59
+ end
60
+
61
+ it "should not add score for mismatching IDs" do
62
+ @view.id = 'my-id'
63
+ score_for(@view, '#another-id').should == 0
64
+ end
65
+
66
+ it "should not crash if ID is missing" do
67
+ score_for(@view, 'button').should == 0
68
+ end
69
+
70
+ it "should not add points if the tag is different" do
71
+ @view.id = 'my-id'
72
+ score_for(@view, 'button#my-id').should == 0
73
+ end
74
+ end
75
+
76
+ describe 'className matching' do
77
+ it "should add score for matching class names" do
78
+ @view.className = 'my-class'
79
+ score_for(@view, '.my-class').should == 1
80
+ end
81
+
82
+ it "should not add score for mismatching class names" do
83
+ @view.className = 'my-class'
84
+ score_for(@view, '.another-class').should == 0
85
+ end
86
+
87
+ it "should add point for every matching class name" do
88
+ @view.className = 'class1 class2'
89
+ score_for(@view, '.class1.class2').should == 2
90
+ score_for(@view, '.class2.class1').should == 2
91
+ end
92
+
93
+ it "should not add points one of multiple classes don't match" do
94
+ @view.className = 'class1 class2'
95
+ score_for(@view, '.class1.class3').should == 0
96
+ score_for(@view, '.class3.class2').should == 0
97
+ end
98
+
99
+ it "should not add points if the tag is different" do
100
+ @view.className = 'my-class'
101
+ score_for(@view, 'button.my-class').should == 0
102
+ end
103
+
104
+ it "should not add points if the ID is different" do
105
+ @view.className = 'my-class'
106
+ score_for(@view, '#another-id.my-class').should == 0
107
+ end
108
+ end
109
+
110
+ describe 'multiple matches' do
111
+ it "should count in all the matches" do
112
+ @view.id = 'my-id'
113
+ @view.className = 'class1 class2'
114
+ score_for(@view, 'view#my-id.class1.class2').should == 4
115
+ end
116
+ end
117
+
118
+ describe 'in multi-leveled structures' do
119
+ before do
120
+ @v1 = UnderOs::UI::View.new(class: 'v1')
121
+ @v2 = UnderOs::UI::View.new(class: 'v2')
122
+ @v3 = UnderOs::UI::View.new(class: 'v3')
123
+ @v4 = UnderOs::UI::View.new(class: 'v4')
124
+
125
+ @v1.append(@v2.append(@v3.append(@v4.append(@view))))
126
+
127
+ @view.id = 'my-view'
128
+ end
129
+
130
+ it "should still match singular rules" do
131
+ score_for(@view, '#my-view').should == 1
132
+ end
133
+
134
+ it "should add points for matching parent" do
135
+ score_for(@view, '.v4 #my-view').should == 2
136
+ score_for(@view, 'view.v4 #my-view').should == 3
137
+ end
138
+
139
+ it "should add multiple points for multiple matching parents" do
140
+ score_for(@view, '.v1 .v2 .v3 .v4 #my-view').should == 5
141
+ end
142
+
143
+ it "should match parents at any level" do
144
+ score_for(@view, '.v3 #my-view').should == 2
145
+ score_for(@view, '.v2 #my-view').should == 2
146
+ score_for(@view, '.v1 .v3 #my-view').should == 3
147
+ end
148
+
149
+ it "should return 0 if no matching parent found" do
150
+ score_for(@view, '.non-existing #my-view').should == 0
151
+ end
152
+ end
153
+ end
154
+ end
@@ -0,0 +1,83 @@
1
+ describe UnderOs::Page::Stylesheet do
2
+ before do
3
+ @stylesheet = UnderOs::Page::Stylesheet.new
4
+ end
5
+
6
+ describe '#initialize' do
7
+ it "should make an empty stylesheet" do
8
+ @stylesheet.rules.should == {}
9
+ end
10
+
11
+ it "should allow initialize with some rules" do
12
+ stylesheet = UnderOs::Page::Stylesheet.new(button: {color: 'orange'})
13
+ stylesheet.rules.should == {'button' => {color: 'orange'}}
14
+ end
15
+ end
16
+
17
+ describe '#[]' do
18
+ it "should allow to set new style rules" do
19
+ @stylesheet['button'] = {color: :red}
20
+ @stylesheet['button'].should == {color: :red}
21
+ end
22
+
23
+ it "should allow to extend the rules" do
24
+ @stylesheet['button'] = {color: 'red'}
25
+ @stylesheet['button'] = {right: 50 }
26
+ @stylesheet['button'].should == {color: 'red', right: 50}
27
+ end
28
+
29
+ it "should overwrite existing rules when match" do
30
+ @stylesheet['button'] = {color: 'red', left: 20}
31
+ @stylesheet['button'] = {color: 'blue'}
32
+ @stylesheet['button'].should == {color: 'blue', left: 20}
33
+ end
34
+ end
35
+
36
+ describe '#<<' do
37
+ it "should merge another stylesheet into the current one" do
38
+ other_sytles = UnderOs::Page::Stylesheet.new(button: { color: 'blue' })
39
+ @stylesheet['button'] = {left: 30}
40
+ @stylesheet << other_sytles
41
+ @stylesheet['button'].should == {color: 'blue', left: 30}
42
+ end
43
+ end
44
+
45
+ describe '#+' do
46
+ it "should create a new stylesheet combined out of the two" do
47
+ sheet1 = UnderOs::Page::Stylesheet.new(button: { color: 'blue' })
48
+ sheet2 = UnderOs::Page::Stylesheet.new(button: { left: 20 })
49
+
50
+ sheet3 = sheet1 + sheet2
51
+
52
+ sheet1['button'].should == {color: 'blue'}
53
+ sheet2['button'].should == {left: 20}
54
+ sheet3['button'].should == {color: 'blue', left: 20}
55
+ end
56
+ end
57
+
58
+ describe '#load' do
59
+ it "should load rules from the given test stylesheet file" do
60
+ @stylesheet.load('test.css')
61
+ @stylesheet.rules.should == {
62
+ "page"=>{:backgroundColor=>"yellow"},
63
+ ".test"=>{:backgroundColor=>"green"}
64
+ }
65
+ end
66
+ end
67
+
68
+ describe '#styles_for' do
69
+ before do
70
+ @view = UnderOs::UI::View.new(class: 'test')
71
+ @stylesheet.load('app.css')
72
+ @stylesheet.load('test.css')
73
+ end
74
+
75
+ it "should calculate the styles correctly" do
76
+ @stylesheet.styles_for(@view).should == {
77
+ color: 'yellow',
78
+ backgroundColor: 'green',
79
+ borderRadius: 10
80
+ }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,5 @@
1
+ describe UnderOs::Page do
2
+ before do
3
+ @page = TestPage.new
4
+ end
5
+ end
@@ -0,0 +1,77 @@
1
+ describe UnderOs::Parser::CSS do
2
+ before do
3
+ @parser = UnderOs::Parser::CSS.new
4
+ end
5
+
6
+ it "should parse simple tags" do
7
+ @parser.parse(%Q[
8
+ page {
9
+ background-color: darkgray;
10
+ }
11
+ ]).should == {'page' => {backgroundColor: "darkgray"}}
12
+ end
13
+
14
+ it "should unquote quoted values" do
15
+ @parser.parse(%Q{
16
+ page {
17
+ background-image: "image.png";
18
+ }
19
+ }).should == {'page' => {backgroundImage: "image.png"}}
20
+ end
21
+
22
+ it "should parse heaps of styles" do
23
+ @parser.parse(%Q{
24
+ button {
25
+ width: 79px;
26
+ height: 79px;
27
+ color: black;
28
+ background: white;
29
+ border-radius: 0px;
30
+ }
31
+ }).should == {'button' => {
32
+ width: 79.0, height: 79.0, color: "black", backgroundColor: "white", borderRadius: 0.0
33
+ }}
34
+ end
35
+
36
+ it "should parse classes" do
37
+ @parser.parse(%Q[
38
+ .row1 { bottom: 0px; }
39
+ .row2 { bottom: 80px; }
40
+
41
+ .col1.col2 { left: 0; }
42
+ ]).should == {
43
+ '.row1' => {bottom: 0.0},
44
+ '.row2' => {bottom: 80.0},
45
+ '.col1.col2' => {left: 0.0}
46
+ }
47
+ end
48
+
49
+ it "should parse tags and styles" do
50
+ @parser.parse(%Q[
51
+ button.double { width: 159; }
52
+ button.ops { background: yellow }
53
+ ]).should == {
54
+ 'button.double' => {width: 159.0},
55
+ 'button.ops' => {backgroundColor: "yellow"}
56
+ }
57
+ end
58
+
59
+ it "should parse complex rules" do
60
+ @parser.parse(%Q{
61
+ icon#delete .col1.col2 { color: red }
62
+ }).should == {
63
+ 'icon#delete .col1.col2' => {color: "red"}
64
+ }
65
+ end
66
+
67
+ it "should parse several rules" do
68
+ @parser.parse(%Q{
69
+ input, textarea {
70
+ width: 100;
71
+ }
72
+ }).should == {
73
+ 'input' => {width: 100.0},
74
+ 'textarea' => {width: 100.0}
75
+ }
76
+ end
77
+ end