yandex_metrika 0.0.0 → 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/CREDITS ADDED
@@ -0,0 +1,5 @@
1
+ Most of the code are taken from Google Analytics plugin if Rubaidh Ltd.
2
+ ( http://github.com/rubaidh/google_analytics )
3
+
4
+ So, thanks to all developers of Rubaidh, and all folks from
5
+ http://github.com/rubaidh/google_analytics/blob/master/CREDITS
data/README.rdoc CHANGED
@@ -1,6 +1,75 @@
1
- = yandex_metrika
1
+ = Yandex.Metrika [ru]
2
+ (skip to next chapter for description in English)
3
+
4
+ == Установка
5
+
6
+ Добавьте в <tt>config/environment.rb</tt>:
7
+
8
+ config.gem "yandex_metrika", :lib => "yandex/metrika", :source => "http://gemcutter.org"
9
+
10
+ и выполните команду:
11
+
12
+ rake gems:install
13
+
14
+ == Описание
15
+
16
+ Быстрая интеграция Яндекс.Метрики в ваше Rails-приложение.
17
+
18
+ По умолчанию код метрики автоматически вставляется в каждую страницу перед
19
+ закрывающим тэгом \</body>.
20
+ Но сначала нужно корректно сконфигурировать плагин, иначе он будет ругаться.
21
+
22
+ == Конфигурация
23
+
24
+ Для этого добавьте следующий код в <tt>config/environment.rb</tt>:
25
+
26
+ if defined?Yandex::Metrika
27
+ Yandex::Metrika.counter_id = '123456'
28
+ end
29
+
30
+ А для избежания замусоривания <tt>environment.rb</tt> всякими плагинами -
31
+ можно добавить этот конфиг в <tt>config/initializers/yandex_metrika.rb</tt>
32
+
33
+ Вместо '123456' нужно вставить ваш личный COUNTER_ID, который можно вытащить
34
+ из javascript-кода, предоставляемого Яндексом: "<tt>new Ya.Metrika(123456)</tt>",
35
+ тут 123456 и есть искомый код.
36
+
37
+ По умолчанию код метрики вставляется в страницы только при использовании
38
+ *production* окружения. Для активации кода и в *development* нужно сделать так:
39
+
40
+ Yandex::Metrika.environments = %w'production development'
41
+
42
+ Если есть необходимость для каких-то страниц выключить код Яндекс.Метрики - то
43
+ добавть следующий код в соответствующий класс контроллера:
44
+
45
+ skip_after_filter :add_yandex_metrika_code
46
+
47
+
48
+ = Yandex.Metrika [en]
49
+
50
+ This plugin enables Yandex.Metrika support in your application. By default
51
+ it will output the metrika code for every single page automatically, if it
52
+ is configured correctly. This is done by adding:
53
+
54
+ Yandex::Metrika.counter_id = '123456'
55
+
56
+ to your <tt>config/environment.rb</tt>, inserting your own COUNTER_ID. This
57
+ can be discovered by looking at the value of "new Ya.Metrika(123456)" in the
58
+ Javascript code.
59
+
60
+ If you want to disable the code insertion for particular pages, add the
61
+ following to controllers that don't want it:
62
+
63
+ skip_after_filter :add_yandex_metrika_code
64
+
65
+ If you are running rails 2.1 or above add install this by adding:
66
+
67
+ config.gem "yandex_metrika", :lib => "yandex/metrika", :source => "http://gemcutter.org"
68
+
69
+ and run:
70
+
71
+ rake gems:install
2
72
 
3
- Description goes here.
4
73
 
5
74
  == Note on Patches/Pull Requests
6
75
 
data/Rakefile CHANGED
@@ -6,17 +6,18 @@ begin
6
6
  Jeweler::Tasks.new do |gem|
7
7
  gem.name = "yandex_metrika"
8
8
  gem.summary = "[Rails] Easily enable Yandex.Metrika support in your Rails application."
9
- gem.description = 'By default this gem will output Yandex.Metrika code for ' +
9
+ gem.description = gem.summary + "\n<br/><br/>\n" +
10
+ 'By default this gem will output Yandex.Metrika code for ' +
10
11
  "every page automagically, if it's configured correctly. " +
11
- "This is done by adding:\n" +
12
- "Yandex::Metrika.counter_id = '123456'\n" +
12
+ "This is done by adding: <br/>\n" +
13
+ "Yandex::Metrika.counter_id = '123456' <br/>\n" +
13
14
  'to your `config/environment.rb`, inserting your own COUNTER_ID. ' +
14
15
  'This can be discovered by looking at the value of "new Ya.Metrika(123456)" ' +
15
16
  'in the Javascript code.'
16
17
 
17
18
  gem.email = "zed.0xff@gmail.com"
18
19
  gem.homepage = "http://github.com/zed-0xff/yandex_metrika"
19
- gem.authors = ["Andrey \"Zed\" Zaikin"]
20
+ gem.authors = ["Andrey 'Zed' Zaikin"]
20
21
  #gem.add_development_dependency "thoughtbot-shoulda"
21
22
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
22
23
  gem.add_dependency 'actionpack', '>= 2.3.3'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -8,14 +8,14 @@ module Yandex # :nodoc:
8
8
  # This module gets mixed in to ActionController::Base
9
9
  module Mixin
10
10
  # The javascript code to enable Yandex.Metrika on the current page.
11
- # Normally you won't need to call this directly; the +add_metrika_code+
11
+ # Normally you won't need to call this directly; the +add_yandex_metrika_code+
12
12
  # after filter will insert it for you.
13
13
  def metrika_code
14
14
  Metrika.code if Metrika.enabled?(request.format)
15
15
  end
16
16
 
17
17
  # An after_filter to automatically add the metrika code.
18
- def add_metrika_code
18
+ def add_yandex_metrika_code
19
19
  if Metrika.defer_load
20
20
  response.body.sub! /<\/[bB][oO][dD][yY]>/, "#{metrika_code}</body>" if response.body.respond_to?(:sub!)
21
21
  else
@@ -24,7 +24,13 @@ module Yandex # :nodoc:
24
24
  end
25
25
  end
26
26
 
27
- class ConfigurationError < StandardError; end
27
+ class ConfigurationError < StandardError #:nodoc:
28
+ DEFAULT_MESSAGE = "Yandex::Metrika.counter_id is not set in config/environment.rb or config/initializers/yandex_metrika.rb"
29
+
30
+ def initialize(message = nil)
31
+ super(message || DEFAULT_MESSAGE)
32
+ end
33
+ end
28
34
 
29
35
  @@counter_id = nil
30
36
  ##
data/rails/init.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  require 'yandex/metrika'
2
2
  ActionController::Base.send :include, Yandex::Metrika::Mixin
3
- ActionController::Base.send :after_filter, :add_metrika_code
3
+ ActionController::Base.send :after_filter, :add_yandex_metrika_code
data/test/test_helper.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  ENV['RAILS_ENV'] = 'test'
2
2
 
3
3
  require 'rubygems'
4
- require 'test/unit'
4
+ gem 'test-unit'
5
+ #require 'test/unit'
5
6
 
6
7
  require File.expand_path(File.dirname(__FILE__) + '/../lib/yandex/metrika.rb')
7
8
 
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
2
  require 'test/unit'
3
- require 'rubygems'
3
+ #require 'rubygems'
4
4
  require 'mocha'
5
5
  RAILS_ENV = 'test'
6
6
 
@@ -81,41 +81,41 @@ class MetrikaTest < Test::Unit::TestCase
81
81
 
82
82
  # Test the before_filter method does what we expect by subsituting the body tags and inserting
83
83
  # some code for us automagically.
84
- def test_add_metrika_code
84
+ def test_add_yandex_metrika_code
85
85
  # setup our test mixin
86
86
  mixin = TestMixin.new
87
87
 
88
88
  # bog standard body tag
89
89
  Yandex::Metrika.defer_load = false
90
90
  mixin.response.body = "<body><p>some text</p></body>"
91
- mixin.add_metrika_code
91
+ mixin.add_yandex_metrika_code
92
92
  assert_equal mixin.response.body, '<body>Sample Code<p>some text</p></body>'
93
93
 
94
94
  Yandex::Metrika.defer_load = true
95
95
  mixin.response.body = "<body><p>some text</p></body>"
96
- mixin.add_metrika_code
96
+ mixin.add_yandex_metrika_code
97
97
  assert_equal mixin.response.body, '<body><p>some text</p>Sample Code</body>'
98
98
 
99
99
  # body tag upper cased (ignoring this is semantically incorrect)
100
100
  Yandex::Metrika.defer_load = false
101
101
  mixin.response.body = "<BODY><p>some text</p></BODY>"
102
- mixin.add_metrika_code
102
+ mixin.add_yandex_metrika_code
103
103
  assert_equal mixin.response.body, '<BODY>Sample Code<p>some text</p></BODY>'
104
104
 
105
105
  Yandex::Metrika.defer_load = true
106
106
  mixin.response.body = "<BODY><p>some text</p></BODY>"
107
- mixin.add_metrika_code
107
+ mixin.add_yandex_metrika_code
108
108
  assert_equal mixin.response.body, '<BODY><p>some text</p>Sample Code</body>'
109
109
 
110
110
  # body tag has additional attributes
111
111
  Yandex::Metrika.defer_load = false
112
112
  mixin.response.body = '<body style="background-color:red"><p>some text</p></body>'
113
- mixin.add_metrika_code
113
+ mixin.add_yandex_metrika_code
114
114
  assert_equal mixin.response.body, '<body style="background-color:red">Sample Code<p>some text</p></body>'
115
115
 
116
116
  Yandex::Metrika.defer_load = true
117
117
  mixin.response.body = '<body style="background-color:red"><p>some text</p></body>'
118
- mixin.add_metrika_code
118
+ mixin.add_yandex_metrika_code
119
119
  assert_equal mixin.response.body, '<body style="background-color:red"><p>some text</p>Sample Code</body>'
120
120
  end
121
121
 
@@ -5,13 +5,15 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{yandex_metrika}
8
- s.version = "0.0.0"
8
+ s.version = "0.0.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Andrey \"Zed\" Zaikin"]
11
+ s.authors = ["Andrey 'Zed' Zaikin"]
12
12
  s.date = %q{2009-10-12}
