yandex-metrika-rails 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.coveralls.yml +1 -0
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/Rakefile +12 -0
- data/lib/yandex-metrika-rails.rb +30 -0
- data/lib/yandex-metrika/counter.rb +46 -0
- data/lib/yandex-metrika/counter/kind.rb +12 -0
- data/lib/yandex-metrika/counter/renderer.rb +15 -0
- data/lib/yandex-metrika/counter/template_options.rb +4 -0
- data/lib/yandex-metrika/rails/railtie.rb +6 -0
- data/lib/yandex-metrika/rails/view_helpers.rb +8 -0
- data/lib/yandex-metrika/templates/async.erb +20 -0
- data/lib/yandex-metrika/templates/sync.erb +6 -0
- data/lib/yandex-metrika/version.rb +3 -0
- data/test/rails/views_helper_test.rb +38 -0
- data/test/test_helper.rb +13 -0
- data/yandex-metrika-rails.gemspec +23 -0
- metadata +99 -0
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: 7XAqRDzxWmghPK1B8UcBIhHnDxULfAuzj
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kirillov Alexander
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Yandex::Metrika::Rails
|
2
|
+
[](https://coveralls.io/r/saratovsource/yandex-metrika-rails)
|
4
|
+
|
5
|
+
TODO: Write a gem description
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'yandex-metrika-rails'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install yandex-metrika-rails
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
1. Fork it
|
28
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
31
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'yandex-metrika/version'
|
2
|
+
require 'yandex-metrika/counter'
|
3
|
+
|
4
|
+
module YandexMetrika
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def counter
|
8
|
+
@counter || nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def counter=(counter)
|
12
|
+
@counter = counter
|
13
|
+
end
|
14
|
+
|
15
|
+
def valid_counter?
|
16
|
+
!invalid_counter?
|
17
|
+
end
|
18
|
+
|
19
|
+
def invalid_counter?
|
20
|
+
counter.nil? || counter == ""
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
YM = YandexMetrika
|
27
|
+
if defined?(Rails)
|
28
|
+
require 'yandex-metrika/rails/railtie'
|
29
|
+
YMR = YandexMetrika::Rails
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'active_support/core_ext/string/output_safety'
|
2
|
+
require 'erb'
|
3
|
+
module YandexMetrika
|
4
|
+
class Counter
|
5
|
+
attr_reader :local, :counter_types, :noscript, :async
|
6
|
+
|
7
|
+
autoload :Kind, 'yandex-metrika/counter/kind'
|
8
|
+
autoload :Renderer, 'yandex-metrika/counter/renderer'
|
9
|
+
autoload :TemplateOptions, 'yandex-metrika/counter/template_options'
|
10
|
+
|
11
|
+
def initialize(args = {})
|
12
|
+
@counter_types ||= []
|
13
|
+
prepare_view_options(args)
|
14
|
+
append_counter_types(args)
|
15
|
+
@options_renderer = YandexMetrika::Counter::Renderer.new(@counter_types)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
template_name = @async ? "async" : "sync"
|
20
|
+
@template ||= ::ERB.new ::File.read ::File.expand_path("../templates/#{template_name}.erb", __FILE__)
|
21
|
+
@template.result(template_options.instance_eval { binding }).html_safe
|
22
|
+
end
|
23
|
+
alias_method :render, :to_s
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def template_options
|
28
|
+
TemplateOptions.new({
|
29
|
+
counter_name: "yaCounter#{YM.counter}",
|
30
|
+
counter_options: @options_renderer.to_s
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
def prepare_view_options(args)
|
35
|
+
@local = args.delete(:local) || false
|
36
|
+
@async = args.delete(:async) || true
|
37
|
+
@noscript = args.delete(:noscript) || true
|
38
|
+
end
|
39
|
+
|
40
|
+
def append_counter_types(args = {})
|
41
|
+
args.each do |k,v|
|
42
|
+
@counter_types << Kind.new(k,v)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module YandexMetrika
|
2
|
+
class Counter::Renderer
|
3
|
+
attr_reader :counter_types_collection
|
4
|
+
DELIMITER = ', '
|
5
|
+
def initialize(counter_types_collection)
|
6
|
+
@counter_types_collection = counter_types_collection
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_s
|
10
|
+
@counter_types_collection.map{|ct| ct.to_s}.join(DELIMITER)
|
11
|
+
end
|
12
|
+
alias_method :render, :to_s
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<script type="text/javascript">
|
2
|
+
(function (d, w, c) {
|
3
|
+
(w[c] = w[c] || []).push(function() {
|
4
|
+
try { w.<%= counter_name %> = new Ya.Metrika(<%= counter_options %>);
|
5
|
+
} catch(e) { }
|
6
|
+
});
|
7
|
+
|
8
|
+
var n = d.getElementsByTagName("script")[0],
|
9
|
+
s = d.createElement("script"),
|
10
|
+
f = function () { n.parentNode.insertBefore(s, n); };
|
11
|
+
s.type = "text/javascript";
|
12
|
+
s.async = true;
|
13
|
+
s.src = (d.location.protocol == "https:" ? "https:" : "http:") + "//mc.yandex.ru/metrika/watch.js";
|
14
|
+
|
15
|
+
if (w.opera == "[object Opera]") {
|
16
|
+
d.addEventListener("DOMContentLoaded", f, false);
|
17
|
+
} else { f(); }
|
18
|
+
})(document, window, "yandex_metrika_callbacks");
|
19
|
+
</script>
|
20
|
+
<noscript><div><img src="//mc.yandex.ru/watch/<%= counter %>" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<script src="//mc.yandex.ru/metrika/watch.js" type="text/javascript"></script>
|
2
|
+
<script type="text/javascript">
|
3
|
+
try { var <%= counter_name %> = new Ya.Metrika(<%= counter_options %>);
|
4
|
+
} catch(e) { }
|
5
|
+
</script>
|
6
|
+
<noscript><div><img src="//mc.yandex.ru/watch/<%= counter %>" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "yandex-metrika/rails/view_helpers"
|
3
|
+
|
4
|
+
class ViewHelpersTest < TestCase
|
5
|
+
include YandexMetrika::Rails::ViewHelpers
|
6
|
+
|
7
|
+
def test_showl_have_default_options
|
8
|
+
metrika_init_script = metrika_init
|
9
|
+
assert_match %r{w\.yaCounter}, metrika_init_script
|
10
|
+
assert_match %r{\<\/noscript\>}, metrika_init_script
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_metrica_should_have_webvisor
|
14
|
+
metrika_init_script = metrika_init(webvisor: true)
|
15
|
+
assert_match %r{webvisor:true}, metrika_init_script
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_metrica_should_have_track_links
|
19
|
+
metrika_init_script = metrika_init(trackLinks: true)
|
20
|
+
assert_match %r{trackLinks:true}, metrika_init_script
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_metrica_should_have_track_hash
|
24
|
+
metrika_init_script = metrika_init(trackHash: true)
|
25
|
+
assert_match %r{trackHash:true}, metrika_init_script
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_metrica_should_have_clickmap
|
29
|
+
metrika_init_script = metrika_init(clickmap: true)
|
30
|
+
assert_match %r{clickmap:true}, metrika_init_script
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_metrica_should_have_accurate_track_bounce
|
34
|
+
metrika_init_script = metrika_init(accurateTrackBounce: true)
|
35
|
+
assert_match %r{accurateTrackBounce:true}, metrika_init_script
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'yandex-metrika-rails'
|
3
|
+
require 'test/unit'
|
4
|
+
require 'simplecov'
|
5
|
+
require 'coveralls'
|
6
|
+
Coveralls.wear!
|
7
|
+
|
8
|
+
ENV["COVERAGE"] = "true"
|
9
|
+
SimpleCov.start if ENV["COVERAGE"]
|
10
|
+
|
11
|
+
YM.counter = "123"
|
12
|
+
class TestCase < MiniTest::Unit::TestCase
|
13
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'yandex-metrika/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yandex-metrika-rails"
|
8
|
+
spec.version = YandexMetrika::VERSION
|
9
|
+
spec.authors = ["Kirillov Alexander"]
|
10
|
+
spec.email = ["saratovsource@gmail.com"]
|
11
|
+
spec.description = %q{Rails 3 helpers to manage Yandex Metrika and other services.}
|
12
|
+
spec.summary = %q{Rails 3 helpers to manage Yandex Metrika and other services.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yandex-metrika-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Kirillov Alexander
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Rails 3 helpers to manage Yandex Metrika and other services.
|
47
|
+
email:
|
48
|
+
- saratovsource@gmail.com
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .coveralls.yml
|
54
|
+
- .gitignore
|
55
|
+
- Gemfile
|
56
|
+
- LICENSE.txt
|
57
|
+
- README.md
|
58
|
+
- Rakefile
|
59
|
+
- lib/yandex-metrika-rails.rb
|
60
|
+
- lib/yandex-metrika/counter.rb
|
61
|
+
- lib/yandex-metrika/counter/kind.rb
|
62
|
+
- lib/yandex-metrika/counter/renderer.rb
|
63
|
+
- lib/yandex-metrika/counter/template_options.rb
|
64
|
+
- lib/yandex-metrika/rails/railtie.rb
|
65
|
+
- lib/yandex-metrika/rails/view_helpers.rb
|
66
|
+
- lib/yandex-metrika/templates/async.erb
|
67
|
+
- lib/yandex-metrika/templates/sync.erb
|
68
|
+
- lib/yandex-metrika/version.rb
|
69
|
+
- test/rails/views_helper_test.rb
|
70
|
+
- test/test_helper.rb
|
71
|
+
- yandex-metrika-rails.gemspec
|
72
|
+
homepage: ''
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.25
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Rails 3 helpers to manage Yandex Metrika and other services.
|
97
|
+
test_files:
|
98
|
+
- test/rails/views_helper_test.rb
|
99
|
+
- test/test_helper.rb
|