teacup 0.3.10 → 0.3.11

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- teacup (0.3.2)
4
+ teacup (0.3.11)
5
5
  rake
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -54,7 +54,7 @@ class SomeController < UIViewController
54
54
 
55
55
  # code to enable orientation changes
56
56
  def shouldAutorotateToInterfaceOrientation(orientation)
57
- if orientation == UIDeviceOrientationPortraitUpsideDown
57
+ if orientation == UIInterfaceOrientationPortraitUpsideDown
58
58
  return false
59
59
  end
60
60
  true
@@ -63,7 +63,7 @@ class SomeController < UIViewController
63
63
  # perform the frame changes depending on orientation
64
64
  def willAnimateRotationToInterfaceOrientation(orientation, duration:duration)
65
65
  case orientation
66
- when UIDeviceOrientationLandscapeLeft, UIDeviceOrientationLandscapeRight
66
+ when UIInterfaceOrientationLandscapeLeft, UIInterfaceOrientationLandscapeRight
67
67
  @field.frame = [[10, 10], [360, 50]]
68
68
  @search.frame = [[10, 70], [360, 50]]
69
69
  else
@@ -6,7 +6,7 @@ class LandscapeOnlyController < UIViewController
6
6
  end
7
7
 
8
8
  def shouldAutorotateToInterfaceOrientation(orientation)
9
- if orientation == UIDeviceOrientationLandscapeLeft or orientation == UIDeviceOrientationLandscapeRight
9
+ if orientation == UIInterfaceOrientationLandscapeLeft or orientation == UIInterfaceOrientationLandscapeRight
10
10
  true
11
11
  else
12
12
  false
@@ -43,7 +43,11 @@ module Teacup
43
43
  target.class.ancestors.each do |ancestor|
44
44
  if Teacup.handlers[ancestor].has_key? key
45
45
  NSLog "#{ancestor.name} is handling #{key} = #{value.inspect}" if target.respond_to? :debug and target.debug
46
- Teacup.handlers[ancestor][key].call(target, value)
46
+ if Teacup.handlers[ancestor][key].arity == 1
47
+ target.instance_exec(value, &Teacup.handlers[ancestor][key])
48
+ else
49
+ Teacup.handlers[ancestor][key].call(target, value)
50
+ end
47
51
  handled = true
48
52
  break
49
53
  end
data/lib/teacup/layout.rb CHANGED
@@ -72,17 +72,26 @@ module Teacup
72
72
  name = name_or_properties.to_sym
73
73
  end
74
74
 
75
+ # prevents the calling of restyle! until we return to this method
76
+ should_restyle = Teacup.should_restyle_and_block
77
+
75
78
  view.stylesheet = stylesheet
76
79
  view.stylename = name
77
- view.style(properties) if properties
80
+ if properties
81
+ view.style(properties) if properties
82
+ end
78
83
 
79
- begin
84
+ if block_given?
80
85
  superview_chain << view
81
86
  instance_exec(view, &block) if block_given?
82
- ensure
83
87
  superview_chain.pop
84
88
  end
85
89
 
90
+ if should_restyle
91
+ view.restyle!
92
+ # restore to whatever it was, either nil or true
93
+ Teacup.should_restyle!
94
+ end
86
95
  view
87
96
  end
88
97
 
@@ -137,7 +146,7 @@ module Teacup
137
146
  protected
138
147
 
139
148
  def to_instance(class_or_instance)
140
- if Class === class_or_instance
149
+ if class_or_instance.is_a? Class
141
150
  unless class_or_instance <= UIView
142
151
  raise "Expected subclass of UIView, got: #{class_or_instance.inspect}"
143
152
  end
@@ -0,0 +1,22 @@
1
+ module Teacup
2
+ module_function
3
+
4
+ def dont_restyle
5
+ @dont_restyle ||= nil
6
+ end
7
+
8
+ def should_restyle?
9
+ return ! self.dont_restyle
10
+ end
11
+
12
+ def should_restyle_and_block
13
+ should_restyle = self.should_restyle?
14
+ @dont_style = true
15
+ return should_restyle
16
+ end
17
+
18
+ def should_restyle!
19
+ @dont_style = nil
20
+ end
21
+
22
+ end
data/lib/teacup/style.rb CHANGED
@@ -34,7 +34,9 @@ module Teacup
34
34
  properties.stylesheet = self.stylesheet
