gbdev-pretty_flash 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +15 -0
- data/MIT-LICENSE +20 -0
- data/README.textile +49 -0
- data/Rakefile +23 -0
- data/init.rb +1 -0
- data/install.rb +23 -0
- data/lib/pretty_flash/pretty_flash.rb +91 -0
- data/lib/pretty_flash.rb +18 -0
- data/public/images/flash-error-bg.jpg +0 -0
- data/public/images/flash-error.png +0 -0
- data/public/images/flash-notice-bg.jpg +0 -0
- data/public/images/flash-notice.png +0 -0
- data/public/images/flash-success-bg.jpg +0 -0
- data/public/images/flash-success.png +0 -0
- data/public/images/flash-warning-bg.jpg +0 -0
- data/public/images/flash-warning.png +0 -0
- data/public/javascripts/pretty_flash.js +29 -0
- data/public/stylesheets/pretty_flash.css +59 -0
- data/test/pretty_flash_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/uninstall.rb +1 -0
- metadata +77 -0
data/CHANGELOG
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
0.1.1
|
2
|
+
* Moved 'assets' to 'public'
|
3
|
+
* Made it copy 'public' stuff to your rails app when application starts
|
4
|
+
* Gem'ified plugin
|
5
|
+
* Refactored flash set methods to add hash options for:
|
6
|
+
:now - Whether to use flash or flash.now
|
7
|
+
:delimiter - separator between messages
|
8
|
+
:clear_flash - delete flash for the type of flash called (:notice, :error, etc)
|
9
|
+
:object - an ActiveRecord object with @errors
|
10
|
+
:check_associations - load errors from model associations of the AR Object
|
11
|
+
|
12
|
+
0.1.0
|
13
|
+
* Forked from http://github.com/rpheath/pretty_flash
|
14
|
+
* Added 'success' and made it take the 'green' action
|
15
|
+
* Made 'notice' into blue/white informational flash message
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
h1. PrettyFlash
|
2
|
+
|
3
|
+
Rails plugin that provides "pretty" flash messages and additional helpers to pull errors from ActiveRecord objects and as well as errors on associated models of an ActiveRecord object.
|
4
|
+
|
5
|
+
h2. In the controller...
|
6
|
+
|
7
|
+
This plugin gives a couple of convenience methods for setting flash messages.
|
8
|
+
|
9
|
+
<pre><code>success "Hooray! You did something good."
|
10
|
+
notice "Hey! This is for tips and general information."
|
11
|
+
warning "Ummm, You're not allowed to do that yet."
|
12
|
+
error "Ooooops! Something went wrong."</code></pre>
|
13
|
+
|
14
|
+
Use those methods instead of the typical @flash[:notice] = "Some String"@
|
15
|
+
|
16
|
+
h2. In the view...
|
17
|
+
|
18
|
+
Then all you have to do to display them is:
|
19
|
+
|
20
|
+
<pre><code><%= display_flash_messages %></code></pre>
|
21
|
+
|
22
|
+
Easy enough?
|
23
|
+
|
24
|
+
h2. Get Started
|
25
|
+
|
26
|
+
Install the Gem
|
27
|
+
<pre><code>sudo gem install gbdev-pretty_flash</code></pre>
|
28
|
+
|
29
|
+
Add the gem to your environment.rb file
|
30
|
+
<pre><code>config.gem 'gbdev-pretty_flash', :lib => 'pretty_flash', :version => '0.1.0', :source => 'http://gems.github.com'</code></pre>
|
31
|
+
|
32
|
+
There's a public folder with this plugin/gem that contains the images, CSS, and javascript (optional). The first time you run your application with the added config.gem line, the images, stylesheet, and javascript will be copied to your public folder.
|
33
|
+
|
34
|
+
On subsequent application starts, the plugin/gem checks for the presence of public/images/flash-error.png. If this file
|
35
|
+
is present, nothing will be copied to your public directory.
|
36
|
+
|
37
|
+
WARNING: this will overwrite any of the files that have the same name. So double check if you don't want that to happen.
|
38
|
+
|
39
|
+
Also, the pretty_flash.js file located in the public/javascripts folder is only used to fade the flash messages after so many
|
40
|
+
seconds (defaults to 2.5 seconds). If you want that capability, just copy the relevant section of code (prototype or jquery) to application.js and you're all set.
|
41
|
+
|
42
|
+
h2. Credits
|
43
|
+
|
44
|
+
Original plugin by Ryan Heath (http://github.com/rpheath/pretty_flash).
|
45
|
+
Converted to a gem and extensively modified by Great Basin Development, LLC.
|
46
|
+
|
47
|
+
h2. Licensing
|
48
|
+
|
49
|
+
Copyright (c) 2008 Ryan Heath, released under the MIT license
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the pretty_flash plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the pretty_flash plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'PrettyFlash'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + "/lib/pretty_flash.rb"
|
data/install.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
message = <<-MESSAGE
|
2
|
+
|
3
|
+
********************************************
|
4
|
+
To get started, navigate to your project
|
5
|
+
root, and type:
|
6
|
+
|
7
|
+
$ rake pretty_flash:install
|
8
|
+
|
9
|
+
That will copy all of the necessary assets
|
10
|
+
to their appropriate homes.
|
11
|
+
|
12
|
+
!! WARNING: there is no protection against
|
13
|
+
file collision, so your files will be
|
14
|
+
overwritten if they already exist. You
|
15
|
+
may want to check that first! (see the
|
16
|
+
pretty_flash/assets/ to check)
|
17
|
+
|
18
|
+
Enjoy!
|
19
|
+
********************************************
|
20
|
+
|
21
|
+
MESSAGE
|
22
|
+
|
23
|
+
puts message
|
@@ -0,0 +1,91 @@
|
|
1
|
+
module PrettyFlash
|
2
|
+
module ControllerMethods
|
3
|
+
|
4
|
+
# clear all flash if you need to ensure it is empty. This shouldn't
|
5
|
+
# normally be needed if you are properly using flash and flash.now
|
6
|
+
def clear_all_flash
|
7
|
+
flash.delete(:success)
|
8
|
+
flash.delete(:notice)
|
9
|
+
flash.delete(:warning)
|
10
|
+
flash.delete(:error)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Flash Message Valid options
|
14
|
+
# :now - Whether to use flash or flash.now
|
15
|
+
# :delimiter - separator between messages
|
16
|
+
# :clear_flash - delete flash for the type of flash called (:notice, :error, etc)
|
17
|
+
# :object - an activerecord object with @errors
|
18
|
+
# :check_associations - model associations of the AR Object that may also have errors that need to be displayed
|
19
|
+
|
20
|
+
# Add a success flash message
|
21
|
+
def success(msg, options={})
|
22
|
+
flash_message(msg, options.merge({:msg_sym => :success}))
|
23
|
+
end
|
24
|
+
|
25
|
+
# Add a notice flash message
|
26
|
+
def notice(msg, options={})
|
27
|
+
flash_message(msg, options.merge({:msg_sym => :notice}))
|
28
|
+
end
|
29
|
+
|
30
|
+
# Add a warning flash message
|
31
|
+
def warning(msg, options={})
|
32
|
+
flash_message(msg, options.merge({:msg_sym => :warning}))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Add an error flash message
|
36
|
+
def error(msg, options={})
|
37
|
+
flash_message(msg, options.merge({:msg_sym => :error}))
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def flash_message(msg, options={})
|
43
|
+
now = options[:now].nil? || options[:now] || (request.xhr? ? true : false)
|
44
|
+
options[:msg_sym] = :error if options[:msg_sym].nil?
|
45
|
+
options[:delimiter] = '<br />' if options[:delimiter].nil?
|
46
|
+
obj = options[:object].nil? ? nil : options[:object]
|
47
|
+
options[:check_associations] = [] if options[:check_associations].nil? or obj.nil?
|
48
|
+
flash.delete(options[:msg_sym]) if options[:clear_flash]
|
49
|
+
|
50
|
+
msgs = []
|
51
|
+
msgs << msg unless msg.empty?
|
52
|
+
|
53
|
+
unless obj.nil?
|
54
|
+
obj.errors.each { |att, dtl|
|
55
|
+
msgs << dtl unless options[:check_associations].include?(att.to_sym)
|
56
|
+
}
|
57
|
+
options[:check_associations].each { |assoc|
|
58
|
+
eval("obj.#{assoc}").each { |obj_assoc|
|
59
|
+
obj_assoc.errors.each { |att, dtl|
|
60
|
+
msgs << dtl
|
61
|
+
}
|
62
|
+
}
|
63
|
+
}
|
64
|
+
end
|
65
|
+
|
66
|
+
unless msgs.empty?
|
67
|
+
if now
|
68
|
+
flash.now[options[:msg_sym]] = '' if flash[options[:msg_sym]].nil?
|
69
|
+
flash.now[options[:msg_sym]] << msgs.join(options[:delimiter])
|
70
|
+
else
|
71
|
+
flash[options[:msg_sym]] = '' if flash[options[:msg_sym]].nil?
|
72
|
+
flash[options[:msg_sym]] << msgs.join(options[:delimiter])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
module Display
|
80
|
+
|
81
|
+
def display_flash_messages
|
82
|
+
returning html = String.new do
|
83
|
+
flash.each do |css_class, message|
|
84
|
+
html << content_tag(:p, content_tag(:span, nil) + message, :class => css_class)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/lib/pretty_flash.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "pretty_flash/pretty_flash.rb"
|
2
|
+
|
3
|
+
if Object.const_defined?(:Rails) && File.directory?(Rails.root + "/public")
|
4
|
+
|
5
|
+
ActionController::Base.send(:include, PrettyFlash::ControllerMethods)
|
6
|
+
ActionView::Base.send(:include, PrettyFlash::Display)
|
7
|
+
|
8
|
+
# install files
|
9
|
+
unless File.exists?(RAILS_ROOT + '/public/images/flash-error.png')
|
10
|
+
['/public/images', '/public/stylesheets', '/public/javascripts'].each do |dir|
|
11
|
+
source = File.dirname(__FILE__) + "/../#{dir}"
|
12
|
+
dest = RAILS_ROOT + dir
|
13
|
+
FileUtils.mkdir_p(dest)
|
14
|
+
FileUtils.cp(Dir.glob(source+'/*.*'), dest)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,29 @@
|
|
1
|
+
// Copy the snippet that applies to you, and paste it in application.js
|
2
|
+
// You can delete this file after copying what you need.
|
3
|
+
|
4
|
+
|
5
|
+
// jQuery -------------------------------------------------------------
|
6
|
+
// $(document).ready(function() {
|
7
|
+
// setTimeout(hideFlashes, 25000);
|
8
|
+
// });
|
9
|
+
//
|
10
|
+
// var hideFlashes = function() {
|
11
|
+
// $('p.notice, p.warning, p.error').fadeOut(1500);
|
12
|
+
// }
|
13
|
+
// --------------------------------------------------------------------
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
// Prototype JS -------------------------------------------------------
|
20
|
+
// document.observe('dom:loaded', function() {
|
21
|
+
// setTimeout(hideFlashes, 25000);
|
22
|
+
// });
|
23
|
+
//
|
24
|
+
// var hideFlashes = function() {
|
25
|
+
// $$('.notice', '.warning', '.error').each(function(e) {
|
26
|
+
// if (e) Effect.Fade(e, { duration: 1.5 });
|
27
|
+
// })
|
28
|
+
// }
|
29
|
+
// --------------------------------------------------------------------
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/*
|
2
|
+
Copy the contents to your default.css and edit as needed or keep this
|
3
|
+
as a separate css file.
|
4
|
+
|
5
|
+
You can delete this file after copying what you need to default.css.
|
6
|
+
*/
|
7
|
+
|
8
|
+
p.success,
|
9
|
+
p.notice,
|
10
|
+
p.warning,
|
11
|
+
p.error {
|
12
|
+
font-size: 18px;
|
13
|
+
padding: 15px 10px;
|
14
|
+
margin-bottom: 10px;
|
15
|
+
}
|
16
|
+
|
17
|
+
p.success span,
|
18
|
+
p.notice span,
|
19
|
+
p.warning span,
|
20
|
+
p.error span {
|
21
|
+
float: left;
|
22
|
+
width: 42px;
|
23
|
+
height: 32px;
|
24
|
+
margin-top: -5px;
|
25
|
+
}
|
26
|
+
|
27
|
+
p.success {
|
28
|
+
background: url(../images/flash-success-bg.jpg) repeat-x left top;
|
29
|
+
color: #41612f;
|
30
|
+
}
|
31
|
+
p.success span {
|
32
|
+
background: url(../images/flash-success.png) no-repeat left top;
|
33
|
+
}
|
34
|
+
|
35
|
+
p.notice {
|
36
|
+
background: url(../images/flash-notice-bg.jpg) repeat-x left top;
|
37
|
+
color: #41612f;
|
38
|
+
}
|
39
|
+
p.notice span {
|
40
|
+
background: url(../images/flash-notice.png) no-repeat left top;
|
41
|
+
}
|
42
|
+
|
43
|
+
p.warning {
|
44
|
+
background: url(../images/flash-warning-bg.jpg) repeat-x left -10px;
|
45
|
+
color: #a26a1a;
|
46
|
+
}
|
47
|
+
p.warning span {
|
48
|
+
margin-top: -6px;
|
49
|
+
background: url(../images/flash-warning.png) no-repeat left top;
|
50
|
+
}
|
51
|
+
|
52
|
+
p.error {
|
53
|
+
background: url(../images/flash-error-bg.jpg) repeat-x left -10px;
|
54
|
+
color: #af0100;
|
55
|
+
}
|
56
|
+
p.error span {
|
57
|
+
margin-top: -6px;
|
58
|
+
background: url(../images/flash-error.png) no-repeat left top;
|
59
|
+
}
|
data/test/test_helper.rb
ADDED
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gbdev-pretty_flash
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Heath
|
8
|
+
- John Dell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-01-15 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: A Rails plugin/gem that provides css friendly success/notice/warning/error flash messages.
|
18
|
+
email:
|
19
|
+
- rpheath@gmail.com
|
20
|
+
- spovich@gmail.com
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions: []
|
24
|
+
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- CHANGELOG
|
29
|
+
- init.rb
|
30
|
+
- install.rb
|
31
|
+
- MIT-LICENSE
|
32
|
+
- Rakefile
|
33
|
+
- README.textile
|
34
|
+
- uninstall.rb
|
35
|
+
- lib/pretty_flash.rb
|
36
|
+
- lib/pretty_flash/pretty_flash.rb
|
37
|
+
- public/images/flash-success.png
|
38
|
+
- public/images/flash-success-bg.jpg
|
39
|
+
- public/images/flash-notice.png
|
40
|
+
- public/images/flash-notice-bg.jpg
|
41
|
+
- public/images/flash-warning.png
|
42
|
+
- public/images/flash-warning-bg.jpg
|
43
|
+
- public/images/flash-error.png
|
44
|
+
- public/images/flash-error-bg.jpg
|
45
|
+
- public/javascripts/pretty_flash.js
|
46
|
+
- public/stylesheets/pretty_flash.css
|
47
|
+
- test/pretty_flash_test.rb
|
48
|
+
- test/test_helper.rb
|
49
|
+
has_rdoc: true
|
50
|
+
homepage: http://github.com/gbdev/pretty_flash
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.2.0
|
72
|
+
signing_key:
|
73
|
+
specification_version: 2
|
74
|
+
summary: Rails plugin/gem that provides pretty flash messages
|
75
|
+
test_files:
|
76
|
+
- test/pretty_flash_test.rb
|
77
|
+
- test/test_helper.rb
|