RedAlert 1.1 → 1.2

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: bb460bb7537e289c09e0a687625240722150b926
4
- data.tar.gz: 8045ee75e15e7e3dd3b30d8f38e827ebc5b50c4e
3
+ metadata.gz: a17fdee3c942135d661b71f10e02a3fa7c897945
4
+ data.tar.gz: 3b1d14668db687b50e4f7f0005246f93dc08b52f
5
5
  SHA512:
6
- metadata.gz: 934d7a4b369c1fab4587fb4f0c83ad32f6a508baf64389f8467d1735e601ca755e2e9dc58eba5935a87469003395ce87ac8dd0c2c32a5e03016b4a7a3e9e8da1
7
- data.tar.gz: 1839259b6393176975b33e3ac73f1b9721ac6962b3dd2ff87e868c1796476486cdda401bc9e470b0670056bbabbd3b3e4d4631ce8815836d3a02679a54a6dc7d
6
+ metadata.gz: d9e215e14fa0911d4c5f5e10226ddf7867457637f255635f4f767faa80604afd86964c9d1dede48e5f0a7e1ea87cac7c281f3174f3eb3ad427e5c31c6b25ad5f
7
+ data.tar.gz: 3129e78629f9b47b6ef29dba0cc6e983dfda0cd322885b9a72b96e26325bf84b6e46759c37a9cca57a95dd8723c98db72f58251f3b7a1d20bfc4fa6afa5882d5
data/README.md CHANGED
@@ -50,6 +50,18 @@ Add the **RedAlert** gem to your Gemfile.
50
50
  puts "You clicked #{action_type}"
51
51
  end
52
52
 
53
+ # Add input fields by setting the style
54
+ rmq.app.alert(title: "Text Field", message: "My style is :login", style: :login) do |action_type, fields|
55
+ puts "you entered '#{fields[:login].text}' as the login and '#{fields[:password].text}' as the password"
56
+ end
57
+
58
+ # Add input fields with settings for placeholder text, whether the field is secure, and the keyboard type by setting the style to :custom
59
+ rmq.app.alert(title: "Text Field", message: "My style is :custom", style: :custom, fields:
60
+ {phone: {placeholder: 'Phone', keyboard_type: :phone_pad},
61
+ email: {placeholder: 'Email', secure: false, keyboard_type: :email_address}}) do |action_type, fields|
62
+ puts "you entered '#{fields[:phone].text}' and '#{fields[:email].text}'"
63
+ end
64
+
53
65
  # Utilize common templates
54
66
  rmq.app.alert(message: "Would you like a sandwich?", actions: :yes_no_cancel, style: :sheet) do |action_type|
55
67
  case action_type
@@ -74,7 +86,7 @@ end
74
86
  ```
75
87
 
76
88
 
77
- You can even use the `make_button` helper to create custom UIAction buttons to add:
89
+ You can even use the `make_button` helper to create custom buttons to add:
78
90
  ```ruby
79
91
  # Use custom UIAction buttons and add them
80
92
  taco = rmq.app.make_button("Taco") {
@@ -89,12 +101,18 @@ You can even use the `make_button` helper to create custom UIAction buttons to a
89
101
 
90
102
  ## Available Templates
91
103
 
92
- Templates are provided [HERE](https://github.com/GantMan/RedAlert/blob/master/lib/project/button_templates.rb)
104
+ Button templates are provided [HERE](https://github.com/GantMan/RedAlert/blob/master/lib/project/button_templates.rb)
93
105
  * `:yes_no` = Simple yes and no buttons.
94
106
  * `:yes_no_cancel` = Yes/no buttons with a separated cancel button.
95
107
  * `:ok_cancel` = OK button with a separated cancel button.
96
108
  * `:delete_cancel` = Delete button (red) with a separated cancel button.
97
109
 
110
+ Field templates are provided [HERE](https://github.com/GantMan/RedAlert/blob/master/lib/project/field_templates.rb)
111
+ * `:input` = One plaintext input field.
112
+ * `:secure` = One secure input field.
113
+ * `:login` = Two fields, one plaintext with placeholder text 'Login' and the other secure with placeholder text 'Password'.
114
+ * `:change_password` = Two fields, one secure with placeholder text 'Current Password' and the other secure with placeholder text 'New Password'.
115
+
98
116
  :heartbeat: _More to come:_ be sure to submit a pull-request with your button template needs.
99
117
 
100
118
 
@@ -113,7 +131,7 @@ Because capabilities of iOS 7 & 8 alert-components are different, just a few edg
113
131
  * `UIAlertView` cares about the order of your `:cancel` actions, so `[:ok, :cancel]` is shown different than `[:cancel, :ok]`.
114
132
  * `UIActionSheet` also cares about the order. It's possible to put a `:cancel` first, which looks slightly awkward when shown. Try to put `:cancel` last.
115
133
  * `UIAlertView`'s `alertViewStyles` are not available through RedAlert as they aren't compatible with iOS 8. You'll have to call that directly.
116
-
134
+ * `UIAlertView only supports up to 2 input fields.`
117
135
 
118
136
  ## Credits and Info
119
137
 
@@ -123,6 +141,8 @@ Because capabilities of iOS 7 & 8 alert-components are different, just a few edg
123
141
 
124
142
  **Automatic button building by [Jamon Holmgren](https://github.com/GantMan/RedAlert/pull/7)**
125
143
 
144
+ **Ability to add textfields to alerts (Like Username/Password) by [Derek Greenberg](https://github.com/GantMan/RedAlert/pull/10) and notable work by [Jon Silverman](https://github.com/GantMan/RedAlert/pull/9)**
145
+
126
146
  Feel free to read up on UIAlertController to see what all is wrapped up in this gem.
127
147
  * [Hayageek](http://hayageek.com/uialertcontroller-example-ios/)
128
148
  * [NSHipster](http://nshipster.com/uialertcontroller/)
@@ -5,7 +5,7 @@ module RubyMotionQuery
5
5
 
6
6
  attr_reader :action_sheet
7
7
 
8
- def build(actions, opts={})
8
+ def build(actions, fieldset=nil, opts={})
9
9
  raise ArgumentError.new "At least 1 action is required." unless actions && actions.length > 0
10
10
  @actions = actions
11
11
  @opts = opts
@@ -53,7 +53,7 @@ module RubyMotionQuery
53
53
  # pull from the view controller instance
54
54
  @view_controller.dismissViewControllerAnimated @opts[:animated], completion: nil
55
55
  action = @actions_in_display_order[buttonIndex]
56
- action.handler.call(action.tag) if action.handler
56
+ action.handler.call(action.tag, nil) if action.handler
57
57
  @view_controller = nil # forget the reference
58
58
  end
59
59
 
@@ -5,7 +5,7 @@ module RubyMotionQuery
5
5
 
6
6
  attr_reader :alert_controller
7
7
 
8
- def build(actions, opts={})
8
+ def build(actions, fieldset = nil, opts={})
9
9
  raise ArgumentError.new("At least 1 action is required.") unless actions && actions.length > 0
10
10
  @actions = actions
11
11
  @opts = opts
@@ -14,6 +14,21 @@ module RubyMotionQuery
14
14
  style = RubyMotionQuery::AlertConstants::ALERT_TYPES[@opts[:style]]
15
15
  @alert_controller = UIAlertController.alertControllerWithTitle @opts[:title], message:@opts[:message], preferredStyle: style
16
16
 
17
+ # add our text fields and build up the callback hash
18
+ @text_fields = {}
19
+ if fieldset
20
+ fieldset[:fields].each_with_index do |field, index|
21
+ handler = lambda do |text_field|
22
+ text_field.placeholder = field.placeholder
23
+ text_field.secureTextEntry = field.secure_text_entry
24
+ text_field.keyboardType = RubyMotionQuery::Stylers::KEYBOARD_TYPES[field.keyboard_type]
25
+ end
26
+ @alert_controller.addTextFieldWithConfigurationHandler(handler)
27
+ @text_fields[field.name] = @alert_controller.textFields[index]
28
+ end
29
+ end
30
+
31
+
17
32
  # load up the UIAlertController's actions
18
33
  @actions.each do |alert_action|
19
34
 
@@ -22,10 +37,10 @@ module RubyMotionQuery
22
37
 
23
38
  # convert the callback
24
39
  handler = lambda do |action|
25
- alert_action.handler.call(alert_action.tag) unless alert_action.handler.nil?
40
+ alert_action.handler.call(alert_action.tag, @text_fields) unless alert_action.handler.nil?
26
41
  end if alert_action.handler
27
42
 
28
- # create teh action
43
+ # create the action
29
44
  action = UIAlertAction.actionWithTitle alert_action.title, style: ios_style, handler: handler
30
45
 
31
46
  # add it to the UIAlertController
@@ -0,0 +1,18 @@
1
+ module RubyMotionQuery
2
+ class AlertField
3
+
4
+ attr_accessor :keyboard_type
5
+ attr_accessor :placeholder
6
+ attr_accessor :secure_text_entry
7
+ attr_accessor :name
8
+
9
+ def initialize(name, opts = {})
10
+ raise ArgumentError.new "A name parameter must be provided" unless name && name.length > 0
11
+ opts = {placeholder: opts, keyboard_type: :default} if opts.is_a? String
12
+ @name = name.is_a?(Symbol) ? name : name.strip.gsub(/\s+/,'_').to_sym
13
+ @keyboard_type = RubyMotionQuery::Stylers::KEYBOARD_TYPES.has_key?(opts[:keyboard_type]) ? opts[:keyboard_type] : :default
14
+ @placeholder = opts[:placeholder] || ''
15
+ @secure_text_entry = opts[:secure_text_entry] || false
16
+ end
17
+ end
18
+ end
@@ -5,7 +5,7 @@ module RubyMotionQuery
5
5
 
6
6
  attr_accessor :alert_view
7
7
 
8
- def build(actions, opts={})
8
+ def build(actions, fieldset=nil, opts={})
9
9
  raise ArgumentError.new("At least 1 action is required.") unless actions && actions.length > 0
10
10
  @actions = actions
11
11
  @opts = opts
@@ -26,6 +26,20 @@ module RubyMotionQuery
26
26
  # mark where our special buttons are
27
27
  @alert_view.cancelButtonIndex = @actions_in_display_order.length-1 if cancel_action
28
28
 
29
+ # add our text fields and build up the callback hash
30
+ @text_fields = {}
31
+
32
+ if fieldset
33
+ @alert_view.alertViewStyle = fieldset[:alert_view_style]
34
+ fieldset[:fields].each_with_index do |field, index|
35
+ text_field = @alert_view.textFieldAtIndex index
36
+ text_field.placeholder = field.placeholder
37
+ text_field.secureTextEntry = field.secure_text_entry
38
+ text_field.keyboardType = RubyMotionQuery::Stylers::KEYBOARD_TYPES[field.keyboard_type]
39
+ @text_fields[field.name] = text_field
40
+ end
41
+ end
42
+
29
43
  self
30
44
  end
31
45
 
@@ -41,7 +55,7 @@ module RubyMotionQuery
41
55
  def alertView(alertView, didDismissWithButtonIndex:buttonIndex)
42
56
  @view_controller.dismissViewControllerAnimated @opts[:animated], completion: nil
43
57
  action = @actions_in_display_order[buttonIndex]
44
- action.handler.call(action.tag) if action.handler
58
+ action.handler.call(action.tag, @text_fields) if action.handler
45
59
  @view_controller = nil # forget the reference
46
60
  end
47
61
 
@@ -0,0 +1,48 @@
1
+ module RubyMotionQuery
2
+ class App
3
+
4
+ # When adding a new template do the following:
5
+ # 1 - Add it here
6
+ # 2 - Add the test
7
+ # 3 - Add symbol to the README.md list
8
+
9
+ def self.add_template_fieldset(template)
10
+
11
+ login = NSLocalizedString("Login", nil)
12
+ password = NSLocalizedString("Password", nil)
13
+ current_password = NSLocalizedString("Current Password", nil)
14
+ new_password = NSLocalizedString("New Password", nil)
15
+
16
+ fieldset = {alert_view_style: UIAlertViewStyleDefault, fields: [] }
17
+ case template
18
+ when :input
19
+ fieldset[:alert_view_style] = UIAlertViewStylePlainTextInput
20
+ fieldset[:fields] =
21
+ [
22
+ rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: false, placeholder: '')
23
+ ]
24
+ when :secure
25
+ fieldset[:alert_view_style] = UIAlertViewStyleSecureTextInput
26
+ fieldset[:fields] =
27
+ [
28
+ rmq.app.make_field(:text, keyboard_type: :default, secure_text_entry: true, placeholder: '')
29
+ ]
30
+ when :login
31
+ fieldset[:alert_view_style] = UIAlertViewStyleLoginAndPasswordInput
32
+ fieldset[:fields] =
33
+ [
34
+ rmq.app.make_field(:login, keyboard_type: :email_address, secure_text_entry: false, placeholder: login),
35
+ rmq.app.make_field(:password, keyboard_type: :default, secure_text_entry: true, placeholder: password)
36
+ ]
37
+ when :change_password
38
+ fieldset[:alert_view_style] = UIAlertViewStyleLoginAndPasswordInput
39
+ fieldset[:fields] =
40
+ [
41
+ rmq.app.make_field(:current_password, keyboard_type: :default, secure_text_entry: true, placeholder: current_password),
42
+ rmq.app.make_field(:new_password, keyboard_type: :default, secure_text_entry: true, placeholder: new_password)
43
+ ]
44
+ end
45
+ fieldset
46
+ end
47
+ end
48
+ end
@@ -2,6 +2,11 @@ module RubyMotionQuery
2
2
  class App
3
3
  class << self
4
4
 
5
+ TEMPLATE_FIELD_STYLES = [:input, :secure, :change_password, :login]
6
+ ALL_FIELD_STYLES = TEMPLATE_FIELD_STYLES + [:custom]
7
+ ALERT_STYLES = ALL_FIELD_STYLES + [:alert]
8
+ VALID_STYLES = ALERT_STYLES + [:sheet]
9
+
5
10
  # Creates and shows the UIAlertController (iOS 8) or UIAlertView/UIActionSheet (iOS 7).
6
11
  # Usage Example:
7
12
  # rmq.app.alert(message: "This is a test")
@@ -15,7 +20,8 @@ module RubyMotionQuery
15
20
  opts = {message: opts} if opts.is_a? String
16
21
  opts = {style: :alert, animated: true, show_now: true}.merge(opts)
17
22
  opts[:message] = opts[:message] ? opts[:message].to_s : NSLocalizedString("Alert!", nil)
18
- opts[:style] = :alert unless opts[:style] == :sheet
23
+ opts[:style] = VALID_STYLES.include?(opts[:style]) ? opts[:style] : :alert
24
+ opts[:fields] = opts[:style] == :custom && opts[:fields] ? opts[:fields] : {text: {placeholder: ''}}
19
25
  api = rmq.device.ios_at_least?(8) ? :modern : :deprecated
20
26
  api = :deprecated if rmq.device.ios_at_least?(8) && opts[:api] == :deprecated
21
27
  opts[:api] = api
@@ -23,16 +29,31 @@ module RubyMotionQuery
23
29
  # -----------------------------------------
24
30
  # -- Who provides the alerts? -------------
25
31
  # -----------------------------------------
32
+
26
33
  if opts[:api] == :modern
27
34
  provider = AlertControllerProvider.new
28
35
  else
29
- if opts[:style] == :alert
36
+ if ALERT_STYLES.include?(opts[:style])
30
37
  provider = AlertViewProvider.new
31
38
  else
32
39
  provider = ActionSheetProvider.new
33
40
  end
34
41
  end
35
42
 
43
+ # -------------------------------------------------
44
+ # -- Configure the input fields --------------
45
+ # -------------------------------------------------
46
+
47
+ fieldset = {alert_view_style: UIAlertViewStyleDefault, fields: []}
48
+
49
+ if TEMPLATE_FIELD_STYLES.include?(opts[:style])
50
+ fieldset = add_template_fieldset(opts[:style])
51
+ elsif opts[:style] == :custom
52
+ fieldset = custom_fieldset(opts[:api], opts[:fields])
53
+ end
54
+
55
+ opts[:style] = :alert if ALL_FIELD_STYLES.include?(opts[:style])
56
+
36
57
  # -------------------------------------------------
37
58
  # -- Configure the actions (choices) --------------
38
59
  # -------------------------------------------------
@@ -50,7 +71,7 @@ module RubyMotionQuery
50
71
  # no actions & no block makes alerts a dull boy
51
72
  actions << [AlertAction.new(NSLocalizedString("OK", nil))]
52
73
  end
53
- provider.build(actions.flatten.compact, opts)
74
+ provider.build(actions.flatten.compact, fieldset, opts)
54
75
 
55
76
  # --------------------------------------------
56
77
  # -- Show the modal right away? --------------
@@ -66,13 +87,44 @@ module RubyMotionQuery
66
87
  provider
67
88
  end # alert
68
89
 
69
- # Returns a UIAlertAction from given parameters
90
+ def custom_fieldset(api_version = :modern, fields)
91
+ raise ArgumentError.new "At least one field must be provided for a custom style" unless fields && fields.count > 0
92
+ fieldset = {alert_view_style: UIAlertViewStyleDefault, fields: [] }
93
+ if api_version == :deprecated
94
+ case fields.count
95
+ when 1
96
+ fieldset[:alert_view_style] = UIAlertViewStylePlainTextInput
97
+ when 2
98
+ fieldset[:alert_view_style] = UIAlertViewStyleLoginAndPasswordInput
99
+ else
100
+ raise ArgumentError.new "When running iOS < 8, up to two fields can be provided for a custom style"
101
+ end
102
+ end
103
+ alert_fields = []
104
+ fields.each do |k, v|
105
+ alert_fields << AlertField.new(k, v)
106
+ end
107
+ fieldset[:fields] = alert_fields
108
+ fieldset
109
+ end
110
+
111
+ # Returns an AlertField from given parameters
112
+ # Usage Example:
113
+ # login = rmq.make_field("Login")
114
+ # password = rmq.make_field(:password, secure: true, placeholder: 'Password')
115
+ # @return [AlertField]
116
+
117
+ def make_field(name, opts={})
118
+ AlertField.new(name, opts)
119
+ end
120
+
121
+ # Returns an AlertAction from given parameters
70
122
  # Usage Example:
71
123
  # yes = rmq.make_button("Yes")
72
124
  # cancel = rmq.make_button(title: "Cancel", style: :cancel) {
73
125
  # puts "Cancel pressed"
74
126
  # }
75
- # @return [UIAlertAction]
127
+ # @return [AlertAction]
76
128
  def make_button(opts={}, &block)
77
129
  AlertAction.new(opts, &block)
78
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RedAlert
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.1'
4
+ version: '1.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gant Laborde
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-16 00:00:00.000000000 Z
11
+ date: 2015-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_motion_query
@@ -38,8 +38,8 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion for
42
- iOS 7 & 8
41
+ description: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion Apps
42
+ on iOS 7 & 8
43
43
  email:
44
44
  - GantMan@gmail.com
45
45
  executables: []
@@ -52,8 +52,10 @@ files:
52
52
  - lib/project/alert_action.rb
53
53
  - lib/project/alert_constants.rb
54
54
  - lib/project/alert_controller_provider.rb
55
+ - lib/project/alert_field.rb
55
56
  - lib/project/alert_view_provider.rb
56
57
  - lib/project/button_templates.rb
58
+ - lib/project/field_templates.rb
57
59
  - lib/project/red_alert.rb
58
60
  - lib/red_alert.rb
59
61
  homepage: https://github.com/GantMan/RedAlert
@@ -79,6 +81,6 @@ rubyforge_project:
79
81
  rubygems_version: 2.4.5
80
82
  signing_key:
81
83
  specification_version: 4
82
- summary: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion for iOS
83
- 7 & 8.
84
+ summary: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion Apps on
85
+ iOS 7 & 8.
84
86
  test_files: []