teacup 1.2.9 → 1.3.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/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ language: objective-c
2
+ before_install: rvm use 1.9.3
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
- gem 'teacup', :path => '.'
3
+ gem 'rake'
4
4
 
5
5
  gemspec
data/Gemfile.lock CHANGED
@@ -1,14 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- teacup (1.2.8)
4
+ teacup (1.3.0)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
+ rake (10.0.3)
9
10
 
10
11
  PLATFORMS
11
12
  ruby
12
13
 
13
14
  DEPENDENCIES
15
+ rake
14
16
  teacup!
data/README.md CHANGED
@@ -3,6 +3,9 @@ Teacup
3
3
 
4
4
  A community-driven DSL for creating user interfaces on the iphone.
5
5
 
6
+ **Note: for a yet-unknown reason teacup does not compile correctly using ruby
7
+ 2.0. Use 1.9.3 instead please, or help determine what is wrong with 2.0.**
8
+
6
9
  Using teacup, you can easily create and style layouts while keeping your code
7
10
  dry. The goal is to offer a rubyesque (well, actually a rubymotion-esque) way
8
11
  to create interfaces programmatically.
data/app/app_delegate.rb CHANGED
@@ -6,7 +6,8 @@ class AppDelegate
6
6
  application.setStatusBarHidden(true, withAnimation:UIStatusBarAnimationSlide)
7
7
 
8
8
  @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
9
- @window.rootViewController = FirstController.new
9
+ ctlr = PresentModalController.new
10
+ @window.rootViewController = UINavigationController.alloc.initWithRootViewController(ctlr)
10
11
  @window.rootViewController.wantsFullScreenLayout = true
11
12
  @window.makeKeyAndVisible
12
13
 
@@ -0,0 +1,96 @@
1
+ class PresentModalController < UIViewController
2
+
3
+ stylesheet :present_modal
4
+
5
+ layout :root do
6
+ @button = subview(UIButton.buttonWithType(UIButtonTypeRoundedRect), :open_modal_button)
7
+ @button.addTarget(self, action: :open_modal_button, forControlEvents:UIControlEventTouchUpInside)
8
+ end
9
+
10
+ def open_modal_button
11
+ self.presentViewController(PresentedController.new, animated:true, completion:nil)
12
+ end
13
+
14
+ end
15
+
16
+ class PresentedController < UIViewController
17
+
18
+ stylesheet :present_modal
19
+
20
+ layout :root do
21
+ subview(UIView, :header)
22
+ subview(UIView, :footer)
23
+ subview(UIView, :center) do
24
+ $left = subview(UIView, :left)
25
+ $top_right = subview(UIView, :top_right)
26
+ $btm_right = subview(UIView, :btm_right)
27
+ end
28
+ end
29
+
30
+ end
31
+
32
+
33
+ Teacup::Stylesheet.new :present_modal do
34
+
35
+ style :root,
36
+ backgroundColor: UIColor.blackColor
37
+
38
+ style :open_modal_button,
39
+ title: 'Open Modal',
40
+ constraints: [
41
+ :centered
42
+ ]
43
+
44
+ style :header,
45
+ backgroundColor: UIColor.blueColor,
46
+ constraints: [
47
+ :full_width,
48
+ :top,
49
+ constrain_height(52),
50
+ ]
51
+
52
+ style :footer,
53
+ backgroundColor: UIColor.magentaColor,
54
+ constraints: [
55
+ :full_width,
56
+ :bottom,
57
+ constrain_height(52),
58
+ ]
59
+
60
+ style :center,
61
+ backgroundColor: UIColor.lightGrayColor,
62
+ constraints: [
63
+ constrain_below(:header).plus(8),
64
+ constrain_above(:footer).minus(8),
65
+ constrain_left(8),
66
+ constrain_right(-8),
67
+ ]
68
+
69
+ style :left,
70
+ backgroundColor: UIColor.redColor,
71
+ constraints: [
72
+ constrain_left(8),
73
+ constrain_top(8),
74
+ constrain(:right).plus(8).equals(:top_right, :left),
75
+ constrain(:right).plus(8).equals(:btm_right, :left),
76
+ constrain_bottom(-8),
77
+ constrain(:width).equals(:top_right, :width),
78
+ constrain(:width).equals(:btm_right, :width),
79
+ ]
80
+
81
+ style :top_right,
82
+ backgroundColor: UIColor.greenColor,
83
+ constraints: [
84
+ constrain(:top).equals(:left, :top),
85
+ constrain_right(-8),
86
+ constrain(:height).equals(:btm_right, :height),
87
+ constrain(:bottom).plus(8).equals(:btm_right, :top),
88
+ ]
89
+
90
+ style :btm_right,
91
+ backgroundColor: UIColor.yellowColor,
92
+ constraints: [
93
+ constrain(:bottom).equals(:left, :bottom),
94
+ ]
95
+
96
+ end
@@ -1,19 +1,23 @@
1
1
  module Teacup
