rack-gauges 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.md +37 -0
- data/lib/rack/gauges.rb +33 -0
- data/lib/rack/templates/gauges.erb +13 -0
- metadata +113 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Lee Hambley
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Rack Gauges
|
2
|
+
|
3
|
+
Simple Rack middleware to help injecting the http://gaug.es tracking code into the footer of your websites.
|
4
|
+
|
5
|
+
This middleware injects the gauges tracker code into the correct place of any request with `Content-Type` containing `html` (therefore `text/html` and similar).
|
6
|
+
|
7
|
+
This code was blatantly stolen (and piped through `sed`) from https://github.com/leehambley/rack-google-analytics.
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
#### Gemfile:
|
12
|
+
gem 'rack-gauges', :require => 'rack/gauges'
|
13
|
+
|
14
|
+
#### Sinatra
|
15
|
+
## app.rb
|
16
|
+
use Rack::Gauges, :tracker => 'UA-xxxxxx-x'
|
17
|
+
|
18
|
+
#### Rails
|
19
|
+
|
20
|
+
## environment.rb:
|
21
|
+
config.gem 'rack-gauges', :lib => 'rack/gauges'
|
22
|
+
config.middleware.use Rack::Gauges, :tracker => '4ec817e9f5a1f5068d000001'
|
23
|
+
|
24
|
+
## Note on Patches/Pull Requests
|
25
|
+
|
26
|
+
* Fork the project.
|
27
|
+
* Make your feature addition or bug fix.
|
28
|
+
* Add tests for it. This is important so I don't break it in a
|
29
|
+
future version unintentionally.
|
30
|
+
* Commit, do not mess with rakefile, version, or history.
|
31
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
32
|
+
* Send me a pull request. Bonus points for topic branches.
|
33
|
+
|
34
|
+
## Copyright
|
35
|
+
|
36
|
+
Copyright (c) 2009-2011 Lee Hambley. See LICENSE for details.
|
37
|
+
With thanks to Ralph von der Heyden http://github.com/ralph/ and Simon `cimm` Schoeters http://github.com/cimm/ - And the biggest hand to Arthur `achiu` Chiu for the huge work that went into the massive 0.9 re-factor.
|
data/lib/rack/gauges.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'erb'
|
3
|
+
|
4
|
+
module Rack
|
5
|
+
|
6
|
+
class Gauges
|
7
|
+
def initialize(app, options = {})
|
8
|
+
raise ArgumentError, "Tracker must be set!" unless options[:tracker] and !options[:tracker].empty?
|
9
|
+
@app, @options = app, options
|
10
|
+
end
|
11
|
+
|
12
|
+
def call(env); dup._call(env); end
|
13
|
+
|
14
|
+
def _call(env)
|
15
|
+
@status, @headers, @response = @app.call(env)
|
16
|
+
return [@status, @headers, @response] unless html?
|
17
|
+
response = Rack::Response.new([], @status, @headers)
|
18
|
+
@response.each { |fragment| response.write inject(fragment) }
|
19
|
+
response.finish
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def html?; @headers['Content-Type'] =~ /html/; end
|
25
|
+
|
26
|
+
def inject(response)
|
27
|
+
@template ||= ::ERB.new ::File.read ::File.expand_path("../templates/gauges.erb",__FILE__)
|
28
|
+
response.gsub(%r{</body>}, @template.result(binding) + "</body>")
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<script type="text/javascript">
|
2
|
+
var _gauges = _gauges || [];
|
3
|
+
(function() {
|
4
|
+
var t = document.createElement('script');
|
5
|
+
t.type = 'text/javascript';
|
6
|
+
t.async = true;
|
7
|
+
t.id = 'gauges-tracker';
|
8
|
+
t.setAttribute('data-site-id', <%= @options[:tracker].inspect %>);
|
9
|
+
t.src = '//secure.gaug.es/track.js';
|
10
|
+
var s = document.getElementsByTagName('script')[0];
|
11
|
+
s.parentNode.insertBefore(t, s);
|
12
|
+
})();
|
13
|
+
</script>
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-gauges
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thunderbolt Labs
|
9
|
+
- Lee Hambley
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-01-27 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rack
|
17
|
+
requirement: &70196627368620 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70196627368620
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rack-test
|
28
|
+
requirement: &70196627367560 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70196627367560
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: shoulda
|
39
|
+
requirement: &70196627366500 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70196627366500
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: rake
|
50
|
+
requirement: &70196627411760 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70196627411760
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: yard
|
61
|
+
requirement: &70196627411120 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70196627411120
|
70
|
+
description: Simple Rack middleware for implementing gauges tracking in your Ruby-Rack
|
71
|
+
based project. Code blatantly stolen from https://github.com/leehambley/rack-google-analytics.
|
72
|
+
email:
|
73
|
+
- us@thunderboltlabs.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- lib/rack/gauges.rb
|
79
|
+
- lib/rack/templates/gauges.erb
|
80
|
+
- README.md
|
81
|
+
- LICENSE
|
82
|
+
homepage: https://github.com/thunderboltlabs/rack-gauges
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
hash: -2682344705186015538
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
hash: -2682344705186015538
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.11
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: Rack middleware to inject the Gauges tracking code into outgoing responses.
|
112
|
+
test_files: []
|
113
|
+
has_rdoc:
|