flash_helper 1.0.0 → 1.0.2
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.
- data/LICENCE +20 -0
- data/Rakefile +69 -0
- data/assets/stylesheets/flash_helper.css +48 -0
- data/init.rb +1 -0
- data/install.rb +1 -0
- data/lib/flash_helper.rb +76 -0
- data/tasks/flash_helper_tasks.rake +15 -0
- data/uninstall.rb +1 -0
- metadata +23 -4
data/LICENCE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [Nicolas Cavigneaux]
|
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/Rakefile
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
require 'rake/contrib/rubyforgepublisher'
|
5
|
+
require 'rubyforge'
|
6
|
+
|
7
|
+
SPEC = Gem::Specification.new do |s|
|
8
|
+
s.name = 'flash_helper'
|
9
|
+
s.version = '1.0.2'
|
10
|
+
s.authors = ['Nicolas Cavigneaux']
|
11
|
+
s.email = 'nico@bounga.org'
|
12
|
+
s.homepage = 'http://www.bitbucket.org/Bounga/flash-helper'
|
13
|
+
s.rubyforge_project = %q{flash-helper}
|
14
|
+
s.summary = 'Rails extension to handle flash messages'
|
15
|
+
s.description = 'This Rails extension provides a simple way to handle flash messages. You can easily display notices, errors and warnings using the convinience method.'
|
16
|
+
s.files = [ "Rakefile", "init.rb", "install.rb", "README", "LICENCE", "uninstall.rb" ] +
|
17
|
+
Dir.glob("{bin,assets,doc,lib,tasks,test}/**/*")
|
18
|
+
s.test_file = "test/flash_helper_test.rb"
|
19
|
+
s.has_rdoc = true
|
20
|
+
s.extra_rdoc_files = ['README']
|
21
|
+
s.require_paths = ["lib"]
|
22
|
+
s.add_dependency('actionpack')
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'run unit tests'
|
26
|
+
task :default => :test
|
27
|
+
|
28
|
+
task :gem
|
29
|
+
Rake::GemPackageTask.new(SPEC) do |pkg|
|
30
|
+
pkg.need_zip = true
|
31
|
+
pkg.need_tar_bz2 = true
|
32
|
+
end
|
33
|
+
|
34
|
+
desc "Install gem file #{SPEC.name}-#{SPEC.version}.gem"
|
35
|
+
task :install => [:gem] do
|
36
|
+
sh "gem install pkg/#{SPEC.name}-#{SPEC.version}.gem"
|
37
|
+
end
|
38
|
+
|
39
|
+
desc "Publish documentation to RubyForge"
|
40
|
+
task :publish_doc => [:rdoc] do
|
41
|
+
rf = Rake::RubyForgePublisher.new(SPEC.rubyforge_project, 'bounga')
|
42
|
+
rf.upload
|
43
|
+
puts "Published documentation to RubyForge"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Release gem #{SPEC.name}-#{SPEC.version}.gem"
|
47
|
+
task :release => [:gem, :publish_doc] do
|
48
|
+
rf = RubyForge.new.configure
|
49
|
+
puts "Logging in"
|
50
|
+
rf.login
|
51
|
+
|
52
|
+
puts "Releasing #{SPEC.name} v.#{SPEC.version}"
|
53
|
+
|
54
|
+
files = Dir.glob('pkg/*.{zip,bz2,gem}')
|
55
|
+
rf.add_release SPEC.rubyforge_project, SPEC.rubyforge_project, SPEC.version, *files
|
56
|
+
end
|
57
|
+
|
58
|
+
Rake::TestTask.new(:test) do |t|
|
59
|
+
t.libs << 'lib'
|
60
|
+
t.pattern = 'test/**/*_test.rb'
|
61
|
+
t.verbose = true
|
62
|
+
end
|
63
|
+
|
64
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
65
|
+
rdoc.title = 'FlashHelper'
|
66
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
67
|
+
rdoc.rdoc_files.include('README')
|
68
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
69
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
.notice,.errors,.warning {
|
2
|
+
padding: 5px 8px;
|
3
|
+
margin: 0 0 10px 0;
|
4
|
+
}
|
5
|
+
.notice {
|
6
|
+
background-color: #CFC;
|
7
|
+
border: solid 1px #6C6;
|
8
|
+
}
|
9
|
+
.warning {
|
10
|
+
background-color: #fcf100;
|
11
|
+
border: solid 1px #ffc707;
|
12
|
+
}
|
13
|
+
.errors {
|
14
|
+
background-color: #FCC;
|
15
|
+
border: solid 1px #C66;
|
16
|
+
}
|
17
|
+
.fieldWithErrors {
|
18
|
+
display: inline;
|
19
|
+
}
|
20
|
+
#errorExplanation {
|
21
|
+
width: 400px;
|
22
|
+
border: 2px solid #CF0000;
|
23
|
+
padding: 0px;
|
24
|
+
padding-bottom: 12px;
|
25
|
+
margin-bottom: 20px;
|
26
|
+
background-color: #f0f0f0;
|
27
|
+
}
|
28
|
+
#errorExplanation h2 {
|
29
|
+
text-align: left;
|
30
|
+
font-weight: bold;
|
31
|
+
padding: 5px 5px 5px 15px;
|
32
|
+
font-size: 12px;
|
33
|
+
margin: 0px;
|
34
|
+
background-color: #c00;
|
35
|
+
color: #fff;
|
36
|
+
}
|
37
|
+
#errorExplanation p {
|
38
|
+
color: #333;
|
39
|
+
margin-bottom: 0;
|
40
|
+
padding: 8px;
|
41
|
+
}
|
42
|
+
#errorExplanation ul {
|
43
|
+
margin: 2px 24px;
|
44
|
+
}
|
45
|
+
#errorExplanation ul li {
|
46
|
+
font-size: 12px;
|
47
|
+
list-style: disc;
|
48
|
+
}
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'flash_helper'
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/flash_helper.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module Bounga
|
4
|
+
module FlashHelper
|
5
|
+
# This extension provides a simple way to handle flash messages.
|
6
|
+
# You can easily display notices, errors and warnings using the convinience method.
|
7
|
+
#
|
8
|
+
# == Example
|
9
|
+
#
|
10
|
+
# For example, in your layout use :
|
11
|
+
#
|
12
|
+
# display_flashes # Use defaults
|
13
|
+
#
|
14
|
+
# Then in your controllers you can use :
|
15
|
+
# flash[:notice] = "Successfully created..."
|
16
|
+
# flash[:errors] = "Creation failed!"
|
17
|
+
# flash[:errors] = @news.errors
|
18
|
+
# flash[:warning] = "The new user has no blog associated..."
|
19
|
+
|
20
|
+
# == Global options for helpers
|
21
|
+
#
|
22
|
+
# Options for flash helpers are optional and get their default values from the
|
23
|
+
# <tt>Bounga::FlashHelper::ViewHelpers.flash_options</tt> hash. You can write to this hash to
|
24
|
+
# override default options on the global level:
|
25
|
+
#
|
26
|
+
# Bounga::FlashHelper::ViewHelpers.flash_options[:notice_class] = 'my_notice'
|
27
|
+
#
|
28
|
+
# By putting this into "config/initializers/flash_helper.rb" (or simply environment.rb in
|
29
|
+
# older versions of Rails) you can easily override any default option.
|
30
|
+
module ViewHelpers
|
31
|
+
# default options that can be overridden on the global level
|
32
|
+
@@flash_options = {
|
33
|
+
:list_class => 'errors_list',
|
34
|
+
:notice_class => 'notice',
|
35
|
+
:errors_class => 'errors',
|
36
|
+
:warning_class => 'warning',
|
37
|
+
:default_message => 'There are problems in your submission:'
|
38
|
+
}
|
39
|
+
mattr_reader :flash_options
|
40
|
+
|
41
|
+
# Display flash messages.
|
42
|
+
# You can pass an optional string as a parameter. It will be display before
|
43
|
+
# error messages.
|
44
|
+
def display_flashes(message = @@flash_options[:default_message])
|
45
|
+
if flash[:notice]
|
46
|
+
flash_to_display, level = flash[:notice], @@flash_options[:notice_class]
|
47
|
+
elsif flash[:warning]
|
48
|
+
flash_to_display, level = flash[:warning], @@flash_options[:warning_class]
|
49
|
+
elsif flash[:errors]
|
50
|
+
level = @@flash_options[:errors_class]
|
51
|
+
if flash[:errors].instance_of? ActiveRecord::Errors
|
52
|
+
flash_to_display = message
|
53
|
+
flash_to_display << activerecord_error_list(flash[:errors])
|
54
|
+
else
|
55
|
+
flash_to_display = flash[:errors]
|
56
|
+
end
|
57
|
+
else
|
58
|
+
return
|
59
|
+
end
|
60
|
+
flash.discard(:notice); flash.discard(:warning); flash.discard(:errors)
|
61
|
+
content_tag 'div', flash_to_display, :class => "#{level}"
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
def activerecord_error_list(errors)
|
66
|
+
error_list = '<ul class="' + @@flash_options[:list_class] + '">'
|
67
|
+
error_list << errors.collect do |e, m|
|
68
|
+
"<li>#{e.humanize unless e == "base"} #{m}</li>"
|
69
|
+
end.to_s << '</ul>'
|
70
|
+
error_list
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
ActionView::Base.send :include, Bounga::FlashHelper::ViewHelpers
|
@@ -0,0 +1,15 @@
|
|
1
|
+
namespace :flash_helper do
|
2
|
+
PLUGIN_ROOT = File.dirname(__FILE__) + '/../'
|
3
|
+
|
4
|
+
desc 'Install sample CSS file for flash messages.'
|
5
|
+
task :install do
|
6
|
+
FileUtils.cp Dir[PLUGIN_ROOT + '/assets/stylesheets/*.css'], RAILS_ROOT + '/public/stylesheets'
|
7
|
+
p "Flash messages stylesheet added."
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Remove sample CSS file for flash messages..'
|
11
|
+
task :remove do
|
12
|
+
FileUtils.rm %{flash_helper.css}.collect { |f| RAILS_ROOT + "/public/stylesheets/" + f }
|
13
|
+
p "Flash messages stylesheet deleted."
|
14
|
+
end
|
15
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flash_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolas Cavigneaux
|
@@ -9,10 +9,19 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-08 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: actionpack
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
16
25
|
description: This Rails extension provides a simple way to handle flash messages. You can easily display notices, errors and warnings using the convinience method.
|
17
26
|
email: nico@bounga.org
|
18
27
|
executables: []
|
@@ -22,7 +31,17 @@ extensions: []
|
|
22
31
|
extra_rdoc_files:
|
23
32
|
- README
|
24
33
|
files:
|
34
|
+
- Rakefile
|
35
|
+
- init.rb
|
36
|
+
- install.rb
|
25
37
|
- README
|
38
|
+
- LICENCE
|
39
|
+
- uninstall.rb
|
40
|
+
- assets/stylesheets
|
41
|
+
- assets/stylesheets/flash_helper.css
|
42
|
+
- lib/flash_helper.rb
|
43
|
+
- tasks/flash_helper_tasks.rake
|
44
|
+
- test/flash_helper_test.rb
|
26
45
|
has_rdoc: true
|
27
46
|
homepage: http://www.bitbucket.org/Bounga/flash-helper
|
28
47
|
post_install_message:
|