gbdev-pretty_flash 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.1.2
2
+ * Added new hash option :message and now the only method argument is the hash option
3
+ * Updated README instructions and examples.
4
+ * Renamed :check_associations to just :associations
5
+ * Added TODO file
6
+
1
7
  0.1.1
2
8
  * Moved 'assets' to 'public'
3
9
  * Made it copy 'public' stuff to your rails app when application starts
data/README.textile CHANGED
@@ -1,17 +1,36 @@
1
1
  h1. PrettyFlash
2
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.
3
+ Rails plugin/gem that provides "pretty" css-driven flash messages and additional helpers to pull all errors from ActiveRecord objects and as well as errors on associated models of an ActiveRecord object.
4
4
 
5
5
  h2. In the controller...
6
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"@
7
+ This plugin/gem provides convenience methods for setting flash messages. Use this instead of the typical @flash[:notice] = "Some String"@
8
+
9
+ <pre><code>
10
+ flash_success :message => "Hooray! You did something good."
11
+ flash_notice :message => "Hey! This is for tips and general information."
12
+ flash_warning :message => "Ummm, You're not allowed to do that yet."
13
+ flash_error :message => 'ID does not exist'
14
+ </code></pre>
15
+
16
+ You can specify whether to use flash() or flash.now() via the options hash. The default is to use flash.now(). This is needed when setting flash and then redirecting. Also, any AJAX request defaults to flash.now()
17
+ <pre><code>
18
+ flash_error :message => 'Blah', :now => false
19
+ redirect_to :list
20
+ </code></pre>
21
+
22
+ You can also load validation errors from ActiveRecord Objects and any specified associated models
23
+ <pre><code>
24
+ flash_error :object => @user, :associations => [:roles, :permissions]
25
+ </code></pre>
26
+
27
+ The complete list of hash options for flash_success, flash_notice, flash_warning, flash_error is as follows:
28
+ :message - the flash message to be added
29
+ :now - Whether to use flash or flash.now
30
+ :delimiter - separator between messages
31
+ :clear_flash - delete flash for the type of flash called (:notice, :error, etc)
32
+ :object - an ActiveRecord object with @errors
33
+ :associations - model associations of the AR Object that should be checked for errors
15
34
 
16
35
  h2. In the view...
17
36
 
@@ -31,13 +50,11 @@ Add the gem to your environment.rb file
31
50
 
32
51
  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
52
 
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.
53
+ On subsequent application starts, the plugin/gem checks for the presence of public/images/flash-error.png. If this file is present, nothing will be copied to your public directory.
36
54
 
37
55
  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
56
 
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.
57
+ Also, the pretty_flash.js file located in the public/javascripts folder is only used to fade the flash messages after so many 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
58
 
42
59
  h2. Credits
43
60
 
data/install.rb CHANGED
@@ -1,20 +1,22 @@
1
1
  message = <<-MESSAGE
2
2
 
3
3
  ********************************************
4
- To get started, navigate to your project
5
- root, and type:
4
+ To get started, install the gem then add
5
+ the gem to your environment.rb
6
6
 
7
- $ rake pretty_flash:install
8
-
9
- That will copy all of the necessary assets
10
- to their appropriate homes.
7
+ $ sudo gem install gbdev-pretty_flash
8
+
9
+ Add the gem to your environment.rb file
11
10
 
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)
11
+ config.gem 'gbdev-pretty_flash',
12
+ :lib => 'pretty_flash',
13
+ :version => '0.1.0',
14
+ :source => 'http://gems.github.com'
17
15
 
16
+ When you start your application, all
17
+ necessary images/css/javascript are copied
18
+ to your public folder.
19
+
18
20
  Enjoy!
19
21
  ********************************************
20
22
 
@@ -11,50 +11,52 @@ module PrettyFlash
11
11
  end
12
12
 
13
13
  # Flash Message Valid options
14
+ # :message - the flash message to be added
14
15
  # :now - Whether to use flash or flash.now
15
16
  # :delimiter - separator between messages
16
17
  # :clear_flash - delete flash for the type of flash called (:notice, :error, etc)
17
18
  # :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
+ # :associations - model associations of the AR Object that may also have errors that need to be displayed
19
20
 
20
21
  # Add a success flash message
21
- def success(msg, options={})
22
- flash_message(msg, options.merge({:msg_sym => :success}))
22
+ def flash_success(options={})
23
+ flash_message(options.merge({:msg_sym => :success}))
23
24
  end
24
25
 
25
26
  # Add a notice flash message
26
- def notice(msg, options={})
27
- flash_message(msg, options.merge({:msg_sym => :notice}))
27
+ def flash_notice(options={})
28
+ flash_message(options.merge({:msg_sym => :notice}))
28
29
  end
29
30
 
30
31
  # Add a warning flash message
31
- def warning(msg, options={})
32
- flash_message(msg, options.merge({:msg_sym => :warning}))
32
+ def flash_warning(options={})
33
+ flash_message(options.merge({:msg_sym => :warning}))
33
34
  end
34
35
 
35
36
  # Add an error flash message
36
- def error(msg, options={})
37
- flash_message(msg, options.merge({:msg_sym => :error}))
37
+ def flash_error(options={})
38
+ flash_message(options.merge({:msg_sym => :error}))
38
39
  end
39
40
 
40
41
  private
41
42
 
42
- def flash_message(msg, options={})
43
+ def flash_message(options={})
43
44
  now = options[:now].nil? || options[:now] || (request.xhr? ? true : false)
45
+ msg = options[:message].nil? ? '' : options[:message]
46
+ obj = options[:object].nil? ? nil : options[:object]
44
47
  options[:msg_sym] = :error if options[:msg_sym].nil?
45
48
  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?
49
+ options[:associations] = [] if options[:associations].nil? or obj.nil?
48
50
  flash.delete(options[:msg_sym]) if options[:clear_flash]
49
51
 
50
52
  msgs = []
51
- msgs << msg unless msg.empty?
53
+ msgs << options[:message] unless options[:message].nil? || options[:message].blank?
52
54
 
53
55
  unless obj.nil?
54
56
  obj.errors.each { |att, dtl|
55
- msgs << dtl unless options[:check_associations].include?(att.to_sym)
57
+ msgs << dtl unless options[:associations].include?(att.to_sym)
56
58
  }
57
- options[:check_associations].each { |assoc|
59
+ options[:associations].each { |assoc|
58
60
  eval("obj.#{assoc}").each { |obj_assoc|
59
61
  obj_assoc.errors.each { |att, dtl|
60
62
  msgs << dtl
@@ -76,7 +78,7 @@ module PrettyFlash
76
78
 
77
79
  end
78
80
 
79
- module Display
81
+ module DisplayMethods
80
82
 
81
83
  def display_flash_messages
82
84
  returning html = String.new do
data/lib/pretty_flash.rb CHANGED
@@ -3,7 +3,7 @@ require "pretty_flash/pretty_flash.rb"
3
3
  if Object.const_defined?(:Rails) && File.directory?(Rails.root + "/public")
4
4
 
5
5
  ActionController::Base.send(:include, PrettyFlash::ControllerMethods)
6
- ActionView::Base.send(:include, PrettyFlash::Display)
6
+ ActionView::Base.send(:include, PrettyFlash::DisplayMethods)
7
7
 
8
8
  # install files
9
9
  unless File.exists?(RAILS_ROOT + '/public/images/flash-error.png')
@@ -8,7 +8,7 @@
8
8
  // });
9
9
  //
10
10
  // var hideFlashes = function() {
11
- // $('p.notice, p.warning, p.error').fadeOut(1500);
11
+ // $('p.notice, p.warning, p.error').fadeOut(2500);
12
12
  // }
13
13
  // --------------------------------------------------------------------
14
14
 
@@ -23,7 +23,7 @@
23
23
  //
24
24
  // var hideFlashes = function() {
25
25
  // $$('.notice', '.warning', '.error').each(function(e) {
26
- // if (e) Effect.Fade(e, { duration: 1.5 });
26
+ // if (e) Effect.Fade(e, { duration: 2.5 });
27
27
  // })
28
28
  // }
29
29
  // --------------------------------------------------------------------
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gbdev-pretty_flash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Heath