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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +16 -0
- data/README.md +70 -0
- data/Rakefile +24 -0
- data/app/config.rb +4 -0
- data/app/layouts/alerts.html +8 -0
- data/app/layouts/calculator.html +26 -0
- data/app/layouts/collections.html +7 -0
- data/app/layouts/home.html +14 -0
- data/app/layouts/http.html +8 -0
- data/app/layouts/inputs.html +44 -0
- data/app/layouts/lockers.html +6 -0
- data/app/layouts/navbar.html +9 -0
- data/app/layouts/scrolls.html +42 -0
- data/app/layouts/sidebars.html +17 -0
- data/app/pages/alerts_page.rb +14 -0
- data/app/pages/calculator_page.rb +36 -0
- data/app/pages/collections_page.rb +9 -0
- data/app/pages/home_page.rb +11 -0
- data/app/pages/http_page.rb +33 -0
- data/app/pages/inputs_page.rb +9 -0
- data/app/pages/lockers_page.rb +16 -0
- data/app/pages/navbar_page.rb +19 -0
- data/app/pages/scrolls_page.rb +5 -0
- data/app/pages/sidebars_page.rb +42 -0
- data/app/pages/stuff_page.rb +35 -0
- data/app/styles/application.css +25 -0
- data/app/styles/calculator.css +37 -0
- data/app/styles/collections.css +19 -0
- data/app/styles/home.css +0 -0
- data/app/styles/http.css +24 -0
- data/app/styles/inputs.css +47 -0
- data/app/styles/scrolls.css +67 -0
- data/app/styles/sidebars.css +19 -0
- data/lib/assets/fontawesome-webfont.ttf +0 -0
- data/lib/assets/under-os.css +115 -0
- data/lib/under-os.rb +9 -1
- data/lib/under_os/app.rb +33 -0
- data/lib/under_os/color.rb +176 -0
- data/lib/under_os/config.rb +28 -1
- data/lib/under_os/core/kernel.rb +16 -0
- data/lib/under_os/core/numeric.rb +23 -0
- data/lib/under_os/core/string.rb +40 -0
- data/lib/under_os/delegate.rb +3 -2
- data/lib/under_os/events.rb +85 -0
- data/lib/under_os/file.rb +110 -0
- data/lib/under_os/history.rb +50 -0
- data/lib/under_os/http/receiver.rb +44 -0
- data/lib/under_os/http/request.rb +89 -0
- data/lib/under_os/http/response.rb +24 -0
- data/lib/under_os/http/session.rb +49 -0
- data/lib/under_os/http.rb +5 -0
- data/lib/under_os/page/builder.rb +96 -0
- data/lib/under_os/page/layout.rb +43 -0
- data/lib/under_os/page/matcher.rb +83 -0
- data/lib/under_os/page/stylesheet.rb +67 -0
- data/lib/under_os/page.rb +153 -0
- data/lib/under_os/parser/css.rb +37 -0
- data/lib/under_os/parser/html.rb +97 -0
- data/lib/under_os/parser.rb +24 -0
- data/lib/under_os/point.rb +47 -0
- data/lib/under_os/screen.rb +9 -0
- data/lib/under_os/timer.rb +65 -0
- data/lib/under_os/ui/alert.rb +52 -0
- data/lib/under_os/ui/button.rb +22 -0
- data/lib/under_os/ui/collection/cell.rb +21 -0
- data/lib/under_os/ui/collection/delegate.rb +68 -0
- data/lib/under_os/ui/collection/item.rb +32 -0
- data/lib/under_os/ui/collection/layout.rb +43 -0
- data/lib/under_os/ui/collection/styles.rb +15 -0
- data/lib/under_os/ui/collection.rb +63 -0
- data/lib/under_os/ui/icon/awesome.rb +376 -0
- data/lib/under_os/ui/icon/engine.rb +10 -0
- data/lib/under_os/ui/icon.rb +42 -0
- data/lib/under_os/ui/image.rb +30 -0
- data/lib/under_os/ui/input.rb +41 -0
- data/lib/under_os/ui/label.rb +21 -0
- data/lib/under_os/ui/locker.rb +42 -0
- data/lib/under_os/ui/navbar.rb +115 -0
- data/lib/under_os/ui/progress.rb +17 -0
- data/lib/under_os/ui/scroll.rb +41 -0
- data/lib/under_os/ui/select.rb +98 -0
- data/lib/under_os/ui/sidebar.rb +45 -0
- data/lib/under_os/ui/slider.rb +49 -0
- data/lib/under_os/ui/spinner.rb +23 -0
- data/lib/under_os/ui/style/fonts.rb +60 -0
- data/lib/under_os/ui/style/margins.rb +160 -0
- data/lib/under_os/ui/style/outlining.rb +98 -0
- data/lib/under_os/ui/style/positioning.rb +169 -0
- data/lib/under_os/ui/style.rb +21 -0
- data/lib/under_os/ui/switch.rb +29 -0
- data/lib/under_os/ui/textarea.rb +14 -0
- data/lib/under_os/ui/utils/animation.rb +99 -0
- data/lib/under_os/ui/utils/commons.rb +70 -0
- data/lib/under_os/ui/utils/dimensions.rb +37 -0
- data/lib/under_os/ui/utils/editable.rb +43 -0
- data/lib/under_os/ui/utils/events.rb +75 -0
- data/lib/under_os/ui/utils/manipulation.rb +44 -0
- data/lib/under_os/ui/utils/position.rb +21 -0
- data/lib/under_os/ui/utils/size.rb +21 -0
- data/lib/under_os/ui/utils/styles.rb +89 -0
- data/lib/under_os/ui/utils/traversing.rb +44 -0
- data/lib/under_os/ui/utils/wrap.rb +77 -0
- data/lib/under_os/ui/view.rb +31 -0
- data/lib/under_os/ui.rb +3 -0
- data/lib/under_os.rb +2 -2
- data/resources/Default-568h@2x.png +0 -0
- data/resources/test.png +0 -0
- data/spec/assets/app.css +13 -0
- data/spec/assets/test.css +7 -0
- data/spec/assets/test.html +3 -0
- data/spec/assets/test_page.rb +2 -0
- data/spec/lib/core/numeric_spec.rb +37 -0
- data/spec/lib/core/string_spec.rb +87 -0
- data/spec/lib/under_os/color_spec.rb +133 -0
- data/spec/lib/under_os/events_spec.rb +71 -0
- data/spec/lib/under_os/file_spec.rb +98 -0
- data/spec/lib/under_os/page/builder_spec.rb +128 -0
- data/spec/lib/under_os/page/layout_spec.rb +18 -0
- data/spec/lib/under_os/page/matcher_spec.rb +154 -0
- data/spec/lib/under_os/page/stylesheet_spec.rb +83 -0
- data/spec/lib/under_os/page_spec.rb +5 -0
- data/spec/lib/under_os/parser/css_spec.rb +77 -0
- data/spec/lib/under_os/parser/html_spec.rb +152 -0
- data/spec/lib/under_os/parser_spec.rb +16 -0
- data/spec/lib/under_os/point_spec.rb +54 -0
- data/spec/lib/under_os/screen_spec.rb +11 -0
- data/spec/lib/under_os/timer_spec.rb +93 -0
- data/spec/lib/under_os/ui/button_spec.rb +5 -0
- data/spec/lib/under_os/ui/collection_spec.rb +19 -0
- data/spec/lib/under_os/ui/icon_spec.rb +26 -0
- data/spec/lib/under_os/ui/image_spec.rb +39 -0
- data/spec/lib/under_os/ui/input_spec.rb +77 -0
- data/spec/lib/under_os/ui/label_spec.rb +22 -0
- data/spec/lib/under_os/ui/locker_spec.rb +31 -0
- data/spec/lib/under_os/ui/progress_spec.rb +31 -0
- data/spec/lib/under_os/ui/scroll_spec.rb +40 -0
- data/spec/lib/under_os/ui/select_spec.rb +131 -0
- data/spec/lib/under_os/ui/sidebar_spec.rb +35 -0
- data/spec/lib/under_os/ui/slider_spec.rb +65 -0
- data/spec/lib/under_os/ui/spinner_spec.rb +57 -0
- data/spec/lib/under_os/ui/style/fonts_spec.rb +73 -0
- data/spec/lib/under_os/ui/style/margins_spec.rb +106 -0
- data/spec/lib/under_os/ui/style/outlining_spec.rb +69 -0
- data/spec/lib/under_os/ui/style/positioning_spec.rb +69 -0
- data/spec/lib/under_os/ui/style_spec.rb +19 -0
- data/spec/lib/under_os/ui/switch_spec.rb +56 -0
- data/spec/lib/under_os/ui/textarea_spec.rb +30 -0
- data/spec/lib/under_os/ui/utils/commons_spec.rb +81 -0
- data/spec/lib/under_os/ui/utils/manipulation_spec.rb +130 -0
- data/spec/lib/under_os/ui/utils/styles_spec.rb +140 -0
- data/spec/lib/under_os/ui/utils/traversing_spec.rb +124 -0
- data/spec/lib/under_os/ui/utils/wrap_spec.rb +69 -0
- data/spec/lib/under_os/ui/view_spec.rb +39 -0
- data/under-os.gemspec +32 -0
- metadata +225 -11
- data/lib/under_os/application.rb +0 -16
- data/lib/under_os/window.rb +0 -5
@@ -0,0 +1,89 @@
|
|
1
|
+
#
|
2
|
+
# The styles handling API for UIView
|
3
|
+
#
|
4
|
+
module UnderOs::UI::Styles
|
5
|
+
def style(hash=nil)
|
6
|
+
if hash
|
7
|
+
self.style = hash
|
8
|
+
self
|
9
|
+
else
|
10
|
+
@_style ||= UnderOs::UI::Style.new(_, tagName.downcase.to_sym)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def style=(hash)
|
15
|
+
hash.each{ |key, value| style.__send__("#{key}=", value)}
|
16
|
+
end
|
17
|
+
|
18
|
+
def className
|
19
|
+
classNames.join(' ')
|
20
|
+
end
|
21
|
+
|
22
|
+
def className=(names)
|
23
|
+
self.classNames = names.scan(/([a-z0-9\-_]+)/).map{|e| e[0]}
|
24
|
+
end
|
25
|
+
|
26
|
+
def classNames
|
27
|
+
@_class_names ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def classNames=(list)
|
31
|
+
repaint_if_classes_change do
|
32
|
+
@_class_names = list.uniq.map(&:to_s)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def hasClass(name)
|
37
|
+
classNames.include?(name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def addClass(name)
|
41
|
+
repaint_if_classes_change do
|
42
|
+
self.classNames += [name]
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def removeClass(name)
|
47
|
+
repaint_if_classes_change do
|
48
|
+
self.classNames -= [name]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def toggleClass(name)
|
53
|
+
if hasClass(name)
|
54
|
+
removeClass name
|
55
|
+
else
|
56
|
+
addClass name
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def radioClass(name)
|
61
|
+
parent.children.each do |view|
|
62
|
+
view.removeClass(name) if view != self
|
63
|
+
end
|
64
|
+
|
65
|
+
addClass name
|
66
|
+
end
|
67
|
+
|
68
|
+
def repaint(stylesheet=nil, &block)
|
69
|
+
stylesheet ||= page && page.stylesheet
|
70
|
+
|
71
|
+
if stylesheet
|
72
|
+
styles = stylesheet.styles_for(self)
|
73
|
+
styles = block.call(styles) if block_given?
|
74
|
+
self.style = styles
|
75
|
+
children.each{ |view| view.repaint(stylesheet) }
|
76
|
+
end
|
77
|
+
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
private
|
82
|
+
|
83
|
+
def repaint_if_classes_change
|
84
|
+
prev_list = @_class_names.to_s
|
85
|
+
yield if block_given?
|
86
|
+
repaint if prev_list != @_class_names.to_s
|
87
|
+
self
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module UnderOs::UI::Traversing
|
2
|
+
def first(css_rule)
|
3
|
+
find(css_rule)[0]
|
4
|
+
end
|
5
|
+
|
6
|
+
def find(css_rule)
|
7
|
+
[].tap do |result|
|
8
|
+
children.each do |view|
|
9
|
+
result << view if view.matches(css_rule)
|
10
|
+
view.find(css_rule).each do |sub|
|
11
|
+
result << sub
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def matches(css_rule)
|
18
|
+
UnderOs::Page::StylesMatcher.new(css_rule).match(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def parent(css_rule=nil)
|
22
|
+
if ! css_rule
|
23
|
+
UnderOs::UI::View.new(@_.superview) if @_.superview
|
24
|
+
else
|
25
|
+
parent = self
|
26
|
+
while parent.is_a?(UnderOs::UI::View) && (parent = parent.parent)
|
27
|
+
return parent if parent.matches(css_rule)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def children(css_rule=nil)
|
33
|
+
result = @_.subviews.map{|v| UnderOs::UI::View.new(v) if v}.compact
|
34
|
+
css_rule ? result.select{|v| v.matches(css_rule)} : result
|
35
|
+
end
|
36
|
+
|
37
|
+
def siblings(css_rule=nil)
|
38
|
+
parent ? (parent.children(css_rule) - [self]) : []
|
39
|
+
end
|
40
|
+
|
41
|
+
def empty?
|
42
|
+
@_.subviews.empty?
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
#
|
2
|
+
# The raw -> abstraction wrapping code
|
3
|
+
# for UI::Views
|
4
|
+
#
|
5
|
+
module UnderOs::UI::Wrap
|
6
|
+
INSTANCES_CACHE = {}
|
7
|
+
RAW_WRAPS_MAP = {}
|
8
|
+
WRAPS_TAGS_MAP = {}
|
9
|
+
|
10
|
+
def self.included(base)
|
11
|
+
base.instance_eval do
|
12
|
+
attr_accessor :_
|
13
|
+
|
14
|
+
def self.wraps(raw_class, options={})
|
15
|
+
RAW_WRAPS_MAP[self] = raw_class
|
16
|
+
tag(options[:tag]) if options[:tag]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.tag(name)
|
20
|
+
WRAPS_TAGS_MAP[name.to_s] = self
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.new(options={}, *args, &block)
|
24
|
+
return INSTANCES_CACHE[options] if INSTANCES_CACHE[options]
|
25
|
+
|
26
|
+
if options.is_a?(UIView)
|
27
|
+
klass = find_wrap_for(options.class)
|
28
|
+
view = options; options = args.shift || {}
|
29
|
+
else
|
30
|
+
klass = self
|
31
|
+
view = find_raw_class_for(self).alloc
|
32
|
+
if view.class == UICollectionView
|
33
|
+
view.initWithFrame([[0, 0], [0, 0]], collectionViewLayout: UICollectionViewFlowLayout.alloc.init)
|
34
|
+
else
|
35
|
+
view.initWithFrame([[0, 0], [0, 0]])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
return nil if ! klass
|
40
|
+
|
41
|
+
klass.alloc.tap do |inst|
|
42
|
+
INSTANCES_CACHE[inst._ = view] = inst
|
43
|
+
inst.__send__ :initialize, options, *args, &block
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.rewrap(view, *args, &block)
|
48
|
+
view = view._ if view.is_a?(UnderOs::UI::View)
|
49
|
+
|
50
|
+
alloc.tap do |inst|
|
51
|
+
INSTANCES_CACHE[inst._ = view] = inst
|
52
|
+
inst.__send__ :initialize, *args, &block
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.find_wrap_for(raw_class)
|
57
|
+
RAW_WRAPS_MAP.each do |wrap, raw|
|
58
|
+
return wrap if raw == raw_class
|
59
|
+
end
|
60
|
+
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.find_raw_class_for(wrap)
|
65
|
+
while wrap
|
66
|
+
return RAW_WRAPS_MAP[wrap] if RAW_WRAPS_MAP[wrap]
|
67
|
+
wrap = wrap.superclass
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.wrap_for(raw_view)
|
72
|
+
INSTANCES_CACHE[raw_view]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class UnderOs::UI::View
|
2
|
+
include UnderOs::UI::Wrap
|
3
|
+
include UnderOs::UI::Events
|
4
|
+
include UnderOs::UI::Styles
|
5
|
+
include UnderOs::UI::Commons
|
6
|
+
include UnderOs::UI::Animation
|
7
|
+
include UnderOs::UI::Dimensions
|
8
|
+
include UnderOs::UI::Traversing
|
9
|
+
include UnderOs::UI::Manipulation
|
10
|
+
|
11
|
+
wraps UIView, tag: 'view'
|
12
|
+
|
13
|
+
def initialize(options={})
|
14
|
+
self.id = options.delete(:id) if options.has_key?(:id)
|
15
|
+
self.className = options.delete(:class) if options.has_key?(:class)
|
16
|
+
self.style = options.delete(:style) if options.has_key?(:style)
|
17
|
+
self.on = options.delete(:on) if options.has_key?(:on)
|
18
|
+
self.data = options.delete(:data) if options.has_key?(:data)
|
19
|
+
end
|
20
|
+
|
21
|
+
def inspect
|
22
|
+
params = {tag: tagName}
|
23
|
+
params[:id] = id if id
|
24
|
+
params[:class] = className unless classNames.empty?
|
25
|
+
params = params.map do |key, value|
|
26
|
+
"#{key}=\"#{value}\""
|
27
|
+
end
|
28
|
+
|
29
|
+
"#<#{self.class.name} #{params.join(" ")}>"
|
30
|
+
end
|
31
|
+
end
|
data/lib/under_os/ui.rb
ADDED
data/lib/under_os.rb
CHANGED
Binary file
|
data/resources/test.png
ADDED
Binary file
|
data/spec/assets/app.css
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
describe Numeric do
|
2
|
+
|
3
|
+
describe '#milliseconds' do
|
4
|
+
it "returns timer duration in milliseconds" do
|
5
|
+
10.milliseconds.should == UnderOs::Timer::Duration.new(0.01)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "has the 'ms' alias" do
|
9
|
+
10.milliseconds.should == 10.ms
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#seconds' do
|
14
|
+
it "returns the time duration in seconds" do
|
15
|
+
10.seconds.should == UnderOs::Timer::Duration.new(10)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#minutes' do
|
20
|
+
it "returns the time duration in minutes" do
|
21
|
+
10.minutes.should == UnderOs::Timer::Duration.new(10 * 60)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#hours' do
|
26
|
+
it "returns the time duration in hours" do
|
27
|
+
10.hours.should == UnderOs::Timer::Duration.new(10 * 60 * 60)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#days' do
|
32
|
+
it "returns the time duration in days" do
|
33
|
+
10.days.should == UnderOs::Timer::Duration.new(10 * 60 * 60 * 24)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
describe String do
|
2
|
+
describe '#underscore' do
|
3
|
+
it "converts camelized strings into underscored" do
|
4
|
+
"SomeStuff".underscore.should == 'some_stuff'
|
5
|
+
end
|
6
|
+
|
7
|
+
it "converts dashed strings into underscored as well" do
|
8
|
+
"some-stuff".underscore.should == "some_stuff"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#camelize" do
|
13
|
+
it "converts underscored strings into camelized" do
|
14
|
+
"some_stuff".camelize.should == "someStuff"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "converts dashed strings into camelized as well" do
|
18
|
+
"some-stuff".camelize.should == "someStuff"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "handles prefixes correctly" do
|
22
|
+
"_some_stuff".camelize.should == "SomeStuff"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#dasherize' do
|
27
|
+
it "converts camelized strings into dashed" do
|
28
|
+
"SomeStuff".dasherize.should == "some-stuff"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "converts underscored strings into dashed as well" do
|
32
|
+
"some_stuff".dasherize.should == "some-stuff"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#capitalize' do
|
37
|
+
it "capitalizes strings" do
|
38
|
+
"some stuff".capitalize.should == "Some stuff"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#starts_with?' do
|
43
|
+
it "returns true if a string starts with the substring" do
|
44
|
+
"some stuff".starts_with?("some").should == true
|
45
|
+
end
|
46
|
+
|
47
|
+
it "returns false if the string doesn't start with the substring" do
|
48
|
+
"some stuff".starts_with?("non matching").should == false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#ends_with?' do
|
53
|
+
it "returns true if the string ends with the given substring" do
|
54
|
+
"some stuff".ends_with?("stuff").should == true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns false if the string doesn't end with the substring" do
|
58
|
+
"some stuff".ends_with?("non matching").should == false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#blank?' do
|
63
|
+
it "returns true if the string is empty" do
|
64
|
+
''.blank?.should == true
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns true if the string has only white spaces" do
|
68
|
+
" \n\t\r ".blank?.should == true
|
69
|
+
end
|
70
|
+
|
71
|
+
it "returns false if the string has non-space chars in it" do
|
72
|
+
" a ".blank?.should == false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#constantize' do
|
77
|
+
it "returns an object from it's value" do
|
78
|
+
"UnderOs::UI::View".constantize.should == UnderOs::UI::View
|
79
|
+
end
|
80
|
+
|
81
|
+
it "raises an error if the constant is missing" do
|
82
|
+
-> {
|
83
|
+
"Something::Totally::Bogus".constantize
|
84
|
+
}.should.raise(NameError)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
describe UnderOs::Color do
|
2
|
+
def from(*args)
|
3
|
+
UnderOs::Color.new(*args)
|
4
|
+
end
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
it "should initialize from a UIColor" do
|
8
|
+
color = from(UIColor.blueColor)
|
9
|
+
color.ui.should == UIColor.blueColor
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should always return the same instance" do
|
13
|
+
color1 = from(UIColor.blackColor)
|
14
|
+
color2 = from(UIColor.blackColor)
|
15
|
+
|
16
|
+
color1.should === color2
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should work with rgba arrays of integers" do
|
20
|
+
from(0, 0, 255, 1.0).should == UIColor.blueColor
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should work with rgba arrays of floats" do
|
24
|
+
from(0.0, 0.0, 1.0, 1.0).should == UIColor.blueColor
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should work with rgb arrays of integers" do
|
28
|
+
from(0, 0, 255).should == UIColor.blueColor
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should work with rgb arrays of floats" do
|
32
|
+
from(0.0, 0.0, 1.0).should == UIColor.blueColor
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should work with string color names" do
|
36
|
+
from('blue').should == UIColor.blueColor
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should work with symbol color names" do
|
40
|
+
from(:blue).should == UIColor.blueColor
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should work with string hex colors" do
|
44
|
+
from('#ff8000').should == UIColor.orangeColor
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should work with short hand colors" do
|
48
|
+
from('#ff0').should == UIColor.yellowColor
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should work with rgb() strings" do
|
52
|
+
from('rgb(10, 20, 30)').to_rgba.should == [10, 20, 30, 1.0]
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should work with rgba() strings" do
|
56
|
+
from('rgba(100, 200, 250, 0.5)').to_rgba.should == [100, 200, 250, 0.5]
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should work with flaot color circle params' do
|
60
|
+
from(0.23).to_s.should == '#9eff00'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should work with integer (in degrees) color circle params' do
|
64
|
+
from(23).to_s.should == '#9eff00'
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#to_rgba' do
|
69
|
+
it "should extract the data correctly" do
|
70
|
+
from(UIColor.blueColor).to_rgba.should == [0, 0, 255, 1.0]
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#to_rgb' do
|
75
|
+
it "should extract the data correctly" do
|
76
|
+
from(UIColor.yellowColor).to_rgb.should == [255, 255, 0]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#to_hex' do
|
81
|
+
it "should extract the data correctly" do
|
82
|
+
from(UIColor.orangeColor).to_hex.should == '#ff8000'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#to_s' do
|
87
|
+
it "should extract the data correctly" do
|
88
|
+
from(UIColor.brownColor).to_s.should == '#996633'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe '#==' do
|
93
|
+
it "should work with other colors" do
|
94
|
+
from(UIColor.blueColor).should == from(UIColor.blueColor)
|
95
|
+
from(UIColor.blueColor).should.not == from(UIColor.orangeColor)
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should work with UIColors" do
|
99
|
+
from(UIColor.blueColor).should == UIColor.blueColor
|
100
|
+
from(UIColor.blueColor).should.not == UIColor.orangeColor
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should work with RGB arrays" do
|
104
|
+
from(UIColor.blueColor).should == [0, 0, 255]
|
105
|
+
from(UIColor.blueColor).should.not == [0, 255, 0]
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should work with RGBA arrays" do
|
109
|
+
from(UIColor.blueColor).should == [0, 0, 255, 1.0]
|
110
|
+
from(UIColor.blueColor).should.not == [0, 255, 0, 1.0]
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should work with string names" do
|
114
|
+
from(UIColor.blueColor).should == 'blue'
|
115
|
+
from(UIColor.blueColor).should.not == 'orange'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should work with symbol names" do
|
119
|
+
from(UIColor.blueColor).should == :blue
|
120
|
+
from(UIColor.blueColor).should.not == :orange
|
121
|
+
end
|
122
|
+
|
123
|
+
it "should work with hex values" do
|
124
|
+
from(UIColor.blueColor).should == '#0000ff'
|
125
|
+
from(UIColor.blueColor).should.not == '#00ff00'
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should work with short hex values" do
|
129
|
+
from(UIColor.blueColor).should == '#00f'
|
130
|
+
from(UIColor.blueColor).should.not == '#0f0'
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
describe UnderOs::Events do
|
2
|
+
class Dummy
|
3
|
+
include UnderOs::Events
|
4
|
+
end
|
5
|
+
|
6
|
+
before do
|
7
|
+
@dummy = Dummy.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#on" do
|
11
|
+
it "should add event listeners" do
|
12
|
+
@dummy.on(:smth) { }
|
13
|
+
UnderOs::Events::Listeners.all(@dummy, :smth).size.should == 1
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return the object itself back" do
|
17
|
+
@dummy.on(:smth) { }.should.be.same_as @dummy
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#off" do
|
22
|
+
it "should remove event listeners" do
|
23
|
+
@dummy.on(:smth) { }
|
24
|
+
@dummy.off(:smth)
|
25
|
+
UnderOs::Events::Listeners.all(@dummy, :smth).size.should == 0
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should return the object itself back" do
|
29
|
+
@dummy.off(:smth).should.be.same_as @dummy
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#emit" do
|
34
|
+
it "should emit events" do
|
35
|
+
kicked = false
|
36
|
+
@dummy.on(:smth) { kicked = true }
|
37
|
+
@dummy.emit(:smth)
|
38
|
+
kicked.should == true
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should return the object itself back" do
|
42
|
+
@dummy.emit(:smth).should.be.same_as @dummy
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should accept optional params" do
|
46
|
+
event = nil
|
47
|
+
@dummy.on(:smth) { |e| event = e }
|
48
|
+
@dummy.emit(:smth, param1: 1, param2: 2)
|
49
|
+
event.params.should == {param1: 1, param2: 2}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe 'UnderOs::Events::Event' do
|
54
|
+
before do
|
55
|
+
@event = UnderOs::Events::Event.new('event-name', param1: 1, param2: 2)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should give access to it's name" do
|
59
|
+
@event.name.should == :"event-name"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should give access to it's params" do
|
63
|
+
@event.params.should == {param1: 1, param2: 2}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should magically pass all the missing requests to the params" do
|
67
|
+
@event.param1.should == 1
|
68
|
+
@event.param2.should == 2
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|