ruby_motion_query 0.7.0 → 0.7.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6f9a3624a7543f1c6a828948bb3d2da590c8ad78
4
- data.tar.gz: f377f2d6321fbe5a18b2e1fa4a8fedfff7023f63
3
+ metadata.gz: aa33d32bc33a3a37c0b275b086ec98e68ad93087
4
+ data.tar.gz: 88136c1a620a6f49c3da516941224405627e6bfe
5
5
  SHA512:
6
- metadata.gz: 25be56991e401ba84649de80eccf69a45f7df4691507a7c1c5e8f1d2bb783bac5a8625608c0d757282bd8fe27bde29fe3afcf1d5b22eedba7b037f684c69a4a2
7
- data.tar.gz: 9ccb416fa1ea67824729649c1b2e884682ec8b04feece7aec42f3dc2b705de0f2d3880a25d3a301ebc9dfd47fa6d86b20bc64df11c426ca975d6b5b313661fc7
6
+ metadata.gz: 56f9eeeb66eea90c517f495318da1709c3c93262365eef4f64fc1f49a3d2cbc7c375ea9f269e2f8ad51ea65500d8dfbc89f3d206224a3b2fb4abcb160a709bba
7
+ data.tar.gz: 715240b7ef7389f0440e5cddf8f9f22955911317544a185634bb46e7b16a66b3c254c72e9bf827b2eb8fb436195168da85b96432ce430bdfd212edd65c3ebb51
@@ -5,6 +5,7 @@ end
5
5
  Motion::Project::App.setup do |app|
6
6
  parent = File.join(File.dirname(__FILE__), '..')
7
7
  files = [File.join(parent, 'motion/ruby_motion_query/stylesheet.rb')]
8
+ files << [File.join(parent, 'motion/ruby_motion_query/validation_event.rb')]
8
9
  files << [File.join(parent, 'motion/ruby_motion_query/stylers/ui_view_styler.rb')]
9
10
  files << File.join(parent, 'motion/ruby_motion_query/stylers/ui_control_styler.rb')
10
11
  files << Dir.glob(File.join(parent, "motion/**/*.rb"))
@@ -23,15 +23,15 @@ module RubyMotionQuery
23
23
 
24
24
  # A grid for layout.
25
25
  # There is an app grid at: rmq.app.grid
26
- # You can also have a grid per stylesheet. If none exists, the app
26
+ # You can also have a grid per stylesheet. If none exists, the app
27
27
  # grid will be used. rmq.stylesheet.grid (this will return app's if nil).
28
28
  # If you want to create a grid for your stylesheet, you can just dup the app one
29
29
  # like so (inside the stylesheet): self.grid = rmq.app.grid.dup
30
30
  # Then you can mod it: self.grid.num_columns = 6
31
31
  #
32
32
  # @example If you want your view to be from b2 to d3, you can do any of the following:
33
- #
34
- # # a b c d e
33
+ #
34
+ # # a b c d e
35
35
  # # ....................
36
36
  # # 1 . a1 b1 c1 d1 e1
37
37
  # # .....------------...
@@ -39,17 +39,17 @@ module RubyMotionQuery
39
39
  # # .....| |...
40
40
  # # 3 . a3 |b3 c3 d3| e3
41
41
  # # .....------------...
42
- # # 4 . a4 b4 c4 d4 e4
43
- # # ....................
42
+ # # 4 . a4 b4 c4 d4 e4
43
+ # # ....................
44
44
  # # 5 . a5 b5 c5 d5 e5
45
- # # ....................
45
+ # # ....................
46
46
  #
47
47
  # st.frame = "b2:d3"
48
48
  # st.origin = "b2:d3"
49
49
  # st.frame = {grid: "b2", w: 100, h: 200}
50
50
  # my_view.frame = some_grid['b2:d3']
51
51
  # my_view.origin = some_grid['b2:d3']
52
- # rmq.append(UIView).layout('b2:d3')
52
+ # rmq.append(UIView).layout('b2:d3')
53
53
  #
54
54
  # @example Create a new grid inside a stylesheet by duping the app's grid
55
55
  # self.grid = rmq.app.grid.dup
@@ -74,8 +74,8 @@ module RubyMotionQuery
74
74
  # @example Log your grid
75
75
  # rmq.app.grid.log
76
76
  #
77
- # # {:num_columns=>10, :num_rows=>13, :column_gutter=>10, :content_left_margin=>5,
78
- # # :content_right_margin=>5, :content_top_margin=>5, :content_bottom_margin=>5,
77
+ # # {:num_columns=>10, :num_rows=>13, :column_gutter=>10, :content_left_margin=>5,
78
+ # # :content_right_margin=>5, :content_top_margin=>5, :content_bottom_margin=>5,
79
79
  # # :row_gutter=>10, :status_bar_bottom=>20, :nav_bar_bottom=>64}
80
80
  #
81
81
  # # a b c d e f g h i j
@@ -94,8 +94,8 @@ module RubyMotionQuery
94
94
  # # 12 . . . . . . . . . .
95
95
  #
96
96
  class Grid
97
- attr_reader :num_columns, :column_gutter, :content_left_margin, :content_right_margin,
98
- :content_bottom_margin, :content_top_margin, :num_rows, :row_gutter,
97
+ attr_reader :num_columns, :column_gutter, :content_left_margin, :content_right_margin,
98
+ :content_bottom_margin, :content_top_margin, :num_rows, :row_gutter,
99
99
  :status_bar_bottom, :nav_bar_bottom
100
100
 
101
101
  MAX_COLUMNS = 26
@@ -207,7 +207,7 @@ module RubyMotionQuery
207
207
  is_end_coord = coord.start_with?(':')
208
208
  parts = coord.split(':')
209
209
  parts.reject!{|o| o == ''}
210
-
210
+
211
211
  case parts.length
212
212
  when 0
213
213
  nil
@@ -241,7 +241,7 @@ module RubyMotionQuery
241
241
  {l: lefts[left_i], t: tops[top_i]}
242
242
  end
243
243
  else
244
- nil
244
+ nil
245
245
  end
246
246
  elsif digits
247
247
  if is_end_coord
@@ -319,6 +319,13 @@ module RubyMotionQuery
319
319
  to_h.inspect
320
320
  end
321
321
 
322
+ def show
323
+ rmq(rmq.window).append(GridHudView).attr(grid: self).layout(l: 0, t: 0, fr: 0, fb: 0).enable_interaction.on(:tap) do |sender|
324
+ rmq(sender).remove
325
+ end
326
+ puts '[RMQ] Tap to dismiss the grid overlay'
327
+ end
328
+
322
329
  def dup
323
330
  Grid.new(self.to_h)
324
331
  end
@@ -367,4 +374,43 @@ module RubyMotionQuery
367
374
  end
368
375
 
369
376
  end
377
+
378
+ class GridHudView < UIView
379
+ attr_accessor :grid
380
+
381
+ def rmq_build
382
+ @light_text_color = rmq.color.from_rgba(213,53,82,0.6).CGColor
383
+ @column_fill_color = rmq.color.from_rgba(213,53,82,0.1).CGColor
384
+ @background_color = rmq.color.from_rgba(255,255,255,0.4)
385
+
386
+ rmq(self).style do |st|
387
+ st.background_color = @background_color
388
+ end
389
+ end
390
+
391
+ def drawRect(rect)
392
+ super
393
+
394
+ return unless @grid
395
+
396
+ context = UIGraphicsGetCurrentContext()
397
+ screen_height = RMQ.device.screen_height
398
+ screen_width = RMQ.device.screen_width
399
+
400
+ CGContextSetTextMatrix(context, CGAffineTransformMake(1.0,0.0, 0.0, -1.0, 0.0, 0.0));
401
+ CGContextSelectFont(context, 'Courier New', 7, KCGEncodingMacRoman)
402
+
403
+ 0.upto(@grid.num_rows - 1) do |r|
404
+ 0.upto(@grid.num_columns - 1) do |c|
405
+ rec = @grid[[c, r]]
406
+ CGContextSetFillColorWithColor(context, @column_fill_color)
407
+ CGContextFillRect(context, rec.to_cgrect)
408
+ text = "#{(c+97).chr}#{r}"
409
+ CGContextSetFillColorWithColor(context, @light_text_color)
410
+ CGContextShowTextAtPoint(context, rec.origin.x + 1, rec.origin.y + 5, text, text.length)
411
+ end
412
+ end
413
+ end
414
+ end
415
+
370
416
  end
@@ -5,6 +5,9 @@ module RubyMotionQuery
5
5
  def text=(value) ; @view.setText value ; end
6
6
  def text ; @view.text ; end
7
7
 
8
+ def attributed_text=(value) ; @view.attributedText = value ; end
9
+ def attributed_text ; @view.attributedText ; end
10
+
8
11
  def font=(value) ; @view.setFont value ; end
9
12
  def font ; @view.font ; end
10
13
 
@@ -23,6 +26,13 @@ module RubyMotionQuery
23
26
  end
24
27
  end
25
28
 
29
+ def line_break_mode=(value)
30
+ @view.lineBreakMode = value
31
+ end
32
+ def line_break_mode
33
+ @view.lineBreakMode
34
+ end
35
+
26
36
  def text_alignment=(value)
27
37
  @view.setTextAlignment(TEXT_ALIGNMENTS[value] || value)
28
38
  end
@@ -106,12 +106,29 @@ module RubyMotionQuery
106
106
 
107
107
  def valid?(data, options={})
108
108
  @options = options.merge(@options)
109
+
110
+ # shortcircuit for universal validation parameters
111
+ return true if universal_validation_checks(data, @options)
112
+
109
113
  @valid_status = @rule.call(data, @options)
110
114
  end
111
115
 
116
+ # this method shortcuts specific validation rules. As such it should only be
117
+ # added to for universal validation needs. It must be kept as efficient as possible.
118
+ def universal_validation_checks (data, options={})
119
+ # shortcircuit if debugging
120
+ return true if RubyMotionQuery::RMQ.debugging?
121
+ # allow blank data if specified
122
+ return true if (options[:allow_blank] && (data.nil? || data.empty?))
123
+ # allow whitelist data if specified
124
+ return true if (options[:white_list] && options[:white_list].include?(data))
125
+
126
+ false
127
+ end
128
+
112
129
  class << self
113
130
  # Validation Regex from jQuery validation -> https://github.com/jzaefferer/jquery-validation/blob/master/src/core.js#L1094-L1200
114
- EMAIL = Regexp.new('^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$')
131
+ EMAIL = Regexp.new('^[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+\/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$')
115
132
  URL = Regexp.new('^(https?|s?ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&\'\(\)\*\+,;=]|:|@)|\/|\?)*)?$')
116
133
  DATEISO = Regexp.new('^\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01])$')
117
134
  NUMBER = Regexp.new('^-?(?:\d+|\d{1,3}(?:,\d{3})+)?(?:\.\d+)?$')
@@ -168,7 +185,8 @@ module RubyMotionQuery
168
185
  v = if opts[:exact_length] then (value.length == opts[:exact_length]) else true end
169
186
  v = v && value.length <= opts[:max_length]
170
187
  v = v && value.length >= opts[:min_length]
171
- }
188
+ },
189
+ :custom => lambda { |value, opts| Validation.regex_match?(value, opts[:regex])},
172
190
  }
173
191
 
174
192
  # Add tags
@@ -182,11 +200,6 @@ module RubyMotionQuery
182
200
  #
183
201
  # @return [Boolean]
184
202
  def valid?(value, rule, options={})
185
- # shortcircuit if debugging
186
- return true if RubyMotionQuery::RMQ.debugging?
187
- # shortcircuit for optionals
188
- return true if (options[:allow_blank] && (value.nil? || value.empty?))
189
-
190
203
  Validation.new(rule).valid?(value, options)
191
204
  end
192
205
 
@@ -194,6 +207,12 @@ module RubyMotionQuery
194
207
  (value.to_s =~ regex) != nil
195
208
  end
196
209
 
210
+ def add_validator(rule, &block)
211
+ raise(ArgumentError, "add_validator requires a block") if block.nil?
212
+
213
+ @@validation_methods[rule] = block
214
+ end
215
+
197
216
  end
198
217
  end
199
218
  end
@@ -1,5 +1,5 @@
1
1
  module RubyMotionQuery
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
 
4
4
  class RMQ
5
5
  def version
@@ -6,7 +6,7 @@ class <%= @name_camel_case %>Cell < UICollectionViewCell
6
6
 
7
7
  q = rmq(self.contentView)
8
8
  # Add your subviews, init stuff here
9
- # @foo = q.append(UILabel, :foo).get
9
+ # @foo = q.append!(UILabel, :foo)
10
10
  end
11
11
 
12
12
  def prepareForReuse
@@ -3,14 +3,14 @@ class <%= @name_camel_case %>Cell < UITableViewCell
3
3
  def rmq_build
4
4
  q = rmq(self.contentView)
5
5
 
6
- # Add your subviews, init stuff here
7
- # @foo = q.append(UILabel, :foo).get
6
+ # Customize your cell: Add your subviews, init stuff here
7
+ # @foo = q.append!(UILabel, :foo)
8
8
 
9
9
  # Or use the built-in table cell controls, if you don't use
10
10
  # these, they won't exist at runtime
11
- # q.build(self.imageView, :cell_image)
12
- # q.build(self.detailTextLabel, :cell_label_detail)
13
- @name = q.build(self.textLabel, :cell_label).get
11
+ # @image = q.build!(self.imageView, :cell_image)
12
+ # @detail = q.build!(self.detailTextLabel, :cell_label_detail)
13
+ @name = q.build!(self.textLabel, :cell_label)
14
14
  end
15
15
 
16
16
  def update(data)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_motion_query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Todd Werth
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-12 00:00:00.000000000 Z
12
+ date: 2014-09-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bacon