2
2
  module_function
3
- def calculate(view, dimension, percent)
4
- if percent.is_a? Proc
5
- view.instance_exec(&percent)
6
- elsif percent.is_a? String and percent[-1] == '%'
7
- percent = percent[0...-1].to_f / 100.0
3
+ def calculate(view, dimension, amount)
4
+ if amount.is_a? Proc
5
+ view.instance_exec(&amount)
6
+ elsif amount.is_a?(String) && amount.include?('%')
7
+ location = amount.index '%'
8
+ offset = amount[(location+1)..-1].gsub(' ', '').to_f
9
+ percent = amount[0...location].to_f / 100.0
8
10
 
9
11
  case dimension
10
12
  when :width
11
- CGRectGetWidth(view.superview.bounds) * percent
13
+ CGRectGetWidth(view.superview.bounds) * percent + offset
12
14
  when :height
13
- CGRectGetHeight(view.superview.bounds) * percent
15
+ CGRectGetHeight(view.superview.bounds) * percent + offset
16
+ else
17
+ raise "Unknown dimension #{dimension}"
14
18
  end
15
19
  else
16
- percent
20
+ amount
17
21
  end
18
22
  end
19
23
  end
@@ -169,6 +169,9 @@ module Teacup
169
169
  end
170
170
 
171
171
  def plus(constant)
172
+ if not self.relationship
173
+ constant = -constant
174
+ end
172
175
  self.constant += constant
173
176
  self
174
177
  end
@@ -131,10 +131,12 @@ module Teacup
131
131
  end
132
132
 
133
133
  def get_stylesheet_cache(stylename, target, orientation)
134
+ orientation ||= UIApplication.sharedApplication.statusBarOrientation
134
135
  stylesheet_cache[stylename][target][orientation]
135
136
  end
136
137
 
137
138
  def set_stylesheet_cache(stylename, target, orientation, value)
139
+ orientation ||= UIApplication.sharedApplication.statusBarOrientation
138
140
  self.stylesheet_cache[stylename][target][orientation] = value
139
141
  end
140
142
 
@@ -255,7 +257,31 @@ module Teacup
255
257
  end
256
258
  end
257
259
 
258
- protected
260
+ # In the [rare] case you need to know whether the style extends another
261
+ # style, this method will find out quickly. This is mostly useful in the
262
+ # `UIView#viewWithStylename` method.
263
+ def extends_style?(stylename, extended_name, checked=[])
264
+ return true if stylename == extended_name
265
+
266
+ extended_style_names = styles[stylename][:extends]
267
+ return false unless extended_style_names
268
+
269
+ extended_style_names = [extended_style_names] unless extended_style_names.is_a? Array
270
+ return true if extended_style_names.any? { |name| name == extended_name }
271
+ retval = false
272
+ extended_style_names.each do |recusive_check|
273
+ next if checked.include?(recusive_check)
274
+
275
+ checked << recusive_check
276
+ if extends_style?(recusive_check, extended_name, checked)
277
+ retval = true
278
+ break
279
+ end
280
+ end
281
+ return retval
282
+ end
283
+
284
+ protected
259
285
 
260
286
  # The list of Stylesheets or names that have been imported into this one.
261
287
  #
@@ -1,5 +1,5 @@
1
1
  module Teacup
2
2
 
3
- VERSION = '1.2.9'
3
+ VERSION = '1.3.0'
4
4
 
5
5
  end
@@ -48,9 +48,12 @@ class UIView
48
48
  end
49
49
 
50
50
  def stylesheet
51
- super
51
+ if @stylesheet.is_a? Symbol
52
+ @stylesheet = Teacup::Stylesheet[@stylesheet]
53
+ end
52
54
  # is a stylesheet assigned explicitly?
53
55
  retval = @stylesheet
56
+ return retval if retval
54
57
 
55
58
  # the 'teacup_next_responder' is assigned in the `layout` method, and links
56
59
  # any views created there to the custom class (could be a controller, could
@@ -37,10 +37,13 @@ class UIView
37
37
 
38
38
  def _teacup_check_stylename(name_or_class)
39
39
  if name_or_class.is_a? Class
40
- self.is_a? name_or_class
41
- else
42
- self.stylename == name_or_class
40
+ return self.is_a?(name_or_class)
41
+ elsif stylename == name_or_class
42
+ return true
43
+ elsif stylesheet.is_a?(Teacup::Stylesheet)
44
+ return stylesheet.extends_style?(self.stylename, name_or_class)
43
45
  end
46
+ return false
44
47
  end
45
48
 
46
49
  end