35
35
 
36
36
  # at this point, we really DO need the orientation
37
- orientation = UIApplication.sharedApplication.statusBarOrientation unless orientation
37
+ unless orientation
38
+ orientation = UIApplication.sharedApplication.statusBarOrientation
39
+ end
38
40
 
39
41
  # first, move orientation settings into properties "base" level.
40
42
  if orientation
@@ -43,10 +45,8 @@ module Teacup
43
45
  # override is first, so it takes precedence
44
46
  if override.is_a? Hash
45
47
  Teacup::merge_defaults override, properties, properties
46
- elsif not properties.has_key? orientation_key
47
- properties[orientation_key] = override
48
48
  end
49
- properties.supports[orientation_key] = properties[orientation_key] ? true : false
49
+ properties.supports[orientation_key] = !!override
50
50
  end
51
51
  end
52
52
  end
@@ -1,5 +1,5 @@
1
1
  module Teacup
2
2
 
3
- VERSION = '0.3.10'
3
+ VERSION = '0.3.11'
4
4
 
5
5
  end
@@ -16,7 +16,7 @@ class UIView
16
16
  # is loaded lazily, so that assignment can occur before the Stylesheet has
17
17
  # been created.
18
18
  def stylesheet
19
- if Symbol === @stylesheet
19
+ if @stylesheet.is_a? Symbol
20
20
  @stylesheet = Teacup::Stylesheet[@stylesheet]
21
21
  end
22
22
 
@@ -30,7 +30,7 @@ class UIView
30
30
  # @param Symbol stylename
31
31
  def stylename=(new_stylename)
32
32
  @stylename = new_stylename
33
- restyle!
33
+ restyle! if Teacup.should_restyle?
34
34
  end
35
35
 
36
36
  # Alter the stylesheet of this view.
@@ -44,14 +44,29 @@ class UIView
44
44
  #
45
45
  # @param Teacup::Stylesheet stylesheet.
46
46
  def stylesheet=(new_stylesheet)
47
+ should_restyle = Teacup.should_restyle_and_block
48
+
47
49
  @stylesheet = new_stylesheet
48
- restyle!
49
- subviews.each{ |subview| subview.stylesheet = new_stylesheet }
50
+ subviews.each{ |subview| subview.set_stylesheet_quickly(new_stylesheet) }
51
+
52
+ if should_restyle
53
+ restyle!
54
+ Teacup.should_restyle!
55
+ end
56
+ end
57
+
58
+ def set_stylesheet_quickly(new_stylesheet)
59
+ @stylesheet = new_stylesheet
60
+ subviews.each{ |subview| subview.set_stylesheet_quickly(new_stylesheet) }
50
61
  end
51
62
 
52
63
  def restyle!(orientation=nil)
53
- style(stylesheet.query(stylename, self, orientation)) if stylesheet
54
- subviews.each{ |subview| subview.restyle!(orientation) }
64
+ if Teacup.should_restyle?
65
+ if stylesheet
66
+ style(stylesheet.query(stylename, self, orientation))
67
+ end
68
+ subviews.each{ |subview| subview.restyle!(orientation) }
69
+ end
55
70
  end
56
71
 
57
72
  # Animate a change to a new stylename.
@@ -66,8 +66,8 @@ class UIViewController
66
66
  # @example
67
67
  #
68
68
  # def stylesheet
69
- # if [UIDeviceOrientationLandscapeLeft,
70
- # UIDeviceOrientationLandscapeRight].include?(UIDevice.currentDevice.orientation)
69
+ # if [UIInterfaceOrientationLandscapeLeft,
70
+ # UIInterfaceOrientationLandscapeRight].include?(UIInterface.currentDevice.orientation)
71
71
  # Teacup::Stylesheet[:ipad]
72
72
  # else
73
73
  # Teacup::Stylesheet[:ipadvertical]
@@ -93,9 +93,8 @@ class UIViewController
93
93
  # stylesheet = :ipadhorizontal
94
94
  def stylesheet=(new_stylesheet)
95
95
  @stylesheet = new_stylesheet
96
- if view
97
- view.stylesheet = new_stylesheet
98
- view.restyle!
96
+ if self.view
97
+ self.view.stylesheet = new_stylesheet
99
98
  end
100
99
  end
101
100
 
