Class: Erector::Widgets::EnvironmentBadge

Inherits:
Erector::Widget show all
Defined in:
lib/erector/widgets/environment_badge.rb

Overview

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

Instance Method Summary collapse

Methods inherited from Erector::Widget

#to_html, #to_s

Methods included from Sass

#sass, #scss

Methods included from JQuery

#jquery, #jquery_load, #jquery_ready

Methods included from Convenience

#css, #dom_id, #javascript, #join, #to_pretty, #to_text, #url

Methods included from Externals

included, #render_externals, #render_with_externals

Methods included from Caching

#cache, included, #should_cache?

Methods included from Needs

included, #initialize

Methods inherited from HTMLWidget

#to_html, #to_s

Methods inherited from XMLWidget

#comment, full_tags, #instruct, #newliney?, self_closing_tags, tag, tag_named

Methods inherited from AbstractWidget

#call_block, #capture_content, #emit, #initialize, inline, prettyprint_default, #prettyprint_default, prettyprint_default=, #to_a, #to_s, #widget

Methods included from AfterInitialize

included, #initialize

Methods included from Text

#character, #h, #nbsp, #raw, #text, #text!

Methods included from Attributes

#format_attributes, #format_sorted, #sort_attributes

Methods included from Element

#_element, #_empty_element, #element, #empty_element

Instance Method Details

#contentObject


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/erector/widgets/environment_badge.rb', line 10

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

#environmentObject


22
23
24
25
26
# File 'lib/erector/widgets/environment_badge.rb', line 22

def environment
  RAILS_ENV
rescue NameError
  ENV['RAILS_ENV'] || ENV['RACK_ENV']
end