Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add some additional options that can be set in the initializer #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ VisualEnvironments.setup do |config|
# By default, the visual-environments will be enabled for all environments except production;
# to exclude additional environments, uncomment the line below and add them to the collection
# config.excluded_environments = []

# The following layout defaults can alow be overridden
#
# config.banner_font = "Verdana"
# config.banner_font_size = "10px"
# config.banner_foreground_colour = "#fff"
# config.banner_background_colour = "#000"
# config.banner_zindex = 1040
end
```

Expand Down
8 changes: 8 additions & 0 deletions lib/generators/visual_environments/templates/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,12 @@
# By default, the visual-environments will be enabled for all environments except production;
# to exclude additional environments, uncomment the line below and add them to the collection
# config.excluded_environments = []

# The following layout defaults can alow be overridden
#
# config.banner_font = "Verdana"
# config.banner_font_size = "10px"
# config.banner_foreground_colour = "#fff"
# config.banner_background_colour = "#000"
# config.banner_zindex = 1040
end
26 changes: 23 additions & 3 deletions lib/visual-environments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ module VisualEnvironments
mattr_accessor :excluded_environments
@@excluded_environments = []

# The font to render the banner text
mattr_accessor :banner_font
@@banner_font = "Verdana"

# The font size for the banner text
mattr_accessor :banner_font_size
@@banner_font = "10px"

# The text colour of the banner
mattr_accessor :banner_foreground_colour
@@banner_foreground_colour = "#fff"

# The background color of the banner
mattr_accessor :banner_background_colour
@@banner_background_colour = "#000"

# The z-index of the banner
mattr_accessor :banner_zindex
@@banner_zindex = 1040

# Use setup with a block to configure the module in an initializer;
# run 'rails generate visual_environments:install' to create a default
# initializer
Expand Down Expand Up @@ -58,9 +78,9 @@ def shim_visual_environments
shim = "<script type='text/javascript'>var con=document.createElement('div');con.id='VisualEnvironment_container';document.body.appendChild(con);var ce=document.createElement('div');ce.id='VisualEnvironment_corner';ce.innerHTML='"+current_env+"';con.appendChild(ce);</script>"

if VisualEnvironments.corner_banner_side == :right
shim += "<style>#VisualEnvironment_corner{position:absolute;top:20px;right:-35px;font-family:Verdana;font-size:10px;color:#fff;padding:9px;width:120px;text-align:center;background:#000;border:#fff 1px solid;filter:alpha(opacity=70);-moz-opacity:0.7;-khtml-opacity:0.7;opacity:0.7;-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);}#VisualEnvironment_container{position:absolute;top:0;right:0;width:120px;height:93px;overflow:hidden;}</style>"
shim += "<style>#VisualEnvironment_corner{position:absolute;top:20px;right:-35px;font-family:#{@@banner_font};font-size:#{@@banner_font_size};color:#{@@banner_foreground_colour};padding:9px;width:120px;text-align:center;background:#{@@banner_background_colour};border:#fff 1px solid;filter:alpha(opacity=70);-moz-opacity:0.7;-khtml-opacity:0.7;opacity:0.7;-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);}#VisualEnvironment_container{position:absolute;top:0;right:0;width:120px;height:93px;overflow:hidden;z-index:#{@@banner_zindex}}</style>"
elsif VisualEnvironments.corner_banner_side == :left
shim += "<style>#VisualEnvironment_corner{position:absolute;top:20px;left:-35px;font-family:Verdana;font-size:10px;color:#fff;padding:9px;width:120px;text-align:center;background:#000;border:#fff 1px solid;filter:alpha(opacity=70);-moz-opacity:0.7;-khtml-opacity:0.7;opacity:0.7;-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);}#VisualEnvironment_container{position:absolute;top:0;left:0;width:120px;height:93px;overflow:hidden;}</style>"
shim += "<style>#VisualEnvironment_corner{position:absolute;top:20px;left:-35px;font-family:#{@@banner_font};font-size:#{@@banner_font_size};color:#{@@banner_foreground_colour};padding:9px;width:120px;text-align:center;background:#{@@banner_background_colour};border:#fff 1px solid;filter:alpha(opacity=70);-moz-opacity:0.7;-khtml-opacity:0.7;opacity:0.7;-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);}#VisualEnvironment_container{position:absolute;top:0;left:0;width:120px;height:93px;overflow:hidden;z-index:#{@@banner_zindex}}</style>"
end
shim += "</body>"
response.body = response.body.gsub /\<\/body\>/, shim
Expand All @@ -74,4 +94,4 @@ def shim_visual_environments
class ActionController::Base
include VisualEnvironments
after_filter :shim_visual_environments
end
end