rack_clicky 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack_clicky.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack_clicky (0.0.1)
5
+ rack
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ rack (1.3.3)
11
+ thoughtbot-shoulda (2.11.1)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ rack_clicky!
18
+ thoughtbot-shoulda
data/Rakefile CHANGED
@@ -1,52 +1,12 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
3
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "rack_clicky"
8
- gem.summary = "Clicky Analytics for your Rack Apps"
9
- gem.description = "Embeds the Clicky tracking code at the end of your HTML"
10
- gem.email = "mark@amerine.net"
11
- gem.homepage = "http://github.com/amerine/rack_clicky"
12
- gem.authors = ["Mark Turner"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- end
15
- Jeweler::GemcutterTasks.new
16
- rescue LoadError
17
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
- end
19
4
 
20
- require 'rake/testtask'
21
5
  Rake::TestTask.new(:test) do |test|
22
6
  test.libs << 'lib' << 'test'
23
7
  test.pattern = 'test/**/test_*.rb'
24
8
  test.verbose = true
25
9
  end
26
10
 
27
- begin
28
- require 'rcov/rcovtask'
29
- Rcov::RcovTask.new do |test|
30
- test.libs << 'test'
31
- test.pattern = 'test/**/test_*.rb'
32
- test.verbose = true
33
- end
34
- rescue LoadError
35
- task :rcov do
36
- abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
- end
38
- end
39
-
40
- task :test => :check_dependencies
41
11
 
42
12
  task :default => :test
43
-
44
- require 'rake/rdoctask'
45
- Rake::RDocTask.new do |rdoc|
46
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
-
48
- rdoc.rdoc_dir = 'rdoc'
49
- rdoc.title = "rack_clicky #{version}"
50
- rdoc.rdoc_files.include('README*')
51
- rdoc.rdoc_files.include('lib/**/*.rb')
52
- end
data/lib/rack_clicky.rb CHANGED
@@ -1,43 +1,55 @@
1
- module Rack
1
+ require "rack_clicky/version"
2
+
3
+ module Rack
2
4
  class Clicky
3
-
5
+
4
6
  TRACKING_CODE = <<-EOTC
5
7
  <script src="http://static.getclicky.com/js" type="text/javascript"></script>
6
8
  <script type="text/javascript">clicky.init({{CODE}});</script>
7
9
  <noscript><p><img alt="Clicky" width="1" height="1" src="http://in.getclicky.com/{{CODE}}ns.gif" /></p></noscript>
8
10
  EOTC
9
-
10
- def initialize(app, site_id, options = {})
11
+
12
+ def initialize app, site_id, options={}
11
13
  @app = app
12
14
  @site_id = site_id
13
15
  end
14
-
15
- def call(env)
16
+
17
+ def call env
16
18
  dup._call(env)
17
19
  end
18
-
19
- def _call(env)
20
-
21
- @status, @headers, @response = @app.call(env)
22
- return [@status, @headers, @response] unless @headers['Content-Type'] =~ /html/
23
-
24
- @headers.delete('Content-Length')
25
- response = Rack::Response.new([], @status, @headers)
26
- @response.each do |fragment|
27
- response.write(inject_tracking(fragment))
20
+
21
+ def _call env
22
+ status, headers, response = @app.call(env)
23
+
24
+ if should_inject_clicky? status, headers, response
25
+ response = inject_tracking(response)
26
+ fix_content_length(headers, response)
27
+ end
28
+
29
+ [status, headers, response]
30
+ end
31
+
32
+ def should_inject_clicky? status, headers, response
33
+ status == 200 &&
34
+ headers["Content-Type"] &&
35
+ (headers["Content-Type"].include?("text/html") || headers["Content-Type"].include?("application/xhtml"))
36
+ end
37
+
38
+ def fix_content_length headers, response
39
+ if headers["Content-Length"]
40
+ length = response.to_ary.inject(0) { |len, part| len + Rack::Utils.bytesize(part) }
41
+ headers['Content-Length'] = length.to_s
28
42
  end
29
- response.finish
30
43
  end
31
-
32
- def inject_tracking(response)
33
- response.sub!(/<\/body>/, "#{track_code}\n</body>")
44
+
45
+ def inject_tracking response, body=""
46
+ response.each { |s| body << s.to_s }
47
+ [body.gsub(/<\/body>/, "#{track_code}\n</body>")]
34
48
  end
35
-
36
- private
37
-
49
+
38
50
  def track_code
39
51
  TRACKING_CODE.gsub(/\{\{CODE\}\}/, @site_id)
40
52
  end
41
-
53
+ private :track_code
42
54
  end
43
55
  end
@@ -0,0 +1,3 @@
1
+ module RackClicky
2
+ VERSION = "1.0.3"
3
+ end
data/rack_clicky.gemspec CHANGED
@@ -1,54 +1,24 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack_clicky/version"
5
4
 
6
5
  Gem::Specification.new do |s|
7
- s.name = %q{rack_clicky}
8
- s.version = "1.0.2"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Mark Turner"]
12
- s.date = %q{2010-10-27}
6
+ s.name = "rack_clicky"
7
+ s.version = RackClicky::VERSION
8
+ s.authors = ["Mark Turner"]
9
+ s.email = ["mark@amerine.net"]
10
+ s.homepage = "http://github.com/amerine/rack_clicky"
11
+ s.summary = %q{Clicky Analytics for your Rack Apps}
13
12
  s.description = %q{Embeds the Clicky tracking code at the end of your HTML}
14
- s.email = %q{mark@amerine.net}
15
- s.extra_rdoc_files = [
16
- "LICENSE",
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- ".document",
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "lib/rack_clicky.rb",
27
- "rack_clicky.gemspec",
28
- "test/helper.rb",
29
- "test/test_rack_clicky.rb"
30
- ]
31
- s.homepage = %q{http://github.com/amerine/rack_clicky}
32
- s.rdoc_options = ["--charset=UTF-8"]
13
+
14
+ s.rubyforge_project = "rack_clicky"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
33
19
  s.require_paths = ["lib"]
34
- s.rubygems_version = %q{1.3.7}
35
- s.summary = %q{Clicky Analytics for your Rack Apps}
36
- s.test_files = [
37
- "test/helper.rb",
38
- "test/test_rack_clicky.rb"
39
- ]
40
20
 
41
- if s.respond_to? :specification_version then
42
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
43
- s.specification_version = 3
21
+ s.add_development_dependency "thoughtbot-shoulda"
44
22
 
45
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
47
- else
48
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
49
- end
50
- else
51
- s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
52
- end
23
+ s.add_dependency "rack"
53
24
  end
54
-
data/test/helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
  require 'shoulda'
4
+ require 'rack/mock'
4
5
 
5
6
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
7
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -1,33 +1,31 @@
1
1
  require 'helper'
2
- require 'rack/mock'
3
2
 
4
3
  class TestRackClicky < Test::Unit::TestCase
5
4
  context "Embedding clicky" do
6
5
  should "place the tracking code at the end of an HTML request" do
7
6
  assert_match EXPECTED_CODE, request.body
8
7
  end
9
-
8
+
10
9
  should "place the tracking code at the end of an XHTML request" do
11
10
  assert_match EXPECTED_CODE, request(:content_type => 'application/xhtml+xml').body
12
11
  end
13
-
12
+
14
13
  should "not place the tracking code in a non HTML request" do
15
14
  assert_no_match EXPECTED_CODE, request(:content_type => 'application/xml', :body => [XML]).body
16
15
  end
17
-
16
+
18
17
  should "insert the site id" do
19
18
  assert_match /clicky\.init\(000000\)/, request.body
20
19
  end
21
-
20
+
22
21
  end
23
-
24
-
22
+
25
23
  private
26
-
24
+
27
25
  EXPECTED_CODE = /<script.*clicky\.init.*<\/script>.*<\/body>/m
28
-
26
+
29
27
  SITE_ID = "000000"
30
-
28
+
31
29
  HTML = <<-EOHTML
32
30
  <html>
33
31
  <head>
@@ -39,7 +37,7 @@ class TestRackClicky < Test::Unit::TestCase
39
37
  </body>
40
38
  </html>
41
39
  EOHTML
42
-
40
+
43
41
  XML = <<-EOXML
44
42
  <?xml version="1.0" encoding="ISO-8859-1"?>
45
43
  <user>
@@ -47,14 +45,14 @@ class TestRackClicky < Test::Unit::TestCase
47
45
  <age>Unknown</age>
48
46
  </user>
49
47
  EOXML
50
-
48
+
51
49
  def request(options={})
52
50
  @app = app(options)
53
51
  request = Rack::MockRequest.new(@app).get('/')
54
52
  yield(@app, request) if block_given?
55
53
  request
56
54
  end
57
-
55
+
58
56
  def app(options={})
59
57
  options = options.clone
60
58
  options[:content_type] ||= "text/html"
@@ -62,5 +60,4 @@ class TestRackClicky < Test::Unit::TestCase
62
60
  rack_app = lambda { |env| [200, { 'Content-Type' => options.delete(:content_type) }, options.delete(:body)] }
63
61
  Rack::Clicky.new(rack_app, SITE_ID)
64
62
  end
65
-
66
63
  end
metadata CHANGED
@@ -1,91 +1,81 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack_clicky
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 0
9
- - 2
10
- version: 1.0.2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.3
5
+ prerelease:
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Mark Turner
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2010-10-27 00:00:00 -07:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2011-09-22 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: thoughtbot-shoulda
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70139124813360 !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
33
22
  type: :development
34
- version_requirements: *id001
23
+ prerelease: false
24
+ version_requirements: *70139124813360
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack
27
+ requirement: &70139124842620 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70139124842620
35
36
  description: Embeds the Clicky tracking code at the end of your HTML
36
- email: mark@amerine.net
37
+ email:
38
+ - mark@amerine.net
37
39
  executables: []
38
-
39
40
  extensions: []
40
-
41
- extra_rdoc_files:
42
- - LICENSE
43
- - README.rdoc
44
- files:
41
+ extra_rdoc_files: []
42
+ files:
45
43
  - .document
46
44
  - .gitignore
45
+ - Gemfile
46
+ - Gemfile.lock
47
47
  - LICENSE
48
48
  - README.rdoc
49
49
  - Rakefile
50
- - VERSION
51
50
  - lib/rack_clicky.rb
51
+ - lib/rack_clicky/version.rb
52
52
  - rack_clicky.gemspec
53
53
  - test/helper.rb
54
54
  - test/test_rack_clicky.rb
55
- has_rdoc: true
56
55
  homepage: http://github.com/amerine/rack_clicky
57
56
  licenses: []
58
-
59
57
  post_install_message:
60
- rdoc_options:
61
- - --charset=UTF-8
62
- require_paths:
58
+ rdoc_options: []
59
+ require_paths:
63
60
  - lib
64
- required_ruby_version: !ruby/object:Gem::Requirement
61
+ required_ruby_version: !ruby/object:Gem::Requirement
65
62
  none: false
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- hash: 3
70
- segments:
71
- - 0
72
- version: "0"
73
- required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
68
  none: false
75
- requirements:
76
- - - ">="
77
- - !ruby/object:Gem::Version
78
- hash: 3
79
- segments:
80
- - 0
81
- version: "0"
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
82
73
  requirements: []
83
-
84
- rubyforge_project:
85
- rubygems_version: 1.3.7
74
+ rubyforge_project: rack_clicky
75
+ rubygems_version: 1.8.6
86
76
  signing_key:
87
77
  specification_version: 3
88
78
  summary: Clicky Analytics for your Rack Apps
89
- test_files:
79
+ test_files:
90
80
  - test/helper.rb
91
81
  - test/test_rack_clicky.rb
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 1.0.2