glennr-flash-message-conductor 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Planet Argon
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.rdoc ADDED
@@ -0,0 +1,70 @@
1
+ == Flash Message Conductor
2
+
3
+ A simple pattern for managing flash messages in your Ruby on Rails application.
4
+
5
+ === Installation
6
+
7
+ ==== Gem
8
+
9
+ In environment.rb;
10
+
11
+ gem 'glennr-flash-message-conductor'
12
+
13
+ config.gem 'glennr-flash-message-conductor', :lib => 'flash-message-conductor', :source => 'http://gemcutter.org', :version => ">=1.1"
14
+
15
+ ==== Plugin
16
+
17
+ script/plugin install git://github.com/glennr/flash-message-conductor.git
18
+
19
+ == Example
20
+
21
+ === Redirect actions
22
+ add_info( 'foo' )
23
+ redirect_to :action => "show"
24
+
25
+ is the equivalent of
26
+
27
+ flash[:info] = 'foo'
28
+
29
+ === Render actions
30
+ add_info_now( 'foo' )
31
+ render :action => "show"
32
+
33
+ is the equivalent of
34
+
35
+ flash[:info] = 'foo'
36
+
37
+ == Controller helpers included:
38
+
39
+ add_success( message )
40
+ add_info( message )
41
+ add_warning( message )
42
+ add_error( message )
43
+ add_message( message ) # alias for add_success
44
+ add_notice( message ) #alias for add_info
45
+
46
+ Plus all the _now methods e.g.
47
+
48
+ add_success_now( message )
49
+
50
+ == View helpers
51
+
52
+ <%= render_flash_messages %>
53
+
54
+ produces:
55
+
56
+ <div id="flash_messages">
57
+ <div class="info">You have successfully done XYZ...</p>
58
+ </div>
59
+
60
+ or... if you set an error
61
+
62
+ <div id="flash_messages">
63
+ <p class="error">Oops! Something went bonkers!</p>
64
+ </div>
65
+
66
+ == Example CSS and Icons
67
+
68
+ See examples/
69
+
70
+ Copyright (c) 2008 Planet Argon, released under the MIT license
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 0
3
+ :patch: 1
4
+ :major: 1
@@ -0,0 +1,30 @@
1
+ #flash_messages
2
+ .success
3
+ padding: 15px 10px 15px 50px
4
+ border-color: #9c9
5
+ color: #4F8A10
6
+ background: url(/images/flash-success-icon.png) #DFF2BF left no-repeat
7
+
8
+ .info
9
+ padding: 15px 10px 15px 50px
10
+ border-color: #9c9
11
+ color: #00529B
12
+ background: url(/images/flash-info-icon.png) #BDE5F8 left no-repeat
13
+
14
+ .warning
15
+ padding: 15px 10px 15px 50px
16
+ border-color: #9c9
17
+ color: #9F6000
18
+ background: url(/images/flash-warning-icon.png) #FEEFB3 left no-repeat
19
+
20
+ .validation_error
21
+ padding: 15px 10px 15px 50px
22
+ border-color: #c99
23
+ color: #D63301
24
+ background: url(/images/flash-validation_error-icon.png) #FFCCBA left no-repeat
25
+
26
+ .error
27
+ padding: 15px 10px 15px 50px
28
+ border-color: #c99
29
+ color: #D8000C
30
+ background: url(/images/flash-error-icon.png) #FFBABA left no-repeat
Binary file
@@ -0,0 +1,85 @@
1
+ # ArgonHelpers
2
+
3
+ module PlanetArgon
4
+ module FlashMessageConductor
5
+ FLASH_MESSAGE_TYPES = [ :error, :warning, :info, :success ]
6
+
7
+ module ControllerHelpers
8
+ def add_error(msg)
9
+ flash[:error] = msg
10
+ end
11
+ def add_error_now(msg)
12
+ flash.now[:error] = msg
13
+ end
14
+
15
+ def add_warning(msg)
16
+ flash[:warning] = msg
17
+ end
18
+
19
+ def add_warning_now(msg)
20
+ flash.now[:warning] = msg
21
+ end
22
+
23
+ def add_info(msg)
24
+ flash[:info] = msg
25
+ end
26
+
27
+ def add_info_now(msg)
28
+ flash.now[:info] = msg
29
+ end
30
+
31
+ def add_success(msg)
32
+ flash[:success] = msg
33
+ end
34
+
35
+ def add_success_now(msg)
36
+ flash.now[:success] = msg
37
+ end
38
+
39
+ #aliases - for convenience
40
+ def add_notice(msg)
41
+ add_info msg
42
+ end
43
+
44
+ def add_notice_now(msg)
45
+ add_info_now msg
46
+ end
47
+
48
+ def add_message(msg)
49
+ add_success msg
50
+ end
51
+
52
+ def add_message_now(msg)
53
+ add_success_now msg
54
+ end
55
+
56
+ end
57
+
58
+ module ViewHelpers
59
+ def render_flash_message( css_class, message = "" )
60
+ return "" if message.nil? or message.blank?
61
+ content_tag( "div", message, :class => "#{css_class}" )
62
+ end
63
+
64
+ def render_flash_messages( div_id = "flash_messages", div_class = "" )
65
+ div_content = ''
66
+ FLASH_MESSAGE_TYPES.each do |key|
67
+ div_content << render_flash_message( key.to_s, flash[key] ) unless flash[key].blank?
68
+ end
69
+ if div_content.blank?
70
+ return ""
71
+ else
72
+ return content_tag( 'div', div_content, :id => div_id, :class => div_class )
73
+ end
74
+ end
75
+
76
+ def flash_message_set?
77
+ flash_set = false
78
+ FLASH_MESSAGE_TYPES.each do |key|
79
+ flash_set = true unless flash[key].blank?
80
+ end
81
+ return flash_set
82
+ end
83
+ end
84
+ end
85
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'flash_message_conductor'
2
+
3
+ ActionController::Base.send( :include, PlanetArgon::FlashMessageConductor::ControllerHelpers )
4
+ ActionView::Base.send( :include, PlanetArgon::FlashMessageConductor::ViewHelpers )
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: glennr-flash-message-conductor
3
+ version: !ruby/object:Gem::Version
4
+ version: "1.1"
5
+ platform: ruby
6
+ authors:
7
+ - Robby Russell
8
+ - Glenn Roberts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2009-12-14 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: A simple pattern for managing flash messages in your Ruby on Rails application
18
+ email: robby@planetargon.com, glenn.roberts@siyelo.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - VERSION.yml
27
+ - lib/flash_message_conductor.rb
28
+ - rails/init.rb
29
+ - README.rdoc
30
+ - MIT-LICENSE
31
+ - examples/example.sass
32
+ - examples/images/flash-error-icon.png
33
+ - examples/images/flash-info-icon.png
34
+ - examples/images/flash-success-icon.png
35
+ - examples/images/flash-warning-icon.png
36
+ has_rdoc: true
37
+ homepage: http://github.com/glennr/flash-message-conductor
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options:
42
+ - --inline-source
43
+ - --charset=UTF-8
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ requirements: []
59
+
60
+ rubyforge_project:
61
+ rubygems_version: 1.3.5
62
+ signing_key:
63
+ specification_version: 3
64
+ summary: Conduct your Flash Messages in Rails
65
+ test_files: []
66
+