ruby_motion_query 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,45 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
+ # @return [Color]
3
4
  def self.color
4
5
  Color
5
6
  end
6
7
 
8
+ # @return [Color]
7
9
  def color
8
10
  Color
9
11
  end
10
12
  end
11
13
 
14
+ # @example
15
+ # # Standard colors:
16
+ #
17
+ # # In a stylesheet, you can just use color. Anywhere else these would be
18
+ # # rmq.color.clear, etc
19
+ #
20
+ # color.clear
21
+ # color.white
22
+ # color.light_gray
23
+ # color.gray
24
+ # color.dark_gray
25
+ # color.black
26
+ #
27
+ # color.red
28
+ # color.green
29
+ # color.blue
30
+ # color.yellow
31
+ # color.orange
32
+ # color.purple
33
+ # color.brown
34
+ # color.cyan
35
+ # color.magenta
36
+ #
37
+ # color.table_view
38
+ # color.scroll_view
39
+ # color.flipside
40
+ # color.under_page
41
+ # color.light_text
42
+ # color.dark_text
12
43
  class Color < UIColor
13
44
 
14
45
  class << self
@@ -36,6 +67,13 @@ module RubyMotionQuery
36
67
  alias :light_text :lightTextColor
37
68
  alias :dark_text :darkTextColor
38
69
 
70
+ # Add your own standard color
71
+ #
72
+ # @return [UIColor]
73
+ #
74
+ # @example
75
+ # rmq.color.add_named(:foo, '#ffffff')
76
+ # my_label.color = rmq.color.foo # or just color.foo in a stylesheet
39
77
  def add_named(key, hex_or_color)
40
78
  color = if hex_or_color.is_a?(String)
41
79
  Color.from_hex(hex_or_color)
@@ -48,7 +86,15 @@ module RubyMotionQuery
48
86
  end
49
87
  end
50
88
 
89
+ # Creates a color from a hex triplet
90
+ #
51
91
  # Thanks bubblewrap for this method
92
+ #
93
+ # @param hex with or without the #
94
+ # @return [UIColor]
95
+ # @example
96
+ # color.from_hex('#ffffff')
97
+ # color.from_hex('ffffff')
52
98
  def from_hex(hex_color)
53
99
  hex_color.gsub!("#", "")
54
100
  case hex_color.size
@@ -66,10 +112,18 @@ module RubyMotionQuery
66
112
  end
67
113
  end
68
114
 
115
+ # @return [UIColor]
116
+ #
117
+ # @example
118
+ # rmq.color.from_rgba(255,255,255,0.5)
69
119
  def from_rgba(r,g,b,a)
70
120
  UIColor.colorWithRed((r/255.0), green: (g/255.0), blue: (b/255.0), alpha: a)
71
121
  end
72
122
 
123
+ # @return [UIColor]
124
+ #
125
+ # @example
126
+ # rmq.color.from_hsva(100,140,80,1.0)
73
127
  def from_hsva(h,s,v,a)
74
128
  UIColor.alloc.initWithHue(h, saturation: s, brightness: v, alpha: a)
75
129
  end
@@ -2,14 +2,19 @@ module RubyMotionQuery
2
2
  class ViewData
3
3
  attr_accessor :events, :style_name
4
4
 
5
+ # @return [Hash] Array of tag names assigned to to this view
5
6
  def tags
6
7
  @_tags ||= {}
7
8
  end
8
9
 
10
+ # @return [Array] Array of tag names assigned to to this view
9
11
  def tag_names
10
12
  tags.keys
11
13
  end
12
14
 
15
+ # *Do not* use this, use {RMQ#tag} instead:
16
+ # @example
17
+ # rmq(my_view).tag(:foo)
13
18
  def tag(*tag_or_tags)
14
19
  tag_or_tags.flatten!
15
20
  tag_or_tags.each do |tag_name|
@@ -17,6 +22,10 @@ module RubyMotionQuery
17
22
  end
18
23
  end
19
24
 
25
+ # Check if this view contains a specific tag
26
+ #
27
+ # @param tag_name name of tag to check
28
+ # @return [Boolean] true if this view has the tag provided
20
29
  def has_tag?(tag_name = nil)
21
30
  if tag_name
22
31
  tags.include?(tag_name)
@@ -1,8 +1,11 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
+ # @return [Device]
3
4
  def device
4
5
  Device
5
6
  end
7
+
8
+ # @return [Device]
6
9
  def self.device
7
10
  Device
8
11
  end
@@ -10,14 +13,17 @@ module RubyMotionQuery
10
13
 
11
14
  class Device
12
15
  class << self
16
+ # @return [UIScreen]
13
17
  def screen
14
18
  UIScreen.mainScreen
15
19
  end
16
20
 
21
+ # @return [Numeric]
17
22
  def width
18
23
  @_width ||= Device.screen.bounds.size.width
19
24
  end
20
25
 
26
+ # @return [Numeric]
21
27
  def height
22
28
  @_height ||= Device.screen.bounds.size.height
23
29
  end
@@ -46,6 +52,7 @@ module RubyMotionQuery
46
52
  @_retina
47
53
  end
48
54
 
55
+ # @return :unknown or from ORIENTATIONS
49
56
  def orientation
50
57
  ORIENTATIONS[UIDevice.currentDevice.orientation] || :unknown
51
58
  end
@@ -3,11 +3,15 @@ module RubyMotionQuery
3
3
  # I'm purposly not including Enumerable,
4
4
  # please use to_a if you want one
5
5
 
6
+
7
+ # @return [RMQ]
6
8
  def <<(value)
7
9
  selected << value if value.is_a?(UIView)
8
10
  self
9
11
  end
10
12
 
13
+ # @return [RMQ]
14
+ #
11
15
  # @example
12
16
  # rmq(UILabel)[3]
13
17
  # or
@@ -17,54 +21,65 @@ module RubyMotionQuery
17
21
  end
18
22
  alias :eq :[]
19
23
 
24
+ # @return [RMQ]
20
25
  def each(&block)
21
26
  return self unless block
22
27
  RMQ.create_with_array_and_selectors(selected.each(&block), @selectors, @context)
23
28
  end
24
29
 
30
+ # @return [RMQ]
25
31
  def map(&block)
26
32
  return self unless block
27
33
  RMQ.create_with_array_and_selectors(selected.map(&block), @selectors, @context)
28
34
  end
29
35
  alias :collect :map
30
36
 
37
+ # @return [RMQ]
31
38
  def select(&block)
32
39
  return self unless block
33
40
  RMQ.create_with_array_and_selectors(selected.select(&block), @selectors, @context)
34
41
  end
35
42
 
43
+ # @return [RMQ]
36
44
  def detect(&block) # Unlike enumerable, detect and find are not the same. See find in transverse
37
45
  return self unless block
38
46
  RMQ.create_with_array_and_selectors(selected.select(&block), @selectors, @context)
39
47
  end
40
48
 
49
+ # @return [RMQ]
41
50
  def grep(&block)
42
51
  return self unless block
43
52
  RMQ.create_with_array_and_selectors(selected.grep(&block), @selectors, @context)
44
53
  end
45
54
 
55
+ # @return [RMQ]
46
56
  def reject(&block)
47
57
  return self unless block
48
58
  RMQ.create_with_array_and_selectors(selected.reject(&block), @selectors, @context)
49
59
  end
50
60
 
61
+ # @return [RMQ]
51
62
  def inject(o, &block)
52
63
  return self unless block
53
64
  RMQ.create_with_array_and_selectors(selected.inject(o, &block), @selectors, @context)
54
65
  end
55
66
  alias :reduce :inject
56
67
 
68
+ # @return [RMQ]
57
69
  def first
58
70
  RMQ.create_with_array_and_selectors([selected.first], @selectors, @context)
59
71
  end
72
+ # @return [RMQ]
60
73
  def last
61
74
  RMQ.create_with_array_and_selectors([selected.last], @selectors, @context)
62
75
  end
63
76
 
77
+ # @return [Array]
64
78
  def to_a
65
79
  selected
66
80
  end
67
81
 
82
+ # @return [Integer] number of views selected
68
83
  def length
