Module: VisualEnvironments
- Included in:
- ActionController::Base
- Defined in:
- lib/visual-environments.rb,
lib/generators/visual_environments/install_generator.rb
Defined Under Namespace
Modules: Generators
Constant Summary collapse
- @@enable_env_in_title =
false
nil
- @@title_aliases =
{}
{}
- @@excluded_environments =
[]
Class Method Summary collapse
-
.aliases=(aliases) ⇒ Object
Set the aliases of both the title and the corner banner to the supplied item.
-
.setup {|_self| ... } ⇒ Object
Use setup with a block to configure the module in an initializer; run ‘rails generate visual_environments:install’ to create a default initializer.
Instance Method Summary collapse
Class Method Details
.aliases=(aliases) ⇒ Object
Set the aliases of both the title and the corner banner to the supplied item
35 36 37 38 |
# File 'lib/visual-environments.rb', line 35 def self.aliases=(aliases) @@title_aliases.replace aliases @@corner_banner_aliases.replace aliases end |
.setup {|_self| ... } ⇒ Object
Use setup with a block to configure the module in an initializer; run ‘rails generate visual_environments:install’ to create a default initializer
29 30 31 |
# File 'lib/visual-environments.rb', line 29 def self.setup yield self end |
Instance Method Details
#shim_visual_environments ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/visual-environments.rb', line 40 def shim_visual_environments unless Rails.env == 'production' || (VisualEnvironments.excluded_environments && VisualEnvironments.excluded_environments.include?(Rails.env)) # Only mess with HTML return unless response.content_type == 'text/html' if VisualEnvironments.enable_env_in_title current_env = Rails.env current_env = VisualEnvironments.title_aliases[current_env] if !VisualEnvironments.title_aliases.nil? && VisualEnvironments.title_aliases.has_key?(current_env) shim = "<script type='text/javascript'>var te=document.getElementsByTagName('title')[0];var t=te.innerHTML;te.innerHTML=\"["+current_env+"] \"+t;</script></body>" response.body = response.body.gsub /\<\/body\>/, shim end unless VisualEnvironments..nil? # Exit if we detect invalid options in the corner_banner_side option return unless [:left,:right].include?(VisualEnvironments.) current_env = Rails.env current_env = VisualEnvironments.[current_env] if !VisualEnvironments..nil? && VisualEnvironments..has_key?(current_env) 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. == :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>" elsif VisualEnvironments. == :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>" end shim += "</body>" response.body = response.body.gsub /\<\/body\>/, shim end end end |