visual-environments 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,11 +1,18 @@
1
1
  = visual-environments
2
2
 
3
- Automatic visual, in-browser cues about your current environment in Rails 3 applications.
3
+ Automatic visual, in-browser cues about your current environment in Rails 3 applications!
4
4
 
5
5
  If you're a developer accustomed to working across multiple development and staging environments, you have certainly been in the position where you have multiple browser windows/tabs open with the same site but pointing at different environments. This gem aims to help you keep your contexts straight!
6
6
 
7
7
  This is a configurable means for showing, via an updated <title> tag or CSS corner banner overlay, what the current runtime environment is (development, staging, test, etc.) This functionality is never enabled for production, and fully configurable to exclude other environments as well.
8
8
 
9
+ == Changelog
10
+
11
+ * 5 March, 2011: Changed format of initializer, added ability to alias title and corner banner strings independently, refactored internal structure of the module, updated docs. This is a NON-BACKWARDS COMPATIBLE update; you must rerun <tt>rails g visual_environments:install</tt> to regenerate a new initializer file and then reset your options.
12
+ * 27 February, 2011: Updated source_root definition, fixing bug in initializer
13
+ * 20 February, 2011: Added generator, documented configuration options, added ability to switch corner banner from left to right side
14
+ * 19 February, 2011: Initial revision- a result of the MadRailers Coding Day!
15
+
9
16
  = Install & Configuration
10
17
 
11
18
  Add the following to your Rails application's Gemfile
@@ -18,20 +25,31 @@ Add the following to your Rails application's Gemfile
18
25
 
19
26
  There should now be a new file <tt>config/initializers/visual-environments.rb</tt> with the content
20
27
 
21
- ActionController::Base::VisualEnvironments.enable_env_in_title = true
22
-
23
- # Uncomment the line below and select which side to display the banner on. Current possible
24
- # values are (:right, :left) corresponding to upper-right and upper-left corners, respectively
25
- # ActionController::Base::VisualEnvironments.corner_banner_side = :right
26
-
27
- # By default, the full environment name is used in the visual cues (development, test, etc.) You
28
- # can map environment names by using the below setting to alias one environment name to another
29
- # Example: 'development' -> 'dev' or 'preproduction' -> 'preprod'
30
- # ActionController::Base::VisualEnvironments.aliases = { 'development' => 'dev' }
31
-
32
- # By default, the visual-environments will be enabled for all environments except production;
33
- # to exclude additional environments, uncomment the line below and add them to the collection
34
- # ActionController::Base::VisualEnvironments.excluded_environments = []
28
+ VisualEnvironments.setup do |config|
29
+ # Turns on the display of the current environment in the title tag of each page in the app
30
+ config.enable_env_in_title = true
31
+
32
+ # Uncomment he line below and select which side to display the banner on. Current possible
33
+ # values are (:right, :left) corresponding to upper-right and upper-left corners, respectively
34
+ # config.corner_banner_side = :right
35
+
36
+ # By default, the full environment name is used in the visual cues (development, test, etc.) You
37
+ # can map environment names by using the below setting to alias one environment name to another.
38
+ # Using the option below configures the alias for both the title tag and the corner banner display;
39
+ # if you would like different strings for each area then see the next section.
40
+ # Example: 'development' -> 'dev' or 'preproduction' -> 'preprod'
41
+ # config.aliases = { 'development' => 'dev' }
42
+
43
+ # You may alternatively declare different aliases for the title tag versus the corner banner
44
+ # using the options below.
45
+ # config.title_aliases = { 'development' => 'dev' }
46
+ # config.corner_banner_aliases = { 'preproduction' => 'preprod' }
47
+
48
+ # By default, the visual-environments will be enabled for all environments except production;
49
+ # to exclude additional environments, uncomment the line below and add them to the collection
50
+ # config.excluded_environments = []
51
+ end
52
+
35
53
 
36
54
  By default, visual environments are enabled in the page title but disabled for corner banner display. Also, by default only production environments are excluded from the gem functionality.
37
55
 
@@ -39,19 +57,15 @@ By default, visual environments are enabled in the page title but disabled for c
39
57
 
40
58
  You can add additional environments to be excluded by adding their names to the <tt>excluded_environments</tt> collection. For example, let's say you have an app with a test-oriented staging environment as well as a 'almost-ready-for-prime-time' preproduction environment. In this case you may want the visual cues on the staging but not on preproduction. In that case you can edit the initializer to:
41
59
 
42
- ActionController::Base::VisualEnvironments.excluded_environments = ['preproduction']
60
+ config.excluded_environments = ['preproduction']
43
61
 
44
62
  And now preproduction will not use the visual-environments functionality.
45
-
46
- Another way to configure is by using Gemfile groups to only conditionally load this gem. For example, if you have many different environments but only want this gem to operate in development and staging you can edit your Gemfile thusly:
47
-
48
- gem 'visual-evironments', :groups => [:development, :staging]
49
63
 