69
84
  selected.length
70
85
  end
@@ -1,5 +1,6 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
+ # @return [RMQ]
3
4
  def on(event, args = {}, &block)
4
5
  selected.each do |view|
5
6
  events(view).on(view, event, args, &block)
@@ -8,6 +9,7 @@ module RubyMotionQuery
8
9
  self
9
10
  end
10
11
 
12
+ # @return [RMQ]
11
13
  def off(*events)
12
14
  selected.each do |view|
13
15
  events(view).off(events)
@@ -2,16 +2,19 @@ module RubyMotionQuery
2
2
  class RMQ
3
3
  # TODO question, should there be a rmq pool to reuse?
4
4
 
5
+ # @return [RMQ]
5
6
  def create_blank_rmq
6
7
  RMQ.create_with_array_and_selectors([], self.selectors, @context)
7
8
  end
8
9
 
10
+ # @return [RMQ]
9
11
  def create_rmq_in_context(*selectors)
10
12
  RMQ.create_with_selectors(selectors, @context)
11
13
  end
12
14
 
13
15
  class << self
14
16
 
17
+ # @return [RMQ]
15
18
  def create_with_selectors(selectors, context)
16
19
  RMQ.new.tap do |o|
17
20
  o.context = context
@@ -19,6 +22,7 @@ module RubyMotionQuery
19
22
  end
20
23
  end
21
24
 
25
+ # @return [RMQ]
22
26
  def create_with_array_and_selectors(array, selectors, context)
23
27
  RMQ.new.tap do |o|
24
28
  o.context = context
@@ -1,10 +1,11 @@
1
- # Add custome app-wide fonts here
2
1
  module RubyMotionQuery
3
2
  class RMQ
3
+ # @return [Font]
4
4
  def self.font
5
5
  Font
6
6
  end
7
7
 
8
+ # @return [Font]
8
9
  def font
9
10
  Font
10
11
  end
@@ -12,24 +13,28 @@ module RubyMotionQuery
12
13
 
13
14
  class Font
14
15
  class << self
15
- # One way to add your own fonts it to open up the Font class and add your
16
- # own message.
17
- #
18
- # STANDARD_FONT = 'Helvetica Neue'
19
- # def standard_at_size(size);
20
- # UIFont.fontWithName(STANDARD_NAME, size: size)
21
- # end
22
- # def standard_large ; @standard_large ||= standard_at_size(18) ; end
23
- # def standard_medium ; @standard_medium ||= standard_at_size(12) ; end
24
16
 
25
-
26
- # Another way is to add named fonts:
17
+ # @example
18
+ # # One way to add your own fonts it to open up the Font class and add your own
19
+ # STANDARD_FONT = 'Helvetica Neue'
20
+ # def standard_at_size(size);
21
+ # UIFont.fontWithName(STANDARD_NAME, size: size)
22
+ # end
23
+ # def standard_large ; @standard_large ||= standard_at_size(18) ; end
24
+ # def standard_medium ; @standard_medium ||= standard_at_size(12) ; end
25
+ #
27
26
  #
28
- # Example
27
+ # # Another way is to add named fonts:
29
28
  # RubyMotionQuery::Font.add_named_font :large, STANDARD_FONT, 44
30
29
  #
30
+ # # In a stylesheet you can just do
31
+ # font.add_named_font :large, STANDARD_FONT, 44
32
+ #
31
33
  # # The use like so in your stylesheet:
32
- # font = font.large
34
+ # font = font.large
35
+ #
36
+ # # The use like so anywhere else:
37
+ # font = rmq.font.large
33
38
  def add_named(key, font_name_or_font, size = nil)
34
39
  font = if font_name_or_font.is_a?(UIFont)
35
40
  font_name_or_font
@@ -42,20 +47,34 @@ module RubyMotionQuery
42
47
  end
43
48
  end
44
49
 
50
+ # @param name [String] Name of font
51
+ # @param size [Float] Size of font
52
+ # @return [UIFont]
53
+ #
54
+ # @example
55
+ # font = rmq.font.font_with_name('Helvetica Neue', 18)
45
56
  def font_with_name(name, size)
57
+ # TODO, should rename this to just with_name, so it's rmq.font.with_name
46
58
  UIFont.fontWithName(name, size: size)
47
59
  end
48
60
  alias :with_name :font_with_name
49
61
 
50
62
  # Use this in the console to get a list of font families
63
+ # @return [Array]
51
64
  def family_list
52
65
  UIFont.familyNames.sort
53
66
  end
54
67
 
68
+ # @return [Array]
55
69
  def for_family(family)
56
70
  UIFont.fontNamesForFamilyName(family)
57
71
  end
58
72
 
73
+ # @param size (Float)
74
+ # @return [UIFont] System font given size
75
+ #
76
+ # @example
77
+ # font = rmq.font.system(18)
59
78
  def system(size = nil)
60
79
  UIFont.systemFontOfSize(size)
61
80
  end
@@ -1,8 +1,11 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
+ # @return [Format]
3
4
  def format
4
5
  Format
5
6
  end
7
+
8
+ # @return [Format]
6
9
  def self.format
7
10
  Format
8
11
  end
@@ -1,9 +1,11 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
+ # @return [ImageUtils]
3
4
  def self.image
4
5
  ImageUtils
5
6
  end
6
7
 
8
+ # @return [ImageUtils]
7
9
  def image
8
10
  ImageUtils
9
11
  end
@@ -12,10 +14,13 @@ module RubyMotionQuery
12
14
  class ImageUtils
13
15
  class << self
14
16
  DEFAULT_IMAGE_EXT = 'png'
17
+
18
+ # @return [UIImage]
15
19
  def resource_for_device(file_base_name, opts = {})
16
20
  resource( RMQ.device.four_inch? ? "#{file_base_name}-568h" : file_base_name, opts)
17
21
  end
18
22
 
23
+ # @return [UIImage]
19
24
  def resource(file_base_name, opts = {})
20
25
  ext = opts[:ext] || DEFAULT_IMAGE_EXT
21
26
  cached = opts[:cached]
@@ -30,6 +35,7 @@ module RubyMotionQuery
30
35
  end
31
36
  end
32
37
 
38
+ # @return [UIImage]
33
39
  def resource_resizable(file_base_name, opts)
34
40
  # TODO, also alloow short syntax, t: instead of top: etc
35
41
  ext = opts[:ext] || DEFAULT_IMAGE_EXT
@@ -37,7 +43,7 @@ module RubyMotionQuery
37
43
  image.resizableImageWithCapInsets([opts[:top], opts[:left], opts[:bottom], opts[:right]], resizingMode: UIImageResizingModeStretch)
38
44
  end
39
45
 
40
- # [FROM Sugarcube, thanks Sugarcube]
46
+ # Note: FROM Sugarcube, thanks Sugarcube
41
47
  #
42
48
  # Easily take a snapshot of a `UIView`.
43
49
  #
@@ -53,6 +59,8 @@ module RubyMotionQuery
53
59
  # It is guaranteed that `true` and `:all` will always have this behavior. In
54
60
  # the future, if this argument becomes something that accepts multiple values,
55
61
  # those two are sacred.
62
+ #
63
+ # @return [UIImage]
56
64
  def from_view(view, use_content_size = false)
57
65
  scale = UIScreen.mainScreen.scale
58
66
  if use_content_size
@@ -1,6 +1,7 @@
1
1
  module RubyMotionQuery
2
2
  class RMQ
3
3
 
4
+ # @return [RMQ]
4
5
  def move(opts)
5
6
  # TODO, add centered and from_bottom and from_top, and bottom and top
6
7
  # TODO, add animate option
@@ -20,12 +21,7 @@ module RubyMotionQuery
20
21
  end
21
22
  alias :resize :move
22
23
 
23
- def align(direction)
24
- # TODO
25
- # rmq(UILabel).align(:left)
26
- # rmq(UILabel).align(:left, :top)
27
- end
28
-
24
+ # @return [RMQ]
29
25
  def nudge(opts)
30
26
  left = opts[:left] || opts[:l] || 0
31
27
  right = opts[:right] || opts[:r] || 0