@@ -109,12 +108,27 @@ class UIViewController
109
108
  # If you want to use Teacup in your controller, please hook into layoutDidLoad,
110
109
  # not viewDidLoad.
111
110
  def viewDidLoad
112
- if not self.stylesheet
113
- self.stylesheet = self.class.stylesheet
111
+ # look for a layout_definition in the list of ancestors
112
+ layout_definition = nil
113
+ my_stylesheet = self.stylesheet
114
+ parent_class = self.class
115
+ while parent_class != NSObject and not (layout_definition && my_stylesheet)
116
+ if not my_stylesheet and parent_class.respond_to?(:stylesheet)
117
+ my_stylesheet = parent_class.stylesheet
118
+ end
119
+
120
+ if not layout_definition and parent_class.respond_to?(:layout_definition)
121
+ layout_definition = parent_class.layout_definition
122
+ end
123
+ parent_class = parent_class.superclass
124
+ end
125
+
126
+ if my_stylesheet and not self.stylesheet
127
+ self.stylesheet = my_stylesheet
114
128
  end
115
129
 
116
- if self.class.layout_definition
117
- stylename, properties, block = self.class.layout_definition
130
+ if layout_definition
131
+ stylename, properties, block = layout_definition
118
132
  layout(view, stylename, properties, &block)
119
133
  end
120
134
 
@@ -1,69 +1,87 @@
1
1
  ##|
2
2
  ##| UIView.frame
3
3
  ##|
