teacup 1.2.8 → 1.2.9

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,26 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- teacup (1.2.7)
5
- rake
4
+ teacup (1.2.8)
6
5
 
7
6
  GEM
8
7
  remote: http://rubygems.org/
9
8
  specs:
10
- diff-lcs (1.1.3)
11
- rake (10.0.2)
12
- rspec (2.10.0)
13
- rspec-core (~> 2.10.0)
14
- rspec-expectations (~> 2.10.0)
15
- rspec-mocks (~> 2.10.0)
16
- rspec-core (2.10.1)
17
- rspec-expectations (2.10.0)
18
- diff-lcs (~> 1.1.3)
19
- rspec-mocks (2.10.1)
20
9
 
21
10
  PLATFORMS
22
11
  ruby
23
12
 
24
13
  DEPENDENCIES
25
- rspec
26
14
  teacup!
@@ -0,0 +1,3 @@
1
+
2
+ class GradientController < UIViewController
3
+ end
data/lib/dummy.rb CHANGED
@@ -9,14 +9,17 @@ private
9
9
  def dummy
10
10
  setFrame(nil)
11
11
  setOpaque(nil)
12
+ setClipsToBounds(nil)
13
+ setUserInteractionEnabled(nil)
12
14
  end
13
15
  end
14
16
 
15
- class DummyTableView < UITableView
16
- def allowsSelection=(value)
17
- setAllowSelection value
18
- end
17
+ class DummyTableView < UITableView
18
+ private
19
+ def dummy
20
+ setAllowSelection(value)
19
21
  end
22
+ end
20
23
 
21
24
  class DummyButton < UIButton
22
25
  private
@@ -51,6 +54,7 @@ end
51
54
  class DummyTextField < UITextField
52
55
  private
53
56
  def dummy
57
+ setSecureTextEntry(nil)
54
58
  setReturnKeyType(nil)
55
59
  setAutocapitalizationType(nil)
56
60
  setAutocorrectionType(nil)
@@ -89,3 +93,4 @@ private
89
93
  setOn(true)
90
94
  end
91
95
  end
96
+
@@ -51,12 +51,12 @@ module Teacup
51
51
  ]
52
52
  when :full_width
53
53
  [
54
- Teacup::Constraint.new(:self, :left).equals(relative_to, :left),
54
+ Teacup::Constraint.new(:self, :center_x).equals(relative_to, :center_x),
55
55
  Teacup::Constraint.new(:self, :width).equals(relative_to, :width),
56
56
  ]
57
57
  when :full_height
58
58
  [
59
- Teacup::Constraint.new(:self, :top).equals(relative_to, :top),
59
+ Teacup::Constraint.new(:self, :center_y).equals(relative_to, :center_y),
60
60
  Teacup::Constraint.new(:self, :height).equals(relative_to, :height),
61
61
  ]
62
62
  when :center_x
@@ -248,12 +248,3 @@ private
248
248
  end
249
249
  end
250
250
  end
251
-
252
- # constraintWithItem: target
253
- # attribute: attribute
254
- # relatedBy: relationship
255
- # toItem: relative_to
256
- # attribute: attribute2
257
- # multiplier: multiplier
258
- # constant: constant
259
-
data/lib/teacup/layout.rb CHANGED
@@ -101,7 +101,7 @@ module Teacup
101
101
  # end
102
102
  #
103
103
  def layout(view_or_class, name_or_properties=nil, properties_or_nil=nil, &block)
104
- view = to_instance(view_or_class)
104
+ view = Teacup.to_instance(view_or_class)
105
105
 
106
106
  name = nil
107
107
  properties = properties_or_nil
@@ -182,7 +182,7 @@ module Teacup
182
182
  # end
183
183
  #
184
184
  def subview(class_or_instance, *args, &block)
185
- instance = to_instance(class_or_instance)
185
+ instance = Teacup.to_instance(class_or_instance)
186
186
 
187
187
  (superview_chain.last || top_level_view).addSubview(instance)
188
188
 
@@ -193,19 +193,6 @@ module Teacup
193
193
 
194
194
  protected
195
195
 
196
- def to_instance(class_or_instance)
197
- if class_or_instance.is_a? Class
198
- unless class_or_instance <= UIView
199
- raise "Expected subclass of UIView, got: #{class_or_instance.inspect}"
200
- end
201
- return class_or_instance.new
202
- elsif class_or_instance.is_a?(UIView)
203
- return class_or_instance
204
- else
205
- raise "Expected a UIView, got: #{class_or_instance.inspect}"
206
- end
207
- end
208
-
209
196
  # Get's the current stack of views in nested calls to layout.
