teacup 1.2.9 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +2 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +4 -2
- data/README.md +3 -0
- data/app/app_delegate.rb +2 -1
- data/app/controllers/present_modal_controller.rb +96 -0
- data/lib/teacup/calculations.rb +12 -8
- data/lib/teacup/constraint.rb +3 -0
- data/lib/teacup/stylesheet.rb +27 -1
- data/lib/teacup/version.rb +1 -1
- data/lib/teacup/z_core_extensions/ui_view.rb +4 -1
- data/lib/teacup/z_core_extensions/ui_view_getters.rb +6 -3
- data/resources/Default-568h@2x.png +0 -0
- data/spec/calculations_spec.rb +55 -0
- data/spec/styling_modal_spec.rb +11 -0
- metadata +9 -3
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
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
|
-
|
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
|
data/lib/teacup/calculations.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
module Teacup
|
2
2
|
module_function
|
3
|
-
def calculate(view, dimension,
|
4
|
-
if
|
5
|
-
view.instance_exec(&
|
6
|
-
elsif
|
7
|
-
|
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
|
-
|
20
|
+
amount
|
17
21
|
end
|
18
22
|
end
|
19
23
|
end
|
data/lib/teacup/constraint.rb
CHANGED
data/lib/teacup/stylesheet.rb
CHANGED
@@ -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
|
-
|
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
|
#
|
data/lib/teacup/version.rb
CHANGED
@@ -48,9 +48,12 @@ class UIView
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def stylesheet
|
51
|
-
|
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?
|
41
|
-
|
42
|
-
|
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
|
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.
|
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-
|
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:
|