0.0
No commit activity in last 3 years
No release in over 3 years
Flash Gordon is a gem written to simplify flash notification calls from anywhere in your application, need a flash message appended during a controller action? model method? or view? The syntax and usage is consistent and simple. Take a spin :)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 3.2
 Project Readme

flash_gordon

Flash Gordon is a Rails Flash helper Gem that allows you to add custom flash notification handlers anywhere within your application.

Installation:

  # Gemfile
  gem 'flash_gordon'

Usage:

Appending to the Flash event

To add a custom flash event user the append method, the default zone will be :alert

  FlashGordon::Flash.append("Notification Message")
  # It also accepts an array and will pad the messages with <br/> or otherwise specified tags
  FlashGordon::Flash.append ["You can include", "Arrays which will be joined", "by your specified glue"]

Specifying a Flash zone

You can specify a zone in append method. The default zones are similar to bootstrap alerts classes, which are :warning, :success, :info, :danger. The rails default :error is included by default also.

  # Available Zones are :warning, :success, :info, :error, :danger
  FlashGordon::Flash.append "Success Message", :success

Configuring custom zones

To create custom zones create an initializer file that contains the following:

  # config/initializers/flash_gordon.rb
  FlashGordon.setup do |config|
    #multi values will be added in next version
    config.add_zone(:pewpewpew)
  end

  # Any view
  FlashGordon::Flash.append("Message",:pewpewpew)
  # this will now work

Rendering the Flash messages

To render the flashes, just put this anywhere in your view where you want to show, e.g application.html.erb

  # application.html.erb
  <%= render_flash %>

Custom Flash Render

If you dont want to use an all in one flash render, you can cherry pick your render by specifying the zone, glue and container tag

For example,

  # For example if you want to build a unordered list of the :danger zone with each listing having
  # a class of 'flash-item' and a unique id of 'flash-i' where i is the index of the element.
  # Note that % is replaced by the index of messages starting from 0
  # Use the following syntax to render a custom zone, 
  # render_flash zone, glue, tag
  <%= render_flash :danger, "li.flash-item#flash-%", "ul" %>

  # If the glue is set to "br" will separate each element by <br> tags instead of a wrapping element.
  # If the glue is set to "" it will just join the messages without spacing.

Produces

  <ul class="alert alert-danger">
    <li class="flash-item" id="flash-0"> Your first message</li>
    <li class="flash-item" id="flash-1"> Your second message</li>
    <li class="flash-item" id="flash-2"> Your third message</li>
  </ul>

License

This project is on a kickass MIT-License :O