sweetify 0.1.0 → 1.0.0
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 +4 -4
- data/LICENSE +26 -26
- data/README.md +96 -91
- data/Rakefile +28 -34
- data/app/views/sweetify/_alert.html.erb +4 -4
- data/lib/sweetify/engine.rb +4 -4
- data/lib/sweetify/sweetalert.rb +97 -0
- data/lib/sweetify/version.rb +3 -3
- data/lib/sweetify.rb +2 -2
- metadata +4 -5
- data/lib/sweetify/sweetify.rb +0 -93
- data/lib/tasks/sweetify_tasks.rake +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0567245ede265266124eaf81f6a8e5bfc5b6dbb
|
4
|
+
data.tar.gz: d4316dc2e7edd6dfa910d3c5290c952777b2227e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e04d2ac5c188c025b53f6deef8be0bd1391fc854765a32df5064b95a2de897f79c095fb6f7c943149eb7fd1f197404bef4df8f52e11a187e85426553dd4846b
|
7
|
+
data.tar.gz: 4dc3cfe1e9333b8c1f58d8ead8f62bc8ca33b7ee2b8832e705162544e6f735b4deaee16beab2a6a5430a087bea97059a3ccb9352e2265a822797412434415a43
|
data/LICENSE
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
-
Copyright (c) 2016, Atrox
|
2
|
-
All rights reserved.
|
3
|
-
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
6
|
-
|
7
|
-
* Redistributions of source code must retain the above copyright notice, this
|
8
|
-
list of conditions and the following disclaimer.
|
9
|
-
|
10
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
-
this list of conditions and the following disclaimer in the documentation
|
12
|
-
and/or other materials provided with the distribution.
|
13
|
-
|
14
|
-
* Neither the name of Sweetify nor the names of its
|
15
|
-
contributors may be used to endorse or promote products derived from
|
16
|
-
this software without specific prior written permission.
|
17
|
-
|
18
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
-
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
-
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
-
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
-
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
1
|
+
Copyright (c) 2016, Atrox
|
2
|
+
All rights reserved.
|
3
|
+
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
5
|
+
modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
list of conditions and the following disclaimer.
|
9
|
+
|
10
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
11
|
+
this list of conditions and the following disclaimer in the documentation
|
12
|
+
and/or other materials provided with the distribution.
|
13
|
+
|
14
|
+
* Neither the name of Sweetify nor the names of its
|
15
|
+
contributors may be used to endorse or promote products derived from
|
16
|
+
this software without specific prior written permission.
|
17
|
+
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
19
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
20
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
21
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
22
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
23
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
24
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
25
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
26
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
27
27
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -1,92 +1,97 @@
|
|
1
|
-
# Sweetify - SweetAlert for Rails
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
```
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
```
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
You
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
#
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
```
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
```
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
sweetalert('Text', 'Title',
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
```
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
1
|
+
# Sweetify - SweetAlert for Rails
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/sweetify)
|
4
|
+
|
5
|
+
This gem allows you to use [SweetAlert](http://t4t5.github.io/sweetalert/) for your flash messages.
|
6
|
+
_See the examples below, to see how to use it_
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
**Note: This package does not provide the client-side files of SweetAlert. You have to provide them yourself.**
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'sweetify'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
```bash
|
19
|
+
$ bundle
|
20
|
+
```
|
21
|
+
|
22
|
+
Next add the following line to the bottom of your application's layout file:
|
23
|
+
```html
|
24
|
+
...
|
25
|
+
|
26
|
+
<%= render 'sweetify/alert' %>
|
27
|
+
|
28
|
+
</body>
|
29
|
+
</html>
|
30
|
+
```
|
31
|
+
|
32
|
+
**You have to restart your rails server after installing the gem**
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
You can now easily create alerts in your controllers with any of the following methods provided by **Sweetify**:
|
36
|
+
```ruby
|
37
|
+
# Base Method, no type specified
|
38
|
+
sweetalert(text, title = '', opts = {})
|
39
|
+
|
40
|
+
# Additional methods with the type already defined
|
41
|
+
sweetalert_info(text, title = '', opts = {})
|
42
|
+
sweetalert_success(text, title = '', opts = {})
|
43
|
+
sweetalert_error(text, title = '', opts = {})
|
44
|
+
sweetalert_warning(text, title = '', opts = {})
|
45
|
+
```
|
46
|
+
|
47
|
+
## Example Usage
|
48
|
+
```ruby
|
49
|
+
# POST /resource
|
50
|
+
def create
|
51
|
+
sweetalert_success('Your resource is created and available.', 'Successfully created', persistent: 'Awesome!')
|
52
|
+
redirect_to resource_path
|
53
|
+
end
|
54
|
+
```
|
55
|
+
|
56
|
+
That would look like this after the redirect:
|
57
|
+
|
58
|
+

|
59
|
+
|
60
|
+
|
61
|
+
## Options
|
62
|
+
**By default, all alerts will dismiss after a sensible default number of seconds.**
|
63
|
+
|
64
|
+
Default Options set by **Sweetify**:
|
65
|
+
```ruby
|
66
|
+
{
|
67
|
+
showConfirmButton: false,
|
68
|
+
timer: 2000,
|
69
|
+
allowOutsideClick: true,
|
70
|
+
confirmButtonText: 'OK'
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
The following special options provided by **Sweetify** are available:
|
75
|
+
```ruby
|
76
|
+
# Shows the alert with a button, but will still close automatically
|
77
|
+
sweetalert('Text', 'Title', button: true)
|
78
|
+
sweetalert('Text', 'Title', button: 'Awesome!') # Custom text for the button
|
79
|
+
|
80
|
+
# Shows the alert with a button and only closes if the button is pressed
|
81
|
+
sweetalert('Text', 'Title', persistent: true)
|
82
|
+
sweetalert('Text', 'Title', persistent: 'Awesome!') # Custom text for the button
|
83
|
+
```
|
84
|
+
|
85
|
+
You also can use any other available option that [SweetAlert accepts](http://t4t5.github.io/sweetalert/):
|
86
|
+
```ruby
|
87
|
+
sweetalert_info('Here is a custom image', 'Sweet!', imageUrl: 'images/thumbs-up.jpg', timer: 5000)
|
88
|
+
```
|
89
|
+
|
90
|
+
|
91
|
+
## Contributing
|
92
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
93
|
+
|
94
|
+
- [Report bugs](https://github.com/atrox/sweetify/issues)
|
95
|
+
- Fix bugs and [submit pull requests](https://github.com/atrox/sweetify/pulls)
|
96
|
+
- Write, clarify, or fix documentation
|
92
97
|
- Suggest or add new features
|
data/Rakefile
CHANGED
@@ -1,34 +1,28 @@
|
|
1
|
-
begin
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'Sweetify'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.md')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
t.pattern = 'test/**/*_test.rb'
|
30
|
-
t.verbose = true
|
31
|
-
end
|
32
|
-
|
33
|
-
|
34
|
-
task default: :test
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Sweetify'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'bundler/gem_tasks'
|
18
|
+
|
19
|
+
require 'rake/testtask'
|
20
|
+
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
22
|
+
t.libs << 'lib'
|
23
|
+
t.libs << 'test'
|
24
|
+
t.pattern = 'test/**/*_test.rb'
|
25
|
+
t.verbose = true
|
26
|
+
end
|
27
|
+
|
28
|
+
task default: :test
|
@@ -1,5 +1,5 @@
|
|
1
|
-
<% if flash[:sweetify].present? %>
|
2
|
-
<script>
|
3
|
-
swal(<%= flash[:sweetify].html_safe %>)
|
4
|
-
</script>
|
1
|
+
<% if flash[:sweetify].present? %>
|
2
|
+
<script>
|
3
|
+
swal(<%= flash[:sweetify].html_safe %>)
|
4
|
+
</script>
|
5
5
|
<% end %>
|
data/lib/sweetify/engine.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
module Sweetify
|
2
|
-
class Engine < ::Rails::Engine
|
3
|
-
end
|
4
|
-
end
|
1
|
+
module Sweetify
|
2
|
+
class Engine < ::Rails::Engine
|
3
|
+
end
|
4
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
module Sweetify
|
2
|
+
module SweetAlert
|
3
|
+
# Display an alert with a text and an optional title
|
4
|
+
# Default without an specific type
|
5
|
+
#
|
6
|
+
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
7
|
+
# @param [String] title Title of the alert
|
8
|
+
# @param [Hash] opts Optional Parameters
|
9
|
+
def sweetalert(text, title = '', opts = {})
|
10
|
+
opts = {
|
11
|
+
showConfirmButton: false,
|
12
|
+
timer: 2000,
|
13
|
+
allowOutsideClick: true,
|
14
|
+
confirmButtonText: 'OK'
|
15
|
+
}.merge(opts)
|
16
|
+
|
17
|
+
opts[:text] = text
|
18
|
+
opts[:title] = title
|
19
|
+
|
20
|
+
if opts[:button]
|
21
|
+
opts[:showConfirmButton] = true
|
22
|
+
opts[:confirmButtonText] = opts[:button] if opts[:button].is_a?(String)
|
23
|
+
|
24
|
+
opts.delete(:button)
|
25
|
+
end
|
26
|
+
|
27
|
+
if opts[:persistent]
|
28
|
+
opts[:showConfirmButton] = true
|
29
|
+
opts[:allowOutsideClick] = false
|
30
|
+
opts[:timer] = nil
|
31
|
+
opts[:confirmButtonText] = opts[:persistent] if opts[:persistent].is_a?(String)
|
32
|
+
|
33
|
+
opts.delete(:persistent)
|
34
|
+
end
|
35
|
+
|
36
|
+
flash_config(opts)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Information Alert
|
40
|
+
#
|
41
|
+
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
42
|
+
# @param [String] title Title of the alert
|
43
|
+
# @param [Hash] opts Optional Parameters
|
44
|
+
def sweetalert_info(text, title = '', opts = {})
|
45
|
+
opts[:type] = :info
|
46
|
+
sweetalert(text, title, opts)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Success Alert
|
50
|
+
#
|
51
|
+
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
52
|
+
# @param [String] title Title of the alert
|
53
|
+
# @param [Hash] opts Optional Parameters
|
54
|
+
def sweetalert_success(text, title = '', opts = {})
|
55
|
+
opts[:type] = :success
|
56
|
+
sweetalert(text, title, opts)
|
57
|
+
end
|
58
|
+
|
59
|
+
# Error Alert
|
60
|
+
#
|
61
|
+
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
62
|
+
# @param [String] title Title of the alert
|
63
|
+
# @param [Hash] opts Optional Parameters
|
64
|
+
def sweetalert_error(text, title = '', opts = {})
|
65
|
+
opts[:type] = :error
|
66
|
+
sweetalert(text, title, opts)
|
67
|
+
end
|
68
|
+
|
69
|
+
# Warning Alert
|
70
|
+
#
|
71
|
+
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
72
|
+
# @param [String] title Title of the alert
|
73
|
+
# @param [Hash] opts Optional Parameters
|
74
|
+
def sweetalert_warning(text, title = '', opts = {})
|
75
|
+
opts[:type] = :warning
|
76
|
+
sweetalert(text, title, opts)
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
# Flash the configuration as json
|
82
|
+
# If no title is specified, use the text as the title
|
83
|
+
#
|
84
|
+
# @param [Hash] opts
|
85
|
+
# @return [Void]
|
86
|
+
def flash_config(opts)
|
87
|
+
if opts[:title].blank?
|
88
|
+
opts[:title] = opts[:text]
|
89
|
+
opts.delete(:text)
|
90
|
+
end
|
91
|
+
|
92
|
+
flash[:sweetify] = opts.to_json
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
ActionController::Base.send :include, Sweetify::SweetAlert
|
data/lib/sweetify/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Sweetify
|
2
|
-
VERSION = '
|
3
|
-
end
|
1
|
+
module Sweetify
|
2
|
+
VERSION = '1.0.0'.freeze
|
3
|
+
end
|
data/lib/sweetify.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require 'sweetify/engine'
|
2
|
-
require 'sweetify/
|
1
|
+
require 'sweetify/engine'
|
2
|
+
require 'sweetify/sweetalert'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sweetify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atrox
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-12-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -37,9 +37,8 @@ files:
|
|
37
37
|
- app/views/sweetify/_alert.html.erb
|
38
38
|
- lib/sweetify.rb
|
39
39
|
- lib/sweetify/engine.rb
|
40
|
-
- lib/sweetify/
|
40
|
+
- lib/sweetify/sweetalert.rb
|
41
41
|
- lib/sweetify/version.rb
|
42
|
-
- lib/tasks/sweetify_tasks.rake
|
43
42
|
homepage: https://github.com/atrox/sweetify
|
44
43
|
licenses:
|
45
44
|
- BSD-3-Clause
|
@@ -60,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
59
|
version: '0'
|
61
60
|
requirements: []
|
62
61
|
rubyforge_project:
|
63
|
-
rubygems_version: 2.
|
62
|
+
rubygems_version: 2.5.2
|
64
63
|
signing_key:
|
65
64
|
specification_version: 4
|
66
65
|
summary: SweetAlert integrated in Ruby on Rails
|
data/lib/sweetify/sweetify.rb
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
module Sweetify
|
2
|
-
|
3
|
-
# Display an alert with a text and an optional title
|
4
|
-
# Default without an specific type
|
5
|
-
#
|
6
|
-
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
7
|
-
# @param [String] title TItle of the alert
|
8
|
-
# @param [Hash] opts Optional Parameters
|
9
|
-
def sweetalert(text, title = '', opts = {})
|
10
|
-
opts = {
|
11
|
-
showConfirmButton: false,
|
12
|
-
timer: 2000,
|
13
|
-
allowOutsideClick: true,
|
14
|
-
confirmButtonText: 'OK'
|
15
|
-
}.merge(opts)
|
16
|
-
|
17
|
-
opts[:text] = text
|
18
|
-
opts[:title] = title
|
19
|
-
|
20
|
-
if opts[:button]
|
21
|
-
opts[:showConfirmButton] = true
|
22
|
-
opts[:confirmButtonText] = opts[:button] if opts[:button].is_a?(String)
|
23
|
-
end
|
24
|
-
|
25
|
-
if opts[:persistent]
|
26
|
-
opts[:showConfirmButton] = true
|
27
|
-
opts[:allowOutsideClick] = false
|
28
|
-
opts[:timer] = nil
|
29
|
-
opts[:confirmButtonText] = opts[:persistent] if opts[:persistent].is_a?(String)
|
30
|
-
end
|
31
|
-
|
32
|
-
flash_config(opts)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Information Alert
|
36
|
-
#
|
37
|
-
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
38
|
-
# @param [String] title TItle of the alert
|
39
|
-
# @param [Hash] opts Optional Parameters
|
40
|
-
def alert_info(text, title = '', opts = {})
|
41
|
-
opts[:type] = :info
|
42
|
-
sweetalert(text, title, opts)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Success Alert
|
46
|
-
#
|
47
|
-
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
48
|
-
# @param [String] title TItle of the alert
|
49
|
-
# @param [Hash] opts Optional Parameters
|
50
|
-
def alert_success(text, title = '', opts = {})
|
51
|
-
opts[:type] = :success
|
52
|
-
sweetalert(text, title, opts)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Error Alert
|
56
|
-
#
|
57
|
-
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
58
|
-
# @param [String] title TItle of the alert
|
59
|
-
# @param [Hash] opts Optional Parameters
|
60
|
-
def alert_error(text, title = '', opts = {})
|
61
|
-
opts[:type] = :error
|
62
|
-
sweetalert(text, title, opts)
|
63
|
-
end
|
64
|
-
|
65
|
-
# Warning Alert
|
66
|
-
#
|
67
|
-
# @param [String] text Body of the alert (gets automatically the title if no title is specified)
|
68
|
-
# @param [String] title TItle of the alert
|
69
|
-
# @param [Hash] opts Optional Parameters
|
70
|
-
def alert_warning(text, title = '', opts = {})
|
71
|
-
opts[:type] = :warning
|
72
|
-
sweetalert(text, title, opts)
|
73
|
-
end
|
74
|
-
|
75
|
-
private
|
76
|
-
|
77
|
-
# Flash the configuration as json
|
78
|
-
# If no title is specified, use the text as the title
|
79
|
-
#
|
80
|
-
# @param [Hash] opts
|
81
|
-
# @return [Void]
|
82
|
-
def flash_config(opts)
|
83
|
-
if opts[:title].blank?
|
84
|
-
opts[:title] = opts[:text]
|
85
|
-
opts.delete(:text)
|
86
|
-
end
|
87
|
-
|
88
|
-
flash[:sweetify] = opts.to_json
|
89
|
-
end
|
90
|
-
|
91
|
-
end
|
92
|
-
|
93
|
-
ActionController::Base.send :include, Sweetify
|