teacup 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- teacup (1.3.1)
4
+ teacup (1.3.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -20,6 +20,10 @@ to create interfaces programmatically.
20
20
  ```bash
21
21
  > gem install teacup
22
22
  ```
23
+ and in your Rakefile
24
+ ```ruby
25
+ require 'teacup'
26
+ ```
23
27
 
24
28
  **Better Install**
25
29
 
@@ -55,7 +59,7 @@ gems on a per-project basis, using a gemset. See the
55
59
  end
56
60
  end
57
61
  ```
58
- 4. Create the stylesheet
62
+ 4. Create the stylesheet (Usually in app/styles/)
59
63
 
60
64
  ```ruby
61
65
  Teacup::Stylesheet.new :main_screen do
@@ -1,5 +1,5 @@
1
1
  module Teacup
2
2
 
3
- VERSION = '1.3.2'
3
+ VERSION = '1.3.3'
4
4
 
5
5
  end
@@ -18,21 +18,30 @@ class UIView
18
18
  view = subviews.find { |subview| found_subview = subview.viewWithStylename(name_or_class) }
19
19
  return found_subview if view
20
20
 
21
- nil # couldn't find it
21
+ return nil # couldn't find it
22
22
  end
23
23
 
24
24
  # get all subviews by stylename or class
25
25
  # my_view.viewsWithStylename :button => [#<UIButton..>, #<UIButton...>]
26
26
  # my_view.viewsWithStylename UIButton => [#<UIButton..>, #<UIButton...>]
27
27
  def viewsWithStylename name_or_class
28
- r = []
29
- r << self if self._teacup_check_stylename(name_or_class)
30
-
31
- subviews.each do |view|
32
- r << view if view._teacup_check_stylename(name_or_class)
33
- r.concat view.viewsWithStylename name_or_class
28
+ retval = []
29
+ retval << self if self._teacup_check_stylename(name_or_class)
30
+
31
+ search_views = [].concat(self.subviews)
32
+ # ewww, a traditional for loop! the search_views array is modified in place,
33
+ # and `each` and other methods don't like that.
34
+ index = 0
35
+ while index < search_views.length
36
+ view = search_views[index]
37
+ if view._teacup_check_stylename(name_or_class)
38
+ retval << view
39
+ end
40
+ search_views.concat(view.subviews)
41
+ index += 1
34
42
  end
35
- r
43
+
44
+ return retval
36
45
  end
37
46
 
38
47
  def _teacup_check_stylename(name_or_class)
@@ -49,12 +49,28 @@ Teacup.handler UIView, :height { |target, h|
49
49
  target.frame = f
50
50
  }
51
51
 
52
+ Teacup.handler UIView, :size { |target, size|
53
+ f = target.frame
54
+ size_x = Teacup::calculate(target, :width, size[0])
55
+ size_y = Teacup::calculate(target, :height, size[1])
56
+ f.size = [size_x, size_y]
57
+ target.frame = f
58
+ }
59
+
52
60
  Teacup.handler UIView, :origin { |target, origin|
53
61
  f = target.frame
54
- f.origin = origin
62
+ origin_x = Teacup::calculate(target, :width, origin[0])
63
+ origin_y = Teacup::calculate(target, :height, origin[1])
64
+ f.origin = [origin_x, origin_y]
55
65
  target.frame = f
56
66
  }
57
67
 
68
+ Teacup.handler UIView, :center { |target, center|
69
+ center_x = Teacup::calculate(target, :width, center[0])
70
+ center_y = Teacup::calculate(target, :height, center[1])
71
+ target.center = [center_x, center_y]
72
+ }
73
+
58
74
  Teacup.handler UIView, :size { |target, size|
59
75
  # odd... if I changed these to .is_a?, weird errors happen. Use ===
60
76
  if Symbol === size && size == :full
@@ -9,5 +9,5 @@ Motion::Project::App.setup do |app|
9
9
  app.name = 'AutoLayout'
10
10
 
11
11
  #include styles
12
- app.files += Dir.glob(File.join(app.project_dir, 'styles/**/*.rb'))
12
+ app.files += Dir.glob(File.join(app.project_dir, 'lib/**/*.rb'))
13
13
  end
@@ -1,13 +1,11 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- teacup (0.3.2)
5
- rake
4
+ teacup (1.3.2)
6
5
 
7
6
  GEM
8
7
  remote: http://rubygems.org/
9
8
  specs:
10
- rake (0.9.2.2)
11
9
 
12
10
  PLATFORMS
13
11
  ruby
@@ -9,5 +9,4 @@ Motion::Project::App.setup do |app|
9
9
  app.identifier = 'com.rubymotion.Hai'
10
10
 
11
11
  app.device_family = :iphone
12
- app.files += Dir.glob(File.join(app.project_dir, 'styles/**/*.rb'))
13
12
  end
@@ -0,0 +1,68 @@
1
+ describe "UIView getters" do
2
+
3
+ before do
4
+ stylesheet1 = Teacup::Stylesheet.new do
5
+ style :parent_style
6
+ end
7
+ stylesheet2 = Teacup::Stylesheet.new do
8
+ import stylesheet1
9
+ style :extended_style, extends: :parent_style
10
+ end
11
+
12
+ @view = UIView.new.tap do |view|
13
+ @some_view = view.subview(UIView, :some_view)
14
+ @extended_style = view.subview(UIView, :extended_style)
15
+ container = view.subview(UIView)
16
+ @label1 = container.subview(UILabel)
17
+ @label2 = container.subview(UILabel)
18
+ @label3 = container.subview(UILabel)
19
+ @stylename1 = view.subview(UIView, :stylename)
20
+ @stylename2 = view.subview(UIView, :stylename)
21
+ @stylename3 = view.subview(UIView, :stylename)
22
+ container = view.subview(UIView)
23
+ @button = container.subview(UIButton)
24
+ end
25
+ @view.stylesheet = stylesheet2
26
+ @view.stylename = :self_style
27
+ end
28
+
29
+ describe "viewWithStylename" do
30
+ it "should return based on stylename" do
31
+ @view.viewWithStylename(:some_view).should == @some_view
32
+ end
33
+
34
+ it "should return self based on stylename" do
35
+ @view.viewWithStylename(:self_style).should == @view
36
+ end
37
+
38
+ it "should return based on class" do
39
+ @view.viewWithStylename(UIButton).should == @button
40
+ end
41
+
42
+ it "should return based on extended stylename" do
43
+ @view.viewWithStylename(:extended_style).should == @extended_style
44
+ @view.viewWithStylename(:parent_style).should == @extended_style
45
+ end
46
+
47
+ it "should nil when there is no match" do
48
+ @view.viewWithStylename(:this_is_not_a_stylename).should == nil
49
+ @view.viewWithStylename(UITableView).should == nil
50
+ end
51
+ end
52
+
53
+ describe "viewsWithStylename" do
54
+ it "should return based on stylename" do
55
+ @view.viewsWithStylename(:stylename).should == [@stylename1, @stylename2, @stylename3]
56
+ end
57
+
58
+ it "should return based on class" do
59
+ @view.viewsWithStylename(UILabel).should == [@label1, @label2, @label3]
60
+ end
61
+
62
+ it "should [] when there is no match" do
63
+ @view.viewsWithStylename(:this_is_not_a_stylename).should == []
64
+ @view.viewsWithStylename(UITableView).should == []
65
+ end
66
+ end
67
+
68
+ 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.3.2
4
+ version: 1.3.3
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-10 00:00:00.000000000 Z
12
+ date: 2013-04-15 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
@@ -72,19 +72,18 @@ files:
72
72
  - samples/AutoLayout/Rakefile
73
73
  - samples/AutoLayout/app/app_delegate.rb
74
74
  - samples/AutoLayout/app/root_controller.rb
75
- - samples/AutoLayout/styles/base.rb
76
- - samples/AutoLayout/styles/dummy.rb
77
- - samples/AutoLayout/styles/handlers.rb
78
- - samples/AutoLayout/styles/root.rb
79
- - samples/AutoLayout/styles/settings.rb
75
+ - samples/AutoLayout/app/styles/root.rb
76
+ - samples/AutoLayout/lib/dummy.rb
77
+ - samples/AutoLayout/lib/handlers.rb
78
+ - samples/AutoLayout/lib/styles/base.rb
80
79
  - samples/Hai/.gitignore
81
80
  - samples/Hai/Gemfile
82
81
  - samples/Hai/Gemfile.lock
83
82
  - samples/Hai/Rakefile
84
83
  - samples/Hai/app/app_delegate.rb
85
84
  - samples/Hai/app/hai_controller.rb
85
+ - samples/Hai/app/styles/iphone.rb
86
86
  - samples/Hai/spec/main_spec.rb
87
- - samples/Hai/styles/iphone.rb
88
87
  - samples/OnePage/Gemfile
89
88
  - samples/OnePage/Rakefile
90
89
  - samples/OnePage/app/app_delegate.rb
@@ -99,6 +98,7 @@ files:
99
98
  - spec/present_modal_spec.rb
100
99
  - spec/style_spec.rb
101
100
  - spec/stylesheet_spec.rb
101
+ - spec/ui_view_getters_spec.rb
102
102
  - spec/uiswitch_spec.rb
103
103
  - spec/view_spec.rb
104
104
  - teacup.gemspec
@@ -135,5 +135,6 @@ test_files:
135
135
  - spec/present_modal_spec.rb
136
136
  - spec/style_spec.rb
137
137
  - spec/stylesheet_spec.rb
138
+ - spec/ui_view_getters_spec.rb
138
139
  - spec/uiswitch_spec.rb
139
140
  - spec/view_spec.rb
@@ -1,13 +0,0 @@
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