Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 30 lines (27 sloc) 1.145 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
module Erector
  module Widgets #:nodoc:

    # Displays a colored badge in the upper-left corner
    # signifying the environment the app is running in.
    # Inspired by Assaf Arkin
    # <http://blog.labnotes.org/2009/10/08/using-a-badge-to-distinguish-development-and-production-environments/>
    # Erectorized by Alex Chaffee
    class EnvironmentBadge < Erector::Widget
      def content
        style <<-STYLE
#environment_badge { position: fixed; left: 1em; font-weight: bold; padding: .2em 0.9em; text-transform: uppercase; display: none }
#environment_badge.staging { color: #000; background: #ffff00; border: 2px solid #cccc20; }
#environment_badge.development { color: #fff; background: #ff0000; border: 2px solid #cc2020; }
#environment_badge.staging, #environment_badge.development { border-top: none; display: block; opacity: 0.6 }
STYLE
        unless environment =~ /production/
          p environment, :class => environment, :id => "environment_badge"
        end
      end

      def environment
        RAILS_ENV
      rescue NameError
        ENV['RAILS_ENV'] || ENV['RACK_ENV']
      end
    end
  end
end
Something went wrong with that request. Please try again.