Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rpheath committed Dec 30, 2008
0 parents commit 6ba6861
Show file tree
Hide file tree
Showing 18 changed files with 222 additions and 0 deletions.
20 changes: 20 additions & 0 deletions MIT-LICENSE
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.
40 changes: 40 additions & 0 deletions README.textile
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
23 changes: 23 additions & 0 deletions Rakefile
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
Binary file added assets/images/check.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/flash-error-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/flash-notice-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/flash-warning-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/images/warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions assets/javascripts/flash.js
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 });
})
}
// --------------------------------------------------------------------
42 changes: 42 additions & 0 deletions assets/stylesheets/flash.css
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;
}
4 changes: 4 additions & 0 deletions init.rb
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)
1 change: 1 addition & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Install hook code here
27 changes: 27 additions & 0 deletions lib/pretty_flash.rb
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
20 changes: 20 additions & 0 deletions tasks/pretty_flash_tasks.rake
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
8 changes: 8 additions & 0 deletions test/pretty_flash_test.rb
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
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit 6ba6861

Please sign in to comment.