forked from rpheath/pretty_flash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ba6861
Showing
18 changed files
with
222 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (c) 2008 [name of plugin creator] | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
h1. PrettyFlash | ||
|
||
Rails plugin that provides "pretty" flash messages. | ||
|
||
h2. In the controller... | ||
|
||
This plugin gives a couple of convenience methods for setting flash messages. | ||
|
||
<pre><code>notice "Hooray! You did something good." | ||
warning "Uhm, You're not allowed to do that yet." | ||
error "Ooooops! Something went wrong."</code></pre> | ||
|
||
Use those instead of the typical @flash[:notice] = "Some String"@ (all it does is set that for you). | ||
|
||
h2. In the view... | ||
|
||
Then all you have to do to display them is: | ||
|
||
<pre><code><%= display_flash_messages %></code></pre> | ||
|
||
Easy enough? | ||
|
||
h2. Get Started | ||
|
||
There's an assets folder with this plugin, that contains the images, CSS, and javascript (optional). There's | ||
a rake task that installs this stuff where it needs to be (inside the public/ directory). | ||
|
||
<pre><code>$ rake pretty_flash:install</code></pre> | ||
|
||
WARNING: this will overwrite any of the files that have the same name. So double check if you don't want that to happen. | ||
|
||
Also, the flash.js file located in the assets/javascripts folder is only used to fade the flash messages after so many | ||
seconds (defaults to 25 seconds). If you want that, I've provide support for prototype and jquery, so just copy whichever | ||
one you're using into application.js and you're all set. If you're not using either, sorry :-) | ||
|
||
Enjoy! | ||
|
||
h2. Licensing | ||
|
||
Copyright (c) 2008 Ryan Heath, released under the MIT license |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'rake' | ||
require 'rake/testtask' | ||
require 'rake/rdoctask' | ||
|
||
desc 'Default: run unit tests.' | ||
task :default => :test | ||
|
||
desc 'Test the pretty_flash plugin.' | ||
Rake::TestTask.new(:test) do |t| | ||
t.libs << 'lib' | ||
t.libs << 'test' | ||
t.pattern = 'test/**/*_test.rb' | ||
t.verbose = true | ||
end | ||
|
||
desc 'Generate documentation for the pretty_flash plugin.' | ||
Rake::RDocTask.new(:rdoc) do |rdoc| | ||
rdoc.rdoc_dir = 'rdoc' | ||
rdoc.title = 'PrettyFlash' | ||
rdoc.options << '--line-numbers' << '--inline-source' | ||
rdoc.rdoc_files.include('README') | ||
rdoc.rdoc_files.include('lib/**/*.rb') | ||
end |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copy the snippet that applies to you, and paste it in application.js | ||
|
||
|
||
|
||
|
||
|
||
// jQuery ------------------------------------------------------------- | ||
|
||
$(document).ready(function() { | ||
setTimeout(hideFlashes, 25000); | ||
}); | ||
|
||
var hideFlashes = function() { | ||
$('p.notice, p.warning, p.error').fadeOut(1500); | ||
} | ||
// -------------------------------------------------------------------- | ||
|
||
|
||
|
||
|
||
|
||
// Prototype JS ------------------------------------------------------- | ||
|
||
document.observe('dom:loaded', function() { | ||
setTimeout(hideFlashes, 25000); | ||
}); | ||
|
||
var hideFlashes = function() { | ||
$$('.notice', '.warning', '.error').each(function(e) { | ||
if (e) Effect.Fade(e, { duration: 1.5 }); | ||
}) | ||
} | ||
// -------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
p.notice, | ||
p.warning, | ||
p.error { | ||
font-size: 18px; | ||
padding: 15px 10px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
p.notice span, | ||
p.warning span, | ||
p.error span { | ||
float: left; | ||
width: 42px; | ||
height: 32px; | ||
margin-top: -5px; | ||
} | ||
|
||
p.notice { | ||
background: url(../images/flash-notice-bg.jpg) repeat-x left top; | ||
color: #41612f; | ||
} | ||
p.notice span { | ||
background: url(../images/check.png) no-repeat left top; | ||
} | ||
|
||
p.warning { | ||
background: url(../images/flash-warning-bg.jpg) repeat-x left -10px; | ||
color: #a26a1a; | ||
} | ||
p.warning span { | ||
margin-top: -6px; | ||
background: url(../images/warning.png) no-repeat left top; | ||
} | ||
|
||
p.error { | ||
background: url(../images/flash-error-bg.jpg) repeat-x left -10px; | ||
color: #af0100; | ||
} | ||
p.error span { | ||
margin-top: -6px; | ||
background: url(../images/error.png) no-repeat left top; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require 'pretty_flash' | ||
|
||
ActionController::Base.send(:include, RPH::PrettyFlash::ControllerMethods) | ||
ActionView::Base.send(:include, RPH::PrettyFlash::Display) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Install hook code here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
module RPH | ||
module PrettyFlash | ||
module ControllerMethods | ||
def notice(msg) | ||
flash[:notice] = msg | ||
end | ||
|
||
def warning(msg) | ||
flash[:warning] = msg | ||
end | ||
|
||
def error(msg) | ||
flash[:error] = msg | ||
end | ||
end | ||
|
||
module Display | ||
def display_flash_messages | ||
returning html = String.new do | ||
flash.each do |css_class, message| | ||
html << content_tag(:p, content_tag(:span, nil) + message, :class => css_class) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace :pretty_flash do | ||
desc "Copies assets to proper application directories" | ||
task :install do | ||
ASSETS = File.join(File.dirname(__FILE__), '..', 'assets') | ||
Dir.glob("#{ASSETS}/*").each do |folder| | ||
folder_name = folder.gsub(/\/.+\//, '') | ||
destination = File.join(Rails.public_path, folder_name) | ||
|
||
FileUtils.mkpath(destination) unless File.directory?(destination) | ||
|
||
Dir[File.join(folder, '/*')].select { |a| File.file?(a) }.each do |asset| | ||
file_to_copy = File.join(destination, '/', File.basename(asset)) | ||
puts " - copying %s to %s" % [File.basename(asset), destination.gsub(Rails.root, '')] | ||
FileUtils.cp asset, destination | ||
end | ||
|
||
puts " - done." | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require 'test_helper' | ||
|
||
class PrettyFlashTest < ActiveSupport::TestCase | ||
# Replace this with your real tests. | ||
test "the truth" do | ||
assert true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rubygems' | ||
require 'active_support' | ||
require 'active_support/test_case' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Uninstall hook code here |