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,376 @@
1
+ class UnderOs::UI::IconEngineAwesome
2
+ NAMES_MAP = {
3
+ 'glass' => 0xF000,
4
+ 'music' => 0xF001,
5
+ 'search' => 0xF002,
6
+ 'envelope-alt' => 0xF003,
7
+ 'heart' => 0xF004,
8
+ 'star' => 0xF005,
9
+ 'star-empty' => 0xF006,
10
+ 'user' => 0xF007,
11
+ 'film' => 0xF008,
12
+ 'th-large' => 0xF009,
13
+ 'th' => 0xF00A,
14
+ 'th-list' => 0xF00B,
15
+ 'ok' => 0xF00C,
16
+ 'cancel' => 0xF00D,
17
+ 'remove' => 0xF00D,
18
+ 'zoom-in' => 0xF00E,
19
+ 'zoom-out' => 0xF010,
20
+ 'off' => 0xF011,
21
+ 'signal' => 0xF012,
22
+ 'cog' => 0xF013,
23
+ 'trash' => 0xF014,
24
+ 'home' => 0xF015,
25
+ 'file-alt' => 0xF016,
26
+ 'time' => 0xF017,
27
+ 'road' => 0xF018,
28
+ 'download-alt' => 0xF019,
29
+ 'download' => 0xF01A,
30
+ 'upload' => 0xF01B,
31
+ 'inbox' => 0xF01C,
32
+ 'play-circle' => 0xF01D,
33
+ 'repeat' => 0xF01E,
34
+ 'refresh' => 0xF021,
35
+ 'list-alt' => 0xF022,
36
+ 'lock' => 0xF023,
37
+ 'flag' => 0xF024,
38
+ 'headphones' => 0xF025,
39
+ 'volume-off' => 0xF026,
40
+ 'volume-down' => 0xF027,
41
+ 'volume-up' => 0xF028,
42
+ 'qrcode' => 0xF029,
43
+ 'barcode' => 0xF02A,
44
+ 'tag' => 0xF02B,
45
+ 'tags' => 0xF02C,
46
+ 'book' => 0xF02D,
47
+ 'bookmark' => 0xF02E,
48
+ 'print' => 0xF02F,
49
+ 'camera' => 0xF030,
50
+ 'font' => 0xF031,
51
+ 'bold' => 0xF032,
52
+ 'italic' => 0xF033,
53
+ 'text-height' => 0xF034,
54
+ 'text-width' => 0xF035,
55
+ 'align-left' => 0xF036,
56
+ 'align-center' => 0xF037,
57
+ 'align-right' => 0xF038,
58
+ 'align-justify' => 0xF039,
59
+ 'list' => 0xF03A,
60
+ 'indent-left' => 0xF03B,
61
+ 'indent-right' => 0xF03C,
62
+ 'facetime-video' => 0xF03D,
63
+ 'picture' => 0xF03E,
64
+ 'pencil' => 0xF040,
65
+ 'map-marker' => 0xF041,
66
+ 'adjust' => 0xF042,
67
+ 'tint' => 0xF043,
68
+ 'edit' => 0xF044,
69
+ 'share' => 0xF045,
70
+ 'check' => 0xF046,
71
+ 'move' => 0xF047,
72
+ 'step-backward' => 0xF048,
73
+ 'fast-backward' => 0xF049,
74
+ 'backward' => 0xF04A,
75
+ 'play' => 0xF04B,
76
+ 'pause' => 0xF04C,
77
+ 'stop' => 0xF04D,
78
+ 'forward' => 0xF04E,
79
+ 'fast-forward' => 0xF050,
80
+ 'step-forward' => 0xF051,
81
+ 'eject' => 0xF052,
82
+ 'chevron-left' => 0xF053,
83
+ 'chevron-right' => 0xF054,
84
+ 'plus-sign' => 0xF055,
85
+ 'minus-sign' => 0xF056,
86
+ 'remove-sign' => 0xF057,
87
+ 'ok-sign' => 0xF058,
88
+ 'question-sign' => 0xF059,
89
+ 'info-sign' => 0xF05A,
90
+ 'screenshot' => 0xF05B,
91
+ 'remove-circle' => 0xF05C,
92
+ 'ok-circle' => 0xF05D,
93
+ 'ban-circle' => 0xF05E,
94
+ 'arrow-left' => 0xF060,
95
+ 'arrow-right' => 0xF061,
96
+ 'arrow-up' => 0xF062,
97
+ 'arrow-down' => 0xF063,
98
+ 'share-alt' => 0xF064,
99
+ 'resize-full' => 0xF065,
100
+ 'resize-small' => 0xF066,
101
+ 'plus' => 0xF067,
102
+ 'minus' => 0xF068,
103
+ 'asterisk' => 0xF069,
104
+ 'exclamation-sign' => 0xF06A,
105
+ 'gift' => 0xF06B,
106
+ 'leaf' => 0xF06C,
107
+ 'fire' => 0xF06D,
108
+ 'eye-open' => 0xF06E,
109
+ 'eye-close' => 0xF070,
110
+ 'warning-sign' => 0xF071,
111
+ 'plane' => 0xF072,
112
+ 'calendar' => 0xF073,
113
+ 'random' => 0xF074,
114
+ 'comment' => 0xF075,
115
+ 'magnet' => 0xF076,
116
+ 'chevron-up' => 0xF077,
117
+ 'chevron-down' => 0xF078,
118
+ 'retweet' => 0xF079,
119
+ 'shopping-cart' => 0xF07A,
120
+ 'folder-close' => 0xF07B,
121
+ 'folder-open' => 0xF07C,
122
+ 'resize-vertical' => 0xF07D,
123
+ 'resize-horizontal' => 0xF07E,
124
+ 'bar-chart' => 0xF080,
125
+ 'twitter-sign' => 0xF081,
126
+ 'facebook-sign' => 0xF082,
127
+ 'camera-retro' => 0xF083,
128
+ 'key' => 0xF084,
129
+ 'cogs' => 0xF085,
130
+ 'comments' => 0xF086,
131
+ 'thumbs-up-alt' => 0xF087,
132
+ 'thumbs-down-alt' => 0xF088,
133
+ 'star-half' => 0xF089,
134
+ 'heart-empty' => 0xF08A,
135
+ 'signout' => 0xF08B,
136
+ 'linkedin-sign' => 0xF08C,
137
+ 'pushpin' => 0xF08D,
138
+ 'external-link' => 0xF08E,
139
+ 'signin' => 0xF090,
140
+ 'trophy' => 0xF091,
141
+ 'github-sign' => 0xF092,
142
+ 'upload-alt' => 0xF093,
143
+ 'lemon' => 0xF094,
144
+ 'phone' => 0xF095,
145
+ 'check-empty' => 0xF096,
146
+ 'bookmark-empty' => 0xF097,
147
+ 'phone-sign' => 0xF098,
148
+ 'twitter' => 0xF099,
149
+ 'facebook' => 0xF09A,
150
+ 'github' => 0xF09B,
151
+ 'unlock' => 0xF09C,
152
+ 'credit-card' => 0xF09D,
153
+ 'rss' => 0xF09E,
154
+ 'hdd' => 0xF0A0,
155
+ 'bullhorn' => 0xF0A1,
156
+ 'bell' => 0xF0A2,
157
+ 'certificate' => 0xF0A3,
158
+ 'hand-right' => 0xF0A4,
159
+ 'hand-left' => 0xF0A5,
160
+ 'hand-up' => 0xF0A6,
161
+ 'hand-down' => 0xF0A7,
162
+ 'circle-arrow-left' => 0xF0A8,
163
+ 'circle-arrow-right' => 0xF0A9,
164
+ 'circle-arrow-up' => 0xF0AA,
165
+ 'circle-arrow-down' => 0xF0AB,
166
+ 'globe' => 0xF0AC,
167
+ 'wrench' => 0xF0AD,
168
+ 'tasks' => 0xF0AE,
169
+ 'filter' => 0xF0B0,
170
+ 'briefcase' => 0xF0B1,
171
+ 'fullscreen' => 0xF0B2,
172
+ 'group' => 0xF0C0,
173
+ 'link' => 0xF0C1,
174
+ 'cloud' => 0xF0C2,
175
+ 'beaker' => 0xF0C3,
176
+ 'cut' => 0xF0C4,
177
+ 'copy' => 0xF0C5,
178
+ 'paper-clip' => 0xF0C6,
179
+ 'save' => 0xF0C7,
180
+ 'sign-blank' => 0xF0C8,
181
+ 'reorder' => 0xF0C9,
182
+ 'list-ul' => 0xF0CA,
183
+ 'list-ol' => 0xF0CB,
184
+ 'strikethrough' => 0xF0CC,
185
+ 'underline' => 0xF0CD,
186
+ 'table' => 0xF0CE,
187
+ 'magic' => 0xF0D0,
188
+ 'truck' => 0xF0D1,
189
+ 'pinterest' => 0xF0D2,
190
+ 'pinterest-sign' => 0xF0D3,
191
+ 'google-plus-sign' => 0xF0D4,
192
+ 'google-plus' => 0xF0D5,
193
+ 'money' => 0xF0D6,
194
+ 'caret-down' => 0xF0D7,
195
+ 'caret-up' => 0xF0D8,
196
+ 'caret-left' => 0xF0D9,
197
+ 'caret-right' => 0xF0DA,
198
+ 'columns' => 0xF0DB,
199
+ 'sort' => 0xF0DC,
200
+ 'sort-down' => 0xF0DD,
201
+ 'sort-up' => 0xF0DE,
202
+ 'envelope' => 0xF0E0,
203
+ 'linkedin' => 0xF0E1,
204
+ 'undo' => 0xF0E2,
205
+ 'legal' => 0xF0E3,
206
+ 'dashboard' => 0xF0E4,
207
+ 'comment-alt' => 0xF0E5,
208
+ 'comments-alt' => 0xF0E6,
209
+ 'bolt' => 0xF0E7,
210
+ 'sitemap' => 0xF0E8,
211
+ 'umbrella' => 0xF0E9,
212
+ 'paste' => 0xF0EA,
213
+ 'lightbulb' => 0xF0EB,
214
+ 'exchange' => 0xF0EC,
215
+ 'cloud-download' => 0xF0ED,
216
+ 'cloud-upload' => 0xF0EE,
217
+ 'user-md' => 0xF0F0,
218
+ 'stethoscope' => 0xF0F1,
219
+ 'suitcase' => 0xF0F2,
220
+ 'bell-alt' => 0xF0F3,
221
+ 'coffee' => 0xF0F4,
222
+ 'food' => 0xF0F5,
223
+ 'file-text-alt' => 0xF0F6,
224
+ 'building' => 0xF0F7,
225
+ 'hospital' => 0xF0F8,
226
+ 'ambulance' => 0xF0F9,
227
+ 'medkit' => 0xF0FA,
228
+ 'fighter-jet' => 0xF0FB,
229
+ 'beer' => 0xF0FC,
230
+ 'h-sign' => 0xF0FD,
231
+ 'plus-sign-alt' => 0xF0FE,
232
+ 'double-angle-left' => 0xF100,
233
+ 'double-angle-right' => 0xF101,
234
+ 'double-angle-up' => 0xF102,
235
+ 'double-angle-down' => 0xF103,
236
+ 'angle-left' => 0xF104,
237
+ 'angle-right' => 0xF105,
238
+ 'angle-up' => 0xF106,
239
+ 'angle-down' => 0xF107,
240
+ 'desktop' => 0xF108,
241
+ 'laptop' => 0xF109,
242
+ 'tablet' => 0xF10A,
243
+ 'mobile-phone' => 0xF10B,
244
+ 'circle-blank' => 0xF10C,
245
+ 'quote-left' => 0xF10D,
246
+ 'quote-right' => 0xF10E,
247
+ 'spinner' => 0xF110,
248
+ 'circle' => 0xF111,
249
+ 'reply' => 0xF112,
250
+ 'github-alt' => 0xF113,
251
+ 'folder-close-alt' => 0xF114,
252
+ 'folder-open-alt' => 0xF115,
253
+ 'expand-alt' => 0xF116,
254
+ 'collapse-alt' => 0xF117,
255
+ 'smile' => 0xF118,
256
+ 'frown' => 0xF119,
257
+ 'meh' => 0xF11A,
258
+ 'gamepad' => 0xF11B,
259
+ 'keyboard' => 0xF11C,
260
+ 'flag-alt' => 0xF11D,
261
+ 'flag-checkered' => 0xF11E,
262
+ 'terminal' => 0xF120,
263
+ 'code' => 0xF121,
264
+ 'reply-all' => 0xF122,
265
+ 'mail-reply-all' => 0xF122,
266
+ 'star-half-empty' => 0xF123,
267
+ 'location-arrow' => 0xF124,
268
+ 'crop' => 0xF125,
269
+ 'code-fork' => 0xF126,
270
+ 'unlink' => 0xF127,
271
+ 'question' => 0xF128,
272
+ 'info' => 0xF129,
273
+ 'exclamation' => 0xF12A,
274
+ 'superscript' => 0xF12B,
275
+ 'subscript' => 0xF12C,
276
+ 'eraser' => 0xF12D,
277
+ 'puzzle-piece' => 0xF12E,
278
+ 'microphone' => 0xF130,
279
+ 'microphone-off' => 0xF131,
280
+ 'shield' => 0xF132,
281
+ 'calendar-empty' => 0xF133,
282
+ 'fire-extinguisher' => 0xF134,
283
+ 'rocket' => 0xF135,
284
+ 'maxcdn' => 0xF136,
285
+ 'chevron-sign-left' => 0xF137,
286
+ 'chevron-sign-right' => 0xF138,
287
+ 'chevron-sign-up' => 0xF139,
288
+ 'chevron-sign-down' => 0xF13A,
289
+ 'html5' => 0xF13B,
290
+ 'css3' => 0xF13C,
291
+ 'anchor' => 0xF13D,
292
+ 'unlock-alt' => 0xF13E,
293
+ 'bullseye' => 0xF140,
294
+ 'ellipsis-horizontal' => 0xF141,
295
+ 'ellipsis-vertical' => 0xF142,
296
+ 'rss-sign' => 0xF143,
297
+ 'play-sign' => 0xF144,
298
+ 'ticket' => 0xF145,
299
+ 'minus-sign-alt' => 0xF146,
300
+ 'check-minus' => 0xF147,
301
+ 'level-up' => 0xF148,
302
+ 'level-down' => 0xF149,
303
+ 'check-sign' => 0xF14A,
304
+ 'edit-sign' => 0xF14B,
305
+ 'external-link-sign' => 0xF14C,
306
+ 'share-sign' => 0xF14D,
307
+ 'compass' => 0xF14E,
308
+ 'collapse' => 0xF150,
309
+ 'collapse-top' => 0xF151,
310
+ 'expand' => 0xF152,
311
+ 'eur' => 0xF153,
312
+ 'gbp' => 0xF154,
313
+ 'usd' => 0xF155,
314
+ 'inr' => 0xF156,
315
+ 'jpy' => 0xF157,
316
+ 'cny' => 0xF158,
317
+ 'krw' => 0xF159,
318
+ 'btc' => 0xF15A,
319
+ 'file' => 0xF15B,
320
+ 'file-text' => 0xF15C,
321
+ 'sort-by-alphabet' => 0xF15D,
322
+ 'sort-by-alphabet-alt' => 0xF15E,
323
+ 'sort-by-attributes' => 0xF160,
324
+ 'sort-by-attributes-alt' => 0xF161,
325
+ 'sort-by-order' => 0xF162,
326
+ 'sort-by-order-alt' => 0xF163,
327
+ 'thumbs-up' => 0xF164,
328
+ 'thumbs-down' => 0xF165,
329
+ 'youtube-sign' => 0xF166,
330
+ 'youtube' => 0xF167,
331
+ 'xing' => 0xF168,
332
+ 'xing-sign' => 0xF169,
333
+ 'youtube-play' => 0xF16A,
334
+ 'dropbox' => 0xF16B,
335
+ 'stackexchange' => 0xF16C,
336
+ 'instagram' => 0xF16D,
337
+ 'flickr' => 0xF16E,
338
+ 'adn' => 0xF170,
339
+ 'bitbucket' => 0xF171,
340
+ 'bitbucket-sign' => 0xF172,
341
+ 'tumblr' => 0xF173,
342
+ 'tumblr-sign' => 0xF174,
343
+ 'long-arrow-down' => 0xF175,
344
+ 'long-arrow-up' => 0xF176,
345
+ 'long-arrow-left' => 0xF177,
346
+ 'long-arrow-right' => 0xF178,
347
+ 'apple' => 0xF179,
348
+ 'windows' => 0xF17A,
349
+ 'android' => 0xF17B,
350
+ 'linux' => 0xF17C,
351
+ 'dribble' => 0xF17D,
352
+ 'skype' => 0xF17E,
353
+ 'foursquare' => 0xF180,
354
+ 'trello' => 0xF181,
355
+ 'female' => 0xF182,
356
+ 'male' => 0xF183,
357
+ 'gittip' => 0xF184,
358
+ 'sun' => 0xF185,
359
+ 'moon' => 0xF186,
360
+ 'archive' => 0xF187,
361
+ 'bug' => 0xF188,
362
+ 'vk' => 0xF189,
363
+ 'weibo' => 0xF18A,
364
+ 'renren' => 0xF18B
365
+ }
366
+
367
+ def self.font(size)
368
+ UIFont.fontWithName("FontAwesome", size:size)
369
+ end
370
+
371
+ def self.text(name)
372
+ name = NAMES_MAP[name.to_s.gsub('_', '-')] || NAMES_MAP['bug']
373
+ name.chr(Encoding::UTF_8)
374
+ end
375
+
376
+ end
@@ -0,0 +1,9 @@
1
+ module UnderOs::UI::IconEngine
2
+ def self.included(base)
3
+ base.instance_eval do
4
+ def self.engine(engine=nil)
5
+ @engine ||= engine
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,31 @@
1
+ class UnderOs::UI::Image < UnderOs::UI::View
2
+ wraps UIImageView, tag: 'img'
3
+
4
+ def initialize(options)
5
+ options = {srs: options} unless options.is_a?(Hash)
6
+
7
+ super(options)
8
+
9
+ @_.contentMode = UIViewContentModeScaleAspectFit
10
+
11
+ self.src = options.delete(:src) if options.has_key?(:src)
12
+ end
13
+
14
+ def src
15
+ @_.image
16
+ end
17
+
18
+ def src=(src)
19
+ src = UIImage.imageNamed(src) if src.is_a?(String)
20
+ src = UIImage.imageWithData(src) if src.is_a?(NSData)
21
+ @_.image = src
22
+ end
23
+
24
+ def load(url, options={}, &complete)
25
+ UnderOs::HTTP.get(url, options) do |response|
26
+ self.src = response.data
27
+ complete.call(response) if complete && complete.arity != 0
28
+ complete.call if complete && complete.arity == 0
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,140 @@
1
+ class UnderOs::UI::Input < UnderOs::UI::View
2
+ wraps UITextField, tag: 'input'
3
+
4
+ def initialize(options={})
5
+ super
6
+
7
+ self.type = options[:type] if options[:type]
8
+ self.name = options[:name] if options[:name]
9
+ self.value = options[:value] if options[:value]
10
+ self.placeholder = options[:placeholder] if options[:placeholder]
11
+ self.keyboard = options[:keyboard] if options[:keyboard]
12
+ self.disabled = true if options[:disabled]
13
+
14
+ @_.delegate = self if @_.respond_to?(:delegate=)
15
+
16
+ if @_.class == UITextField
17
+ @_.addTarget self, action: :handle_focus, forControlEvents:UIControlEventEditingDidBegin
18
+ @_.addTarget self, action: :handle_change, forControlEvents:UIControlEventEditingChanged
19
+ @_.addTarget self, action: :handle_blur, forControlEvents:UIControlEventEditingDidEnd
20
+ end
21
+ end
22
+
23
+ def name
24
+ @name
25
+ end
26
+
27
+ def name=(text)
28
+ @name = text
29
+ end
30
+
31
+ def value
32
+ @_.text
33
+ end
34
+
35
+ def value=(value)
36
+ @_.text = value
37
+ end
38
+
39
+ def placeholder
40
+ @_.placeholder
41
+ end
42
+
43
+ def placeholder=(value)
44
+ @_.placeholder = value
45
+ end
46
+
47
+ def type
48
+ if @_.respond_to?(:secureTextEntry) && @_.secureTextEntry
49
+ :password
50
+ else
51
+ keyboard == :default ? :text : keyboard
52
+ end
53
+ end
54
+
55
+ def type=(type)
56
+ case type.to_sym
57
+ when :password then @_.secureTextEntry = true
58
+ else self.keyboard = type
59
+ end
60
+ end
61
+
62
+ def keyboard
63
+ KEYBOARDS.index(@_.keyboardType)
64
+ end
65
+
66
+ def keyboard=(keyboard)
67
+ keyboard = keyboard.to_sym if keyboard.is_a?(String)
68
+ keyboard = KEYBOARDS[keyboard] || keyboard
69
+
70
+ raise "Unknown keyboard type: #{keyboard}" if keyboard.is_a?(Symbol)
71
+
72
+ @_.keyboardType = keyboard
73
+ end
74
+
75
+ def hide_keyboard
76
+ puts "DEPRECATED: please use the `#blur` method instead of `#hide_keyboard`"
77
+ blur
78
+ end
79
+
80
+ KEYBOARDS = {
81
+ default: UIKeyboardTypeDefault,
82
+ text: UIKeyboardTypeDefault,
83
+ ascii: UIKeyboardTypeASCIICapable,
84
+ numeric: UIKeyboardTypeNumbersAndPunctuation,
85
+ url: UIKeyboardTypeURL,
86
+ numbers: UIKeyboardTypeNumberPad,
87
+ phone: UIKeyboardTypePhonePad,
88
+ name: UIKeyboardTypeNamePhonePad,
89
+ email: UIKeyboardTypeEmailAddress,
90
+ decimal: UIKeyboardTypeDecimalPad,
91
+ twitter: UIKeyboardTypeTwitter,
92
+ search: UIKeyboardTypeWebSearch
93
+ }
94
+
95
+ def disabled
96
+ ! @_.isEnabled
97
+ end
98
+
99
+ alias :disabled? :disabled
100
+
101
+ def disabled=(value)
102
+ @_.enabled = ! value
103
+ end
104
+
105
+ def disable
106
+ self.disabled = true
107
+ end
108
+
109
+ def enable
110
+ self.disabled = false
111
+ end
112
+
113
+ def focus
114
+ @_.becomeFirstResponder
115
+ end
116
+
117
+ def blur
118
+ @_.resignFirstResponder
119
+ end
120
+
121
+ # delegate
122
+
123
+ def textFieldShouldReturn(textField)
124
+ blur
125
+ end
126
+
127
+ protected
128
+
129
+ def handle_focus
130
+ emit('focus')
131
+ end
132
+
133
+ def handle_change
134
+ emit('change')
135
+ end
136
+
137
+ def handle_blur
138
+ emit('blur')
139
+ end
140
+ end