embed_google 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .DS_Store
5
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --colour
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+ rvm_gemset_create_on_use_flag=1
2
+ rvm_project_rvmrc_default=1
3
+ rvm 1.8.7@embed_google
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ embed_google (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ fuubar (0.0.5)
11
+ rspec (~> 2.0)
12
+ rspec-instafail (~> 0.1.4)
13
+ ruby-progressbar (~> 0.0.10)
14
+ rspec (2.6.0)
15
+ rspec-core (~> 2.6.0)
16
+ rspec-expectations (~> 2.6.0)
17
+ rspec-mocks (~> 2.6.0)
18
+ rspec-core (2.6.4)
19
+ rspec-expectations (2.6.0)
20
+ diff-lcs (~> 1.1.2)
21
+ rspec-instafail (0.1.8)
22
+ rspec-mocks (2.6.0)
23
+ ruby-progressbar (0.0.10)
24
+
25
+ PLATFORMS
26
+ ruby
27
+
28
+ DEPENDENCIES
29
+ embed_google!
30
+ fuubar
31
+ rspec
File without changes
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "embed_google"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "embed_google"
7
+ s.version = EmbedGoogle::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Sebastian von Conrad"]
10
+ s.email = ["sebastian@vonconrad.com"]
11
+ s.homepage = "http://github.com/vonconrad/embed_google"
12
+ s.summary = %q{Gem for embedding various Google services (e.g. analytics tracking) in Rack apps}
13
+ s.description = %q{This gem allows easy and flexible embedding of Google services (currently only analytics tracking) in Rack apps, including Ruby on Rails}
14
+
15
+ s.rubyforge_project = "embed_google"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.add_development_dependency "rspec"
23
+ s.add_development_dependency "fuubar"
24
+ end
@@ -0,0 +1,11 @@
1
+ require 'embed_google/analytics'
2
+
3
+ module EmbedGoogle
4
+ unless const_defined?(:VERSION)
5
+ VERSION = '0.0.1'
6
+ end
7
+
8
+ def self.analytics(id=nil, options={})
9
+ Analytics.new(id, options).script
10
+ end
11
+ end
@@ -0,0 +1,26 @@
1
+ module EmbedGoogle
2
+ class Analytics
3
+ class << self
4
+ attr_accessor :id
5
+ end
6
+
7
+ attr_accessor :account_id
8
+
9
+ def initialize(id=nil, options={})
10
+ self.account_id = id || self.class.id
11
+ raise ArgumentError, 'Account ID is required' unless account_id
12
+ end
13
+
14
+ def script
15
+ str = "var _gaq = _gaq || [];\n"
16
+ str += "_gaq.push(['_setAccount', '#{account_id}']);\n"
17
+ str += "_gaq.push(['_trackPageview']);\n\n"
18
+ str += "(function() {\n"
19
+ str += " var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n"
20
+ str += " ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n"
21
+ str += " var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n"
22
+ str += "})();\n"
23
+ "<script type='text/javascript'>\n" + str + "</script>\n"
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe EmbedGoogle::Analytics do
4
+ it 'refuses to initiate without an account id' do
5
+ lambda { EmbedGoogle::Analytics.new }.should raise_error('Account ID is required')
6
+ end
7
+
8
+ it 'uses a prespecified account id' do
9
+ EmbedGoogle::Analytics.id = 'UA-1234567-1'
10
+
11
+ instance = EmbedGoogle::Analytics.new
12
+ instance.account_id.should == 'UA-1234567-1'
13
+ end
14
+
15
+ it 'overwrites a prespecified account id' do
16
+ EmbedGoogle::Analytics.id = 'UA-1234567-1'
17
+
18
+ instance = EmbedGoogle::Analytics.new('UA-1234567-2')
19
+ instance.account_id.should == 'UA-1234567-2'
20
+ end
21
+
22
+ it 'returns the simplest variation of Analytics javascript' do
23
+ javascript = EmbedGoogle::Analytics.new('UA-1234567-1').script
24
+ javascript.should == <<-SCRIPT
25
+ <script type='text/javascript'>
26
+ var _gaq = _gaq || [];
27
+ _gaq.push(['_setAccount', 'UA-1234567-1']);
28
+ _gaq.push(['_trackPageview']);
29
+
30
+ (function() {
31
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
32
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
33
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
34
+ })();
35
+ </script>
36
+ SCRIPT
37
+ end
38
+ end
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'embed_google')
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: embed_google
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Sebastian von Conrad
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-07-16 00:00:00 +09:30
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rspec
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: fuubar
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: This gem allows easy and flexible embedding of Google services (currently only analytics tracking) in Rack apps, including Ruby on Rails
50
+ email:
51
+ - sebastian@vonconrad.com
52
+ executables: []
53
+
54
+ extensions: []
55
+
56
+ extra_rdoc_files: []
57
+
58
+ files:
59
+ - .gitignore
60
+ - .rspec
61
+ - .rvmrc
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - README.rdoc
65
+ - Rakefile
66
+ - embed_google.gemspec
67
+ - lib/embed_google.rb
68
+ - lib/embed_google/analytics.rb
69
+ - spec/embed_google/analytics.rb
70
+ - spec/spec_helper.rb
71
+ has_rdoc: true
72
+ homepage: http://github.com/vonconrad/embed_google
73
+ licenses: []
74
+
75
+ post_install_message:
76
+ rdoc_options: []
77
+
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
88
+ version: "0"
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ requirements: []
99
+
100
+ rubyforge_project: embed_google
101
+ rubygems_version: 1.6.2
102
+ signing_key:
103
+ specification_version: 3
104
+ summary: Gem for embedding various Google services (e.g. analytics tracking) in Rack apps
105
+ test_files:
106
+ - spec/embed_google/analytics.rb
107
+ - spec/spec_helper.rb