13
- s.description = %q{By default this gem will output Yandex.Metrika code for every page automagically, if it's configured correctly. This is done by adding:
14
- Yandex::Metrika.counter_id = '123456'
13
+ s.description = %q{[Rails] Easily enable Yandex.Metrika support in your Rails application.
14
+ <br/><br/>
15
+ By default this gem will output Yandex.Metrika code for every page automagically, if it's configured correctly. This is done by adding: <br/>
16
+ Yandex::Metrika.counter_id = '123456' <br/>
15
17
  to your `config/environment.rb`, inserting your own COUNTER_ID. This can be discovered by looking at the value of "new Ya.Metrika(123456)" in the Javascript code.}
16
18
  s.email = %q{zed.0xff@gmail.com}
17
19
  s.extra_rdoc_files = [
@@ -21,6 +23,7 @@ to your `config/environment.rb`, inserting your own COUNTER_ID. This can be disc
21
23
  s.files = [
22
24
  ".document",
23
25
  ".gitignore",
26
+ "CREDITS",
24
27
  "LICENSE",
25
28
  "README.rdoc",
26
29
  "Rakefile",
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yandex_metrika
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
- - Andrey "Zed" Zaikin
7
+ - Andrey 'Zed' Zaikin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
@@ -33,8 +33,10 @@ dependencies:
33
33
  version: 2.3.3
34
34
  version:
35
35
  description: |-
36
- By default this gem will output Yandex.Metrika code for every page automagically, if it's configured correctly. This is done by adding:
37
- Yandex::Metrika.counter_id = '123456'
36
+ [Rails] Easily enable Yandex.Metrika support in your Rails application.
37
+ <br/><br/>
38
+ By default this gem will output Yandex.Metrika code for every page automagically, if it's configured correctly. This is done by adding: <br/>
39
+ Yandex::Metrika.counter_id = '123456' <br/>
38
40
  to your `config/environment.rb`, inserting your own COUNTER_ID. This can be discovered by looking at the value of "new Ya.Metrika(123456)" in the Javascript code.
39
41
  email: zed.0xff@gmail.com
40
42
  executables: []
@@ -47,6 +49,7 @@ extra_rdoc_files:
47
49
  files:
48
50
  - .document
49
51
  - .gitignore
52
+ - CREDITS
50
53
  - LICENSE
51
54
  - README.rdoc
52
55
  - Rakefile