Skip to content

Instantly share code, notes, and snippets.

@sshaw
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sshaw/54235580e1d53b1a9e36 to your computer and use it in GitHub Desktop.
Save sshaw/54235580e1d53b1a9e36 to your computer and use it in GitHub Desktop.
Render Flash Messages Using Ruby's Bootstrap Helpers (Bh)
Gem::Specification.new do |s|
s.name = "bh-flash"
s.version = "0.0.2"
s.date = "2015-08-02"
s.summary = "Render flash messages using Bootstrap Helpers"
s.description =<<-DESC
Render flash messages using Bootstrap Helpers: http://fullscreen.github.io/bh/
Inspired by: https://github.com/planetargon/flash-message-conductor
DESC
s.authors = ["Skye Shaw"]
s.email = "skye.shaw@gmail.com"
s.files = Dir["*.rb"]
s.require_paths = ["."]
s.homepage = "https://gist.github.com/sshaw/54235580e1d53b1a9e36"
s.license = "MIT"
s.add_dependency "bh", "~> 1.0"
end
# https://gist.github.com/sshaw/54235580e1d53b1a9e36
#
# Render flash messages using Bootstrap Helpers: http://fullscreen.github.io/bh/
# Inspired by: https://github.com/planetargon/flash-message-conductor
#
# Usage:
#
# In your controller
#
# require "bh-flash"
# helper Bh::Flash
#
# In your view
#
# render_flash_messages
# render_flash_messages(false) # do no allow dismissal
require "bh"
module Bh
module Flash
include Helpers
# Flash key to Bootstrap alert level
TYPES = {
:notice => :success,
:alert => :warning,
:message => :info,
:error => :danger
}
class << self
attr_accessor :dismissible
end
self.dismissible = true
def render_flash_messages(dismissible = Bh::Flash.dismissible)
html = ""
TYPES.each do |key, context|
next if flash[key].blank?
html << alert_box(flash[key], :dismissible => dismissible, :context => context)
end
html.html_safe
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment