Created
October 23, 2009 18:32
-
-
Save abriening/217093 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Like ck_fu ( http://github.com/r38y/ck_fu ) but not | |
# I really like ck_fu. But I am not fond of adding tests, rake tasks, and a whole plugin folder for | |
# one method, two helper methods and some css. I also made it safe for Rails 1.2.6. | |
# | |
# in app/helpers/application_helper.rb | |
def environment_div(options={}) | |
return '' if (options.has_key?(:if) ? !options[:if] : RAILS_ENV.to_s == 'production' ) | |
separator = options[:separator] || "|" | |
text = [content_tag(:strong, RAILS_ENV.to_s.titlecase)] | |
text << "Database: #{ActiveRecord::Base.connection.current_database}" if ActiveRecord::Base.connection.respond_to?(:current_database) | |
text << "Database: #{ActiveRecord::Base::configurations[RAILS_ENV]['dbfile']}" if ActiveRecord::Base::configurations[RAILS_ENV]['adapter'] == 'sqlite3' | |
text << "Revision: #{deployed_revision}" unless deployed_revision.blank? || options[:revision] | |
text << "Deployed: #{deployed_date}" unless deployed_date.blank? || options[:date] | |
(options[:links] || []).each do |link| | |
text << "#{link_to link[0], link[1]}" | |
end | |
content_tag :div, text.join(" #{separator} "), :class => RAILS_ENV | |
end | |
def deployed_revision | |
unless defined?(@deployed_revision) | |
file = RAILS_ROOT + '/REVISION' | |
@deployed_revision = File.exists?(file) ? File.open(file).read.strip : nil | |
end | |
@deployed_revision | |
end | |
def deployed_date | |
unless defined?(@deployed_date) | |
file = RAILS_ROOT + '/DATE' | |
@deployed_date = File.exists?(file) ? File.open(file).read.strip : nil | |
end | |
@deployed_date | |
end | |
# in app/views/layouts/*.haml | |
%body | |
= environment_div | |
# in application.css | |
/* Styles for environment_div bar */ | |
.environment { | |
color: white; | |
font-size: 1.2em; | |
padding: 0.2em 0; | |
margin: 0; | |
text-align: center; | |
font-family: Helvetica, sans-serif; | |
width: 100%; | |
line-height: 1.5em; | |
background: red; | |
} | |
.production { | |
display: none; | |
} | |
.environment a { | |
color: white; | |
} | |
.development { | |
background: green; | |
} | |
.demo { | |
background: orange; | |
} | |
.test { | |
background: darkCyan; | |
} | |
.staging { | |
background: darkMagenta; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment