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,67 +0,0 @@
1
- class UnderOs::Page::Stylesheet
2
- attr_reader :rules
3
-
4
- def initialize(styles={})
5
- @rules = {}
6
-
7
- styles.each do |rule, style|
8
- self[rule] = style
9
- end
10
- end
11
-
12
- def styles_for(view)
13
- {}.tap do |styles|
14
- weighted_styles_for(view).each do |hash|
15
- hash.each do |key, value|
16
- styles[key] = value
17
- end
18
- end
19
- end
20
- end
21
-
22
- def [](rule)
23
- @rules[rule.to_s]
24
- end
25
-
26
- def []=(rule, values)
27
- @rules[rule.to_s] ||= {}
28
- @rules[rule.to_s].merge! values
29
- end
30
-
31
- def <<(another_stylesheet)
32
- another_stylesheet.rules.each do |rule, styles|
33
- self[rule] = styles
34
- end
35
- end
36
-
37
- def +(another_stylesheet)
38
- self.class.new.tap do |combined_sheet|
39
- combined_sheet << self
40
- combined_sheet << another_stylesheet
41
- end
42
- end
43
-
44
- def load(filename)
45
- UnderOs::Parser.parse(filename).each do |rule, styles|
46
- self[rule] = styles
47
- end
48
- end
49
-
50
- private
51
-
52
- def weighted_styles_for(view)
53
- find_styles_for(view).
54
- sort{|a,b| a[:score] <=> b[:score]}.
55
- map{|e| e[:style]}
56
- end
57
-
58
- def find_styles_for(view)
59
- [].tap do |styles|
60
- @rules.each do |css, rule|
61
- score = UnderOs::Page::StylesMatcher.new(css).score_for(view)
62
- styles << {score: score, style: rule} if score != 0
63
- end
64
- end
65
- end
66
-
67
- end
@@ -1,24 +0,0 @@
1
- #
2
- # Generic templates/stylesheets parsing engine
3
- #
4
- class UnderOs::Parser
5
- def self.parse(*args)
6
- @inst ||= new
7
- @inst.parse *args
8
- end
9
-
10
- def initialize
11
- @css = CSS.new
12
- @html = HTML.new
13
- end
14
-
15
- def parse(filename)
16
- filepath = NSBundle.mainBundle.pathForResource(filename, ofType:nil)
17
- content = filepath ? UnderOs::File.read(filepath) : ''
18
-
19
- case filename.split('.').pop
20
- when 'css' then @css.parse(content)
21
- when 'html' then @html.parse(content)
22
- end
23
- end
24
- end
@@ -1,37 +0,0 @@
1
- class UnderOs::Parser::CSS
2
- def parse(style)
3
- style = style.gsub(/\/\*[\s\S]+?\*\//, '').strip
4
-
5
- {}.tap do |result|
6
- style.scan(/(\A|\})([a-z0-9_\*\-\.\s#:,]+)\{([^}]+)/).map do |rule|
7
- values = parse_styles(rule[2])
8
-
9
- rule[1].split(',').each do |css_rule|
10
- result[css_rule.gsub(/\s+/, ' ').strip] = values
11
- end
12
- end
13
- end
14
- end
15
-
16
- def parse_styles(styles)
17
- {}.tap do |hash|
18
- styles.scan(/([a-z\-]+)\s*:\s*([^;]+)\s*/).each do |param|
19
- hash.merge! normalized_values(param[0], param[1])
20
- end
21
- end
22
- end
23
-
24
- def normalized_values(key, value)
25
- key = key.camelize.to_sym
26
- value = value.strip.gsub(/px$/, '')
27
- value = value.gsub(/^('|")(.*?)\1$/, '\2')
28
- value = value.to_f if value =~ /^[\-\d\.]+$/
29
-
30
- if key == :background && value =~ /^[\S]+$/
31
- key = :backgroundColor
32
- end
33
-
34
-
35
- {key => value}
36
- end
37
- end
@@ -1,97 +0,0 @@
1
- class UnderOs::Parser::HTML
2
- def parse(html)
3
- html = html.strip.gsub(/<\!--[\s\S]*?-->/, '').gsub(/>\s+/, '>').gsub(/\s+</, '<')
4
-
5
- [].tap do |top|
6
- @top = top
7
- @stack = []
8
- @node = nil
9
- i = 0
10
-
11
- while i < html.size
12
- @chunk = html.slice(i, html.size)
13
-
14
- i += open_tag || close_tag || plain_text
15
- end
16
-
17
- # closing all the missing tags
18
- while node = @stack.shift
19
- node.delete(:children)
20
- node.delete(:text)
21
- @top << node if ! @top.include?(node)
22
- end
23
- end
24
- end
25
-
26
- def open_tag
27
- if m = @chunk.match(/\A<([a-z]+)([^>]*)>/)
28
- @node = {tag: m[1], attrs: parse_attrs_in(m[2])}
29
-
30
- if parent = @stack.last
31
- parent[:children] ||= []
32
- parent[:children] << @node
33
- parent.delete(:text) # it can have either text or children
34
- else
35
- @top << @node
36
- end
37
-
38
- @stack << @node
39
-
40
- m[0].size
41
- end
42
- end
43
-
44
- def close_tag
45
- if m = @chunk.match(/\A<\/([a-z]+)>/)
46
- while node = @stack.pop
47
- if node[:tag] != m[1]
48
- if @stack.size > 0
49
- @stack.last[:children] += node[:children] || []
50
- node.delete(:children)
51
- node.delete(:text)
52
- end
53
- else
54
- break
55
- end
56
- end
57
-
58
- @node = @stack.last
59
-
60
- m[0].size
61
- end
62
- end
63
-
64
- def plain_text
65
- if m = @chunk.match(/\A([^<]+)/)
66
- @stack.last[:text] = m[1] if @stack.last
67
-
68
- m[0].size
69
- end
70
- end
71
-
72
- def parse_attrs_in(string)
73
- merge_data_attrs({}.tap do |hash|
74
- string.scan(/([a-z][a-z_\-\d]+)=('|")(.+?)(\2)/).each do |match|
75
- value = match[0] == match[2] ? true : match[2]
76
- value = true if value == 'true'
77
- value = false if value == 'false'
78
- hash[match[0].to_sym] = value
79
- end
80
- end)
81
- end
82
-
83
- def merge_data_attrs(hash)
84
- hash.keys.each do |key|
85
- if key.to_s.starts_with?('data-')
86
- hash[:data] ||= {}
87
-
88
- value = hash.delete(key)
89
- key = key.to_s.gsub(/^data\-/, '').camelize
90
-
91
- hash[:data][key.to_sym] = value
92
- end
93
- end
94
-
95
- hash
96
- end
97
- end
@@ -1,47 +0,0 @@
1
- #
2
- # Generic Point/Size unit
3
- #
4
- class UnderOs::Point
5
-
6
- def initialize(x, y=nil)
7
- if x.is_a?(UnderOs::Point)
8
- y = x.y if x.y
9
- x = x.x
10
- elsif x.is_a?(Hash)
11
- y = x[:y] || x['y'] || nil
12
- x = x[:x] || x['x'] || nil
13
- end
14
-
15
- @x = x
16
- @y = y
17
- end
18
-
19
- def x
20
- @x
21
- end
22
-
23
- def y
24
- @y
25
- end
26
-
27
- def ==(*args)
28
- point = UnderOs::Point.new(*args) # normalizing
29
- x == point.x && y == point.y
30
- end
31
-
32
- def *(multiplier)
33
- self.class.new(x: @x * multiplier, y: @y * multiplier)
34
- end
35
-
36
- def /(divider)
37
- self.class.new(x: @x / divider.to_f, y: @y / divider.to_f)
38
- end
39
-
40
- def to_s
41
- "x=#{x} y=#{y}"
42
- end
43
-
44
- def inspect
45
- "#<#{self.class.name}:0x#{__id__.to_s(16)} #{to_s}>"
46
- end
47
- end
@@ -1,9 +0,0 @@
1
- class UnderOs::Screen
2
- def self.size
3
- # TODO make it handle the screen orientation
4
- UnderOs::Point.new({
5
- x: UIScreen.mainScreen.bounds.size.width,
6
- y: UIScreen.mainScreen.bounds.size.height
7
- })
8
- end
9
- end
@@ -1,65 +0,0 @@
1
- class UnderOs::Timer
2
- def self.in(duration, options={}, &block)
3
- duration = Duration.new(duration) if duration.is_a?(Numeric)
4
- new duration.to_f, options.merge(repeat: false), &block
5
- end
6
-
7
- def self.every(duration, options={}, &block)
8
- duration = Duration.new(duration) if duration.is_a?(Numeric)
9
- new duration.to_f, options.merge(repeat: true), &block
10
- end
11
-
12
- attr_reader :block, :counter, :interval, :repeats, :_
13
-
14
- def initialize(seconds, options={}, &block)
15
- @block = block
16
- @counter = options[:repeat].to_i if options[:repeat].is_a?(Numeric)
17
- @interval = seconds
18
- @repeats = options[:repeat] != false
19
-
20
- @_ = NSTimer.scheduledTimerWithTimeInterval @interval,
21
- target: self, selector: :kick, userInfo: nil, repeats: @repeats
22
- end
23
-
24
- def stop
25
- @_.invalidate
26
- self
27
- end
28
-
29
- def kick
30
- @block.call
31
- stop if @counter && (@counter -= 1) <= 0
32
- end
33
-
34
- class Duration
35
- attr_reader :seconds
36
-
37
- def initialize(seconds)
38
- @seconds = seconds.to_f
39
- end
40
-
41
- def to_f
42
- @seconds
43
- end
44
-
45
- def to_i
46
- to_f.to_i
47
- end
48
-
49
- def to_s
50
- "#{to_f} seconds"
51
- end
52
-
53
- def ==(duration)
54
- duration.is_a?(UnderOs::Timer::Duration) && duration.seconds == @seconds
55
- end
56
-
57
- def later(options={}, &block)
58
- UnderOs::Timer.in self, options={}, &block
59
- end
60
-
61
- def repeat(options={}, &block)
62
- UnderOs::Timer.every self, options={}, &block
63
- end
64
- end
65
- end
@@ -1,3 +0,0 @@
1
- module UnderOs::UI
2
- # Just a namespace for UI things
3
- end
@@ -1,52 +0,0 @@
1
- class UnderOs::UI::Alert
2
- include UnderOs::Events
3
-
4
- def initialize(options={})
5
- options = {message: options} if options.is_a?(String)
6
- self.on = options.delete[:on] if options[:on]
7
-
8
- @_ = CustomAlertView.alloc.initiWithOptions(self, options)
9
- @_.show unless options[:show] == false
10
- end
11
-
12
- def show
13
- @_.show
14
- self
15
- end
16
-
17
- def hide(animated=true)
18
- @_.dismissWithClickedButtonIndex(0, animated: animated)
19
- self
20
- end
21
-
22
- def visible
23
- @_.visible
24
- end
25
-
26
- def hidden
27
- !visible
28
- end
29
-
30
- class CustomAlertView < UIAlertView
31
- def initiWithOptions(wrapper, options)
32
- @wrapper = wrapper
33
-
34
- initWithTitle( options[:title] || "",
35
- message: options[:message] || "No message given",
36
- delegate: self,
37
- cancelButtonTitle: options[:button] || "Ok",
38
- otherButtonTitles: nil )
39
-
40
- (options[:buttons] || []).each do |title|
41
- addButtonWithTitle title
42
- end
43
-
44
- self
45
- end
46
-
47
- def alertView(alertView, willDismissWithButtonIndex:buttonIndex)
48
- @wrapper.emit(:tap, buttonIndex: buttonIndex, buttonTitle: buttonTitleAtIndex(buttonIndex))
49
- @wrapper.emit(:close)
50
- end
51
- end
52
- end
@@ -1,42 +0,0 @@
1
- class UnderOS::UI::Button < UnderOS::UI::View
2
- wraps UIButton, tag: 'button'
3
-
4
- def initialize(options={})
5
- super
6
-
7
- self.text = options.delete(:text) || ''
8
- self.disable if options[:disabled]
9
-
10
- @_.showsTouchWhenHighlighted = true
11
- @_.setBackgroundImage(options.delete(:image), forState:UIControlStateNormal) if options[:image]
12
- @_.sizeToFit
13
- end
14
-
15
- def text
16
- @_.currentTitle
17
- end
18
-
19
- def text=(new_text, state=UIControlStateNormal)
20
- @_.setTitle new_text, forState:state
21
- repaint
22
- end
23
-
24
- def disabled
25
- ! @_.isEnabled
26
- end
27
-
28
- alias :disabled? :disabled
29
-
30
- def disabled=(value)
31
- @_.enabled = ! value
32
- end
33
-
34
- def disable
35
- self.disabled = true
36
- end
37
-
38
- def enable
39
- self.disabled = false
40
- end
41
-
42
- end