under-os 1.3.0 → 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 (140) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/Gemfile.lock +25 -2
  4. data/README.md +1 -1
  5. data/Rakefile +2 -4
  6. data/lib/under-os.rb +3 -8
  7. data/under-os.gemspec +6 -2
  8. metadata +47 -191
  9. data/lib/assets/fontawesome-webfont.ttf +0 -0
  10. data/lib/assets/under-os.css +0 -115
  11. data/lib/under_os.rb +0 -41
  12. data/lib/under_os/app.rb +0 -33
  13. data/lib/under_os/color.rb +0 -184
  14. data/lib/under_os/config.rb +0 -33
  15. data/lib/under_os/core/array.rb +0 -5
  16. data/lib/under_os/core/hash.rb +0 -10
  17. data/lib/under_os/core/json.rb +0 -19
  18. data/lib/under_os/core/kernel.rb +0 -16
  19. data/lib/under_os/core/numeric.rb +0 -23
  20. data/lib/under_os/core/object.rb +0 -9
  21. data/lib/under_os/core/string.rb +0 -80
  22. data/lib/under_os/delegate.rb +0 -10
  23. data/lib/under_os/events.rb +0 -85
  24. data/lib/under_os/file.rb +0 -110
  25. data/lib/under_os/history.rb +0 -53
  26. data/lib/under_os/http.rb +0 -31
  27. data/lib/under_os/http/cookies.rb +0 -30
  28. data/lib/under_os/http/receiver.rb +0 -44
  29. data/lib/under_os/http/request.rb +0 -106
  30. data/lib/under_os/http/response.rb +0 -28
  31. data/lib/under_os/http/session.rb +0 -49
  32. data/lib/under_os/page.rb +0 -169
  33. data/lib/under_os/page/builder.rb +0 -96
  34. data/lib/under_os/page/layout.rb +0 -43
  35. data/lib/under_os/page/matcher.rb +0 -128
  36. data/lib/under_os/page/stylesheet.rb +0 -67
  37. data/lib/under_os/parser.rb +0 -24
  38. data/lib/under_os/parser/css.rb +0 -37
  39. data/lib/under_os/parser/html.rb +0 -97
  40. data/lib/under_os/point.rb +0 -47
  41. data/lib/under_os/screen.rb +0 -9
  42. data/lib/under_os/timer.rb +0 -65
  43. data/lib/under_os/ui.rb +0 -3
  44. data/lib/under_os/ui/alert.rb +0 -52
  45. data/lib/under_os/ui/button.rb +0 -42
  46. data/lib/under_os/ui/collection.rb +0 -65
  47. data/lib/under_os/ui/collection/cell.rb +0 -21
  48. data/lib/under_os/ui/collection/delegate.rb +0 -70
  49. data/lib/under_os/ui/collection/item.rb +0 -32
  50. data/lib/under_os/ui/collection/layout.rb +0 -43
  51. data/lib/under_os/ui/collection/styles.rb +0 -15
  52. data/lib/under_os/ui/div.rb +0 -3
  53. data/lib/under_os/ui/form.rb +0 -60
  54. data/lib/under_os/ui/icon.rb +0 -61
  55. data/lib/under_os/ui/icon/awesome.rb +0 -376
  56. data/lib/under_os/ui/icon/engine.rb +0 -10
  57. data/lib/under_os/ui/image.rb +0 -31
  58. data/lib/under_os/ui/input.rb +0 -140
  59. data/lib/under_os/ui/label.rb +0 -21
  60. data/lib/under_os/ui/locker.rb +0 -42
  61. data/lib/under_os/ui/navbar.rb +0 -123
  62. data/lib/under_os/ui/progress.rb +0 -17
  63. data/lib/under_os/ui/scroll.rb +0 -41
  64. data/lib/under_os/ui/select.rb +0 -95
  65. data/lib/under_os/ui/sidebar.rb +0 -45
  66. data/lib/under_os/ui/slider.rb +0 -37
  67. data/lib/under_os/ui/spinner.rb +0 -23
  68. data/lib/under_os/ui/style.rb +0 -21
  69. data/lib/under_os/ui/style/fonts.rb +0 -54
  70. data/lib/under_os/ui/style/margins.rb +0 -164
  71. data/lib/under_os/ui/style/outlining.rb +0 -170
  72. data/lib/under_os/ui/style/positioning.rb +0 -169
  73. data/lib/under_os/ui/switch.rb +0 -26
  74. data/lib/under_os/ui/textarea.rb +0 -19
  75. data/lib/under_os/ui/utils/animation.rb +0 -99
  76. data/lib/under_os/ui/utils/commons.rb +0 -70
  77. data/lib/under_os/ui/utils/dimensions.rb +0 -37
  78. data/lib/under_os/ui/utils/events.rb +0 -170
  79. data/lib/under_os/ui/utils/manipulation.rb +0 -44
  80. data/lib/under_os/ui/utils/position.rb +0 -21
  81. data/lib/under_os/ui/utils/size.rb +0 -21
  82. data/lib/under_os/ui/utils/styles.rb +0 -89
  83. data/lib/under_os/ui/utils/traversing.rb +0 -44
  84. data/lib/under_os/ui/utils/wrap.rb +0 -77
  85. data/lib/under_os/ui/view.rb +0 -31
  86. data/resources/test.png +0 -0
  87. data/spec/assets/app.css +0 -13
  88. data/spec/assets/test.css +0 -7
  89. data/spec/assets/test.html +0 -3
  90. data/spec/assets/test_page.rb +0 -2
  91. data/spec/lib/core/hash_spec.rb +0 -19
  92. data/spec/lib/core/json_spec.rb +0 -32
  93. data/spec/lib/core/numeric_spec.rb +0 -37
  94. data/spec/lib/core/string_spec.rb +0 -121
  95. data/spec/lib/under_os/color_spec.rb +0 -133
  96. data/spec/lib/under_os/events_spec.rb +0 -71
  97. data/spec/lib/under_os/file_spec.rb +0 -98
  98. data/spec/lib/under_os/http/cookies_spec.rb +0 -13
  99. data/spec/lib/under_os/http/request_spec.rb +0 -44
  100. data/spec/lib/under_os/http_spec.rb +0 -20
  101. data/spec/lib/under_os/page/builder_spec.rb +0 -128
  102. data/spec/lib/under_os/page/layout_spec.rb +0 -18
  103. data/spec/lib/under_os/page/matcher_spec.rb +0 -260
  104. data/spec/lib/under_os/page/stylesheet_spec.rb +0 -83
  105. data/spec/lib/under_os/page_spec.rb +0 -5
  106. data/spec/lib/under_os/parser/css_spec.rb +0 -77
  107. data/spec/lib/under_os/parser/html_spec.rb +0 -152
  108. data/spec/lib/under_os/parser_spec.rb +0 -16
  109. data/spec/lib/under_os/point_spec.rb +0 -54
  110. data/spec/lib/under_os/screen_spec.rb +0 -11
  111. data/spec/lib/under_os/timer_spec.rb +0 -93
  112. data/spec/lib/under_os/ui/button_spec.rb +0 -50
  113. data/spec/lib/under_os/ui/collection_spec.rb +0 -19
  114. data/spec/lib/under_os/ui/div_spec.rb +0 -24
  115. data/spec/lib/under_os/ui/form_spec.rb +0 -156
  116. data/spec/lib/under_os/ui/icon_spec.rb +0 -57
  117. data/spec/lib/under_os/ui/image_spec.rb +0 -39
  118. data/spec/lib/under_os/ui/input_spec.rb +0 -109
  119. data/spec/lib/under_os/ui/label_spec.rb +0 -22
  120. data/spec/lib/under_os/ui/locker_spec.rb +0 -31
  121. data/spec/lib/under_os/ui/progress_spec.rb +0 -31
  122. data/spec/lib/under_os/ui/scroll_spec.rb +0 -40
  123. data/spec/lib/under_os/ui/select_spec.rb +0 -135
  124. data/spec/lib/under_os/ui/sidebar_spec.rb +0 -35
  125. data/spec/lib/under_os/ui/slider_spec.rb +0 -69
  126. data/spec/lib/under_os/ui/spinner_spec.rb +0 -57
  127. data/spec/lib/under_os/ui/style/fonts_spec.rb +0 -73
  128. data/spec/lib/under_os/ui/style/margins_spec.rb +0 -106
  129. data/spec/lib/under_os/ui/style/outlining_spec.rb +0 -101
  130. data/spec/lib/under_os/ui/style/positioning_spec.rb +0 -69
  131. data/spec/lib/under_os/ui/style_spec.rb +0 -19
  132. data/spec/lib/under_os/ui/switch_spec.rb +0 -60
  133. data/spec/lib/under_os/ui/textarea_spec.rb +0 -34
  134. data/spec/lib/under_os/ui/utils/commons_spec.rb +0 -81
  135. data/spec/lib/under_os/ui/utils/events_spec.rb +0 -87
  136. data/spec/lib/under_os/ui/utils/manipulation_spec.rb +0 -130
  137. data/spec/lib/under_os/ui/utils/styles_spec.rb +0 -140
  138. data/spec/lib/under_os/ui/utils/traversing_spec.rb +0 -124
  139. data/spec/lib/under_os/ui/utils/wrap_spec.rb +0 -69
  140. data/spec/lib/under_os/ui/view_spec.rb +0 -39
