Skip to content

Instantly share code, notes, and snippets.

@stefanosc
Forked from Beengie/show_env
Created November 17, 2013 08:35
Show Gist options
  • Save stefanosc/7510871 to your computer and use it in GitHub Desktop.
Save stefanosc/7510871 to your computer and use it in GitHub Desktop.
# Sinatra environment
# Make sure that the link to the "bootstrap.min.js" file is correct in your layout.erb (shown below):
<script src="/vendor/bootstrap/js/bootstrap.min.js"></script>
# Put this in your .erb
<%= show_env %>
# Place constant inside of your main.rb
SHOW_ENVIRONMENT = true
# Method to be placed inside of the "helpers" method
def show_env
if SHOW_ENVIRONMENT
string = "<div class=\"dropdown\">"
string << "<a class=\"btn dropdown-toggle\" data-toggle=\"dropdown\" href=\"#\">Click to see environment details <span class=\"caret\"></span></a>"
string << "<ul id=\"menu1\" class=\"dropdown-menu\" role=\"menu\" aria-labelledby=\"dLabel\">"
env.each do |k, v|
f v.is_a?(Hash)
v.each do |l, m|
unless m.is_a?(Array)
string << "<li role=\"presentation\" id=\"dLabel\">#{l}: #{m}</li>"
else
string << "<li>#{l}:</li>"
string << "<ul>"
m.each do |p|
string << "<li>#{p}</li>"
end
string << "</ul>"
end
end
else
string << "<li>#{k}: #{v}</li>"
end
end
string << "</ul></div>"
return string
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment