sweetify 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +27 -0
- data/README.md +92 -0
- data/Rakefile +34 -0
- data/app/views/sweetify/_alert.html.erb +5 -0
- data/lib/sweetify.rb +2 -0
- data/lib/sweetify/engine.rb +4 -0
- data/lib/sweetify/sweetify.rb +93 -0
- data/lib/sweetify/version.rb +3 -0
- data/lib/tasks/sweetify_tasks.rake +4 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f789039fd2d9f4ab21db360af580e92b1af57315
|
4
|
+
data.tar.gz: ef1a2472e02d7713835d70172bdc5639713d6846
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 81b4a5787bfbb2ed630fc5be61dd9f1dcca5565e8909867fc01be63a63a98d269a5d73a28725b02b3c7bfcedc00329c6e3798c596331b9162380e5f3360d730b
|
7
|
+
data.tar.gz: 0ec18b7173fe8a1005950f455f7eb352044509d171e5d0a3ce51df7c13050d2cd508d973e3b8382b162389b0c38e5fa5b617b4e9010a31b839e4632d225aa0b5
|
data/LICENSE
ADDED
@@ -0,0 +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
|
27
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Sweetify - SweetAlert for Rails
|
2
|
+
This gem allows you to use [SweetAlert](http://t4t5.github.io/sweetalert/) for your flash messages.
|
3
|
+
_See the examples below, to see how it looks like_
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
**Note: This package does not provide the client side javascript and css files of SweetAlert. You have to provide them yourself.**
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'sweetify'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
```bash
|
16
|
+
$ bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Next add the following line to the bottom of your application's layout file:
|
20
|
+
```html
|
21
|
+
...
|
22
|
+
|
23
|
+
<%= render 'sweetify/alert' %>
|
24
|
+
|
25
|
+
</body>
|
26
|
+
</html>
|
27
|
+
```
|
28
|
+
|
29
|
+
**You have to restart your rails server after installing the gem**
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
You can now easily create alerts in your controllers with any of the following methods provided by **Sweetify**:
|
33
|
+
```ruby
|
34
|
+
# Base Method, no type specified
|
35
|
+
sweetalert(text, title = '', opts = {})
|
36
|
+
|
37
|
+
# Additional methods with the type already defined
|
38
|
+
alert_info(text, title = '', opts = {})
|
39
|
+
alert_success(text, title = '', opts = {})
|
40
|
+
alert_error(text, title = '', opts = {})
|
41
|
+
alert_warning(text, title = '', opts = {})
|
42
|
+
```
|
43
|
+
|
44
|
+
## Example Usage
|
45
|
+
```ruby
|
46
|
+
# POST /resource
|
47
|
+
def create
|
48
|
+
alert_success('Your resource is created and available.', 'Successfully created', persistent: 'Awesome!')
|
49
|
+
redirect_to resource_path
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
That would look like this after the redirect:
|
54
|
+
|
55
|
+
![Example Alert](http://i.imgur.com/3WMvk0y.png)
|
56
|
+
|
57
|
+
|
58
|
+
## Options
|
59
|
+
**By default, all alerts will dismiss after a sensible default number of seconds.**
|
60
|
+
|
61
|
+
Default Options set by **Sweetify**:
|
62
|
+
```ruby
|
63
|
+
{
|
64
|
+
showConfirmButton: false,
|
65
|
+
timer: 2000,
|
66
|
+
allowOutsideClick: true,
|
67
|
+
confirmButtonText: 'OK'
|
68
|
+
}
|
69
|
+
```
|
70
|
+
|
71
|
+
The following special options provided by **Sweetify** are available:
|
72
|
+
```ruby
|
73
|
+
sweetalert('Text', 'Title', button: true) # Shows an button with the default content on the alert but still closes automatically
|
74
|
+
sweetalert('Text', 'Title', button: 'Awesome!') # Same as above just with a specified text
|
75
|
+
|
76
|
+
sweetalert('Text', 'Title', persistent: true) # Shows the dialog with an button and the alert only closes if the button is pressed
|
77
|
+
sweetalert('Text', 'Title', persistent: 'Awesome!') # Same as above just with a specified text
|
78
|
+
```
|
79
|
+
|
80
|
+
You also can use any other available option that [SweetAlert accepts](http://t4t5.github.io/sweetalert/):
|
81
|
+
```ruby
|
82
|
+
alert_info('Here is a custom image', 'Sweet!', imageUrl: 'images/thumbs-up.jpg', timer: 5000)
|
83
|
+
```
|
84
|
+
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
Everyone is encouraged to help improve this project. Here are a few ways you can help:
|
88
|
+
|
89
|
+
- [Report bugs](https://github.com/atrox/sweetify/issues)
|
90
|
+
- Fix bugs and [submit pull requests](https://github.com/atrox/sweetify/pulls)
|
91
|
+
- Write, clarify, or fix documentation
|
92
|
+
- Suggest or add new features
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
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
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = true
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
data/lib/sweetify.rb
ADDED
@@ -0,0 +1,93 @@
|
|
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
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sweetify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Atrox
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionpack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
description: Sweetify allows you to easily use SweetAlert within your controllers
|
28
|
+
email:
|
29
|
+
- mail@atrox.me
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- app/views/sweetify/_alert.html.erb
|
38
|
+
- lib/sweetify.rb
|
39
|
+
- lib/sweetify/engine.rb
|
40
|
+
- lib/sweetify/sweetify.rb
|
41
|
+
- lib/sweetify/version.rb
|
42
|
+
- lib/tasks/sweetify_tasks.rake
|
43
|
+
homepage: https://github.com/atrox/sweetify
|
44
|
+
licenses:
|
45
|
+
- BSD-3-Clause
|
46
|
+
metadata: {}
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 2.4.5.1
|
64
|
+
signing_key:
|
65
|
+
specification_version: 4
|
66
|
+
summary: SweetAlert integrated in Ruby on Rails
|
67
|
+
test_files: []
|