4
- Teacup.handler UIView, :left, :x { |view, x|
5
- f = view.frame
4
+ Teacup.handler UIView, :left, :x { |x|
5
+ f = self.frame
6
6
  f.origin.x = x
7
- view.frame = f
7
+ self.frame = f
8
8
  }
9
9
 
10
- Teacup.handler UIView, :right { |view, r|
11
- f = view.frame
10
+ Teacup.handler UIView, :right { |r|
11
+ f = self.frame
12
12
  f.origin.x = r - f.size.width
13
- view.frame = f
13
+ self.frame = f
14
14
  }
15
15
 
16
- Teacup.handler UIView, :center_x, :middle_x { |view, x|
17
- c = view.center
16
+ Teacup.handler UIView, :center_x, :middle_x { |x|
17
+ c = self.center
18
18
  c.x = x
19
- view.center = c
19
+ self.center = c
20
20
  }
21
21
 
22
- Teacup.handler UIView, :top, :y { |view, y|
23
- f = view.frame
22
+ Teacup.handler UIView, :top, :y { |y|
23
+ f = self.frame
24
24
  f.origin.y = y
25
- view.frame = f
25
+ self.frame = f
26
26
  }
27
27
 
28
- Teacup.handler UIView, :bottom { |view, b|
29
- f = view.frame
28
+ Teacup.handler UIView, :bottom { |b|
29
+ f = self.frame
30
30
  f.origin.y = b - f.size.height
31
- view.frame = f
31
+ self.frame = f
32
32
  }
33
33
 
34
- Teacup.handler UIView, :center_y, :middle_y { |view, y|
35
- c = view.center
34
+ Teacup.handler UIView, :center_y, :middle_y { |y|
35
+ c = self.center
36
36
  c.y = y
37
- view.center = c
37
+ self.center = c
38
38
  }
39
39
 
40
- Teacup.handler UIView, :width { |view, w|
41
- f = view.frame
40
+ Teacup.handler UIView, :width { |w|
41
+ f = self.frame
42
42
  f.size.width = w
43
- view.frame = f
43
+ self.frame = f
44
44
  }
45
45
 
46
- Teacup.handler UIView, :height { |view, h|
47
- f = view.frame
46
+ Teacup.handler UIView, :height { |h|
47
+ f = self.frame
48
48
  f.size.height = h
49
- view.frame = f
49
+ self.frame = f
50
50
  }
51
51
 
52
- Teacup.handler UIView, :origin { |view, origin|
53
- f = view.frame
52
+ Teacup.handler UIView, :origin { |origin|
53
+ f = self.frame
54
54
  f.origin = origin
55
- view.frame = f
55
+ self.frame = f
56
56
  }
57
57
 
58
- Teacup.handler UIView, :size { |view, size|
59
- f = view.frame
58
+ Teacup.handler UIView, :size { |size|
59
+ if Symbol === size && size == :full
60
+ if self.superview
61
+ size = Size(self.superview.bounds.size)
62
+ else
63
+ size = self.frame.size
64
+ end
65
+ end
66
+ f = self.frame
60
67
  f.size = size
61
- view.frame = f
68
+ self.frame = f
69
+ }
70
+
71
+ Teacup.handler UIView, :frame { |frame|
72
+ if Symbol === frame && frame == :full
73
+ if self.superview
74
+ frame = Rect(self.superview.bounds)
75
+ else
76
+ frame = self.frame
77
+ end
78
+ end
79
+ self.frame = frame
62
80
  }
63
81
 
64
82
  ##|
65
83
  ##| UIButton
66
84
  ##|
67
- Teacup.handler UIButton, :title { |view, title|
68
- view.setTitle(title, forState: UIControlStateNormal)
85
+ Teacup.handler UIButton, :title { |title|
86
+ self.setTitle(title, forState: UIControlStateNormal)
69
87
  }
data/spec/main_spec.rb CHANGED
@@ -22,10 +22,10 @@ describe "Application 'Teacup'" do
22
22
  describe "view controller" do
23
23
 
24
24
  it "should be able to rotate" do
25
- @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIDeviceOrientationPortrait).should == true
26
- @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIDeviceOrientationLandscapeLeft).should == true
27
- @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIDeviceOrientationLandscapeRight).should == true
28
- @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIDeviceOrientationPortraitUpsideDown).should == false
25
+ @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIInterfaceOrientationPortrait).should == true
26
+ @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIInterfaceOrientationLandscapeRight).should == true
27
+ @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIInterfaceOrientationLandscapeLeft).should == true
28
+ @view_ctrlr.shouldAutorotateToInterfaceOrientation(UIInterfaceOrientationPortraitUpsideDown).should == nil
29
29
  end
30
30
  end
31
31
 
@@ -131,7 +131,7 @@ describe "Application 'Teacup'" do
131
131
  before do
132
132
  @background = @app.windows[0].subviews[0].subviews[0]
133
133
  @view_ctrlr.landscape_only
134
- UIApplication.sharedApplication.setStatusBarOrientation(UIDeviceOrientationLandscapeLeft, animated:false)
134
+ UIApplication.sharedApplication.setStatusBarOrientation(UIInterfaceOrientationLandscapeLeft, animated:false)
135
135
  end
136
136
 
137
137
  it "should be in landscape" do
data/spec/style_spec.rb CHANGED
@@ -23,7 +23,11 @@ describe "Teacup::Style" do
23
23
  name: :upside_down_name,
24
24
  }
25
25
  # no orientation, which ends up being portrait anyway.
26
- style.build()[:name].should == :portrait_name
26
+ if UIApplication.sharedApplication.statusBarOrientation == UIInterfaceOrientationPortrait
27
+ style.build()[:name].should == :portrait_name
28
+ else
29
+ style.build()[:name].should == :landscape_name
30
+ end
27
31
  # landscape
28
32
  style.build(nil, UIInterfaceOrientationLandscapeLeft)[:name].should == :landscape_name
29
33
 
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: 0.3.10
4
+ version: 0.3.11
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000 Z
12
+ date: 2012-09-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70310569785840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
24
+ version_requirements: *70310569785840
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: rspec
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70310569785180 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,12 +32,7 @@ dependencies:
37
32
  version: '0'
38
33
  type: :development
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
35
+ version_requirements: *70310569785180
46
36
  description: ! 'Teacup is a community-driven DSL for making CSS-like styling, and
47
37
  layouts for
48
38
 
@@ -78,6 +68,7 @@ files:
78
68
  - lib/teacup/handler.rb
79
69
  - lib/teacup/layout.rb
80
70
  - lib/teacup/merge_defaults.rb
71
+ - lib/teacup/restyle.rb
81
72
  - lib/teacup/style.rb
82
73
  - lib/teacup/stylesheet.rb
83
74
  - lib/teacup/stylesheet_extensions/rotation.rb
@@ -121,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
112
  version: '0'
122
113
  requirements: []
123
114
  rubyforge_project:
124
- rubygems_version: 1.8.19
115
+ rubygems_version: 1.8.11
125
116
  signing_key:
126
117
  specification_version: 3
127
118
  summary: A community-driven DSL for creating user interfaces on iOS.