@@ -1,28 +0,0 @@
1
- class UnderOs::HTTP::Response
2
- attr_reader :data
3
-
4
- def initialize(response, data)
5
- @response = response
6
- @data = data # raw NSData
7
- end
8
-
9
- def headers
10
- @response.allHeaderFields
11
- end
12
-
13
- def body
14
- @body ||= @data.to_s
15
- end
16
-
17
- def json
18
- JSON.parse(body)
19
- end
20
-
21
- def content_length
22
- headers["Content-Length"].to_i
23
- end
24
-
25
- def content_type
26
- headers["Content-Type"]
27
- end
28
- end
@@ -1,49 +0,0 @@
1
- #
2
- # Basically keeps track of cookies between the requests
3
- #
4
- class Session
5
- def initialize(default_options={})
6
- @options = default_options
7
- @options[:cookies] ||= {}
8
- end
9
-
10
- def cookies
11
- @options[:cookies]
12
- end
13
-
14
- def get(url, options={}, &block)
15
- request(url, {method: 'GET'}.merge(options), &block).send
16
- end
17
-
18
- def post(url, options={}, &block)
19
- request(url, {method: 'POST'}.merge(options), &block).send
20
- end
21
-
22
- def put(url, options={}, &block)
23
- request(url, {method: 'PUT'}.merge(options), &block).send
24
- end
25
-
26
- def delete(url, options={}, &block)
27
- request(url, {method: 'DELETE'}.merge(options), &block).send
28
- end
29
-
30
- def request(url, options={}, &block)
31
- options = options.merge(@options){|k,a,b| a.merge(b) }
32
-
33
- UnderOs::HTTP::Request.new(url, options, &block).tap do |request|
34
- request.on :response do |response|
35
- save_cookies response.headers["Set-Cookie"] || ''
36
- end
37
- end
38
- end
39
-
40
- protected
41
-
42
- def save_cookies(cookies)
43
- cookies.scan(/([a-z_]+?)=([^; ]+)/).each do |key, value|
44
- unless ['path', 'domain', 'expires'].include?(key)
45
- @options[:cookies][key] = value
46
- end
47
- end
48
- end
49
- end
@@ -1,169 +0,0 @@
1
- #
2
- # UOS::Page is kind of a wrap over an iOS controller
3
- # but instead of the controller, it presents more the
4
- # main (root) view of the controller in a sence you've
5
- # got for DOM documents in web
6
- #
7
- class UnderOs::Page
8
- include UnderOs::Events
9
- include UnderOs::UI
10
-
11
- attr_reader :_, :stylesheet
12
-
13
- def self.new(*args)
14
- alloc.setup_wrap(*args)
15
- end
16
-
17
- def self.layout(name=nil)
18
- name ? (@layout = name) : @layout
19
- end
20
-
21
- def initialize
22
- # page building goes in here
23
- end
24
-
25
- def view
26
- @_view
27
- end
28
-
29
- def view=(view)
30
- @_view = view
31
- end
32
-
33
- %w[insert append prepend find first].each do |method|
34
- define_method method do |*args|
35
- @_view.__send__ method, *args
36
- end
37
- end
38
-
39
- def alert(*args)
40
- Alert.new(*args)
41
- end
42
-
43
- def history
44
- UnderOs::App.history
45
- end
46
-
47
- def navbar
48
- history.navbar
49
- end
50
-
51
- def title
52
- @_.navigationItem.title
53
- end
54
-
55
- def title=(text)
56
- @_.navigationItem.title = text
57
- end
58
-
59
- def name
60
- self.class.name.underscore.sub(/_page$/, '')
61
- end
62
-
63
- def setup_wrap(*args)
64
- @_ = UIViewControllerWrap.alloc.init(self, {
65
- on_load_view: Proc.new{ emit('init') },
66
- on_view_loaded: Proc.new{ emit('load') },
67
- on_view_appear: Proc.new{ emit('appear') },
68
- on_view_disappear: Proc.new{ emit('disappear') },
69
- on_view_rerender: Proc.new{ emit('rerender') },
70
- on_view_rotate: Proc.new{ emit('rotate') }
71
- })
72
-
73
- on 'init' do
74
- build_layout
75
- compile_styles
76
- end
77
-
78
- on 'load' do
79
- repaint
80
- initialize(*args)
81
- repaint
82
- end
83
-
84
- on 'rotate' do
85
- repaint
86
- end
87
-
88
- self
89
- end
90
-
91
- def build_layout
92
- @_layout = Layout.new(self)
93
- end
94
-
95
- def compile_styles
96
- @stylesheet = Stylesheet.new
97
- @stylesheet << UnderOs::App.stylesheet
98
- @stylesheet.load("#{name}.css")
99
- end
100
-
101
- def repaint
102
- view.repaint(stylesheet) if view
103
- navbar.repaint(stylesheet) if navbar
104
- end
105
-
106
- #
107
- # A simple wrap over UIViewController to intercept
108
- # the iOS events
109
- #
110
- class UIViewControllerWrap < UIViewController
111
- attr_reader :wrapper
112
-
113
- def init(wrapper, options)
114
- @wrapper = wrapper
115
- @options = options
116
- initWithNibName(nil, bundle: nil)
117
- end
118
-
119
- def loadView
120
- super
121
- @options[:on_load_view].call
122
- end
123
-
124
- def viewDidLoad
125
- super
126
- @options[:on_view_loaded].call
127
- end
128
-
129
- def viewDidAppear(animated)
130
- super
131
- @options[:on_view_appear].call
132
- end
133
-
134
- def viewDidDisappear(animated)
135
- super
136
- @options[:on_view_disappear].call
137
- end
138
-
139
- def viewWillLayoutSubviews
140
- super
141
- @options[:on_view_rerender].call
142
- end
143
-
144
- def didRotateFromInterfaceOrientation(orientation)
145
- super
146
- @options[:on_view_rotate].call
147
- end
148
-
149
- def prefersStatusBarHidden
150
- !UnderOs::App.config.status_bar
151
- end
152
-
153
- def touchesBegan(touches, withEvent:event)
154
- UnderOs::UI::Events::TouchListeners.notify :touchstart, event
155
- end
156
-
157
- def touchesMoved(touches, withEvent:event)
158
- UnderOs::UI::Events::TouchListeners.notify :touchmove, event
159
- end
160
-
161
- def touchesEnded(touches, withEvent: event)
162
- UnderOs::UI::Events::TouchListeners.notify :touchend, event
163
- end
164
-
165
- def touchesCancelled(touches, withEvent: event)
166
- UnderOs::UI::Events::TouchListeners.notify :touchcancel, event
167
- end
168
- end
169
- end
@@ -1,96 +0,0 @@
1
- class UnderOs::Page::Builder
2
-
3
- def self.views_from(source)
4
- @inst ||= new
5
- if source.is_a?(String)
6
- @inst.from_html(source)
7
- else
8
- @inst.from_nodes(source)
9
- end
10
- end
11
-
12
- def from_html(source)
13
- @html ||= UnderOs::Parser::HTML.new
14
- from_nodes @html.parse(source)
15
- end
16
-
17
- def from_nodes(list)
18
- list.map do |node|
19
- build_view_from(node)
20
- end
21
- end
22
-
23
- def build_view_from(node)
24
- klass = class_for(node)
25
- options = options_from_attrs(node[:attrs] || {})
26
-
27
- if klass.instance_methods.include?(:text) && node[:text]
28
- options[:text] = node[:text]
29
- end
30
-
31
- klass.new(options).tap do |view|
32
- if node[:children] && node[:children].any?
33
- build_children_for(view, node[:children])
34
- end
35
- end
36
- end
37
-
38
- def class_for(node)
39
- if node[:attrs] && node[:attrs][:wrapper].is_a?(String)
40
- node[:attrs].delete(:wrapper).constantize
41
- else
42
- UnderOs::UI::Wrap::WRAPS_TAGS_MAP[node[:tag]] || UnderOs::UI::View
43
- end
44
- end
45
-
46
- def options_from_attrs(hash)
47
- {}.tap do |options|
48
- hash.each do |key, value|
49
- options[key] = value
50
- end
51
- end
52
- end
53
-
54
- def build_children_for(view, nodes)
55
- if view.is_a?(UnderOs::UI::Select)
56
- view.optgroups = select_optgroups_from(nodes)
57
- elsif view.is_a?(UnderOs::UI::Collection)
58
- find_collection_items_for(view, nodes)
59
- else
60
- from_nodes(nodes).each do |child|
61
- view.insert child
62
- end
63
- end
64
- end
65
-
66
- def select_optgroups_from(nodes)
67
- nodes = [{tag: 'optgroup', children: nodes}] if nodes[0][:tag] == 'option'
68
-
69
- nodes.map do |group|
70
- {}.tap do |options|
71
- group[:children].each do |option|
72
- if option[:tag] == 'option'
73
- label = option[:text]
74
- value = option[:attrs][:value] || label
75
-
76
- options[value] = label if value && label
77
- end
78
- end
79
- end
80
- end
81
- end
82
-
83
- def find_collection_items_for(collection, nodes)
84
- nodes.each do |node|
85
- klass = class_for(node)
86
-
87
- if klass <= UnderOs::UI::Collection::Item
88
- klass.build(collection) { from_nodes(node[:children]) }
89
- end
90
-
91
- # header
92
- # footer
93
- end
94
- end
95
-
96
- end
@@ -1,43 +0,0 @@
1
- class UnderOs::Page::Layout
2
-
3
- def initialize(page)
4
- @page = page
5
-
6
- build_layout_from_xib || build_layout_from_html || build_layout_from_nothing
7
-
8
- @page.view = UnderOs::UI::View.new(@page._.view)
9
- @page.view.instance_variable_set('@_tag_name', 'PAGE')
10
- end
11
-
12
- def build_layout_from_xib
13
- if filename = find_layout_with_type('xib')
14
- @page._.view = NSBundle.mainBundle.loadNibNamed(filename.sub(/\.xib$/, ''), owner:self, options:nil)[0]
15
- end
16
- end
17
-
18
- def build_layout_from_html
19
- if filename = find_layout_with_type('html')
20
- if layout = UnderOs::Parser.parse(filename)
21
- if view = UnderOs::Page::Builder.views_from(layout)[0]
22
- @page._.view = view._
23
- @page.title = layout[0][:attrs][:title] || ''
24
- end
25
- end
26
- end
27
- end
28
-
29
- def build_layout_from_nothing
30
- @page._.view = UIView.alloc.init
31
- @page._.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
32
- end
33
-
34
- def find_layout_with_type(ext)
35
- filename = @page.class.layout || "#{@page.name}.#{ext}"
36
- filename, type = filename.match(/^(.+?)\.([a-z]+)$/).to_a.slice(1,2)
37
-
38
- if type == ext && NSBundle.mainBundle.pathForResource(filename, ofType:type)
39
- "#{filename}.#{type}"
40
- end
41
- end
42
-
43
- end
@@ -1,128 +0,0 @@
1
- class UnderOs::Page::StylesMatcher
2
-
3
- def self.new(css_rule)
4
- @cache ||= {}
5
- @cache[css_rule] ||= super
6
- end
7
-
8
- def initialize(css_rule)
9
- css_rules = css_rule.strip.split(/\s*,\s*/)
10
-
11
- if css_rules.size == 1
12
- rules = css_rules[0].scan(/([\S]+)/).map(&:first)
13
- @rule = parse(rules.pop)
14
- @parent = rules.size == 0 ? false : self.class.new(rules.join(' '))
15
- else
16
- @multiple_matchers = css_rules.map{ |rule| self.class.new(rule) }
17
- end
18
- end
19
-
20
- def match(view)
21
- score_for(view) != 0
22
- end
23
-
24
- def score_for(view)
25
- return summary_score_for(view) if @multiple_matchers
26
-
27
- id_score = id_score_for(view)
28
- tag_score = tag_score_for(view)
29
- class_score = class_score_for(view)
30
- attrs_score = attrs_score_for(view)
31
- total_score = id_score + tag_score + class_score + attrs_score
32
-
33
- total_score = 0 if id_score == 0 && @rule[:id]
34
- total_score = 0 if tag_score == 0 && @rule[:tag]
35
- total_score = 0 if class_score == 0 && @rule[:classes].size != 0
36
- total_score = 0 if attrs_score == 0 && @rule[:attrs].size != 0
37
-
38
- if @parent && total_score != 0
39
- parent_score = parent_score_for(view)
40
- total_score = parent_score == 0 ? 0 : total_score + parent_score
41
- end
42
-
43
- total_score
44
- end
45
-
46
- private
47
-
48
- def summary_score_for(view)
49
- @multiple_matchers.map{ |matcher| matcher.score_for(view) }.max
50
- end
51
-
52
- def id_score_for(view)
53
- @rule[:id] == view.id ? 1 : 0
54
- end
55
-
56
- def tag_score_for(view)
57
- @rule[:tag] == '*' || @rule[:tag] == view.tagName ? 1 : 0
58
- end
59
-
60
- def class_score_for(view)
61
- return 0 if @rule[:classes].size == 0
62
- match = @rule[:classes] & view.classNames
63
- match.size == @rule[:classes].size ? match.size : 0
64
- end
65
-
66
- def attrs_score_for(view)
67
- score = 0; return 0 if @rule[:attrs].size == 0
68
-
69
- @rule[:attrs].each do |key, value, operand|
70
- attr = view.respond_to?(key) && view.__send__(key)
71
- attr = attr.to_s if attr.is_a?(Symbol) || attr.is_a?(Numeric)
72
-
73
- if attr && attr.is_a?(String)
74
- matches = case operand
75
- when '=' then attr == value
76
- when '*=' then attr.include?(value)
77
- when '^=' then attr.starts_with?(value)
78
- when '$=' then attr.ends_with?(value)
79
- when '~=' then attr.split(' ').include?(value)
80
- when '|=' then attr.split('-').include?(value)
81
- end
82
-
83
- score += 1 if matches
84
- end
85
- end
86
-
87
- score
88
- end
89
-
90
- def parent_score_for(view)
91
- parent = view; score = 0
92
-
93
- while parent = parent.parent
94
- score = @parent.score_for(parent)
95
- break if score > 0
96
- end
97
-
98
- score
99
- end
100
-
101
- def parse(string)
102
- {}.tap do |rule|
103
- if m = string.match(/^([a-z\*]+)/)
104
- rule[:tag] = m[1].upcase
105
- else
106
- rule[:tag] = false # so it wouldn't match nil
107
- end
108
-
109
- if m = string.match(/#([a-z_\-0-9]+)/)
110
- rule[:id] = m[1]
111
- else
112
- rule[:id] = false # so it wouldn't match nil
113
- end
114
-
115
- if m = string.scan(/(\.)([a-z_\-0-9]+)/)
116
- rule[:classes] = m.map{|c| c[1]}
117
- else
118
- rule[:classes] = []
119
- end
120
-
121
- if m = string.scan(/\[\s*([a-z]+)\s*([*^$~|]{0,1}=)\s*('|")?(.+?)(\3)?\s*\]/)
122
- rule[:attrs] = m.map{|c| [c[0], c[3], c[1]] }
123
- else
124
- rule[:attrs] = []
125
- end
126
- end
127
- end
128
- end