rack-piwik 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/rack/piwik.rb CHANGED
@@ -3,12 +3,10 @@ require 'erb'
3
3
 
4
4
  module Rack
5
5
 
6
- class GoogleAnalytics
6
+ class Piwik
7
7
 
8
- DEFAULT = { :async => true }
9
-
10
8
  def initialize(app, options = {})
11
- raise ArgumentError, "Tracker must be set!" unless options[:tracker] and !options[:tracker].empty?
9
+ raise ArgumentError, "piwik_url must be present" unless options[:piwik_url] and !options[:piwik_url].empty?
12
10
  @app, @options = app, DEFAULT.merge(options)
13
11
  end
14
12
 
@@ -27,15 +25,9 @@ module Rack
27
25
  def html?; @headers['Content-Type'] =~ /html/; end
28
26
 
29
27
  def inject(response)
30
- file = @options[:async] ? 'async' : 'sync'
28
+ file = 'async'
31
29
  @template ||= ::ERB.new ::File.read ::File.expand_path("../templates/#{file}.erb",__FILE__)
32
- if @options[:async]
33
- response.gsub(%r{</head>}, @template.result(binding) + "</head>")
34
- else
35
- response.gsub(%r{</body>}, @template.result(binding) + "</body>")
36
- end
30
+ response.gsub(%r{</head>}, @template.result(binding) + "</head>")
37
31
  end
38
-
39
32
  end
40
-
41
33
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-piwik
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Maxwell Salzberg
@@ -28,7 +28,6 @@ extensions: []
28
28
  extra_rdoc_files: []
29
29
 
30
30
  files:
31
- - lib/rack/google-analytics.rb
32
31
  - lib/rack/piwik.rb
33
32
  - lib/rack/templates/async.erb
34
33
  - README.md
@@ -1,40 +0,0 @@
1
- require 'rack'
2
- require 'erb'
3
-
4
- module Rack
5
-
6
- class Piwik
7
-
8
-
9
- def initialize(app, options = {})
10
- raise ArgumentError, "piwik_url must be user" unless options[:piwik_url] and !options[:piwik_url].empty?
11
- @app, @options = app, DEFAULT.merge(options)
12
- end
13
-
14
- def call(env); dup._call(env); end
15
-
16
- def _call(env)
17
- @status, @headers, @response = @app.call(env)
18
- return [@status, @headers, @response] unless html?
19
- response = Rack::Response.new([], @status, @headers)
20
- @response.each { |fragment| response.write inject(fragment) }
21
- response.finish
22
- end
23
-
24
- private
25
-
26
- def html?; @headers['Content-Type'] =~ /html/; end
27
-
28
- def inject(response)
29
- file = @options[:async] ? 'async' : 'sync'
30
- @template ||= ::ERB.new ::File.read ::File.expand_path("../templates/#{file}.erb",__FILE__)
31
- if @options[:async]
32
- response.gsub(%r{</head>}, @template.result(binding) + "</head>")
33
- else
34
- response.gsub(%r{</body>}, @template.result(binding) + "</body>")
35
- end
36
- end
37
-
38
- end
39
-
40
- end