simple_si 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ .DS_Store
data/README.md CHANGED
@@ -3,25 +3,26 @@ SimpleSI for RubyMotion
3
3
 
4
4
  I wanted a dead simple way to call SIAlertView (https://github.com/Sumi-Interactive/SIAlertView) in one line, similar to BubbleWrap's `App.alert()`.
5
5
 
6
+ ## Setup
6
7
 
7
- ## Installation
8
-
8
+ Add simple_si to your Gemfile, and run `bundle install`:
9
9
  ```ruby
10
- gem install simple_si
10
+ gem 'motion-cocoapods'
11
+ gem 'simple_si'
11
12
  ```
12
13
 
13
- ## Setup
14
-
15
- Edit the `Rakefile` of your RubyMotion project and add the following require line:
16
-
14
+ Edit the Rakefile of your RubyMotion project and add the following require line:
17
15
  ```ruby
18
- require 'simple_si'
16
+ # After the line that require Rubymotion
17
+ require 'bundler'
18
+ Bundler.require
19
19
  ```
20
- or
21
20
 
22
- Add simple_si to your Gemfile, and run `bundle install`:
21
+ Then add SIAlertView to your pods list in your Rakefile:
23
22
  ```ruby
24
- gem 'simple_si'
23
+ app.pods do
24
+ pod 'SIAlertView'
25
+ end
25
26
  ```
26
27
 
27
28
  Usage
@@ -33,26 +34,42 @@ Basic:
33
34
  SimpleSI.alert('Hello World!')
34
35
  ```
35
36
 
36
- If you want a title:
37
-
37
+ Custom:
38
38
  ```ruby
39
- SimpleSI.alert_with_title('My App', 'Hello World!')
39
+ SimpleSI.alert({
40
+ title: "My App",
41
+ message: "Are you sure?",
42
+ transition: "drop down", # or "slide from down", "slide from up", "fade" or "bounce"
43
+ buttons: [
44
+ {title: "Destroy", action: :destroy}, # no type specify become default styling
45
+ {title: "Cancel", type: "cancel"} # action is secondary
46
+ ],
47
+ delegate: self # Needed if you want to call method of a class with your button
48
+ })
40
49
  ```
41
50
 
42
- You can also leverage the following transitions:
43
- ```ruby
44
- # SIAlertViewTransitionStyleSlideFromBottom (default)
45
- # SIAlertViewTransitionStyleSlideFromTop
46
- # SIAlertViewTransitionStyleFade
47
- # SIAlertViewTransitionStyleBounce
48
- # SIAlertViewTransitionStyleDropDown
51
+ ## Transition
52
+
53
+ Here's the string you can pass to the transition property of the constructor (secondary). The default value is `"slide from bottom"`.
54
+
55
+ * `"drop_down"`
56
+ * `"slide_from_top"`
57
+ * `"slide_from_bottom"`
58
+ * `"fade"`
59
+ * `"bounce"`
60
+
61
+ ## Buttons
62
+
63
+ You have 3 types of styling for buttons (secondary). The default value is `"default"` (that's original).
64
+
65
+ * `"default"`
66
+ * `"destructive"`
67
+ * `"cancel"`
49
68
 
50
- SimpleSI.alert('Hello World!', SIAlertViewTransitionStyleDropDown)
51
- ```
52
69
  ## To-do
53
70
 
54
71
  * Write specs
55
72
 
56
73
  ## Contributions
57
74
 
58
- Fork, improve, submit a pull request.
75
+ Fork, improve, submit a pull request.
@@ -1,17 +1,62 @@
1
- class SimpleSI
2
-
3
- def self.alert(text, transition_style = SIAlertViewTransitionStyleSlideFromBottom)
4
- alert = SIAlertView.alloc.initWithTitle(nil, andMessage:text)
5
- alert.transitionStyle = transition_style
6
- alert.addButtonWithTitle("OK", type:SIAlertViewButtonTypeDefault, handler:nil)
7
- alert.show
8
- end
1
+ module SimpleSI
2
+
3
+ module_function
4
+
5
+ def alert(args = {})
6
+ args.kind_of?(String) ? build({ message: args }) : build(args)
7
+ end
8
+
9
+ def build(args)
10
+ @message = args[:message] || "No message"
11
+ @title = args[:title] || nil
12
+ @delegate = args[:delegate] || self
13
+
14
+ @transition = transitionBuild args[:transition]
15
+ @buttons = buttonsBuild args[:buttons]
16
+
17
+ alert = SIAlertView.alloc.initWithTitle(@title, andMessage:@message)
18
+ alert.transitionStyle = @transition
19
+
20
+ @buttons.each do |b|
21
+ alert.addButtonWithTitle(
22
+ b[:title],
23
+ type: b[:type],
24
+ handler: proc {|a| @delegate.send(b[:action]) if b[:action]}
25
+ )
26
+ end
9
27
 
10
- def self.alert_with_title(title, text, transition_style = SIAlertViewTransitionStyleSlideFromBottom)
11
- alert = SIAlertView.alloc.initWithTitle(title, andMessage:text)
12
- alert.transitionStyle = transition_style
13
- alert.addButtonWithTitle("OK", type:SIAlertViewButtonTypeDefault, handler:nil)
14
28
  alert.show
15
29
  end
16
30
 
31
+ def transitionBuild(transition)
32
+ return case transition
33
+ when "slide_from_bottom" then SIAlertViewTransitionStyleSlideFromBottom
34
+ when "slide_from_top" then SIAlertViewTransitionStyleSlideFromTop
35
+ when "fade" then SIAlertViewTransitionStyleFade
36
+ when "bounce" then SIAlertViewTransitionStyleBounce
37
+ when "drop_down" then SIAlertViewTransitionStyleDropDown
38
+ else SIAlertViewTransitionStyleSlideFromBottom
39
+ end
40
+ end
41
+
42
+ def buttonsBuild(buttons)
43
+ build = buttons || [{title: "OK", type: "default"}]
44
+ build.each do |b|
45
+ if b[:action] && @delegate==self
46
+ b[:action] = :warning_delegate
47
+ end
48
+
49
+ b[:type] = case b[:type]
50
+ when "default" then SIAlertViewButtonTypeDefault
51
+ when "destructive" then SIAlertViewButtonTypeDestructive
52
+ when "cancel" then SIAlertViewButtonTypeCancel
53
+ else SIAlertViewButtonTypeDefault
54
+ end
55
+ end
56
+ build
57
+ end
58
+
59
+ def warning_delegate
60
+ warn "SimpleSI [WARNING] : You need to specify a delegate in the constructor to call action on your buttons."
61
+ end
17
62
  end
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "simple_si"
4
- s.version = '0.0.3'
4
+ s.version = '0.0.4'
5
5
  s.summary = "Rubymotion gem to easily call Sumi-Interactive's SIAlertView"
6
6
  s.description = "Quickly call an SIAlertView in one line: SimpleSI.alert('Hello World!')"
7
7
  s.authors = ["Forrest Grant"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_si
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-30 00:00:00.000000000 Z
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'Quickly call an SIAlertView in one line: SimpleSI.alert(''Hello World!'')'
15
15
  email: forrest@forrestgrant.com
@@ -17,7 +17,7 @@ executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
- - .DS_Store
20
+ - .gitignore
21
21
  - README.md
22
22
  - lib/simple_si.rb
23
23
  - lib/simple_si/simple_si.rb
data/.DS_Store DELETED
Binary file