rack-environmental 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +10 -0
- data/README.rdoc +8 -8
- data/Rakefile +1 -1
- data/lib/rack-environmental.rb +34 -12
- data/test/railsapp/log/development.log +6 -0
- data/test/sinatraapp/app.rb +2 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,4 +1,14 @@
|
|
1
|
+
1.1.0 (December 5, 2009)
|
2
|
+
* Added :background option.
|
3
|
+
|
4
|
+
1.0.5 (December 3, 2009)
|
5
|
+
* Updated gem dependency information.
|
6
|
+
|
7
|
+
1.0.4 (December 3, 2009)
|
8
|
+
* Refactored to (correctly) use rack-plastic gem.
|
9
|
+
|
1
10
|
1.0.3 (December 3, 2009)
|
11
|
+
* Do not use this version. It has a wrong gem dependency.
|
2
12
|
* Refactored to use rack-plastic gem.
|
3
13
|
|
4
14
|
1.0.2 (November 17, 2009)
|
data/README.rdoc
CHANGED
@@ -34,11 +34,11 @@ Each environment can be further configured:
|
|
34
34
|
|
35
35
|
Here's the full list of configuration options:
|
36
36
|
|
37
|
-
:url
|
38
|
-
:style
|
39
|
-
:color
|
40
|
-
:size
|
41
|
-
:opacity
|
42
|
-
:top
|
43
|
-
:left
|
44
|
-
|
37
|
+
:url => a regular expression
|
38
|
+
:style => either :badge (a transparent, floating badge) or :banner (default)
|
39
|
+
:color => a string that represents a CSS color, such as "red", "rgb(6,70,14)", or "#8e6630"
|
40
|
+
:size => :small, :medium, or :large; defaults to :medium
|
41
|
+
:opacity => a number from 0 (completely transparent) to 1; only works with the badge style
|
42
|
+
:top => distance in pixels from the top; only works with the badge style
|
43
|
+
:left => distance in pixels from the left; only works with the badge style
|
44
|
+
:background => true or false; when true, the body's background color is changed
|
data/Rakefile
CHANGED
data/lib/rack-environmental.rb
CHANGED
@@ -4,25 +4,30 @@ module Rack
|
|
4
4
|
class Environmental < Plastic
|
5
5
|
|
6
6
|
def change_nokogiri_doc(doc)
|
7
|
+
initialize_environment_options
|
7
8
|
add_to_top_of_web_page(doc, create_sticker(doc))
|
9
|
+
if @environment_options[:background]
|
10
|
+
body = doc.at_css("body")
|
11
|
+
background_style = "background-color: #{options[:color] || default_color};"
|
12
|
+
if body['style']
|
13
|
+
body['style'] << ";#{background_style}"
|
14
|
+
else
|
15
|
+
body['style'] = background_style
|
16
|
+
end
|
17
|
+
end
|
8
18
|
doc
|
9
19
|
end
|
10
20
|
|
11
21
|
private
|
12
22
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
23
|
+
def initialize_environment_options
|
24
|
+
@environment_name = environment(request.url)
|
25
|
+
if @environment_name
|
26
|
+
@environment_options = options[@environment_name]
|
27
|
+
else
|
28
|
+
@environment_options = {}
|
16
29
|
end
|
17
30
|
end
|
18
|
-
|
19
|
-
def create_sticker(doc)
|
20
|
-
environment_name = environment(request.url)
|
21
|
-
return nil if environment_name.nil?
|
22
|
-
div = create_node(doc, "div", environment_name.to_s)
|
23
|
-
div['style'] = style(options[environment_name])
|
24
|
-
div
|
25
|
-
end
|
26
31
|
|
27
32
|
def environment(url)
|
28
33
|
url = url.split('//').last # remove http://
|
@@ -34,6 +39,19 @@ module Rack
|
|
34
39
|
return nil
|
35
40
|
end
|
36
41
|
|
42
|
+
def add_to_top_of_web_page(doc, node)
|
43
|
+
if node
|
44
|
+
add_first_child(doc.at_css("body"), node)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_sticker(doc)
|
49
|
+
return nil if @environment_name.nil?
|
50
|
+
div = create_node(doc, "div", @environment_name.to_s)
|
51
|
+
div['style'] = style(@environment_options)
|
52
|
+
div
|
53
|
+
end
|
54
|
+
|
37
55
|
def style(options)
|
38
56
|
style = ""
|
39
57
|
style << "font-family: Verdana, Arial, sans-serif;"
|
@@ -42,7 +60,7 @@ module Rack
|
|
42
60
|
style << "text-align: center;"
|
43
61
|
style << "color: black;"
|
44
62
|
style << "padding: 3px;"
|
45
|
-
style << "background-color: #{options[:color] ||
|
63
|
+
style << "background-color: #{options[:color] || default_color};"
|
46
64
|
case options[:size]
|
47
65
|
when :large
|
48
66
|
style << "font-size: 20px;"
|
@@ -64,6 +82,10 @@ module Rack
|
|
64
82
|
style << "margin: 0px;"
|
65
83
|
end
|
66
84
|
end
|
85
|
+
|
86
|
+
def default_color
|
87
|
+
"blue"
|
88
|
+
end
|
67
89
|
|
68
90
|
end
|
69
91
|
end
|
@@ -124,3 +124,9 @@ Processing TommyBoyController#index (for 127.0.0.1 at 2009-12-03 01:37:05) [GET]
|
|
124
124
|
Rendering template within layouts/application
|
125
125
|
Rendering tommy_boy/index
|
126
126
|
Completed in 3ms (View: 1, DB: 0) | 200 OK [http://localhost/]
|
127
|
+
|
128
|
+
|
129
|
+
Processing TommyBoyController#index (for 127.0.0.1 at 2009-12-05 13:32:22) [GET]
|
130
|
+
Rendering template within layouts/application
|
131
|
+
Rendering tommy_boy/index
|
132
|
+
Completed in 71ms (View: 69, DB: 0) | 200 OK [http://localhost/]
|
data/test/sinatraapp/app.rb
CHANGED
@@ -5,7 +5,8 @@ require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'rack-environmental
|
|
5
5
|
use Rack::Environmental, :staging => { :url => /^staging.+$/ },
|
6
6
|
:test => { :url => /^test.+$/ },
|
7
7
|
:development => { :url => /^localhost.+$/,
|
8
|
-
:style => :badge
|
8
|
+
:style => :badge,
|
9
|
+
:background => true }
|
9
10
|
|
10
11
|
get '/' do
|
11
12
|
%Q{
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-environmental
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wyatt Greene
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-05 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|