in_bed_with 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ pkg/*
2
+ *.gem
3
+ *.log
4
+ .bundle
5
+ .DS_Store
6
+ *.swp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format Fuubar
2
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,3 @@
1
+ rvm_gemset_create_on_use_flag=1
2
+ rvm_project_rvmrc_default=1
3
+ rvm 1.9.2@in_bed_with
@@ -0,0 +1,6 @@
1
+ ## 0.1.0
2
+
3
+ * Initial release, support for:
4
+ * Google Anaytics
5
+ * Google Adsense
6
+ * Gauges
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,112 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ in_bed_with (0.1.0)
5
+ activesupport (~> 3.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ actionmailer (3.1.3)
11
+ actionpack (= 3.1.3)
12
+ mail (~> 2.3.0)
13
+ actionpack (3.1.3)
14
+ activemodel (= 3.1.3)
15
+ activesupport (= 3.1.3)
16
+ builder (~> 3.0.0)
17
+ erubis (~> 2.7.0)
18
+ i18n (~> 0.6)
19
+ rack (~> 1.3.5)
20
+ rack-cache (~> 1.1)
21
+ rack-mount (~> 0.8.2)
22
+ rack-test (~> 0.6.1)
23
+ sprockets (~> 2.0.3)
24
+ activemodel (3.1.3)
25
+ activesupport (= 3.1.3)
26
+ builder (~> 3.0.0)
27
+ i18n (~> 0.6)
28
+ activerecord (3.1.3)
29
+ activemodel (= 3.1.3)
30
+ activesupport (= 3.1.3)
31
+ arel (~> 2.2.1)
32
+ tzinfo (~> 0.3.29)
33
+ activeresource (3.1.3)
34
+ activemodel (= 3.1.3)
35
+ activesupport (= 3.1.3)
36
+ activesupport (3.1.3)
37
+ multi_json (~> 1.0)
38
+ arel (2.2.1)
39
+ builder (3.0.0)
40
+ diff-lcs (1.1.3)
41
+ erubis (2.7.0)
42
+ fuubar (0.0.6)
43
+ rspec (~> 2.0)
44
+ rspec-instafail (~> 0.1.8)
45
+ ruby-progressbar (~> 0.0.10)
46
+ hike (1.2.1)
47
+ i18n (0.6.0)
48
+ json (1.6.4)
49
+ mail (2.3.0)
50
+ i18n (>= 0.4.0)
51
+ mime-types (~> 1.16)
52
+ treetop (~> 1.4.8)
53
+ mime-types (1.17.2)
54
+ multi_json (1.0.4)
55
+ polyglot (0.3.3)
56
+ rack (1.3.6)
57
+ rack-cache (1.1)
58
+ rack (>= 0.4)
59
+ rack-mount (0.8.3)
60
+ rack (>= 1.0.0)
61
+ rack-ssl (1.3.2)
62
+ rack
63
+ rack-test (0.6.1)
64
+ rack (>= 1.0)
65
+ rails (3.1.3)
66
+ actionmailer (= 3.1.3)
67
+ actionpack (= 3.1.3)
68
+ activerecord (= 3.1.3)
69
+ activeresource (= 3.1.3)
70
+ activesupport (= 3.1.3)
71
+ bundler (~> 1.0)
72
+ railties (= 3.1.3)
73
+ railties (3.1.3)
74
+ actionpack (= 3.1.3)
75
+ activesupport (= 3.1.3)
76
+ rack-ssl (~> 1.3.2)
77
+ rake (>= 0.8.7)
78
+ rdoc (~> 3.4)
79
+ thor (~> 0.14.6)
80
+ rake (0.9.2.2)
81
+ rdoc (3.12)
82
+ json (~> 1.4)
83
+ rspec (2.8.0)
84
+ rspec-core (~> 2.8.0)
85
+ rspec-expectations (~> 2.8.0)
86
+ rspec-mocks (~> 2.8.0)
87
+ rspec-core (2.8.0)
88
+ rspec-expectations (2.8.0)
89
+ diff-lcs (~> 1.1.2)
90
+ rspec-instafail (0.1.9)
91
+ rspec-mocks (2.8.0)
92
+ ruby-progressbar (0.0.10)
93
+ sprockets (2.0.3)
94
+ hike (~> 1.2)
95
+ rack (~> 1.0)
96
+ tilt (~> 1.1, != 1.3.0)
97
+ thor (0.14.6)
98
+ tilt (1.3.3)
99
+ treetop (1.4.10)
100
+ polyglot
101
+ polyglot (>= 0.3.1)
102
+ tzinfo (0.3.31)
103
+
104
+ PLATFORMS
105
+ ruby
106
+
107
+ DEPENDENCIES
108
+ fuubar
109
+ in_bed_with!
110
+ rails (~> 3.1)
111
+ rake
112
+ rspec (~> 2.8.0)
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (C) 2010 Sebastian von Conrad
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the "Software"), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,152 @@
1
+ # in_bed_with
2
+ in_bed_with is a gem to easily embed common javascript snippets in your application. It's both very simple and much webscale!
3
+
4
+ Works with or without Rails, so it's very possible to use it with Sinatra or any other Ruby lib/framework.
5
+
6
+ ## Installation
7
+ ### As a rubygem
8
+ ```
9
+ gem install in_bed_with
10
+ ```
11
+
12
+ ### With Bundler
13
+ In your Gemfile, add:
14
+
15
+ ```
16
+ gem 'in_bed_with'
17
+ ```
18
+
19
+ ## How to use
20
+ ### Rails
21
+ The simplest way to use **in_bed_with** in Rails is to create an initializer file `config/initializers/in_bed_with.rb`. Use it to specify the properties of the relevant service:
22
+
23
+ ```
24
+ InBedWith.config do |config|
25
+ config.analytics_property_id = 'UA-1234567-1'
26
+ end
27
+ ```
28
+
29
+ Then, in your view, simply use:
30
+
31
+ ```
32
+ <%= in_bed_with.analytics %>
33
+ ```
34
+
35
+ That's it!
36
+
37
+ If you don't want to set the properties through config, you can also pass any property into the method directly:
38
+
39
+ ```
40
+ <%= in_bed_with.analytics(property_id: 'UA-1234567-1') %>
41
+ ```
42
+
43
+ This approach is also useful if you have multiple objects with different properties to embed. You can still specify defaults through the config:
44
+
45
+ ```
46
+ # config/initializers/in_bed_with.rb
47
+ InBedWith.config do |config|
48
+ config.adsense_client = 'ca-pub-1234567890123456'
49
+ config.adsense_ad_type = :small_rectangle
50
+ end
51
+
52
+ # app/views/layouts/application.html.erb
53
+ # Will create a small rectangle ad with a slot parameter of '1234567890'
54
+ <%= in_bed_with.adsense(ad_slot: '1234567890') %>
55
+
56
+ # Will create a wide skyscraper ad with a slot parameter of '0987654321'
57
+ <%= in_bed_with.adsense(ad_slot: '0987654321', ad_type: :wide_skyscraper) %>
58
+ ```
59
+
60
+ ### Sinatra/Other
61
+ With Sinatra, you'll need to use the `helper` method to register the `in_bed_with` helper.
62
+
63
+ ```
64
+ helper InBedWith::Helper
65
+ ```
66
+
67
+ With any other lib/framework, use extend:
68
+
69
+ ```
70
+ extend InBedWith::Helper
71
+ ```
72
+
73
+ You can also forego the helper completely and call the `InBedWith` module directly:
74
+
75
+ ```
76
+ InBedWith.analytics
77
+ # same as:
78
+ in_bed_with.analytics
79
+ ```
80
+
81
+ ## Service support
82
+ **in_bed_with** currently supports Google Analytics, Adsense and Gauges. Many more are planned--feel free to open an issue/pull request for integration with your favorite service!
83
+
84
+ ### Google Analytics
85
+ **Available properties:**
86
+
87
+ * `property_id`: The ID of the property. Usually a string formatted along the likes of `UA-xxxxxxx-x`, where `x` is a digit.
88
+
89
+ **Example:**
90
+
91
+ ```
92
+ # initializer
93
+ InBedWith.config do |config|
94
+ config.analytics_property_id = 'UA-1234567-1'
95
+ end
96
+
97
+ # view
98
+ <%= in_bed_with.analytics %>
99
+ ```
100
+
101
+ ### Google Adsense
102
+ **Available properties:**
103
+
104
+ * `client`: The Adsense client id. Usually a string formatted along the likes of `ca-pub–xxxxxxxxxxxxxxxx`, where `x` is a digit.
105
+ * `ad_slot`: The ad slot. Usually a 10-digit number.
106
+ * `ad_type`: The type of the ad. **Does not need to be set if both `ad_width` and `ad_height` are set**. Can be any of (see [here](https://support.google.com/adsense/bin/answer.py?hl=en-GB&answer=185665&topic=29561) for exact sizes):
107
+ * `:banner`, `:button`, `:half_banner`, `:large_rectangle`, `:leaderboard`, `:medium_rectangle`, `:skyscraper`, `:small_rectangle`, `:small_square`, `:square`, `:vertical_banner`, `:wide_skyscraper`
108
+ * `ad_width`: The width of the ad. **Does not need to be set if `ad_type` is set**. Usually a 2 or 3-digit number.
109
+ * `ad_height`: The height of the ad. **Does not need to be set if `ad_type` is set**. Usually a 2 or 3-digit number.
110
+
111
+ **Example:**
112
+
113
+ ```
114
+ # initializer
115
+ InBedWith.config do |config|
116
+ config.adsense_client = 'ca-pub-1234567890123456'
117
+ config.adsense_ad_type = :small_rectangle
118
+ end
119
+
120
+ # view
121
+ <%= in_bed_with.adsense(ad_slot: '1234567890') %>
122
+ ```
123
+
124
+ ### Gauges
125
+ **Available properties:**
126
+
127
+ * `site_id`: The ID of the site. (As far as I know) a 24-character hexadecimal string.
128
+
129
+ **Example:**
130
+
131
+ ```
132
+ # initializer
133
+ InBedWith.config do |config|
134
+ config.gauges_site_id = '1234567890abcdef12345678'
135
+ end
136
+
137
+ # view
138
+ <%= in_bed_with.gauges %>
139
+ ```
140
+
141
+ ## Contributions
142
+ Pull requests for integration with additional service are very welcome!
143
+
144
+ ### Pull requests
145
+ 1. Fork the project.
146
+ 2. Make your feature addition or bug fix.
147
+ 3. Add tests for it. This is important so I don't break it in a future version unintentionally.
148
+ 4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
149
+ 5. Send me a pull request. Bonus points for topic branches.
150
+
151
+ ## License
152
+ `in_bed_with` is licensed under the MIT license. See `LICENSE` for details.
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require 'in_bed_with/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'in_bed_with'
7
+ s.version = InBedWith::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/in_bed_with'
12
+ s.summary = %q{in_bed_with embeds popular javascript codes into markup}
13
+ s.description = %q{in_bed_with allows javascript code embedding of popular services (such as Google Analytics, Google Adsense and Gauges) into Rails views and other markup}
14
+ s.license = 'MIT'
15
+
16
+ s.rubyforge_project = 'in_bed_with'
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
20
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
21
+ s.require_paths = ['lib']
22
+
23
+ s.add_dependency 'activesupport', '~> 3.1'
24
+ s.add_development_dependency 'rails', '~> 3.1'
25
+ s.add_development_dependency 'rake'
26
+ s.add_development_dependency 'rspec', '~> 2.8.0'
27
+ s.add_development_dependency 'fuubar'
28
+ end
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'active_support/core_ext'
5
+ require 'active_support/inflector'
6
+
7
+ require 'in_bed_with/base'
8
+ require 'in_bed_with/adsense'
9
+ require 'in_bed_with/analytics'
10
+ require 'in_bed_with/gauges'
11
+ require 'in_bed_with/version'
12
+
13
+ require 'in_bed_with/railtie' if defined?(Rails)
14
+
15
+ module InBedWith
16
+ def self.config(&block)
17
+ yield self
18
+ end
19
+
20
+ def self.method_missing(method, *args, &block)
21
+ str = "InBedWith::#{method.to_s.camelize}".constantize.new(*args).code
22
+ str.respond_to?(:html_safe) ? str.html_safe : str
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ module InBedWith
2
+ class Adsense < Base
3
+ register :client
4
+ register :ad_slot
5
+ register :ad_type, optional: true
6
+ register :ad_width, optional: true
7
+ register :ad_height, optional: true
8
+
9
+ AD_TYPES = {
10
+ button: { width: 125, height: 125 },
11
+ half_banner: { width: 234, height: 60 },
12
+ banner: { width: 468, height: 60 },
13
+ vertical_banner: { width: 120, height: 240 },
14
+ leaderboard: { width: 728, height: 90 },
15
+ skyscraper: { width: 468, height: 600 },
16
+ wide_skyscraper: { width: 160, height: 600 },
17
+ small_square: { width: 200, height: 200 },
18
+ square: { width: 250, height: 250 },
19
+ small_rectangle: { width: 180, height: 150 },
20
+ medium_rectangle: { width: 300, height: 250 },
21
+ large_rectangle: { width: 336, height: 280 }
22
+ }
23
+
24
+ def code
25
+ "<script type=\"text/javascript\">google_ad_client = '#{client}'; google_ad_slot = '#{ad_slot}'; google_ad_width = #{properties[:width]}; google_ad_height = #{properties[:height]};</script><script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>"
26
+ end
27
+
28
+ private
29
+
30
+ def properties
31
+ if ad_width && ad_height
32
+ { width: ad_width, height: ad_height }
33
+ elsif ad_type
34
+ AD_TYPES[ad_type.to_sym] or raise ArgumentError, "Ad type '#{ad_type}' is not known: Please use ad_width and ad_height parameters instead."
35
+ else
36
+ raise ArgumentError, 'Please set either ad_type or ad_height/ad_width of the ad.'
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module InBedWith
2
+ class Analytics < Base
3
+ register :property_id
4
+
5
+ def code
6
+ "<script type=\"text/javascript\">var _gaq = _gaq || []; _gaq.push(['_setAccount', '#{property_id}']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script>"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,42 @@
1
+ module InBedWith
2
+ class Base
3
+ class << self
4
+ attr_reader :attributes
5
+
6
+ def register(attribute, options={})
7
+ InBedWith.mattr_accessor module_attr(attribute)
8
+ attr_accessor attribute
9
+
10
+ @attributes ||= {}
11
+ @attributes.merge!({ attribute.to_sym => options })
12
+ end
13
+
14
+ def module_attr(attribute)
15
+ "#{name.demodulize.underscore}_#{attribute}"
16
+ end
17
+ end
18
+
19
+ def initialize(attributes={})
20
+ attributes.symbolize_keys!
21
+
22
+ self.class.attributes.each do |attribute, options|
23
+ value = attributes[attribute] || InBedWith.send(self.class.module_attr(attribute))
24
+
25
+ raise ArgumentError, missing(attribute) unless value || options[:optional]
26
+
27
+ self.send "#{attribute}=", value
28
+ end
29
+ end
30
+
31
+ private
32
+ def missing(attribute)
33
+ "Please set #{self.class.name.demodulize} #{attribute.to_s.camelize} through config.#{self.class.module_attr(attribute)} or by supplying :#{attribute} when calling in_bed_with.#{self.class.name.demodulize.underscore}."
34
+ end
35
+ end
36
+
37
+ module Helper
38
+ def in_bed_with
39
+ InBedWith
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module InBedWith
2
+ class Gauges < Base
3
+ register :site_id
4
+
5
+ def code
6
+ "<script type=\"text/javascript\">var _gauges = _gauges || []; (function() { var t = document.createElement('script'); t.type = 'text/javascript'; t.async = true; t.id = 'gauges-tracker'; t.setAttribute('data-site-id', '#{site_id}'); t.src = '//secure.gaug.es/track.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(t, s); })();</script>"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails/railtie'
2
+
3
+ module InBedWith
4
+ module Rails
5
+ class Railtie < ::Rails::Railtie
6
+ initializer 'in_bed_with' do |app|
7
+ ActiveSupport.on_load(:action_view) do
8
+ include Helper
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module InBedWith
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe InBedWith::Adsense do
4
+ it 'prints a javascript tag based on argument' do
5
+ js = InBedWith.adsense(client: 'ca-pub-1234567890123456', ad_slot: '1234567890', ad_width: 728, ad_height: 90)
6
+ js.should == "<script type=\"text/javascript\">google_ad_client = 'ca-pub-1234567890123456'; google_ad_slot = '1234567890'; google_ad_width = 728; google_ad_height = 90;</script><script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>"
7
+ end
8
+
9
+ it 'prints a javascript tag based on configuration option' do
10
+ InBedWith.config do |config|
11
+ config.adsense_client = 'ca-pub-1234567890123456'
12
+ config.adsense_ad_slot = '1234567890'
13
+ config.adsense_ad_width = 728
14
+ config.adsense_ad_height = 90
15
+ end
16
+
17
+ js = InBedWith.adsense
18
+ js.should == "<script type=\"text/javascript\">google_ad_client = 'ca-pub-1234567890123456'; google_ad_slot = '1234567890'; google_ad_width = 728; google_ad_height = 90;</script><script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>"
19
+ end
20
+
21
+ context 'predefined ad types' do
22
+ before do
23
+ InBedWith.config do |config|
24
+ %w(adsense_client adsense_ad_slot adsense_ad_width adsense_ad_height).each { |opt| config.send("#{opt}=", nil) }
25
+ end
26
+ end
27
+
28
+ it 'prints a javascript tag based on a predefined ad type' do
29
+ js = InBedWith.adsense(client: 'ca-pub-1234567890123456', ad_slot: '1234567890', ad_type: :leaderboard)
30
+ js.should == "<script type=\"text/javascript\">google_ad_client = 'ca-pub-1234567890123456'; google_ad_slot = '1234567890'; google_ad_width = 728; google_ad_height = 90;</script><script type=\"text/javascript\" src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\"></script>"
31
+ end
32
+
33
+ it 'raises an exception if the ad type is not known' do
34
+ lambda { InBedWith.adsense(client: 'ca-pub-1234567890123456', ad_slot: '1234567890', ad_type: :foobarbaz) }.should raise_exception ArgumentError, /'foobarbaz' is not known/
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe InBedWith::Analytics do
4
+ it 'prints a javascript tag based on argument' do
5
+ js = InBedWith.analytics(property_id: 'UA-1234567-1')
6
+ js.should == "<script type=\"text/javascript\">var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-1234567-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script>"
7
+ end
8
+
9
+ it 'prints a javascript tag based on configuration option' do
10
+ InBedWith.config { |config| config.analytics_property_id = 'UA-7654321-1' }
11
+ js = InBedWith.analytics
12
+ js.should == "<script type=\"text/javascript\">var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-7654321-1']); _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script>"
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ module InBedWith
4
+ class Test < Base
5
+ register :foo
6
+ register :bar, :optional => true
7
+
8
+ def code
9
+ "foo_with_value_#{foo}"
10
+ end
11
+ end
12
+ end
13
+
14
+ describe InBedWith::Base do
15
+ it 'raises an exception if a required attribute is missing' do
16
+ lambda { InBedWith::Test.new }.should raise_exception ArgumentError, /config\.test_foo/
17
+ end
18
+
19
+ it 'does not raise an exception if an optional attribute is missing' do
20
+ InBedWith::Test.new(foo: 'gazonk').code.should == 'foo_with_value_gazonk'
21
+ end
22
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe InBedWith::Gauges do
4
+ it 'prints a javascript tag based on argument' do
5
+ js = InBedWith.gauges(site_id: '1234567890abcdef12345678')
6
+ js.should == "<script type=\"text/javascript\">var _gauges = _gauges || []; (function() { var t = document.createElement('script'); t.type = 'text/javascript'; t.async = true; t.id = 'gauges-tracker'; t.setAttribute('data-site-id', '1234567890abcdef12345678'); t.src = '//secure.gaug.es/track.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(t, s); })();</script>"
7
+ end
8
+
9
+ it 'prints a javascript tag based on configuration option' do
10
+ InBedWith.config { |config| config.gauges_site_id = '87654321fedcba0987654321' }
11
+ js = InBedWith.gauges
12
+ js.should == "<script type=\"text/javascript\">var _gauges = _gauges || []; (function() { var t = document.createElement('script'); t.type = 'text/javascript'; t.async = true; t.id = 'gauges-tracker'; t.setAttribute('data-site-id', '87654321fedcba0987654321'); t.src = '//secure.gaug.es/track.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(t, s); })();</script>"
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ module TestApp
4
+ class Application < Rails::Application
5
+ config.active_support.deprecation = :log
6
+ end
7
+ end
8
+ TestApp::Application.initialize!
9
+
10
+ describe ActionView::Base do
11
+ it 'should add in_bed_with helper through railtie' do
12
+ InBedWith.config { |config| config.analytics_property_id = 'UA-7654321-1' }
13
+
14
+ view = ActionView::Base.new
15
+ view.should respond_to(:in_bed_with)
16
+
17
+ view.in_bed_with.should == InBedWith
18
+ view.in_bed_with.analytics.should =~ /UA-7654321-1/
19
+ end
20
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rails/all'
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'in_bed_with')
4
+
5
+ RSpec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: in_bed_with
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sebastian von Conrad
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: &70180001148040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70180001148040
25
+ - !ruby/object:Gem::Dependency
26
+ name: rails
27
+ requirement: &70180001147500 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.1'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70180001147500
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70180001147080 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70180001147080
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec
49
+ requirement: &70180001146500 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.8.0
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70180001146500
58
+ - !ruby/object:Gem::Dependency
59
+ name: fuubar
60
+ requirement: &70180001146060 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70180001146060
69
+ description: in_bed_with allows javascript code embedding of popular services (such
70
+ as Google Analytics, Google Adsense and Gauges) into Rails views and other markup
71
+ email:
72
+ - sebastian@vonconrad.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - .rspec
79
+ - .rvmrc
80
+ - CHANGELOG.md
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE
84
+ - README.md
85
+ - Rakefile
86
+ - in_bed_with.gemspec
87
+ - lib/in_bed_with.rb
88
+ - lib/in_bed_with/adsense.rb
89
+ - lib/in_bed_with/analytics.rb
90
+ - lib/in_bed_with/base.rb
91
+ - lib/in_bed_with/gauges.rb
92
+ - lib/in_bed_with/railtie.rb
93
+ - lib/in_bed_with/version.rb
94
+ - spec/in_bed_with/adsense_spec.rb
95
+ - spec/in_bed_with/analytics_spec.rb
96
+ - spec/in_bed_with/base_spec.rb
97
+ - spec/in_bed_with/gauges_spec.rb
98
+ - spec/in_bed_with/rails_spec.rb
99
+ - spec/spec_helper.rb
100
+ homepage: http://github.com/vonconrad/in_bed_with
101
+ licenses:
102
+ - MIT
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project: in_bed_with
121
+ rubygems_version: 1.8.10
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: in_bed_with embeds popular javascript codes into markup
125
+ test_files:
126
+ - spec/in_bed_with/adsense_spec.rb
127
+ - spec/in_bed_with/analytics_spec.rb
128
+ - spec/in_bed_with/base_spec.rb
129
+ - spec/in_bed_with/gauges_spec.rb
130
+ - spec/in_bed_with/rails_spec.rb
131
+ - spec/spec_helper.rb