banner 0.0.1.pre → 0.0.3.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,73 +1,6 @@
1
- require 'banner/version'
1
+ require 'banner/middleware'
2
2
  require 'banner/railtie'
3
+ require 'banner/version'
3
4
 
4
5
  module Banner
5
- class Middleware
6
- def initialize(app, options={})
7
- @app = app
8
- @environments = options.fetch(:environments, [:staging])
9
- @message = options.fetch(:message, 'Banner')
10
-
11
- @style = {}
12
- @style[:width] = options.fetch(:width, 300).to_i
13
- @style[:color] = options.fetch(:color, '255, 255, 0')
14
- @style[:transparency] = options.fetch(:transparency, '0.5')
15
- end
16
-
17
- def call(env)
18
- status, headers, response = @app.call(env)
19
-
20
- content = ''
21
- response.each { |part| content += part }
22
-
23
- content = with_banner(content)
24
- content = with_style(content)
25
- content = Array(content)
26
-
27
- [status, headers, content]
28
- end
29
-
30
- protected
31
-
32
- def with_banner(content)
33
- match = /<body.*>/.match(content)
34
- unless match.nil?
35
- start_pos, end_pos = match.offset(0)
36
- content.insert(end_pos, "\n\n<div id=\"notification-banner\" onclick=\"javascript:this.style.display='none'\" title=\"Click the banner to hide it\"><span>#{@message}</span></div>")
37
- end
38
- content
39
- end
40
-
41
- def with_style(content)
42
- match = /<\/head>/.match(content)
43
- unless match.nil?
44
- start_pos, end_pos = match.offset(0)
45
-
46
- css = <<-CODE
47
- <style>
48
- div#notification-banner {
49
- background: rgba(#{@style[:color]}, #{@style[:transparency]});
50
- border-radius: 0 0 6px 6px;
51
- color: rgba(0, 0, 0, #{@style[:transparency]});
52
- cursor: pointer;
53
- font-weight: bold;
54
- left: 50%;
55
- line-height: 25px;
56
- margin-left: -#{@style[:width]/2}px;
57
- position: fixed;
58
- text-align: center;
59
- top: 0;
60
- width: #{@style[:width]}px;
61
- }
62
- div#notification-banner span {
63
- padding: 3px 10px;
64
- }
65
- </style>
66
- CODE
67
-
68
- content.insert(start_pos, css)
69
- end
70
- content
71
- end
72
- end
73
6
  end
@@ -0,0 +1,71 @@
1
+ module Banner
2
+ class Middleware
3
+ def initialize(app, options={})
4
+ @app = app
5
+ @environments = options.fetch(:environments, [:staging])
6
+ @message = options.fetch(:message, 'Banner')
7
+
8
+ @style = {}
9
+ @style[:width] = options.fetch(:width, 300).to_i
10
+ @style[:color] = options.fetch(:color, '255, 255, 0')
11
+ @style[:transparency] = options.fetch(:transparency, '0.5')
12
+ end
13
+
14
+ def call(env)
15
+ status, headers, response = @app.call(env)
16
+
17
+ content = ''
18
+ response.each { |part| content += part }
19
+
20
+ content = with_banner(content)
21
+ content = with_style(content)
22
+ content = Array(content)
23
+
24
+ [status, headers, content]
25
+ end
26
+
27
+ protected
28
+
29
+ def with_banner(content)
30
+ match = /<body.*>/.match(content)
31
+ unless match.nil?
32
+ start_pos, end_pos = match.offset(0)
33
+ content.insert(end_pos, "\n\n<div id=\"notification-banner\" onclick=\"javascript:this.style.display='none'\" title=\"Click the banner to hide it\"><span>#{@message}</span></div>")
34
+ end
35
+ content
36
+ end
37
+
38
+ def with_style(content)
39
+ match = /<\/head>/.match(content)
40
+ unless match.nil?
41
+ start_pos, end_pos = match.offset(0)
42
+
43
+ css = <<-CODE
44
+ <style>
45
+ div#notification-banner {
46
+ background: rgba(#{@style[:color]}, #{@style[:transparency]});
47
+ border-radius: 0 0 6px 6px;
48
+ color: rgba(0, 0, 0, #{@style[:transparency]});
49
+ cursor: pointer;
50
+ font-weight: bold;
51
+ left: 50%;
52
+ line-height: 25px;
53
+ margin-left: -#{@style[:width]/2}px;
54
+ position: fixed;
55
+ text-align: center;
56
+ top: 0;
57
+ width: #{@style[:width]}px;
58
+ }
59
+ div#notification-banner span {
60
+ padding: 3px 10px;
61
+ }
62
+ </style>
63
+ CODE
64
+
65
+ content.insert(start_pos, css)
66
+ end
67
+ content
68
+ end
69
+ end
70
+ end
71
+
@@ -1,3 +1,3 @@
1
1
  module Banner
2
- VERSION = "0.0.1.pre"
2
+ VERSION = "0.0.3.pre"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: banner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.pre
4
+ version: 0.0.3.pre
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-23 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Add a banner to the top of all pages in an app
15
15
  email:
@@ -25,6 +25,7 @@ files:
25
25
  - Rakefile
26
26
  - banner.gemspec
27
27
  - lib/banner.rb
28
+ - lib/banner/middleware.rb
28
29
  - lib/banner/railtie.rb
29
30
  - lib/banner/version.rb
30
31
  homepage: http://github.com/slant/banner