teacup 1.3.4 → 2.0.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.
- data/Gemfile +1 -1
- data/Gemfile.lock +3 -3
- data/README.md +1172 -319
- data/Rakefile +8 -1
- data/app/app_delegate.rb +1 -1
- data/app/controllers/appearance_controller.rb +13 -0
- data/app/controllers/landscape_only_controller.rb +1 -1
- data/app/controllers/{first_controller.rb → main_controller.rb} +4 -3
- data/app/controllers/motion_layout_controller.rb +22 -0
- data/app/styles/appearance.rb +24 -0
- data/app/styles/main_styles.rb +8 -6
- data/app/views/custom_view.rb +1 -0
- data/lib/teacup/calculations.rb +2 -2
- data/lib/teacup/{z_core_extensions → core_extensions}/ca_layer.rb +0 -0
- data/lib/teacup/core_extensions/view_getters.rb +61 -0
- data/lib/teacup/handler.rb +14 -14
- data/lib/teacup/layout.rb +94 -17
- data/lib/teacup/stylesheet.rb +61 -26
- data/lib/teacup/stylesheet_extensions/transform.rb +88 -0
- data/lib/teacup/teacup_controller.rb +122 -0
- data/lib/teacup/teacup_util.rb +12 -7
- data/lib/teacup/teacup_view.rb +329 -0
- data/lib/teacup/version.rb +1 -1
- data/lib/teacup-ios/appearance.rb +96 -0
- data/lib/teacup-ios/core_extensions/teacup_handlers.rb +183 -0
- data/lib/teacup-ios/core_extensions/ui_view.rb +30 -0
- data/lib/teacup-ios/core_extensions/ui_view_controller.rb +110 -0
- data/lib/{dummy.rb → teacup-ios/dummy.rb} +2 -6
- data/lib/teacup-ios/handler.rb +23 -0
- data/lib/{teacup → teacup-ios}/style.rb +9 -10
- data/lib/teacup-ios/stylesheet_extensions/autoresize.rb +169 -0
- data/lib/{teacup/stylesheet_extensions/geometry.rb → teacup-ios/stylesheet_extensions/device.rb} +0 -0
- data/lib/teacup-osx/core_extensions/ns_view.rb +39 -0
- data/lib/teacup-osx/core_extensions/ns_view_controller.rb +21 -0
- data/lib/teacup-osx/core_extensions/ns_window.rb +39 -0
- data/lib/teacup-osx/core_extensions/ns_window_controller.rb +29 -0
- data/lib/{teacup/z_core_extensions/z_handlers.rb → teacup-osx/core_extensions/teacup_handlers.rb} +30 -47
- data/lib/teacup-osx/dummy.rb +80 -0
- data/lib/teacup-osx/handler.rb +16 -0
- data/lib/teacup-osx/style.rb +83 -0
- data/lib/teacup-osx/style_extensions/autoresize.rb +169 -0
- data/lib/teacup.rb +12 -11
- data/samples/Tweets/Gemfile +4 -0
- data/samples/Tweets/Gemfile.lock +16 -0
- data/samples/Tweets/README +7 -0
- data/samples/Tweets/Rakefile +9 -0
- data/samples/Tweets/app/app_delegate.rb +18 -0
- data/samples/Tweets/app/data_parser.rb +10 -0
- data/samples/Tweets/app/json_parser.rb +12 -0
- data/samples/Tweets/app/main_window.rb +99 -0
- data/samples/Tweets/app/menu.rb +108 -0
- data/samples/Tweets/app/stylesheet.rb +21 -0
- data/samples/Tweets/app/tweet.rb +11 -0
- data/samples/Tweets/resources/Credits.rtf +29 -0
- data/samples/Tweets/spec/main_spec.rb +9 -0
- data/samples/teacup-osx/.gitignore +1 -0
- data/samples/teacup-osx/Gemfile +4 -0
- data/samples/teacup-osx/Gemfile.lock +16 -0
- data/samples/teacup-osx/Rakefile +9 -0
- data/samples/teacup-osx/app/app_delegate.rb +23 -0
- data/samples/teacup-osx/app/controller.rb +11 -0
- data/samples/teacup-osx/app/menu.rb +108 -0
- data/samples/teacup-osx/app/window.rb +12 -0
- data/samples/teacup-osx/resources/Credits.rtf +29 -0
- data/samples/teacup-osx/resources/teacup.png +0 -0
- data/samples/teacup-osx/spec/main_spec.rb +9 -0
- data/spec/ios/appearance_spec.rb +18 -0
- data/spec/{calculations_spec.rb → ios/calculations_spec.rb} +0 -0
- data/spec/{constraints_spec.rb → ios/constraints_spec.rb} +0 -0
- data/spec/{custom_class_spec.rb → ios/custom_class_spec.rb} +0 -0
- data/spec/{gradient_spec.rb → ios/gradient_spec.rb} +1 -1
- data/spec/ios/layout_module_spec.rb +54 -0
- data/spec/ios/layout_spec.rb +50 -0
- data/spec/{main_spec.rb → ios/main_spec.rb} +52 -13
- data/spec/ios/motion_layout_spec.rb +44 -0
- data/spec/{present_modal_spec.rb → ios/present_modal_spec.rb} +0 -0
- data/spec/{style_spec.rb → ios/style_spec.rb} +1 -1
- data/spec/ios/stylesheet_extensions/autoresize_spec.rb +50 -0
- data/spec/{stylesheet_spec.rb → ios/stylesheet_spec.rb} +12 -0
- data/spec/{ui_view_getters_spec.rb → ios/ui_view_getters_spec.rb} +0 -0
- data/spec/{uiswitch_spec.rb → ios/uiswitch_spec.rb} +0 -0
- data/spec/{view_spec.rb → ios/view_spec.rb} +23 -2
- metadata +85 -35
- data/lib/teacup/stylesheet_extensions/autoresize.rb +0 -39
- data/lib/teacup/stylesheet_extensions/rotation.rb +0 -37
- data/lib/teacup/z_core_extensions/ui_view.rb +0 -262
- data/lib/teacup/z_core_extensions/ui_view_controller.rb +0 -263
- data/lib/teacup/z_core_extensions/ui_view_getters.rb +0 -58
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
class NSWindowController
|
|
2
|
+
include Teacup::Layout
|
|
3
|
+
include Teacup::Controller
|
|
4
|
+
|
|
5
|
+
def windowDidLoad
|
|
6
|
+
teacupDidLoad
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def top_level_view
|
|
10
|
+
window.contentView
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TeacupWindowController < NSWindowController
|
|
17
|
+
|
|
18
|
+
def self.new
|
|
19
|
+
alloc.initWithWindowNibName(self.class.name)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def loadWindow
|
|
23
|
+
self.window = NSWindow.alloc.initWithContentRect([[240, 180], [480, 360]],
|
|
24
|
+
styleMask: NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
|
|
25
|
+
backing: NSBackingStoreBuffered,
|
|
26
|
+
defer: false)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
data/lib/{teacup/z_core_extensions/z_handlers.rb → teacup-osx/core_extensions/teacup_handlers.rb}
RENAMED
|
@@ -1,77 +1,77 @@
|
|
|
1
1
|
##|
|
|
2
|
-
##|
|
|
2
|
+
##| NSView.frame
|
|
3
3
|
##|
|
|
4
|
-
Teacup.handler
|
|
4
|
+
Teacup.handler NSView, :left, :x do |target, x|
|
|
5
5
|
f = target.frame
|
|
6
6
|
f.origin.x = Teacup::calculate(target, :width, x)
|
|
7
7
|
target.frame = f
|
|
8
|
-
|
|
8
|
+
end
|
|
9
9
|
|
|
10
|
-
Teacup.handler
|
|
10
|
+
Teacup.handler NSView, :right do |target, r|
|
|
11
11
|
f = target.frame
|
|
12
12
|
f.origin.x = Teacup::calculate(target, :width, r) - f.size.width
|
|
13
13
|
target.frame = f
|
|
14
|
-
|
|
14
|
+
end
|
|
15
15
|
|
|
16
|
-
Teacup.handler
|
|
16
|
+
Teacup.handler NSView, :center_x, :middle_x do |target, x|
|
|
17
17
|
c = target.center
|
|
18
18
|
c.x = Teacup::calculate(target, :width, x)
|
|
19
19
|
target.center = c
|
|
20
|
-
|
|
20
|
+
end
|
|
21
21
|
|
|
22
|
-
Teacup.handler
|
|
22
|
+
Teacup.handler NSView, :top, :y do |target, y|
|
|
23
23
|
f = target.frame
|
|
24
24
|
f.origin.y = Teacup::calculate(target, :height, y)
|
|
25
25
|
target.frame = f
|
|
26
|
-
|
|
26
|
+
end
|
|
27
27
|
|
|
28
|
-
Teacup.handler
|
|
28
|
+
Teacup.handler NSView, :bottom do |target, b|
|
|
29
29
|
f = target.frame
|
|
30
30
|
f.origin.y = Teacup::calculate(target, :height, b) - f.size.height
|
|
31
31
|
target.frame = f
|
|
32
|
-
|
|
32
|
+
end
|
|
33
33
|
|
|
34
|
-
Teacup.handler
|
|
34
|
+
Teacup.handler NSView, :center_y, :middle_y do |target, y|
|
|
35
35
|
c = target.center
|
|
36
36
|
c.y = Teacup::calculate(target, :height, y)
|
|
37
37
|
target.center = c
|
|
38
|
-
|
|
38
|
+
end
|
|
39
39
|
|
|
40
|
-
Teacup.handler
|
|
40
|
+
Teacup.handler NSView, :width do |target, w|
|
|
41
41
|
f = target.frame
|
|
42
42
|
f.size.width = Teacup::calculate(target, :width, w)
|
|
43
43
|
target.frame = f
|
|
44
|
-
|
|
44
|
+
end
|
|
45
45
|
|
|
46
|
-
Teacup.handler
|
|
46
|
+
Teacup.handler NSView, :height do |target, h|
|
|
47
47
|
f = target.frame
|
|
48
48
|
f.size.height = Teacup::calculate(target, :height, h)
|
|
49
49
|
target.frame = f
|
|
50
|
-
|
|
50
|
+
end
|
|
51
51
|
|
|
52
|
-
Teacup.handler
|
|
52
|
+
Teacup.handler NSView, :size do |target, size|
|
|
53
53
|
f = target.frame
|
|
54
54
|
size_x = Teacup::calculate(target, :width, size[0])
|
|
55
55
|
size_y = Teacup::calculate(target, :height, size[1])
|
|
56
56
|
f.size = [size_x, size_y]
|
|
57
57
|
target.frame = f
|
|
58
|
-
|
|
58
|
+
end
|
|
59
59
|
|
|
60
|
-
Teacup.handler
|
|
60
|
+
Teacup.handler NSView, :origin do |target, origin|
|
|
61
61
|
f = target.frame
|
|
62
62
|
origin_x = Teacup::calculate(target, :width, origin[0])
|
|
63
63
|
origin_y = Teacup::calculate(target, :height, origin[1])
|
|
64
64
|
f.origin = [origin_x, origin_y]
|
|
65
65
|
target.frame = f
|
|
66
|
-
|
|
66
|
+
end
|
|
67
67
|
|
|
68
|
-
Teacup.handler
|
|
68
|
+
Teacup.handler NSView, :center do |target, center|
|
|
69
69
|
center_x = Teacup::calculate(target, :width, center[0])
|
|
70
70
|
center_y = Teacup::calculate(target, :height, center[1])
|
|
71
71
|
target.center = [center_x, center_y]
|
|
72
|
-
|
|
72
|
+
end
|
|
73
73
|
|
|
74
|
-
Teacup.handler
|
|
74
|
+
Teacup.handler NSView, :size do |target, size|
|
|
75
75
|
# odd... if I changed these to .is_a?, weird errors happen. Use ===
|
|
76
76
|
if Symbol === size && size == :full
|
|
77
77
|
if target.superview
|
|
@@ -85,9 +85,9 @@ Teacup.handler UIView, :size { |target, size|
|
|
|
85
85
|
f = target.frame
|
|
86
86
|
f.size = size
|
|
87
87
|
target.frame = f
|
|
88
|
-
|
|
88
|
+
end
|
|
89
89
|
|
|
90
|
-
Teacup.handler
|
|
90
|
+
Teacup.handler NSView, :frame do |target, frame|
|
|
91
91
|
# odd... if I changed these to .is_a?, weird errors happen. Use ===
|
|
92
92
|
if Symbol === frame && frame == :full
|
|
93
93
|
if target.superview
|
|
@@ -100,16 +100,16 @@ Teacup.handler UIView, :frame { |target, frame|
|
|
|
100
100
|
[Teacup::calculate(target, :width, frame[0]), Teacup::calculate(target, :height, frame[1])],
|
|
101
101
|
[Teacup::calculate(target, :width, frame[2]), Teacup::calculate(target, :height, frame[3])]
|
|
102
102
|
]
|
|
103
|
-
elsif Array === frame && frame.length == 2
|
|
103
|
+
elsif (Array === frame && frame.length == 2) || NSRect === frame
|
|
104
104
|
frame = [
|
|
105
105
|
[Teacup::calculate(target, :width, frame[0][0]), Teacup::calculate(target, :height, frame[0][1])],
|
|
106
106
|
[Teacup::calculate(target, :width, frame[1][0]), Teacup::calculate(target, :height, frame[1][1])]
|
|
107
107
|
]
|
|
108
108
|
end
|
|
109
109
|
target.frame = frame
|
|
110
|
-
|
|
110
|
+
end
|
|
111
111
|
|
|
112
|
-
Teacup.handler
|
|
112
|
+
Teacup.handler NSView, :gradient do |target, gradient|
|
|
113
113
|
gradient_layer = target.instance_variable_get(:@teacup_gradient_layer) || begin
|
|
114
114
|
gradient_layer = CAGradientLayer.layer
|
|
115
115
|
gradient_layer.frame = target.bounds
|
|
@@ -128,21 +128,4 @@ Teacup.handler UIView, :gradient { |target, gradient|
|
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
target.instance_variable_set(:@teacup_gradient_layer, gradient_layer)
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
##|
|
|
134
|
-
##| UIButton
|
|
135
|
-
##|
|
|
136
|
-
Teacup.handler UIButton, :title { |target, title|
|
|
137
|
-
target.setTitle(title, forState: UIControlStateNormal)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
Teacup.handler UIButton, :titleColor { |target, color|
|
|
142
|
-
target.setTitleColor(color, forState: UIControlStateNormal)
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
Teacup.handler UIButton, :titleFont, :font { |target, font|
|
|
147
|
-
target.titleLabel.font = font
|
|
148
|
-
}
|
|
131
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
class DummyView < NSView
|
|
2
|
+
private
|
|
3
|
+
def dummy
|
|
4
|
+
setFrame(nil)
|
|
5
|
+
setOpaque(nil)
|
|
6
|
+
setClipsToBounds(nil)
|
|
7
|
+
setUserInteractionEnabled(nil)
|
|
8
|
+
setAutoresizingMask(nil)
|
|
9
|
+
NSView.appearanceWhenContainedIn(NSView, nil)
|
|
10
|
+
NSView.appearance
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class DummyTableView < NSTableView
|
|
15
|
+
private
|
|
16
|
+
def dummy
|
|
17
|
+
setAllowSelection(value)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class DummyTableColumn < NSTableColumn
|
|
22
|
+
private
|
|
23
|
+
def dummy
|
|
24
|
+
setEditable(nil)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class DummyButton < NSButton
|
|
29
|
+
private
|
|
30
|
+
def dummy
|
|
31
|
+
setTitleEdgeInsets(nil)
|
|
32
|
+
setTarget(nil)
|
|
33
|
+
setAction(nil)
|
|
34
|
+
setBezelStyle(nil)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
class DummyScrollView < NSScrollView
|
|
39
|
+
private
|
|
40
|
+
def dummy
|
|
41
|
+
setScrollEnabled(nil)
|
|
42
|
+
setHasVerticalScroller(nil)
|
|
43
|
+
setHasHorizontalScroller(nil)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
class DummyTextField < NSTextField
|
|
48
|
+
private
|
|
49
|
+
def dummy
|
|
50
|
+
setAdjustsFontSizeToFitWidth(nil)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class DummyTextView < NSTextView
|
|
55
|
+
private
|
|
56
|
+
def dummy
|
|
57
|
+
setSecureTextEntry(nil)
|
|
58
|
+
setReturnKeyType(nil)
|
|
59
|
+
setAutocapitalizationType(nil)
|
|
60
|
+
setAutocorrectionType(nil)
|
|
61
|
+
setSpellCheckingType(nil)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class DummyLayer < CALayer
|
|
66
|
+
private
|
|
67
|
+
def dummy
|
|
68
|
+
setCornerRadius(nil)
|
|
69
|
+
setTransform(nil)
|
|
70
|
+
setMasksToBounds(nil)
|
|
71
|
+
setShadowOffset(nil)
|
|
72
|
+
setShadowOpacity(nil)
|
|
73
|
+
setShadowRadius(nil)
|
|
74
|
+
setShadowOffset(nil)
|
|
75
|
+
setShadowColor(nil)
|
|
76
|
+
setShadowPath(nil)
|
|
77
|
+
setOpaque(nil)
|
|
78
|
+
setTranslucent(nil)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Teacup
|
|
2
|
+
module_function
|
|
3
|
+
|
|
4
|
+
def apply_method(target, assign, setter, value)
|
|
5
|
+
if assign and target.respond_to?(assign)
|
|
6
|
+
NSLog "Setting #{key} = #{value.inspect}" if target.respond_to? :debug and target.debug
|
|
7
|
+
target.send(assign, value)
|
|
8
|
+
elsif target.respondsToSelector(setter)
|
|
9
|
+
NSLog "Calling target.#{setter}(#{value.inspect})" if target.respond_to? :debug and target.debug
|
|
10
|
+
target.send(setter, value)
|
|
11
|
+
else
|
|
12
|
+
NSLog "TEACUP WARNING: Can't apply #{setter.inspect}#{assign and " or " + assign.inspect or ""} to #{target.inspect}"
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Teacup
|
|
2
|
+
# The Style class is where the precedence rules are applied. A Style can
|
|
3
|
+
# query the Stylesheet that created it to look up other styles (for
|
|
4
|
+
# `extends:`) and to import other Stylesheets. If it is handed a target (e.g.
|
|
5
|
+
# a `UIView` instance) and orientation, it will merge those in appropriately
|
|
6
|
+
# as well.
|
|
7
|
+
class Style < Hash
|
|
8
|
+
attr_accessor :stylename
|
|
9
|
+
attr_accessor :stylesheet
|
|
10
|
+
|
|
11
|
+
# A hash of orientation => true/false. true means the orientation is
|
|
12
|
+
# supported.
|
|
13
|
+
def supports
|
|
14
|
+
@supports ||= {}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# returns the value - `nil` has special meaning when querying :portrait or :upside_up
|
|
18
|
+
def supports? orientation_key
|
|
19
|
+
false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def build(target=nil, rotation_orientation=nil, seen={})
|
|
23
|
+
properties = Style.new
|
|
24
|
+
properties.stylename = self.stylename
|
|
25
|
+
properties.stylesheet = self.stylesheet
|
|
26
|
+
|
|
27
|
+
# if we have an orientation, only apply those styles. otherwise apply the
|
|
28
|
+
# entire style, including the current orientation.
|
|
29
|
+
if rotation_orientation
|
|
30
|
+
# in order to preserve the "local-first" override, we need to *delete*
|
|
31
|
+
# the keys in imported_stylesheets and extended_properties that are
|
|
32
|
+
# present in this style - even though we don't ultimately *apply* the
|
|
33
|
+
# styles
|
|
34
|
+
delete_keys = self.keys
|
|
35
|
+
orientation = rotation_orientation
|
|
36
|
+
else
|
|
37
|
+
delete_keys = []
|
|
38
|
+
properties.update(self)
|
|
39
|
+
orientation = nil
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# now we can merge extends, and imported_stylesheets. before merging,
|
|
43
|
+
# these will go through the same process that we just finished on the
|
|
44
|
+
# local style
|
|
45
|
+
if stylesheet && stylesheet.is_a?(Teacup::Stylesheet)
|
|
46
|
+
stylesheet.imported_stylesheets.reverse.each do |stylesheet|
|
|
47
|
+
imported_properties = stylesheet.query(self.stylename, target, rotation_orientation, seen)
|
|
48
|
+
delete_keys.each do |key|
|
|
49
|
+
imported_properties.delete(key)
|
|
50
|
+
end
|
|
51
|
+
Teacup::merge_defaults! properties, imported_properties
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
if also_includes = self[:extends]
|
|
55
|
+
also_includes = [also_includes] unless also_includes.is_a? Array
|
|
56
|
+
|
|
57
|
+
# turn style names into Hashes by querying them on the stylesheet
|
|
58
|
+
# (this does not pass `seen`, because this is a new query)
|
|
59
|
+
also_includes.each do |also_include|
|
|
60
|
+
extended_properties = stylesheet.query(also_include, target, rotation_orientation)
|
|
61
|
+
delete_keys.each do |key|
|
|
62
|
+
extended_properties.delete(key)
|
|
63
|
+
end
|
|
64
|
+
Teacup::merge_defaults! properties, extended_properties
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
properties.delete(:extends)
|
|
68
|
+
|
|
69
|
+
# if we know the class of the target, we can apply styles via class
|
|
70
|
+
# inheritance. We do not pass `target` in this case.
|
|
71
|
+
if target
|
|
72
|
+
target.class.ancestors.each do |ancestor|
|
|
73
|
+
extended_properties = stylesheet.query(ancestor, nil, rotation_orientation)
|
|
74
|
+
Teacup::merge_defaults!(properties, extended_properties)
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
return properties
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
# Example:
|
|
2
|
+
# Teacup::Stylesheet.new :main do
|
|
3
|
+
# style :root,
|
|
4
|
+
# # stays centered and grows in height
|
|
5
|
+
# autoresizingMask: autoresize.flexible_left | autoresize.flexible_right | autoresize.flexible_height
|
|
6
|
+
# # same, in block form
|
|
7
|
+
# autoresizingMask: autoresize { flexible_left | flexible_right | flexible_height }
|
|
8
|
+
# end
|
|
9
|
+
module Teacup
|
|
10
|
+
class Stylesheet
|
|
11
|
+
|
|
12
|
+
def autoresize &block
|
|
13
|
+
@@autoresize ||= Autoresize.new
|
|
14
|
+
if block
|
|
15
|
+
return @@autoresize.instance_exec &block
|
|
16
|
+
else
|
|
17
|
+
return @@autoresize
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
##|
|
|
22
|
+
##| DEPRECATED
|
|
23
|
+
##|
|
|
24
|
+
|
|
25
|
+
def flexible_left
|
|
26
|
+
NSLog("The Stylesheet method `flexible_left` is deprecated, use `autoresize.flexible_left` instead")
|
|
27
|
+
NSViewMinXMargin
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def flexible_width
|
|
31
|
+
NSLog("The Stylesheet method `flexible_width` is deprecated, use `autoresize.flexible_width` instead")
|
|
32
|
+
NSViewWidthSizable
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def flexible_right
|
|
36
|
+
NSLog("The Stylesheet method `flexible_right` is deprecated, use `autoresize.flexible_right` instead")
|
|
37
|
+
NSViewMaxXMargin
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def flexible_top
|
|
41
|
+
NSLog("The Stylesheet method `flexible_top` is deprecated, use `autoresize.flexible_top` instead")
|
|
42
|
+
NSViewMaxYMargin
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def flexible_height
|
|
46
|
+
NSLog("The Stylesheet method `flexible_height` is deprecated, use `autoresize.flexible_height` instead")
|
|
47
|
+
NSViewHeightSizable
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def flexible_bottom
|
|
51
|
+
NSLog("The Stylesheet method `flexible_bottom` is deprecated, use `autoresize.flexible_bottom` instead")
|
|
52
|
+
NSViewMinYMargin
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
class Autoresize
|
|
58
|
+
|
|
59
|
+
def none
|
|
60
|
+
NSViewNotSizable
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
##|
|
|
64
|
+
##| FLEXIBLE
|
|
65
|
+
##|
|
|
66
|
+
|
|
67
|
+
def flexible_left
|
|
68
|
+
NSViewMinXMargin
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def flexible_width
|
|
72
|
+
NSViewWidthSizable
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def flexible_right
|
|
76
|
+
NSViewMaxXMargin
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def flexible_top
|
|
80
|
+
NSViewMaxYMargin
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def flexible_height
|
|
84
|
+
NSViewHeightSizable
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def flexible_bottom
|
|
88
|
+
NSViewMinYMargin
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
##|
|
|
92
|
+
##| FILL
|
|
93
|
+
##|
|
|
94
|
+
|
|
95
|
+
def fill
|
|
96
|
+
flexible_width | flexible_height
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def fill_top
|
|
100
|
+
flexible_width | flexible_bottom
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def fill_bottom
|
|
104
|
+
flexible_width | flexible_top
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def fill_left
|
|
108
|
+
flexible_height | flexible_right
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
def fill_right
|
|
112
|
+
flexible_height | flexible_left
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
##|
|
|
116
|
+
##| FIXED
|
|
117
|
+
##|
|
|
118
|
+
|
|
119
|
+
def fixed_top_left
|
|
120
|
+
flexible_right | flexible_bottom
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def fixed_top_middle
|
|
124
|
+
flexible_left | flexible_right | flexible_bottom
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def fixed_top_right
|
|
128
|
+
flexible_left | flexible_bottom
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def fixed_middle_left
|
|
132
|
+
flexible_top | flexible_bottom | flexible_right
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
def fixed_middle
|
|
136
|
+
flexible_top | flexible_bottom | flexible_left | flexible_right
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def fixed_middle_right
|
|
140
|
+
flexible_top | flexible_bottom | flexible_left
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def fixed_bottom_left
|
|
144
|
+
flexible_right | flexible_top
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def fixed_bottom_middle
|
|
148
|
+
flexible_left | flexible_right | flexible_top
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
def fixed_bottom_right
|
|
152
|
+
flexible_left | flexible_top
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
##|
|
|
156
|
+
##| FLOAT
|
|
157
|
+
##|
|
|
158
|
+
|
|
159
|
+
def float_horizontal
|
|
160
|
+
flexible_left | flexible_right
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def float_vertical
|
|
164
|
+
flexible_top | flexible_bottom
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
end
|
data/lib/teacup.rb
CHANGED
|
@@ -4,21 +4,22 @@ end
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
Motion::Project::App.setup do |app|
|
|
7
|
+
teacup_lib = File.join(File.dirname(__FILE__), 'teacup')
|
|
8
|
+
platform = app.respond_to?(:template) ? app.template : :ios
|
|
9
|
+
teacup_platform_lib = File.join(File.dirname(__FILE__), "teacup-#{platform}")
|
|
10
|
+
unless File.exists? teacup_platform_lib
|
|
11
|
+
raise "Sorry, the platform #{platform.inspect} is not supported by teacup"
|
|
12
|
+
end
|
|
13
|
+
|
|
7
14
|
# scans app.files until it finds app/ (the default)
|
|
8
15
|
# if found, it inserts just before those files, otherwise it will insert to
|
|
9
16
|
# the end of the list
|
|
10
|
-
insert_point = 0
|
|
11
|
-
app.files.each_index do |index|
|
|
12
|
-
file = app.files[index]
|
|
13
|
-
if file =~ /^(?:\.\/)?app\//
|
|
14
|
-
# found app/, so stop looking
|
|
15
|
-
break
|
|
16
|
-
end
|
|
17
|
-
insert_point = index + 1
|
|
18
|
-
end
|
|
17
|
+
insert_point = app.files.find_index { |file| file =~ /^(?:\.\/)?app\// } || 0
|
|
19
18
|
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
Dir.glob(File.join(teacup_platform_lib, '**/*.rb')).reverse.each do |file|
|
|
20
|
+
app.files.insert(insert_point, file)
|
|
21
|
+
end
|
|
22
|
+
Dir.glob(File.join(teacup_lib, '**/*.rb')).reverse.each do |file|
|
|
22
23
|
app.files.insert(insert_point, file)
|
|
23
24
|
end
|
|
24
25
|
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
class AppDelegate
|
|
2
|
+
def applicationDidFinishLaunching(notification)
|
|
3
|
+
buildMenu
|
|
4
|
+
buildWindow
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def buildWindow
|
|
8
|
+
@controller = MainController.new
|
|
9
|
+
@mainWindow = @controller.window
|
|
10
|
+
# @mainWindow = NSWindow.alloc.initWithContentRect([[240, 180], [480, 360]],
|
|
11
|
+
# styleMask: NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask,
|
|
12
|
+
# backing: NSBackingStoreBuffered,
|
|
13
|
+
# defer: false)
|
|
14
|
+
@mainWindow.title = NSBundle.mainBundle.infoDictionary['CFBundleName']
|
|
15
|
+
@mainWindow.orderFrontRegardless
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class JSONParser
|
|
2
|
+
def self.parse_from_url(url)
|
|
3
|
+
data = DataParser.parse(url)
|
|
4
|
+
|
|
5
|
+
error_ptr = Pointer.new(:object)
|
|
6
|
+
json = NSJSONSerialization.JSONObjectWithData(data, options:0, error:error_ptr)
|
|
7
|
+
unless json
|
|
8
|
+
raise error_ptr[0]
|
|
9
|
+
end
|
|
10
|
+
json
|
|
11
|
+
end
|
|
12
|
+
end
|