Binary file
@@ -0,0 +1,55 @@
1
+ class Viewish
2
+ def superview
3
+ @superview ||= Viewish.new
4
+ end
5
+
6
+ def bounds
7
+ CGRect.new([0, 0,], [100, 44])
8
+ end
9
+ end
10
+
11
+
12
+ describe 'Teacup.calculate' do
13
+
14
+ it 'should return static numbers' do
15
+ Teacup.calculate(nil, nil, 1).should == 1
16
+ end
17
+
18
+ it 'should call blocks' do
19
+ a = 'hi!'
20
+ Teacup.calculate(a, nil, ->{
21
+ self.should == a
22
+ 2
23
+ }).should == 2
24
+ end
25
+
26
+ it 'should return percents with :width' do
27
+ Teacup.calculate(Viewish.new, :width, '50%').should == 50
28
+ end
29
+
30
+ it 'should return percents with :height' do
31
+ Teacup.calculate(Viewish.new, :height, '50%').should == 22
32
+ end
33
+
34
+ describe 'should return percents with offset' do
35
+ it ':width, 50% + 10' do
36
+ Teacup.calculate(Viewish.new, :width, '50% + 10').should == 60
37
+ end
38
+ it ':width, 50% - 10' do
39
+ Teacup.calculate(Viewish.new, :width, '50% - 10').should == 40
40
+ end
41
+ it ':width, 25% + 5' do
42
+ Teacup.calculate(Viewish.new, :width, '25% + 5').should == 30
43
+ end
44
+ it ':height, 50% + 10' do
45
+ Teacup.calculate(Viewish.new, :height, '50% + 10').should == 32
46
+ end
47
+ it ':height, 50% - 10' do
48
+ Teacup.calculate(Viewish.new, :height, '50% - 10').should == 12
49
+ end
50
+ it ':height, 25% + 5' do
51
+ Teacup.calculate(Viewish.new, :height, '25% + 5').should == 16
52
+ end
53
+ end
54
+
55
+ end
@@ -0,0 +1,11 @@
1
+ describe 'Styling a modal view' do
2
+ tests PresentModalController
3
+
4
+ it 'should open a modal' do
5
+ tap 'Open Modal'
6
+ wait 10 {
7
+ 1.should == 1
8
+ }
9
+ end
10
+
11
+ 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.9
4
+ version: 1.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-03 00:00:00.000000000 Z
12
+ date: 2013-04-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Teacup is a community-driven DSL for making CSS-like styling, and
15
15
  layouts for
@@ -28,6 +28,7 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
  files:
30
30
  - .gitignore
31
+ - .travis.yml
31
32
  - CHANGES.md
32
33
  - Gemfile
33
34
  - Gemfile.lock
@@ -38,6 +39,7 @@ files:
38
39
  - app/controllers/first_controller.rb
39
40
  - app/controllers/gradient_controller.rb
40
41
  - app/controllers/landscape_only_controller.rb
42
+ - app/controllers/present_modal_controller.rb
41
43
  - app/controllers/tableview_controller.rb
42
44
  - app/custom_class.rb
43
45
  - app/styles/main_styles.rb
@@ -63,6 +65,7 @@ files:
63
65
  - lib/teacup/z_core_extensions/ui_view_controller.rb
64
66
  - lib/teacup/z_core_extensions/ui_view_getters.rb
65
67
  - lib/teacup/z_core_extensions/z_handlers.rb
68
+ - resources/Default-568h@2x.png
66
69
  - samples/AutoLayout/Gemfile
67
70
  - samples/AutoLayout/Gemfile.lock
68
71
  - samples/AutoLayout/Rakefile
@@ -88,11 +91,13 @@ files:
88
91
  - samples/OnePage/resources/you_didnt_see_this
89
92
  - samples/OnePage/spec/main_spec.rb
90
93
  - samples/README.md
94
+ - spec/calculations_spec.rb
91
95
  - spec/custom_class_spec.rb
92
96
  - spec/gradient_spec.rb
93
97
  - spec/main_spec.rb
94
98
  - spec/style_spec.rb
95
99
  - spec/stylesheet_spec.rb
100
+ - spec/styling_modal_spec.rb
96
101
  - spec/uiswitch_spec.rb
97
102
  - spec/view_spec.rb
98
103
  - teacup.gemspec
@@ -121,11 +126,12 @@ signing_key:
121
126
  specification_version: 3
122
127
  summary: A community-driven DSL for creating user interfaces on iOS.
123
128
  test_files:
129
+ - spec/calculations_spec.rb
124
130
  - spec/custom_class_spec.rb
125
131
  - spec/gradient_spec.rb
126
132
  - spec/main_spec.rb
127
133
  - spec/style_spec.rb
128
134
  - spec/stylesheet_spec.rb
135
+ - spec/styling_modal_spec.rb
129
136
  - spec/uiswitch_spec.rb
130
137
  - spec/view_spec.rb
131
- has_rdoc: