RedAlert 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8fdabf0f5f8e1bf91a9f0011a1364df64391e9e2
4
- data.tar.gz: 9eba51d49bb9963101eaa8599f1b4fe7042436dc
3
+ metadata.gz: 24b9cea163ecc89a14bd430541cce2ef68d1b481
4
+ data.tar.gz: 523230fefd756501194b7fbce9f70543facacbf4
5
5
  SHA512:
6
- metadata.gz: 309e8754b89b2bc44a2745e5ded3cface2b14a5831237ef98075491806843a2a29ef6647b7b85d009a89f9ff348a4d102d69f9c93988b5a23f0d43aaa6e8a4c8
7
- data.tar.gz: db0d2a6c17c14d675fe34652895dd5be0a9718fbd003950cdb3d52a9e87f907352d18373f8db47854b535b4ba28a9f64567e74d38c2981ce3ea08b3b6f3a49c9
6
+ metadata.gz: 99ce20158fa93775969ec3b5aa88691cf30ca7f489b128821bbef3c819532b8acd126a2b8fbedd40ee5222557503bacba711be40697cb17df212cc26e6c912be
7
+ data.tar.gz: c95f987cdaa2c52662007c2fe942692d88475190179a8fbaa9f5e3f887878ba0d1c5cf0ec7aa8aaeb1392e3742c29050a0f975e42aaedb53dead289e5520e63f
data/README.md CHANGED
@@ -1,64 +1,108 @@
1
- [![image](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/19/2014/09/rmq_plugin.png)](http://rubymotionquery.com)
1
+ <img src="./_art/logo.png" alt="RedAlert Logo" width="100" />
2
+ [![image](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/19/2014/09/rmq_plugin.png)](http://rubymotionquery.com)
2
3
 
3
4
  # RedAlert
5
+ [![Gem Version](https://badge.fury.io/rb/RedAlert.svg)](http://badge.fury.io/rb/RedAlert) [![Build Status](https://travis-ci.org/GantMan/RedAlert.svg)](https://travis-ci.org/GantMan/RedAlert) _Alerts and ActionSheets with ease_
4
6
 
5
- **Did you know that UIAlertView and UIActionSheet (as well as their respective delegate protocols) are deprecated in iOS 8?**
7
+ ### Did you know that UIAlertView and UIActionSheet (as well as their respective delegate protocols) are deprecated in iOS 8?
6
8
 
7
- `UIAlertController` is used in this gem. Gracefully falls back to `UIAlertView` for versions older than iOS8
9
+ Apple requests you start using the new `UIAlertController`. This gem is built on `UIAlertController` and RMQ, along with support for antiquated `UIAlertView`s for the gnostalgic.
10
+
11
+ With an emphasis on ease of use, this gem allows you to quickly implement Alerts and Actionsheets in your RMQ RubyMotion applications.
12
+
13
+ ## Screenshot
14
+
15
+ <img src="./_art/screen.png" alt="Screen Shot" width="500" />
8
16
 
9
17
  ## Installation
10
18
 
11
- **Requires RMQ 0.8.0 or later, and iOS 7 or later**#
19
+ **Requires RMQ 1.2.0 or later, and iOS 8 or later**
12
20
 
13
- TODO: Write install instructions here
21
+ Add the **RedAlert** gem to your Gemfile.
22
+ ```ruby
23
+ gem 'RedAlert'
24
+ ```
14
25
 
15
26
  ## Usage
27
+ **Note: If you're using [RedPotion](https://github.com/infinitered/redpotion) then `rmq.app` can be accessed by simply typing `app`, so `rmq.app.alert` would be simply `app.alert`. The following examples are verbose and assume only [RMQ](https://github.com/infinitered/rmq).**
16
28
 
17
- TODO: Write usage instructions here
18
29
  ```ruby
19
30
 
20
- rmq.alert("Are you alive?") do
21
- p "He is alive!"
22
- end
31
+ # Simply do an alert
32
+ rmq.app.alert("Minimal Alert")
33
+
34
+ # Alert with callback
35
+ rmq.app.alert("Alert with Block") {
36
+ puts "Alert with Block worked!"
37
+ }
23
38
 
24
- rmq.alert(title: "foo", message: "Are you alive?") do
25
- p "He is alive!"
39
+ # Modify some snazzy options
40
+ rmq.app.alert(title: "New Title", message: "Great message", animated: false)
41
+
42
+ # Switch it to look like an ActionSheet by setting the style
43
+ rmq.app.alert(title: "Hey there!", message: "My style is :sheet", style: :sheet) do |action_type|
44
+ puts "You clicked #{action_type}"
26
45
  end
27
46
 
28
- rmq.alert(message: "Would you like a sandwich?", actions: :yes_no_cancel, style: :sheet) { |action_type|
47
+ # Utilize common templates
48
+ rmq.app.alert(message: "Would you like a sandwich?", actions: :yes_no_cancel, style: :sheet) do |action_type|
29
49
  case action_type
30
50
  when :yes
31
- p "yes"
51
+ puts "Here's your Sandwich!"
32
52
  when :no
33
- p "no"
53
+ puts "FINE!"
34
54
  end
35
- }
36
-
37
-
38
- rmq.alert(title: "foo", message: "Would you like a sandwich?", actions: []
39
- }
40
-
55
+ end
56
+ ```
41
57
 
42
- rmq.alert(title: "More Actions",
43
- message: "UIViewController 2",
44
- actions: [
45
- {text: "OK", style: :default, handler: ->{}}
46
- {text: "OK", style: :default, handler: ->{}}
47
- ])
58
+ You can even use the `make_button` helper to create custom UIAction buttons to add:
59
+ ```ruby
60
+ # Use custom UIAction buttons and add them
61
+ taco = rmq.app.make_button("Taco") {
62
+ puts "Taco pressed"
63
+ }
64
+ nacho = rmq.app.make_button(title: "Nacho", style: :destructive) {
65
+ puts "Nacho pressed"
66
+ }
67
+ button_list = [taco, nacho]
68
+ rmq.app.alert(title: "Actions!", message: "Actions created with `make_button` helper.", actions: button_list)
48
69
  ```
49
70
 
71
+ ## Available Templates
72
+
73
+ Templates are provided [HERE](https://github.com/GantMan/RedAlert/blob/master/lib/project/button_templates.rb)
74
+ * `:yes_no` = Simple yes and no buttons.
75
+ * `:yes_no_cancel` = Yes/no buttons with a separated cancel button.
76
+ * `:ok_cancel` = OK button with a separated cancel button.
77
+ * `:delete_cancel` = Delete button (red) with a separated cancel button.
50
78
 
51
- ### Example using stylesheet:
79
+ _More to come:_ be sure to submit a pull-request with your button template needs.
52
80
 
53
- TODO: stylesheet example here
81
+ ## More info
54
82
 
55
- ### Example without stylesheet:
83
+ Feel free to read up on UIAlertController to see what all is wrapped up in this gem.
84
+ * [Hayageek](http://hayageek.com/uialertcontroller-example-ios/)
85
+ * [NSHipster](http://nshipster.com/uialertcontroller/)
56
86
 
57
- TODO: no stylesheet example here
87
+ ## Classic UIAlertView Helpers
58
88
 
59
- ### Methods
89
+ If you'd like to still support pre-iOS8, you can easily use `rmq.app.alert_view` with a similar syntax, and instead of actions you'll used the predefined delegates.
60
90
 
61
- TODO: list methods available to user here
91
+ **`UIAlertView` Classic:**
92
+ ```ruby
93
+ # support the elderly
94
+ rmq.app.alert_view("Hey look at this old trick")
95
+
96
+ # Still feels like magic!
97
+ rmq.app.alert_view({
98
+ title: "Hey There",
99
+ message: "Check out this complex alert!",
100
+ cancel_button: 'Nevermind',
101
+ other_buttons: ['Log In'],
102
+ delegate: nil,
103
+ view_style: UIAlertViewStyleLoginAndPasswordInput
104
+ })
105
+ ```
62
106
 
63
107
  ## Contributing
64
108
 
@@ -0,0 +1,16 @@
1
+ module RubyMotionQuery
2
+ module AlertConstants
3
+
4
+ ALERT_TYPES = {
5
+ alert: UIAlertControllerStyleAlert,
6
+ sheet: UIAlertControllerStyleActionSheet
7
+ }
8
+
9
+ ALERT_ACTION_STYLE = {
10
+ default: UIAlertActionStyleDefault,
11
+ cancel: UIAlertActionStyleCancel,
12
+ destructive: UIAlertActionStyleDestructive
13
+ }
14
+
15
+ end
16
+ end
@@ -0,0 +1,27 @@
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
+ def self.add_template_actions(uiac, template, &block)
9
+ case template
10
+ when :yes_no
11
+ uiac.addAction(rmq.app.make_button("Yes", &block))
12
+ uiac.addAction(rmq.app.make_button("No", &block))
13
+ when :yes_no_cancel
14
+ uiac.addAction(rmq.app.make_button("Yes", &block))
15
+ uiac.addAction(rmq.app.make_button("No", &block))
16
+ uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
17
+ when :ok_cancel
18
+ uiac.addAction(rmq.app.make_button("OK", &block))
19
+ uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
20
+ when :delete_cancel
21
+ uiac.addAction(rmq.app.make_button({title: "Delete", style: :destructive}, &block))
22
+ uiac.addAction(rmq.app.make_button({title: "Cancel", style: :cancel}, &block))
23
+ end
24
+ end
25
+
26
+ end
27
+ end
@@ -0,0 +1,42 @@
1
+ module RubyMotionQuery
2
+ class App
3
+
4
+ # Creates and shows the old UIAlertView. Added here for use in fallback.
5
+ # Fallback won't run actions, but the old system needed delegates anyhow.
6
+ # Usage Example:
7
+ # rmq.app.alert_view("This is a test")
8
+ # rmq.app.alert_view(title: "Hey there", message: "Enjoying this?")
9
+ # @return [UIAlertView]
10
+ def self.alert_view(opts = {})
11
+
12
+ # shortcut sending a string
13
+ opts = {message: opts} if opts.is_a? String
14
+ # An alert is nothing without a message
15
+ raise(ArgumentError, "RedAlert requires a message") if opts[:message].nil? || opts[:message].empty?
16
+
17
+ opts = {
18
+ title: "Alert!",
19
+ cancel_button: "OK",
20
+ other_buttons: [],
21
+ delegate: nil,
22
+ view_style: UIAlertViewStyleDefault,
23
+ show_now: true,
24
+ }.merge(opts)
25
+
26
+ alert_view = UIAlertView.alloc.initWithTitle(
27
+ opts[:title],
28
+ message: opts[:message],
29
+ delegate: opts[:delegate],
30
+ cancelButtonTitle: opts[:cancel_button],
31
+ otherButtonTitles: nil
32
+ )
33
+ Array(opts[:other_buttons]).each { |button| alert_view.addButtonWithTitle(button) }
34
+
35
+ alert_view.alertViewStyle = opts[:view_style]
36
+
37
+ alert_view.show if opts[:show_now]
38
+ alert_view
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,44 @@
1
+ module RubyMotionQuery
2
+ class App
3
+
4
+ class << self
5
+ # UIAlertController Magic
6
+ def core_alert(opts = {}, &block)
7
+
8
+ opts = {
9
+ title: "Alert!",
10
+ style: :alert,
11
+ actions: [make_button(&block)],
12
+ animated: true,
13
+ show_now: true,
14
+ }.merge(opts)
15
+ style = RubyMotionQuery::AlertConstants::ALERT_TYPES[opts[:style]] || opts[:style]
16
+
17
+ ac = UIAlertController.alertControllerWithTitle(opts[:title], message:opts[:message], preferredStyle: style)
18
+
19
+ # Add correct actions (buttons) to the UIAC
20
+ if opts[:actions].is_a? Symbol
21
+ template_symbol = opts[:actions]
22
+ add_template_actions(ac, template_symbol, &block)
23
+ elsif opts[:actions].is_a? Array
24
+ opts[:actions].each do |action|
25
+ if action.is_a? UIAlertAction
26
+ ac.addAction(action)
27
+ else
28
+ raise ArgumentError, "RedAlert actions array must contain UIAlertAction objects"
29
+ end
30
+ end
31
+ else
32
+ raise ArgumentError, "RedAlert actions parameter must be an Array or a Template symbol"
33
+ end
34
+
35
+ # Present it, if that's what we want
36
+ rmq.view_controller.presentViewController(ac, animated: opts[:animated], completion: nil) if opts[:show_now]
37
+
38
+ # return controller (should I wrap it in RMQ?)
39
+ ac
40
+ end
41
+ end # close eigenclass
42
+
43
+ end
44
+ end
@@ -1,124 +1,48 @@
1
1
  module RubyMotionQuery
2
- class RMQ
3
-
4
- ALERT_TYPES = {
5
- alert: UIAlertControllerStyleAlert,
6
- sheet: UIAlertControllerStyleActionSheet
7
- }
8
-
9
- ALERT_ACTION_STYLE = {
10
- default: UIAlertActionStyleDefault,
11
- cancel: UIAlertActionStyleCancel,
12
- destructive: UIAlertActionStyleDestructive
13
- }
14
-
15
-
16
- # Creates and shows the UIAlertController.
17
- # Usage Example:
18
- # rmq.alert(message: "This is a test")
19
- # rmq.alert(title: "Hey there", message: "Are you happy?")
20
- # @return [RMQ]
21
- def alert(opts = {}, &block)
22
-
23
- if opts.is_a? String
24
- ok = make_button(&block)
25
- core_alert(message: opts, actions: [ok])
26
- else
27
- core_alert(opts)
2
+ class App
3
+ class << self
4
+
5
+ # Creates and shows the UIAlertController.
6
+ # Usage Example:
7
+ # rmq.app.alert(message: "This is a test")
8
+ # rmq.app.alert(title: "Hey there", message: "Are you happy?")
9
+ # @return [UIAlertController]
10
+ def alert(opts = {}, &block)
11
+ # Shortcut: assume a string is the message
12
+ opts = {message: opts} if opts.is_a? String
13
+
14
+ # An alert is nothing without a message
15
+ raise(ArgumentError, "RedAlert alert requires a message") if RubyMotionQuery::RMQ.is_blank?(opts[:message])
16
+ # iOS8 and above only for UIAlertController
17
+ raise "RedAlert requires iOS8 for alerts. Please try `rmq.app.alert_view`" unless rmq.device.ios_at_least? 8
18
+ core_alert(opts, &block)
28
19
  end
29
20
 
30
- end
31
-
32
-
33
- def core_alert(opts = {})
34
- # An alert is nothing without a message
35
- raise(ArgumentError, "RedAlert alert requires a message") unless opts[:message]
36
-
37
- opts = {
38
- title: "Alert!",
39
- style: :alert,
40
- actions: [make_button],
41
- animated: true,
42
- show_now: true,
43
- }.merge(opts)
44
-
45
-
46
- # UIAlertController introduced in iOS8 only
47
- if rmq.device.ios_at_least? 8
48
- style = ALERT_TYPES[opts[:style]] || opts[:style]
49
-
50
- ac = UIAlertController.alertControllerWithTitle(opts[:title], message:opts[:message], preferredStyle: style)
51
-
52
- opts[:actions].each do |action|
53
- if action.is_a? UIAlertAction
54
- ac.addAction(action)
55
- elsif action.is_a? Hash
56
- p "Parse and use hash as action"
57
- else
58
- raise ArgumentError, "RedAlert actions must be of type UIAlertAction or Hash"
59
- end
60
- end
61
-
62
- # Present it, if that's what we want
63
- rmq.view_controller.presentViewController(ac, animated: opts[:animated], completion: nil) if opts[:show_now]
64
-
65
- # return it wrapped in RMQ
66
- rmq(ac)
67
- else
68
- alert_view(opts)
21
+ # Returns a UIAlertAction from given parameters
22
+ # Usage Example:
23
+ # yes = rmq.make_button("Yes")
24
+ # cancel = rmq.make_button(title: "Cancel", style: :cancel) {
25
+ # puts "Cancel pressed"
26
+ # }
27
+ # @return [UIAlertAction]
28
+ def make_button (opts = {}, &block)
29
+ # shortcut sending a string
30
+ opts = {title: opts} if opts.is_a? String
31
+
32
+ opts = {
33
+ title: "OK",
34
+ style: :default,
35
+ }.merge(opts)
36
+
37
+ style = RubyMotionQuery::AlertConstants::ALERT_ACTION_STYLE[opts[:style]] || opts[:style]
38
+
39
+ UIAlertAction.actionWithTitle(opts[:title], style: style, handler: -> (action) {
40
+ title_symbol = action.title.gsub(/\s+/,"_").downcase.to_sym
41
+ block.call(title_symbol) unless block.nil?
42
+ })
69
43
  end
70
- end
71
-
72
- def make_button (opts = {}, &block)
73
- opts = {
74
- title: "OK",
75
- style: :default,
76
- }.merge(opts)
77
-
78
- style = ALERT_ACTION_STYLE[opts[:style]] || opts[:style]
79
-
80
- UIAlertAction.actionWithTitle(opts[:title], style: style, handler: -> (action) {
81
- block.call unless block.nil?
82
- })
83
- end
84
-
85
-
86
- # Creates and shows the old UIAlertView. Added here for use in fallback.
87
- # Fallback won't run actions, but the old system needed delegates anyhow.
88
- # Usage Example:
89
- # rmq.alert_view(message: "This is a test")
90
- # rmq.alert_view(title: "Hey there", message: "Are you happy?")
91
- # @return [RMQ]
92
- def alert_view(opts = {})
93
-
94
- # shortcut sending a string
95
- opts = {message: opts} if opts.is_a? String
96
- # An alert is nothing without a message
97
- raise(ArgumentError, "RedAlert requires a message") if opts[:message].nil? || opts[:message].empty?
98
-
99
- opts = {
100
- title: "Alert!",
101
- cancel_button: "OK",
102
- other_buttons: [],
103
- delegate: nil,
104
- view_style: UIAlertViewStyleDefault,
105
- show_now: true,
106
- }.merge(opts)
107
-
108
- alert_view = UIAlertView.alloc.initWithTitle(
109
- opts[:title],
110
- message: opts[:message],
111
- delegate: opts[:delegate],
112
- cancelButtonTitle: opts[:cancel_button],
113
- otherButtonTitles: nil
114
- )
115
- Array(opts[:other_buttons]).each { |button| alert_view.addButtonWithTitle(button) }
116
-
117
- alert_view.alertViewStyle = opts[:view_style]
118
44
 
119
- alert_view.show if opts[:show_now]
120
- rmq(alert_view)
121
- end
45
+ end # close eigenclass
122
46
 
123
- end
47
+ end # close App
124
48
  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: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gant
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-21 00:00:00.000000000 Z
11
+ date: 2015-03-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_motion_query
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.8.0
19
+ version: 1.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.0
26
+ version: 1.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Plugin adds efficient and dynamic alerts/sheets for RMQ
41
+ description: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion
42
42
  email:
43
43
  - GantMan@gmail.com
44
44
  executables: []
@@ -46,6 +46,10 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - README.md
49
+ - lib/project/alert_constants.rb
50
+ - lib/project/button_templates.rb
51
+ - lib/project/classic_alert.rb
52
+ - lib/project/core_alert.rb
49
53
  - lib/project/red_alert.rb
50
54
  - lib/red_alert.rb
51
55
  homepage: https://github.com/GantMan/RedAlert
@@ -71,5 +75,5 @@ rubyforge_project:
71
75
  rubygems_version: 2.4.5
72
76
  signing_key:
73
77
  specification_version: 4
74
- summary: Plugin adds efficient and dynamic alerts/sheets for RMQ
78
+ summary: RMQ Plugin adds efficient and dynamic alerts/sheets for RubyMotion.
75
79
  test_files: []