exvo_helpers 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Note, that only significant changes are listed.
4
4
 
5
+ ## 0.2.2 (2012-01-30)
6
+
7
+ * `google_analytics` view helper
8
+
9
+
5
10
  ## 0.2.1 (2012-01-27)
6
11
 
7
12
  * Bugfix (`ENV["AUTH_REQUIRE_SSL"]` and `ENV["AUTH_DEBUG"]` were not being respected when set to `false`)
data/README.md CHANGED
@@ -145,4 +145,20 @@ Note, that this helper does not support full API of Rails' `stylesheet_link_tag`
145
145
  ```
146
146
 
147
147
 
148
+ ### google_analytics(domain, account)
149
+
150
+ New, asynchronous Google Analytics javascript snippet to track page views. Note, that it will output the javascript analytics snippet only in production environment.
151
+
152
+ ```ruby
153
+ = google_analytics('exvo.com', 'UA-2491324-1')
154
+ ```
155
+
156
+ ```html
157
+ <script type="text/javascript">
158
+ var _gaq = _gaq || [];
159
+ ...
160
+ ```
161
+
162
+
163
+
148
164
  Copyright © 2011-2012 Exvo.com Development BV, released under the MIT license
@@ -1,3 +1,3 @@
1
1
  module ExvoHelpers
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -27,6 +27,37 @@ module Exvo
27
27
  image_tag(Exvo::Helpers.themes_uri + '/stylesheets/images' + path, options)
28
28
  end
29
29
 
30
+ def google_analytics(domain, account)
31
+ script = <<END
32
+ <script type="text/javascript">
33
+ var _gaq = _gaq || [];
34
+ _gaq.push(['_setAccount', '#{account}']);
35
+ _gaq.push(['_setDomainName', '#{domain}']);
36
+ _gaq.push(['_setAllowLinker', true]);
37
+ _gaq.push(['_trackPageview']);
38
+
39
+ (function() {
40
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
41
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
42
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
43
+ })();
44
+
45
+ var current_location_hash = window.location.hash;
46
+ var update_hash = function() {
47
+ if (current_location_hash != window.location.hash) {
48
+ current_location_hash = window.location.hash;
49
+ _gaq.push(['_trackPageview', current_location_hash]);
50
+ }
51
+ }
52
+ setInterval(update_hash, 500);
53
+ </script>
54
+ END
55
+
56
+ if Exvo::Helpers.env.to_sym == :production
57
+ script.respond_to?(:html_safe) ? script.html_safe : script
58
+ end
59
+ end
60
+
30
61
  end
31
62
 
32
63
  end
@@ -6,25 +6,36 @@ end
6
6
 
7
7
  describe Exvo::ViewHelpers do
8
8
 
9
- describe "javascript_bundle_include_tag" do
10
-
11
- let(:view_helper) { SpecViewHelper.new }
9
+ let(:view_helper) { SpecViewHelper.new }
12
10
 
11
+ describe "#javascript_bundle_include_tag" do
13
12
  it "returns a javascript_include_tag based on env" do
14
13
  view_helper.should_receive(:javascript_include_tag).with("//d33gjlr95u9pgf.cloudfront.net/javascripts/plugins.js")
15
14
  view_helper.javascript_bundle_include_tag("plugins")
16
15
  end
16
+ end
17
17
 
18
+ describe "#themes_stylesheet_link_tag" do
18
19
  it "returns a stylesheet_link_tag based on env" do
19
20
  view_helper.should_receive(:stylesheet_link_tag).with("//themes.exvo.com/stylesheets/themes/frost/all.css", { :media => 'all' })
20
21
  view_helper.themes_stylesheet_link_tag("frost/all", :media => 'all')
21
22
  end
23
+ end
22
24
 
25
+ describe "#themes_image_tag" do
23
26
  it "returns an image_tag based on env" do
24
27
  view_helper.should_receive(:image_tag).with("//themes.exvo.com/stylesheets/images/icons/exvo.png", { :alt => 'Exvo' })
25
28
  view_helper.themes_image_tag("icons/exvo.png", :alt => 'Exvo')
26
29
  end
30
+ end
31
+
32
+ describe "#google_analytics" do
33
+ let(:snippet) { view_helper.google_analytics("exvo.com", "123") }
27
34
 
35
+ specify { snippet.should match('<script type="text/javascript">') }
36
+ specify { snippet.should match("['_setAccount', 'exvo.com']") }
37
+ specify { snippet.should match("['_setDomainName', '123']") }
38
+ specify { snippet.should match("window.location.hash") }
28
39
  end
29
40
 
30
41
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exvo_helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-27 00:00:00.000000000Z
12
+ date: 2012-01-30 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &83264590 !ruby/object:Gem::Requirement
16
+ requirement: &72764340 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.8'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *83264590
24
+ version_requirements: *72764340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: guard
27
- requirement: &83264220 !ruby/object:Gem::Requirement
27
+ requirement: &72725620 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.10.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *83264220
35
+ version_requirements: *72725620
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: guard-rspec
38
- requirement: &83263770 !ruby/object:Gem::Requirement
38
+ requirement: &72722530 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.6.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *83263770
46
+ version_requirements: *72722530
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rb-fsevent
49
- requirement: &83263450 !ruby/object:Gem::Requirement
49
+ requirement: &72636770 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *83263450
57
+ version_requirements: *72636770
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rb-inotify
60
- requirement: &83263090 !ruby/object:Gem::Requirement
60
+ requirement: &72634350 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *83263090
68
+ version_requirements: *72634350
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &83262810 !ruby/object:Gem::Requirement
71
+ requirement: &72633850 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *83262810
79
+ version_requirements: *72633850
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov-rcov
82
- requirement: &83262530 !ruby/object:Gem::Requirement
82
+ requirement: &72633250 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *83262530
90
+ version_requirements: *72633250
91
91
  description: Ruby gem providing various helper methods, like auth_host, auth_uri,
92
92
  auth_require_ssl, cdn_host, etc.
93
93
  email: