Module: GritterNotices::ViewHelpers
- Includes:
- Gritter::Helpers
- Defined in:
- lib/gritter_notices/view_helpers.rb
Constant Summary collapse
- GRITTER_CONVERT_KEYS =
{ :info=>:notice, :alert=>:warning, :failure=>:error, :other=>:notice }. merge Hash[*GritterNotices::KEYS.map {|k| [k,k]
Instance Method Summary collapse
- #add_flashes_to_gritters(gritters, list, titles) ⇒ Object
- #add_notices_to_gitters(gritters, list, titles) ⇒ Object
-
#gritter_flash_messages(*args) ⇒ Object
Ключи понимаемые гриттером: :success, :warning, :notice, :error, :progress.
- #move_gritter_notices_to_flashes ⇒ Object
Instance Method Details
#add_flashes_to_gritters(gritters, list, titles) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gritter_notices/view_helpers.rb', line 42 def add_flashes_to_gritters(gritters, list, titles) list.to_hash.each_pair do |key, | next unless = [] unless .is_a? Array .flatten.each { || key = key.to_sym # Превращаем системные флешки в гритеровские gritter_key = GRITTER_CONVERT_KEYS[key] || GRITTER_CONVERT_KEYS[:other] || key title = titles[gritter_key] || key.to_s gritters << add_gritter(, :image => gritter_key, :title => title) } end end |
#add_notices_to_gitters(gritters, list, titles) ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gritter_notices/view_helpers.rb', line 31 def add_notices_to_gitters(gritters, list, titles) list.each do |notice| = notice. gritter_key = GRITTER_CONVERT_KEYS[[:level]] || GRITTER_CONVERT_KEYS[:other] || [:level] [:title] = titles[gritter_key] || [:level].to_s unless [:title] [:image] = gritter_key unless [:image] gritters << add_gritter(notice.text, ) notice.mark_as_delivered end end |
#gritter_flash_messages(*args) ⇒ Object
Ключи понимаемые гриттером: :success, :warning, :notice, :error, :progress
Все возможные (системные): :success, :warning, :notice, :error, :alert, :info, :failure
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gritter_notices/view_helpers.rb', line 18 def *args = args. titles = gflash_titles() gritters = [] # Собираем flash-сообщения add_flashes_to_gritters( gritters, flash, titles ) defined?(current_user) and current_user.respond_to?(:gritter_notices) and add_notices_to_gitters( gritters, current_user.gritter_notices.fresh, titles) js(gritters).html_safe unless gritters.empty? end |
#move_gritter_notices_to_flashes ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/gritter_notices/view_helpers.rb', line 57 def move_gritter_notices_to_flashes return unless current_user current_user.gritter_notices.fresh.each do |notice| notice.level, notice.text notice.mark_as_delivered end end |