lib/gritter/gflash.rb in gritter-0.6.3 vs lib/gritter/gflash.rb in gritter-1.0.0

- old
+ new

@@ -1,28 +1,50 @@ module Gritter module Gflash + def redirect_to(options = {}, response_status_and_flash = {}) + if response_status_and_flash.has_key?(:gflash) + gflash(response_status_and_flash[:gflash]) + response_status_and_flash.delete(:gflash) + end + super(options, response_status_and_flash) + end + def gflash *args session[:gflash] ||= {} options = args.extract_options! + + if args.present? + args.each do |key| + gflash_push(key, gflash_translation(key)) + end + end + options.each do |key, value| if value.is_a?(Hash) - gflash_value = value - gflash_value[:value] = gflash_text(key, gflash_value[:value]) if gflash_value.has_key?(:value) + if value.has_key?(:value) + value[:value] = gflash_text(key, value[:value]) + else + value[:value] = gflash_translation(key) + end else - gflash_value = gflash_text(key, value) + value = gflash_text(key, value) end - - if session[:gflash].has_key?(key) - session[:gflash][key].push(gflash_value) - else - session[:gflash][key] = [gflash_value] - end + gflash_push(key, value) end end private def gflash_text(key, value) - value == true ? I18n.t("gflash.#{params[:controller]}.#{params[:action]}.#{key}") : value + value == true ? gflash_translation(key) : value + end + + def gflash_push(key, value) + session[:gflash][key] ||= [] + session[:gflash][key].push(value) + end + + def gflash_translation(key) + I18n.t("gflash.#{params[:controller]}.#{params[:action]}.#{key}") end end end \ No newline at end of file