210
197
  #
211
198
  # The view at the end of the stack is the one into which subviews
@@ -227,7 +227,8 @@ module Teacup
227
227
  # reset the stylesheet_cache for this stylename
228
228
  @stylesheet_cache.delete(stylename) if @stylesheet_cache
229
229
 
230
- # merge into styles[stylename], new properties "win"
230
+ # merge into styles[stylename] (an instance of Teacup::Style). new
231
+ # properties "win" over existing properties.
231
232
  Teacup::merge_defaults(properties, styles[stylename], styles[stylename])
232
233
  end
233
234
  end
@@ -0,0 +1,17 @@
1
+ module Teacup
2
+ module_function
3
+
4
+ def to_instance(class_or_instance)
5
+ if class_or_instance.is_a? Class
6
+ unless class_or_instance <= UIView
7
+ raise "Expected subclass of UIView, got: #{class_or_instance.inspect}"
8
+ end
9
+ return class_or_instance.new
10
+ elsif class_or_instance.is_a?(UIView)
11
+ return class_or_instance
12
+ else
13
+ raise "Expected a UIView, got: #{class_or_instance.inspect}"
14
+ end
15
+ end
16
+
17
+ end
@@ -1,5 +1,5 @@
1
1
  module Teacup
2
2
 
3
- VERSION = '1.2.8'
3
+ VERSION = '1.2.9'
4
4
 
5
5
  end
@@ -249,7 +249,7 @@ class UIView
249
249
  constraint.each { |sym, relative_to|
250
250
  @teacup_constraints[sym] = relative_to
251
251
  }
252
- elsif constraint.is_a? Teacup::Constraint or constraint.is_a? Symbol
252
+ elsif constraint.is_a?(Teacup::Constraint) || constraint.is_a?(Symbol)
253
253
  @teacup_constraints[constraint] = true
254
254
  else
255
255
  raise "Unsupported constraint: #{constraint.inspect}"
@@ -125,14 +125,9 @@ class UIViewController
125
125
  true
126
126
  end
127
127
 
128
- # The compiling mechanisms combined with how UIKit works of rubymotion do
129
- # not allow the `shouldAutorotateToInterfaceOrientation` method to be
130
- # overridden in modules/extensions. So instead, HERE is the code for what
131
- # `shouldAutorotateToInterfaceOrientation` should look like if you want
132
- # to use the teacup rotation stuff. Call this method from your own
133
- # `shouldAutorotateToInterfaceOrientation` method.
134
- #
135
- # the teacup developers apologize for any inconvenience. :-)
128
+ # This method *used* to be useful for the `shouldAutorotateToOrientation`
129
+ # method, but the iOS 6 update deprecates that method. Instead, use the
130
+ # `supportedInterfaceOrientations` and return `autorotateMask`.
136
131
  def autorotateToOrientation(orientation)
137
132
  if view.stylesheet and view.stylesheet.is_a?(Teacup::Stylesheet) and view.stylename
138
133
  properties = view.stylesheet.query(view.stylename, self, orientation)
@@ -164,14 +159,22 @@ class UIViewController
164
159
  return false
165
160
  end
166
161
 
167
- return orientation == UIInterfaceOrientationPortrait
162
+ # returns the system default
163
+ if device == UIUserInterfaceIdiomPhone
164
+ return orientation != UIInterfaceOrientationPortraitUpsideDown
165
+ else
166
+ return true
167
+ end
168
168
  end
169
169
 
170
+ # You can use this method in `supportedInterfaceOrientations`, and it will
171
+ # query the stylesheet for the supported orientations, based on what
172
+ # orientations are defined. At a minimum, to opt-in to this feature, you'll
173
+ # need to define styles like `style :root, landscape: true`
170
174
  def autorotateMask
175
+ device = UIDevice.currentDevice.userInterfaceIdiom
171
176
  if view.stylesheet and view.stylesheet.is_a?(Teacup::Stylesheet) and view.stylename
172
177
  properties = view.stylesheet.query(view.stylename, self, orientation)
173
- device = UIDevice.currentDevice.userInterfaceIdiom
174
- device == UIUserInterfaceIdiomPhone
175
178
 