50
64
  == Corner Banner & Changing the Side of the Banner
51
65
 
52
66
  The corner banner is not included by default. To enable it, choose which side it should be displayed on via the <tt>corner_banner_side</tt> option in <tt>config/initializers/visual-environments.rb</tt>:
53
67
 
54
- ActionController::Base::VisualEnvironments.corner_banner_side = :right
68
+ config.corner_banner_side = :right
55
69
 
56
70
  Valid options are currently <tt>:left</tt> and <tt>:right</tt>, corresponding to the upper-left and upper-right corners, respectively.
57
71
 
@@ -59,13 +73,21 @@ Valid options are currently <tt>:left</tt> and <tt>:right</tt>, corresponding to
59
73
 
60
74
  Having the string "[development]" prepended to your title may make things a bit unwieldy for some people. In that case, you may use the aliasing option to change such an identifier to something shorter (but still identifiable with the environment in question). For example, you can alias 'development' to 'dev' or 'D', which would result in "[dev]" or "[D]" being prepended to the page title.
61
75
 
62
- To add an alias, uncomment and set the <tt>aliases</tt> setting as follows:
76
+ To add an alias that is used both in the title and the banner, uncomment and set the <tt>aliases</tt> setting as follows:
63
77
 
64
- ActionController::Base::VisualEnvironments.aliases = { 'development' => 'dev', 'preproduction' => 'preprod' }
78
+ config.aliases = { 'development' => 'dev', 'preproduction' => 'preprod' }
65
79
 
66
80
  The above example would show use 'dev' in a development environment and 'preprod' in a preproduction environment. The point is, you can alias any environment you may use, not just the out-of-the-box environments Rails uses (development, test, production).
67
81
 
68
- == Contributing to visual-environments
82
+ You can also set the aliases for ONLY the title or ONLY the corner banner. For example, I like the full environment used in the banner but like the title identifier to be much shorter:
83
+
84
+ config.title_aliases = { 'development' => 'D', 'staging' => 'S' }
85
+
86
+ You can do the same to change the alias of the corner banner:
87
+
88
+ config.corner_banner_aliases = { 'development' => 'dev', 'preproduction' => 'preprod' }
89
+
90
+ = Contributing to visual-environments
69
91
 
70
92
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
71
93
  * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
@@ -75,7 +97,7 @@ The above example would show use 'dev' in a development environment and 'preprod
75
97
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
76
98
  * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
77
99
 
78
- == Copyright
100
+ = Copyright
79
101
 
80
102
  Copyright (c) 2011 Zachery Moneypenny, David van Leeuwen. See LICENSE.txt for further details.
81
103
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.1
@@ -9,7 +9,7 @@ module VisualEnvironments
9
9
  end
10
10
 
11
11
  def copy_initializer_file
12
- copy_file "initializer.rb", "config/initializers/visual-environment.rb"
12
+ copy_file "initializer.rb", "config/initializers/visual-environments.rb"
13
13
  end
14
14
 
15
15
  def self.banner
@@ -1,14 +1,24 @@
1
- ActionController::Base::VisualEnvironments.enable_env_in_title = true
1
+ VisualEnvironments.setup do |config|
2
+ # Turns on the display of the current environment in the title tag of each page in the app
3
+ config.enable_env_in_title = true
2
4
 
3
- # Uncomment he line below and select which side to display the banner on. Current possible
4
- # values are (:right, :left) corresponding to upper-right and upper-left corners, respectively
5
- ActionController::Base::VisualEnvironments.corner_banner_side = :right
5
+ # Uncomment he line below and select which side to display the banner on. Current possible
6
+ # values are (:right, :left) corresponding to upper-right and upper-left corners, respectively
7
+ # config.corner_banner_side = :right
6
8
 
7
- # By default, the full environment name is used in the visual cues (development, test, etc.) You
8
- # can map environment names by using the below setting to alias one environment name to another
9
- # Example: 'development' -> 'dev' or 'preproduction' -> 'preprod'
10
- # ActionController::Base::VisualEnvironments.aliases = { 'development' => 'dev' }
9
+ # By default, the full environment name is used in the visual cues (development, test, etc.) You
10
+ # can map environment names by using the below setting to alias one environment name to another.
11
+ # Using the option below configures the alias for both the title tag and the corner banner display;
12
+ # if you would like different strings for each area then see the next section.
13
+ # Example: 'development' -> 'dev' or 'preproduction' -> 'preprod'
14
+ # config.aliases = { 'development' => 'dev' }
15
+
16
+ # You may alternatively declare different aliases for the title tag versus the corner banner
17
+ # using the options below.
18
+ # config.title_aliases = { 'development' => 'dev' }
19
+ # config.corner_banner_aliases = { 'preproduction' => 'preprod' }
11
20
 
12
- # By default, the visual-environments will be enabled for all environments except production;
13
- # to exclude additional environments, uncomment the line below and add them to the collection
14
- # ActionController::Base::VisualEnvironments.excluded_environments = []
21
+ # By default, the visual-environments will be enabled for all environments except production;
22
+ # to exclude additional environments, uncomment the line below and add them to the collection
23
+ # config.excluded_environments = []
24
+ end
@@ -1,13 +1,54 @@
1
+ module VisualEnvironments
2
+
3
+ # Whether the current environment should be shown in the title tag
4
+ mattr_accessor :enable_env_in_title
5
+ @@enable_env_in_title = false
6
+
7
+ # If non-nil, describes which side of the page the banner should be
8
+ # displayed on (valid values are :left, :right)
9
+ mattr_accessor :corner_banner_side
10
+ @@corner_banner_side = nil
11
+
12
+ # Allows config to map different strings to the environments displayed
13
+ # in the title tag
14
+ mattr_accessor :title_aliases
15
+ @@title_aliases = {}
16
+
17
+ # Allows config to map different strings to the environments displayed
18
+ # in the corner banner display
19
+ mattr_accessor :corner_banner_aliases
20
+ @@corner_banner_aliases = {}
21
+
22
+ # A collection of environments that this gem should not operate in
23
+ mattr_accessor :excluded_environments
24
+ @@excluded_environments = []
25
+
26
+ # Use setup with a block to configure the module in an initializer;
27
+ # run 'rails generate visual_environments:install' to create a default
28
+ # initializer
29
+ def self.setup
30
+ yield self
31
+ end
32
+
33
+ # Set the aliases of both the title and the corner
34
+ # banner to the supplied item
35
+ def self.aliases=(aliases)
36
+ @@title_aliases.replace aliases
37
+ @@corner_banner_aliases.replace aliases
38
+ end
39
+
40
+ end
41
+
1
42
  class ActionController::Base
43
+ include VisualEnvironments
2
44
  after_filter :shim_visual_environments
3
45
 
4
46
  def shim_visual_environments
5
47
  unless Rails.env == 'production' || (VisualEnvironments.excluded_environments && VisualEnvironments.excluded_environments.include?(Rails.env))
6
48
 
7
- current_env = Rails.env
8
- current_env = VisualEnvironments.aliases[current_env] if !VisualEnvironments.aliases.nil? && VisualEnvironments.aliases.has_key?(current_env)
9
-
10
49
  if VisualEnvironments.enable_env_in_title
50
+ current_env = Rails.env
51
+ current_env = VisualEnvironments.title_aliases[current_env] if !VisualEnvironments.title_aliases.nil? && VisualEnvironments.title_aliases.has_key?(current_env)
11
52
  shim = "<script type='text/javascript'>var te=document.getElementsByTagName('title')[0];var t=te.innerHTML;te.innerHTML=\"["+current_env+"] \"+t;</script></body>"
12
53
  response.body = response.body.gsub /\<\/body\>/, shim
13
54
  end
@@ -15,6 +56,8 @@ class ActionController::Base
15
56
  unless VisualEnvironments.corner_banner_side.nil?
16
57
  # Exit if we detect invalid options in the corner_banner_side option
17
58
  return unless [:left,:right].include?(VisualEnvironments.corner_banner_side)
59
+ current_env = Rails.env
60
+ current_env = VisualEnvironments.corner_banner_aliases[current_env] if !VisualEnvironments.corner_banner_aliases.nil? && VisualEnvironments.corner_banner_aliases.has_key?(current_env)
18
61
  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>"
19
62
 
20
63
  if VisualEnvironments.corner_banner_side == :right
@@ -26,16 +69,7 @@ class ActionController::Base
26
69
  response.body = response.body.gsub /\<\/body\>/, shim
27
70
  end
28
71
 
29
-
30
72
  end
31
73
  end
32
74
 
33
- module VisualEnvironments
34
- class << self
35
- attr_accessor :enable_env_in_title
36
- attr_accessor :corner_banner_side
37
- attr_accessor :aliases
38
- attr_accessor :excluded_environments
39
- end
40
- end
41
75
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{visual-environments}
8
- s.version = "0.2.1"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Zachery Moneypenny, David van Leeuwen"]
12
- s.date = %q{2011-02-27}
12
+ s.date = %q{2011-03-05}
13
13
  s.description = %q{This gem provides a configurable means for showing, via an updated <title> tag or CSS corner banner, what the current runtime environment is (development, staging, test, etc.) This functionality is never enabled for production, and for all other environments you can exclude specific ones.}
14
14
  s.email = %q{whazzmaster@gmail.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: visual-environments
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.3.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zachery Moneypenny, David van Leeuwen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-27 00:00:00 -06:00
13
+ date: 2011-03-05 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -94,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
- hash: 251171772694086353
97
+ hash: 810695887365503587
98
98
  segments:
99
99
  - 0
100
100
  version: "0"