RedAlert 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +69 -0
- data/lib/project/red_alert.rb +124 -0
- data/lib/red_alert.rb +10 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8fdabf0f5f8e1bf91a9f0011a1364df64391e9e2
|
4
|
+
data.tar.gz: 9eba51d49bb9963101eaa8599f1b4fe7042436dc
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 309e8754b89b2bc44a2745e5ded3cface2b14a5831237ef98075491806843a2a29ef6647b7b85d009a89f9ff348a4d102d69f9c93988b5a23f0d43aaa6e8a4c8
|
7
|
+
data.tar.gz: db0d2a6c17c14d675fe34652895dd5be0a9718fbd003950cdb3d52a9e87f907352d18373f8db47854b535b4ba28a9f64567e74d38c2981ce3ea08b3b6f3a49c9
|
data/README.md
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
[![image](http://ir_wp.s3.amazonaws.com/wp-content/uploads/sites/19/2014/09/rmq_plugin.png)](http://rubymotionquery.com)
|
2
|
+
|
3
|
+
# RedAlert
|
4
|
+
|
5
|
+
**Did you know that UIAlertView and UIActionSheet (as well as their respective delegate protocols) are deprecated in iOS 8?**
|
6
|
+
|
7
|
+
`UIAlertController` is used in this gem. Gracefully falls back to `UIAlertView` for versions older than iOS8
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
**Requires RMQ 0.8.0 or later, and iOS 7 or later**#
|
12
|
+
|
13
|
+
TODO: Write install instructions here
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
TODO: Write usage instructions here
|
18
|
+
```ruby
|
19
|
+
|
20
|
+
rmq.alert("Are you alive?") do
|
21
|
+
p "He is alive!"
|
22
|
+
end
|
23
|
+
|
24
|
+
rmq.alert(title: "foo", message: "Are you alive?") do
|
25
|
+
p "He is alive!"
|
26
|
+
end
|
27
|
+
|
28
|
+
rmq.alert(message: "Would you like a sandwich?", actions: :yes_no_cancel, style: :sheet) { |action_type|
|
29
|
+
case action_type
|
30
|
+
when :yes
|
31
|
+
p "yes"
|
32
|
+
when :no
|
33
|
+
p "no"
|
34
|
+
end
|
35
|
+
}
|
36
|
+
|
37
|
+
|
38
|
+
rmq.alert(title: "foo", message: "Would you like a sandwich?", actions: []
|
39
|
+
}
|
40
|
+
|
41
|
+
|
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
|
+
])
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
### Example using stylesheet:
|
52
|
+
|
53
|
+
TODO: stylesheet example here
|
54
|
+
|
55
|
+
### Example without stylesheet:
|
56
|
+
|
57
|
+
TODO: no stylesheet example here
|
58
|
+
|
59
|
+
### Methods
|
60
|
+
|
61
|
+
TODO: list methods available to user here
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
1. Fork it
|
66
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
67
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
68
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
69
|
+
5. Create new Pull Request
|
@@ -0,0 +1,124 @@
|
|
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)
|
28
|
+
end
|
29
|
+
|
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)
|
69
|
+
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
|
+
|
119
|
+
alert_view.show if opts[:show_now]
|
120
|
+
rmq(alert_view)
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
data/lib/red_alert.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
unless defined?(Motion::Project::Config)
|
4
|
+
raise "This file must be required within a RubyMotion project Rakefile."
|
5
|
+
end
|
6
|
+
|
7
|
+
lib_dir_path = File.dirname(File.expand_path(__FILE__))
|
8
|
+
Motion::Project::App.setup do |app|
|
9
|
+
app.files.unshift(Dir.glob(File.join(lib_dir_path, "project/**/*.rb")))
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: RedAlert
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gant
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby_motion_query
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Plugin adds efficient and dynamic alerts/sheets for RMQ
|
42
|
+
email:
|
43
|
+
- GantMan@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- README.md
|
49
|
+
- lib/project/red_alert.rb
|
50
|
+
- lib/red_alert.rb
|
51
|
+
homepage: https://github.com/GantMan/RedAlert
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.4.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Plugin adds efficient and dynamic alerts/sheets for RMQ
|
75
|
+
test_files: []
|