176
179
  orientations = 0
177
180
  if properties.supports?(:portrait) or properties.supports?(:upside_up)
@@ -203,11 +206,63 @@ class UIViewController
203
206
  end
204
207
  return orientations
205
208
  end
206
- return UIInterfaceOrientationPortrait
209
+
210
+ # returns the system default
211
+ if device == UIUserInterfaceIdiomPhone
212
+ return UIInterfaceOrientationMaskAllButUpsideDown
213
+ else
214
+ return UIInterfaceOrientationMaskAll
215
+ end
207
216
  end
208
217
 
218
+ # restyles the view! be careful about putting styles in your stylesheet that
219
+ # you change in your controller. anything that might change over time should
220
+ # be applied in your controller using `style`
209
221
  def willAnimateRotationToInterfaceOrientation(orientation, duration:duration)
210
222
  view.restyle!(orientation)
211
223
  end
212
224
 
225
+ ##|
226
+ ##| Motion-Layout support
227
+ ##|
228
+
229
+ # Calling this method uses Nick Quaranto's motion-layout gem to provide ASCII
230
+ # art style access to autolayout. It assigns all the subviews by stylename,
231
+ # and assigns `self.view` as the target view. Beyond that, it's up to you to
232
+ # implement the layout methods:
233
+ #
234
+ # auto do
235
+ # metrics 'margin' => 20
236
+ # vertical "|-[top]-margin-[bottom]-|"
237
+ # horizontal "|-margin-[top]-margin-|"
238
+ # horizontal "|-margin-[bottom]-margin-|"
239
+ # end
240
+ def auto(layout_view=self.view, layout_subviews={}, &layout_block)
241
+ raise "gem install 'motion-layout'" unless defined? Motion::Layout
242
+
243
+ Teacup.get_subviews(self.view).each do |view|
244
+ if view.stylename && ! layout_subviews[view.stylename.to_s]
245
+ layout_subviews[view.stylename.to_s] = view
246
+ end
247
+ end
248
+
249
+ Motion::Layout.new do |layout|
250
+ layout.view layout_view
251
+ layout.subviews layout_subviews
252
+ layout.instance_eval(&layout_block)
253
+ end
254
+ end
255
+
256
+ end
257
+
258
+
259
+ module Teacup
260
+
261
+ module_function
262
+ def get_subviews(target)
263
+ [target] + target.subviews.map { |subview|
264
+ get_subviews(subview).select{ |v| v.stylename }
265
+ }.flatten
266
+ end
267
+
213
268
  end
@@ -1,103 +1,103 @@
1
1
  ##|
2
2
  ##| UIView.frame
3
3
  ##|
4
- Teacup.handler UIView, :left, :x { |x|
5
- f = self.frame
6
- f.origin.x = Teacup::calculate(self, :width, x)
7
- self.frame = f
4
+ Teacup.handler UIView, :left, :x { |target, x|
5
+ f = target.frame
6
+ f.origin.x = Teacup::calculate(target, :width, x)
7
+ target.frame = f
8
8
  }
9
9
 
10
- Teacup.handler UIView, :right { |r|
11
- f = self.frame
12
- f.origin.x = Teacup::calculate(self, :width, r) - f.size.width
13
- self.frame = f
10
+ Teacup.handler UIView, :right { |target, r|
11
+ f = target.frame
12
+ f.origin.x = Teacup::calculate(target, :width, r) - f.size.width
13
+ target.frame = f
14
14
  }
15
15
 
16
- Teacup.handler UIView, :center_x, :middle_x { |x|
17
- c = self.center
18
- c.x = Teacup::calculate(self, :width, x)
19
- self.center = c
16
+ Teacup.handler UIView, :center_x, :middle_x { |target, x|
17
+ c = target.center
18
+ c.x = Teacup::calculate(target, :width, x)
19
+ target.center = c
20
20
  }
21
21
 
22
- Teacup.handler UIView, :top, :y { |y|
23
- f = self.frame
24
- f.origin.y = Teacup::calculate(self, :height, y)
25
- self.frame = f
22
+ Teacup.handler UIView, :top, :y { |target, y|
23
+ f = target.frame
24
+ f.origin.y = Teacup::calculate(target, :height, y)
25
+ target.frame = f
26
26
  }
27
27
 
28
- Teacup.handler UIView, :bottom { |b|
29
- f = self.frame
30
- f.origin.y = Teacup::calculate(self, :height, b) - f.size.height
31
- self.frame = f
28
+ Teacup.handler UIView, :bottom { |target, b|
29
+ f = target.frame
30
+ f.origin.y = Teacup::calculate(target, :height, b) - f.size.height
31
+ target.frame = f
32
32
  }
33
33
 
34
- Teacup.handler UIView, :center_y, :middle_y { |y|
35
- c = self.center
36
- c.y = Teacup::calculate(self, :height, y)
37
- self.center = c
34
+ Teacup.handler UIView, :center_y, :middle_y { |target, y|
35
+ c = target.center
36
+ c.y = Teacup::calculate(target, :height, y)
37
+ target.center = c
38
38
  }
39
39
 
40
- Teacup.handler UIView, :width { |w|
41
- f = self.frame
42
- f.size.width = Teacup::calculate(self, :width, w)
43
- self.frame = f
40
+ Teacup.handler UIView, :width { |target, w|
41
+ f = target.frame
42
+ f.size.width = Teacup::calculate(target, :width, w)
43
+ target.frame = f
44
44
  }
45
45
 
46
- Teacup.handler UIView, :height { |h|
47
- f = self.frame
48
- f.size.height = Teacup::calculate(self, :height, h)
49
- self.frame = f
46
+ Teacup.handler UIView, :height { |target, h|
47
+ f = target.frame
48
+ f.size.height = Teacup::calculate(target, :height, h)
49
+ target.frame = f
50
50
  }
51
51
 
52
- Teacup.handler UIView, :origin { |origin|
53
- f = self.frame
52
+ Teacup.handler UIView, :origin { |target, origin|
53
+ f = target.frame
54
54
  f.origin = origin
55
- self.frame = f
55
+ target.frame = f
56
56
  }
57
57
 
58
- Teacup.handler UIView, :size { |size|
58
+ Teacup.handler UIView, :size { |target, size|
59
59
  # odd... if I changed these to .is_a?, weird errors happen. Use ===
60
60
  if Symbol === size && size == :full
61
- if self.superview
62
- size = self.superview.bounds.size
61
+ if target.superview
62
+ size = target.superview.bounds.size
63
63
  else
64
- size = self.frame.size
64
+ size = target.frame.size
65
65
  end
66
66
  elsif Array === size
67
- size = [Teacup::calculate(self, :width, size[0]), Teacup::calculate(self, :height, size[1])]
67
+ size = [Teacup::calculate(target, :width, size[0]), Teacup::calculate(target, :height, size[1])]
68
68
  end
69
- f = self.frame
69
+ f = target.frame
70
70
  f.size = size
71
- self.frame = f
71
+ target.frame = f
72
72
  }
73
73
 
74
- Teacup.handler UIView, :frame { |frame|
74
+ Teacup.handler UIView, :frame { |target, frame|
75
75
  # odd... if I changed these to .is_a?, weird errors happen. Use ===
76
76
  if Symbol === frame && frame == :full
77
- if self.superview
78
- frame = self.superview.bounds
77
+ if target.superview
78
+ frame = target.superview.bounds
79
79
  else
80
- frame = self.frame
80
+ frame = target.frame
81
81
  end
82
82
  elsif Array === frame && frame.length == 4
83
83
  frame = [
84
- [Teacup::calculate(self, :width, frame[0]), Teacup::calculate(self, :height, frame[1])],
85
- [Teacup::calculate(self, :width, frame[2]), Teacup::calculate(self, :height, frame[3])]
84
+ [Teacup::calculate(target, :width, frame[0]), Teacup::calculate(target, :height, frame[1])],
85
+ [Teacup::calculate(target, :width, frame[2]), Teacup::calculate(target, :height, frame[3])]
86
86
  ]
87
87
  elsif Array === frame && frame.length == 2
88
88
  frame = [
89
- [Teacup::calculate(self, :width, frame[0][0]), Teacup::calculate(self, :height, frame[0][1])],
90
- [Teacup::calculate(self, :width, frame[1][0]), Teacup::calculate(self, :height, frame[1][1])]
89
+ [Teacup::calculate(target, :width, frame[0][0]), Teacup::calculate(target, :height, frame[0][1])],
90
+ [Teacup::calculate(target, :width, frame[1][0]), Teacup::calculate(target, :height, frame[1][1])]
91
91
  ]
92
92
  end
93
- self.frame = frame
93
+ target.frame = frame
94
94
  }
95
95
 
96
- Teacup.handler UIView, :gradient { |gradient|
97
- gradient_layer = self.instance_variable_get(:@gradient_layer) || begin
96
+ Teacup.handler UIView, :gradient { |target, gradient|
97
+ gradient_layer = target.instance_variable_get(:@teacup_gradient_layer) || begin
98
98
  gradient_layer = CAGradientLayer.layer
99
- gradient_layer.frame = self.bounds
100
- self.layer.insertSublayer(gradient_layer, atIndex:0)
99
+ gradient_layer.frame = target.bounds
100
+ target.layer.insertSublayer(gradient_layer, atIndex:0)
101
101
  gradient_layer
102
102
  end
103
103
 
@@ -111,23 +111,23 @@ Teacup.handler UIView, :gradient { |gradient|
111
111
  end
112
112
  end
113
113
 
114
- self.instance_variable_set(:@gradient_layer, gradient_layer)
114
+ target.instance_variable_set(:@teacup_gradient_layer, gradient_layer)
115
115
  }
116
116
 
117
117
  ##|
118
118
  ##| UIButton
119
119
  ##|
120
- Teacup.handler UIButton, :title { |title|
121
- self.setTitle(title, forState: UIControlStateNormal)
120
+ Teacup.handler UIButton, :title { |target, title|
121
+ target.setTitle(title, forState: UIControlStateNormal)
122
122
  }
123
123
 
124
124
 
125
- Teacup.handler UIButton, :titleColor { |color|
126
- self.setTitleColor(color.uicolor, forState: UIControlStateNormal)
125
+ Teacup.handler UIButton, :titleColor { |target, color|
126
+ target.setTitleColor(color.uicolor, forState: UIControlStateNormal)
127
127
  }
128
128
 
129
129
 
130
- Teacup.handler UIButton, :titleFont, :font { |font|
130
+ Teacup.handler UIButton, :titleFont, :font { |target, font|
131
131
  font = font.uifont
132
- self.titleLabel.font = font
132
+ target.titleLabel.font = font
133
133
  }
@@ -0,0 +1,4 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem "teacup"
@@ -0,0 +1,12 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ rake (10.0.3)
5
+ teacup (1.2.8)
6
+ rake
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ teacup
@@ -0,0 +1,13 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ require 'motion/project'
4
+ require 'bundler'
5
+ Bundler.require
6
+
7
+ Motion::Project::App.setup do |app|
8
+ # Use `rake config' to see complete project settings.
9
+ app.name = 'AutoLayout'
10
+
11
+ #include styles
12
+ app.files += Dir.glob(File.join(app.project_dir, 'styles/**/*.rb'))
13
+ end
@@ -0,0 +1,12 @@
1
+ class AppDelegate
2
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
3
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
4
+ myNavController = RootController.alloc.init
5
+
6
+ @window.rootViewController = UINavigationController.alloc.initWithRootViewController(myNavController)
7
+ @window.rootViewController.wantsFullScreenLayout = true
8
+ @window.makeKeyAndVisible
9
+
10
+ true
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ class RootController < UIViewController
2
+ stylesheet :root
3
+
4
+ layout :root do
5
+ @label = subview(UILabel, :label)
6
+ @button = subview(UIButton.buttonWithType(UIButtonTypeRoundedRect), :button)
7
+ @switch = subview(UISwitch, :switch)
8
+ end
9
+
10
+ def viewDidLoad
11
+ super
12
+ # Title for this view
13
+ self.title = "Autolayout Example"
14
+ end
15
+
16
+ end
@@ -0,0 +1,33 @@
1
+ Teacup::Stylesheet.new :base do
2
+ back_color = UIColor.grayColor
3
+ dark_color = UIColor.blackColor
4
+ mid_color = UIColor.redColor
5
+
6
+ style UIView,
7
+ backgroundColor: back_color,
8
+ nav_btn_tint: mid_color
9
+
10
+ style :custom_label,
11
+ text: 'App Stuff!',
12
+ backgroundColor: UIColor.clearColor,
13
+ numberOfLines: 0,
14
+ font: UIFont.boldSystemFontOfSize(40),
15
+ textColor: UIColor.whiteColor,
16
+ shadowColor: UIColor.blackColor,
17
+ textAlignment: UITextAlignmentCenter,
18
+ layer: {
19
+ transform: identity,
20
+ shadowRadius: 20,
21
+ shadowOpacity: 0.5,
22
+ masksToBounds: false
23
+ }
24
+
25
+ style :custom_button,
26
+ width: 142,
27
+ height: 34,
28
+ title: "Button"
29
+
30
+ style :custom_switch,
31
+ on: true
32
+
33
+ end
@@ -0,0 +1,2 @@
1
+ # for when I come across one of those silly precompile issues
2
+ # that is not yet supported by teacup
@@ -0,0 +1,3 @@
1
+ Teacup.handler UIView, :nav_btn_tint do |color|
2
+ UIBarButtonItem.appearance.setTintColor(color)
3
+ end
@@ -0,0 +1,29 @@
1
+ Teacup::Stylesheet.new :root do
2
+ import :base
3
+
4
+ v_padding = 10
5
+
6
+ style :label, extends: :custom_label,
7
+ constraints: [
8
+ :full_width,
9
+ constrain_top(50)
10
+ ],
11
+ backgroundColor: UIColor.clearColor
12
+
13
+ style :button, extends: :custom_button,
14
+ constraints: [
15
+ constrain_below(:label).plus(v_padding),
16
+ # Position at half of middle (q1)
17
+ constrain(:center_x).equals(:superview, :center_x).times(0.5),
18
+ constrain(:left).equals(:superview, :left).plus(10)
19
+ ]
20
+
21
+ style :switch, extends: :custom_switch,
22
+ constraints: [
23
+ constrain_below(:label).plus(v_padding * 2),
24
+ # Position at Middle + half (75%)
25
+ constrain(:center_x).equals(:superview, :center_x).times(1.5)
26
+ ]
27
+
28
+ end
29
+
@@ -0,0 +1,13 @@
1
+ Teacup::Stylesheet.new :settings do
2
+ import :base
3
+
4
+ v_padding = 10
5
+
6
+ style :label, extends: :custom_label,
7
+ constraints: [
8
+ :full_width,
9
+ constrain_top(150)
10
+ ],
11
+ backgroundColor: :clear
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+ gem 'sugarcube'
5
+ gem 'teacup'
6
+ gem 'sweettea'
7
+ gem 'geomotion'
@@ -0,0 +1,11 @@
1
+ # -*- coding: utf-8 -*-
2
+ $:.unshift("/Library/RubyMotion/lib")
3
+ require 'motion/project'
4
+ require 'bundler'
5
+ Bundler.require
6
+
7
+
8
+ Motion::Project::App.setup do |app|
9
+ # Use `rake config' to see complete project settings.
10
+ app.name = 'one-page'
11
+ end
@@ -0,0 +1,43 @@
1
+ include SugarCube::Adjust
2
+
3
+ class AppDelegate
4
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
5
+ @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
6
+ ctlr = MyController.new
7
+ first = UINavigationController.alloc.initWithRootViewController(ctlr)
8
+ @window.rootViewController = first
9
+ @window.makeKeyAndVisible
10
+
11
+ true
12
+ end
13
+ end
14
+
15
+
16
+ Teacup::Stylesheet.new(:teacup) do
17
+ style :label,
18
+ color: :white,
19
+ background: :clear,
20
+ constraints: [
21
+ :center_x,
22
+ :center_y,
23
+ ]
24
+
25
+ style :button,
26
+ title: 'neat.',
27
+ constraints: [
28
+ :center_x,
29
+ constrain_below(:label).plus(0),
30
+ ]
31
+
32
+ end
33
+
34
+
35
+ class MyController < UIViewController
36
+ stylesheet :teacup
37
+
38
+ layout do
39
+ @label = subview(UILabel, :label, text: 'nifty?')
40
+ @button = subview(UIButton, :button)
41
+ end
42
+
43
+ end
@@ -0,0 +1,125 @@
1
+ include SugarCube::Adjust
2
+
3
+ class AppDelegate
4
+ def application(application, didFinishLaunchingWithOptions:launchOptions)
5
+ @window = Kiln::KilnWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
6
+ ctlr = MyController.new
7
+ first = UINavigationController.alloc.initWithRootViewController(ctlr)
8
+ @window.rootViewController = first
9
+ @window.makeKeyAndVisible
10
+ true
11
+ end
12
+ end
13
+
14
+
15
+ Teacup::Stylesheet.new(:teacup) do
16
+ style :label,
17
+ color: :white,
18
+ background: :clear,
19
+ portrait: {
20
+ text: 'portrait',
21
+ },
22
+ landscape: {
23
+ text: 'landscape',
24
+ },
25
+ constraints: [
26
+ :center_x,
27
+ :center_y,
28
+ ]
29
+
30
+ style :button,
31
+ constraints: [
32
+ :center_x,
33
+ constrain_below(:label).plus(0),
34
+ ]
35
+
36
+ end
37
+
38
+
39
+ class MyController < UIViewController
40
+ stylesheet :teacup
41
+
42
+ layout do
43
+ @label = subview(UILabel, :label)
44
+ @button = subview(NiftyButton, :button)
45
+
46
+ auto do
47
+ metrics 'margin' => 20,
48
+ 'height' => 75,
49
+ 'top' => 95
50
+ horizontal '|-margin-[label]-margin-|'
51
+ horizontal '|-margin-[button]-margin-|'
52
+ vertical '|-[label]-margin-[button]-margin-|'
53
+ end
54
+ end
55
+
56
+ def viewDidAppear(animated)
57
+ @label.text = 'testing'
58
+ end
59
+
60
+ end
61
+
62
+
63
+ class NiftyButton < UIButton
64
+ attr_accessor :text
65
+ attr_accessor :font
66
+
67
+ def foreground_color
68
+ (@touched ? :black : :white).uicolor
69
+ end
70
+
71
+ def background_color
72
+ (@touched ? :white : :black).uicolor
73
+ end
74
+
75
+ def drawRect(rect)
76
+ background_color.setFill
77
+ UIBezierPath.bezierPathWithRoundedRect(bounds, cornerRadius:5).fill
78
+
79
+ foreground_color.uicolor.setFill
80
+ UIBezierPath.bezierPathWithRoundedRect(bounds.shrink(2), cornerRadius:5).fill
81
+
82
+ background_color.setFill
83
+ text.drawAtPoint([5, 5], withFont: font)
84
+ end
85
+
86
+ def text
87
+ @text || 'neat.'
88
+ end
89
+
90
+ def font
91
+ @font || :bold.uifont
92
+ end
93
+
94
+ def intrinsicContentSize
95
+ text.sizeWithFont(font).wider(10).taller(10)
96
+ end
97
+
98
+ def accessibilityLabel
99
+ text
100
+ end
101
+
102
+ def touchesBegan(touches, withEvent:event)
103
+ @touched = true
104
+ setNeedsDisplay
105
+ end
106
+
107
+ def touchesEnded(touches, withEvent:event)
108
+ @touched = false
109
+ setNeedsDisplay
110
+ end
111
+
112
+ def touchesCancelled(touches, withEvent:event)
113
+ @touched = false
114
+ setNeedsDisplay
115
+ end
116
+
117
+ def self.kiln
118
+ @kiln ||= {
119
+ 'Content' => {
120
+ text: Kiln::TextEditor,
121
+ }
122
+ }
123
+ end
124
+
125
+ end
@@ -0,0 +1,9 @@
1
+ describe "Application 'teacup-example'" do
2
+ before do
3
+ @app = UIApplication.sharedApplication
4
+ end
5
+
6
+ it "has one window" do
7
+ @app.windows.size.should == 1
8
+ end
9
+ end
@@ -1,5 +1,5 @@
1
1
  describe "Gradient" do
2
- tests FirstController
2
+ tests GradientController
3
3
 
4
4
  before do
5
5
  @root_view = window.subviews[0]
@@ -7,14 +7,14 @@ describe "Gradient" do
7
7
 
8
8
  it "should insert gradient layer when gradient style is set" do
9
9
  @root_view.style(gradient: { colors: [UIColor.redColor, UIColor.yellowColor] })
10
- @root_view.layer.sublayers.size.should == 2
10
+ @root_view.layer.sublayers.size.should == 1
11
11
  @root_view.layer.sublayers.first.class.should == CAGradientLayer
12
12
  end
13
13
 
14
14
  it "should not insert another gradient layer when gradient style is changed" do
15
15
  @root_view.style(gradient: { colors: [UIColor.redColor, UIColor.yellowColor] })
16
16
  @root_view.style(gradient: { colors: [UIColor.greenColor, UIColor.whiteColor] })
17
- @root_view.layer.sublayers.size.should == 2
17
+ @root_view.layer.sublayers.size.should == 1
18
18
  end
19
19
 
20
20
  it "should change gradient layer when gradient style is changed" do
@@ -27,6 +27,6 @@ describe "Gradient" do
27
27
 
28
28
  it "should accept CGColors" do
29
29
  @root_view.style(gradient: { colors: [UIColor.redColor.CGColor, UIColor.yellowColor.CGColor] })
30
- @root_view.layer.sublayers.size.should == 2
30
+ @root_view.layer.sublayers.size.should == 1
31
31
  end
32
32
  end
data/teacup.gemspec CHANGED
@@ -21,8 +21,4 @@ DESC
21
21
  gem.files = `git ls-files`.split($\)
22
22
  gem.require_paths = ['lib']
23
23
  gem.test_files = gem.files.grep(%r{^spec/})
24
-
25
- gem.add_dependency 'rake'
26
- gem.add_development_dependency 'rspec'
27
-
28
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: teacup
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.8
4
+ version: 1.2.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,40 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-05 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: rake
16
- requirement: !ruby/object:Gem::Requirement
17
- none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
22
- type: :runtime
23
- prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
31
- name: rspec
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
+ dependencies: []
46
14
  description: ! 'Teacup is a community-driven DSL for making CSS-like styling, and
47
15
  layouts for
48
16
 
@@ -68,6 +36,7 @@ files:
68
36
  - Rakefile
69
37
  - app/app_delegate.rb
70
38
  - app/controllers/first_controller.rb
39
+ - app/controllers/gradient_controller.rb
71
40
  - app/controllers/landscape_only_controller.rb
72
41
  - app/controllers/tableview_controller.rb
73
42
  - app/custom_class.rb
@@ -87,12 +56,23 @@ files:
87
56
  - lib/teacup/stylesheet_extensions/constraints.rb
88
57
  - lib/teacup/stylesheet_extensions/geometry.rb
89
58
  - lib/teacup/stylesheet_extensions/rotation.rb
59
+ - lib/teacup/teacup_util.rb
90
60
  - lib/teacup/version.rb
91
61
  - lib/teacup/z_core_extensions/ca_layer.rb
92
62
  - lib/teacup/z_core_extensions/ui_view.rb
93
63
  - lib/teacup/z_core_extensions/ui_view_controller.rb
94
64
  - lib/teacup/z_core_extensions/ui_view_getters.rb
95
65
  - lib/teacup/z_core_extensions/z_handlers.rb
66
+ - samples/AutoLayout/Gemfile
67
+ - samples/AutoLayout/Gemfile.lock
68
+ - samples/AutoLayout/Rakefile
69
+ - samples/AutoLayout/app/app_delegate.rb
70
+ - samples/AutoLayout/app/root_controller.rb
71
+ - samples/AutoLayout/styles/base.rb
72
+ - samples/AutoLayout/styles/dummy.rb
73
+ - samples/AutoLayout/styles/handlers.rb
74
+ - samples/AutoLayout/styles/root.rb
75
+ - samples/AutoLayout/styles/settings.rb
96
76
  - samples/Hai/.gitignore
97
77
  - samples/Hai/Gemfile
98
78
  - samples/Hai/Gemfile.lock
@@ -101,6 +81,12 @@ files:
101
81
  - samples/Hai/app/hai_controller.rb
102
82
  - samples/Hai/spec/main_spec.rb
103
83
  - samples/Hai/styles/iphone.rb
84
+ - samples/OnePage/Gemfile
85
+ - samples/OnePage/Rakefile
86
+ - samples/OnePage/app/app_delegate.rb
87
+ - samples/OnePage/resources/Default-568h@2x.png
88
+ - samples/OnePage/resources/you_didnt_see_this
89
+ - samples/OnePage/spec/main_spec.rb
104
90
  - samples/README.md
105
91
  - spec/custom_class_spec.rb
106
92
  - spec/gradient_spec.rb
@@ -130,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
116
  version: '0'
131
117
  requirements: []
132
118
  rubyforge_project:
133
- rubygems_version: 1.8.24
119
+ rubygems_version: 1.8.25
134
120
  signing_key:
135
121
  specification_version: 3
136
122
  summary: A community-driven DSL for creating user interfaces on iOS.
@@ -142,3 +128,4 @@ test_files:
142
128
  - spec/stylesheet_spec.rb
143
129
  - spec/uiswitch_spec.rb
144
130
  - spec/view_spec.rb
131
+ has_rdoc: