social-buttons 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +111 -0
- data/LICENSE +20 -0
- data/README.md +188 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/init.rb +1 -0
- data/lib/social_buttons.rb +29 -0
- data/lib/social_buttons/engine.rb +9 -0
- data/lib/social_buttons/view_helper.rb +30 -0
- data/lib/social_buttons/view_helpers/assistant.rb +36 -0
- data/lib/social_buttons/view_helpers/google_plus.rb +79 -0
- data/lib/social_buttons/view_helpers/google_plus/help.rb +42 -0
- data/lib/social_buttons/view_helpers/like.rb +45 -0
- data/lib/social_buttons/view_helpers/pinit.rb +48 -0
- data/lib/social_buttons/view_helpers/scripter.rb +22 -0
- data/lib/social_buttons/view_helpers/tweet.rb +45 -0
- data/social-buttons.gemspec +81 -0
- data/spec/social_buttons/config_spec.rb +34 -0
- data/spec/social_buttons/google_plus_spec.rb +34 -0
- data/spec/social_buttons/like_spec.rb +39 -0
- data/spec/social_buttons/pinit_spec.rb +33 -0
- data/spec/social_buttons/tweet_spec.rb +33 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/view_helper_config.rb +60 -0
- metadata +171 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
## Changelog
|
2
|
+
|
3
|
+
### 0.3.6
|
4
|
+
|
5
|
+
- Added Scripter for handling script logic
|
6
|
+
- Ensure script is only output once for each request, but again for next request
|
7
|
+
by moving state to instance level (fixes bug in 3.5)
|
8
|
+
- Specs added to test if script works correctly on multiple requests
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'rails', '>= 3.0.0'
|
4
|
+
|
5
|
+
group :test do
|
6
|
+
gem 'hashie', '~> 1.2.0'
|
7
|
+
end
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem "rspec", ">= 2.8.0"
|
11
|
+
gem "rdoc", ">= 3.12"
|
12
|
+
gem "bundler", ">= 1.0.0"
|
13
|
+
gem "jeweler", "~> 1.8.4"
|
14
|
+
gem "simplecov", ">= 0.5"
|
15
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
actionmailer (3.2.8)
|
5
|
+
actionpack (= 3.2.8)
|
6
|
+
mail (~> 2.4.4)
|
7
|
+
actionpack (3.2.8)
|
8
|
+
activemodel (= 3.2.8)
|
9
|
+
activesupport (= 3.2.8)
|
10
|
+
builder (~> 3.0.0)
|
11
|
+
erubis (~> 2.7.0)
|
12
|
+
journey (~> 1.0.4)
|
13
|
+
rack (~> 1.4.0)
|
14
|
+
rack-cache (~> 1.2)
|
15
|
+
rack-test (~> 0.6.1)
|
16
|
+
sprockets (~> 2.1.3)
|
17
|
+
activemodel (3.2.8)
|
18
|
+
activesupport (= 3.2.8)
|
19
|
+
builder (~> 3.0.0)
|
20
|
+
activerecord (3.2.8)
|
21
|
+
activemodel (= 3.2.8)
|
22
|
+
activesupport (= 3.2.8)
|
23
|
+
arel (~> 3.0.2)
|
24
|
+
tzinfo (~> 0.3.29)
|
25
|
+
activeresource (3.2.8)
|
26
|
+
activemodel (= 3.2.8)
|
27
|
+
activesupport (= 3.2.8)
|
28
|
+
activesupport (3.2.8)
|
29
|
+
i18n (~> 0.6)
|
30
|
+
multi_json (~> 1.0)
|
31
|
+
arel (3.0.2)
|
32
|
+
builder (3.0.0)
|
33
|
+
diff-lcs (1.1.3)
|
34
|
+
erubis (2.7.0)
|
35
|
+
git (1.2.5)
|
36
|
+
hashie (1.2.0)
|
37
|
+
hike (1.2.1)
|
38
|
+
i18n (0.6.0)
|
39
|
+
jeweler (1.8.4)
|
40
|
+
bundler (~> 1.0)
|
41
|
+
git (>= 1.2.5)
|
42
|
+
rake
|
43
|
+
rdoc
|
44
|
+
journey (1.0.4)
|
45
|
+
json (1.7.5)
|
46
|
+
mail (2.4.4)
|
47
|
+
i18n (>= 0.4.0)
|
48
|
+
mime-types (~> 1.16)
|
49
|
+
treetop (~> 1.4.8)
|
50
|
+
mime-types (1.19)
|
51
|
+
multi_json (1.3.6)
|
52
|
+
polyglot (0.3.3)
|
53
|
+
rack (1.4.1)
|
54
|
+
rack-cache (1.2)
|
55
|
+
rack (>= 0.4)
|
56
|
+
rack-ssl (1.3.2)
|
57
|
+
rack
|
58
|
+
rack-test (0.6.1)
|
59
|
+
rack (>= 1.0)
|
60
|
+
rails (3.2.8)
|
61
|
+
actionmailer (= 3.2.8)
|
62
|
+
actionpack (= 3.2.8)
|
63
|
+
activerecord (= 3.2.8)
|
64
|
+
activeresource (= 3.2.8)
|
65
|
+
activesupport (= 3.2.8)
|
66
|
+
bundler (~> 1.0)
|
67
|
+
railties (= 3.2.8)
|
68
|
+
railties (3.2.8)
|
69
|
+
actionpack (= 3.2.8)
|
70
|
+
activesupport (= 3.2.8)
|
71
|
+
rack-ssl (~> 1.3.2)
|
72
|
+
rake (>= 0.8.7)
|
73
|
+
rdoc (~> 3.4)
|
74
|
+
thor (>= 0.14.6, < 2.0)
|
75
|
+
rake (0.9.2.2)
|
76
|
+
rdoc (3.12)
|
77
|
+
json (~> 1.4)
|
78
|
+
rspec (2.11.0)
|
79
|
+
rspec-core (~> 2.11.0)
|
80
|
+
rspec-expectations (~> 2.11.0)
|
81
|
+
rspec-mocks (~> 2.11.0)
|
82
|
+
rspec-core (2.11.1)
|
83
|
+
rspec-expectations (2.11.2)
|
84
|
+
diff-lcs (~> 1.1.3)
|
85
|
+
rspec-mocks (2.11.2)
|
86
|
+
simplecov (0.6.4)
|
87
|
+
multi_json (~> 1.0)
|
88
|
+
simplecov-html (~> 0.5.3)
|
89
|
+
simplecov-html (0.5.3)
|
90
|
+
sprockets (2.1.3)
|
91
|
+
hike (~> 1.2)
|
92
|
+
rack (~> 1.0)
|
93
|
+
tilt (~> 1.1, != 1.3.0)
|
94
|
+
thor (0.16.0)
|
95
|
+
tilt (1.3.3)
|
96
|
+
treetop (1.4.10)
|
97
|
+
polyglot
|
98
|
+
polyglot (>= 0.3.1)
|
99
|
+
tzinfo (0.3.33)
|
100
|
+
|
101
|
+
PLATFORMS
|
102
|
+
ruby
|
103
|
+
|
104
|
+
DEPENDENCIES
|
105
|
+
bundler (>= 1.0.0)
|
106
|
+
hashie (~> 1.2.0)
|
107
|
+
jeweler (~> 1.8.4)
|
108
|
+
rails (>= 3.0.0)
|
109
|
+
rdoc (>= 3.12)
|
110
|
+
rspec (>= 2.8.0)
|
111
|
+
simplecov (>= 0.5)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Jeremy McAnally
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,188 @@
|
|
1
|
+
# Social Buttons
|
2
|
+
|
3
|
+
This gem is a Rails 3+ engine (but can be used without the engine).
|
4
|
+
|
5
|
+
Currently there is support for the following social buttons:
|
6
|
+
|
7
|
+
* Twitter *tweet* button
|
8
|
+
* Facebook *like* button
|
9
|
+
* Pinterest *pinit* button
|
10
|
+
* Google+ *+1* button
|
11
|
+
|
12
|
+
# Installation
|
13
|
+
|
14
|
+
Add the gem to your Gemfile and use Bundler to install the gem.
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem "social-buttons", '~> 0.3'
|
18
|
+
```
|
19
|
+
|
20
|
+
# Usage
|
21
|
+
|
22
|
+
This gem is a Rails 3+ compatible engine and now automatically includes all the view helper modules into `ActionView::Base`
|
23
|
+
|
24
|
+
This gem includes the following view helper modules in `social_buttons/view_helpers`:
|
25
|
+
|
26
|
+
* `Tweet`
|
27
|
+
* `Like`
|
28
|
+
* `Pinit`
|
29
|
+
* `GooglePlus`
|
30
|
+
|
31
|
+
Using SocialButtons is as simple as adding a single method call to your views:
|
32
|
+
|
33
|
+
ERB example:
|
34
|
+
```erb
|
35
|
+
<%= tweet_button %>
|
36
|
+
<%= like_button(app_id) %>
|
37
|
+
<%= pinit_button %>
|
38
|
+
<%= google_plus_button %>
|
39
|
+
```
|
40
|
+
|
41
|
+
HAML example:
|
42
|
+
|
43
|
+
```haml
|
44
|
+
= tweet_button
|
45
|
+
= like_button(app_id)
|
46
|
+
= pinit_button
|
47
|
+
= google_plus_button
|
48
|
+
```
|
49
|
+
|
50
|
+
Bam. Done. You'll have a sweet lookin' Social Buttons all up in your view.
|
51
|
+
|
52
|
+
Of course, you can customize it. Depending on the type of button, there are different options.
|
53
|
+
|
54
|
+
### Tweet Button
|
55
|
+
|
56
|
+
* `:url` - The URL to share; the default is the current URL.
|
57
|
+
* `:text` - The text that will appear in the tweet; the default is "Check this out!"
|
58
|
+
* `:via` - The attribution. Defaults to "tweetbutton", but you should change that.
|
59
|
+
* `:lang` - Set the language for the tweet (no default).
|
60
|
+
* `:related` - Related Twitter accounts (no default).
|
61
|
+
* `:count` - The tweet count box position (values can be "none", "horizontal", or "vertical"; default is "vertical").
|
62
|
+
|
63
|
+
More information can be found from [Twitter](https://twitter.com/about/resources/buttons#tweet)
|
64
|
+
|
65
|
+
So, if you wanted to tweet about Hacker News, attribute it to Peter Cooper, and add some custom text, all from a tweet button with a horizontal counter, you'd do this:
|
66
|
+
|
67
|
+
```erb
|
68
|
+
<%= tweet_button(via: => "peterc", url: "http://news.ycombinator.com", :text => "AWESOME.") %>
|
69
|
+
```
|
70
|
+
|
71
|
+
### Like Button
|
72
|
+
|
73
|
+
NOTE: Facebook App Id is mandatory
|
74
|
+
|
75
|
+
* `:href` - The URL to like, the default is the current URL.
|
76
|
+
* `:send` - Whether to add a send button or not.
|
77
|
+
* `:layout` - Size and amount of social context next to button. Has 3 options `:standard`, `:button_count`, and `:box_count`
|
78
|
+
* `:width` - Width of the button
|
79
|
+
* `"show-faces"` - Show profile photos
|
80
|
+
* `:action` - Action name like 'like' or 'recommend'
|
81
|
+
* `:font` - Font for the button
|
82
|
+
* `:colorscheme` - Current colorscheme
|
83
|
+
|
84
|
+
More information can be found from [Facebook](http://developers.facebook.com/docs/reference/plugins/like/)
|
85
|
+
|
86
|
+
So, a simple like button can be added like this:
|
87
|
+
|
88
|
+
```erb
|
89
|
+
<%= like_button(app_id) %>
|
90
|
+
```
|
91
|
+
|
92
|
+
### Pinit Button
|
93
|
+
|
94
|
+
* `:url` - The URL to share; the default is the current URL.
|
95
|
+
* `:media` - The image to be shared.
|
96
|
+
* `:description` - Description for the link.
|
97
|
+
* `"count-layout"` - Specify pinit count. It can be `horizontal`, `vertical` or `none`.
|
98
|
+
|
99
|
+
More information can be found from [Pinterest](http://pinterest.com/about/goodies/)
|
100
|
+
|
101
|
+
So, a simple pinit button can be added like this:
|
102
|
+
|
103
|
+
```erb
|
104
|
+
<%= pinit_button(url: request.url, media: @picture.image.url, description: "Amazing Picture") %>
|
105
|
+
```
|
106
|
+
|
107
|
+
### Google Plus Button
|
108
|
+
|
109
|
+
* `:href` - The URL to share; the default is the current URL.
|
110
|
+
* `:size` - Size of button: 'small', 'tall' or 'medium'
|
111
|
+
* `:annotation` - The style of button: 'inline', 'bubble', 'none'
|
112
|
+
* `:lang` - The locale, fx 'es' for Spanish (alias :locale)
|
113
|
+
|
114
|
+
See [Google+ button](http://www.google.com/intl/en/webmasters/+1/button/index.html) for more info.
|
115
|
+
|
116
|
+
### Setting universal defaults
|
117
|
+
|
118
|
+
You can set a new default for any option in your `social_buttons.rb` initializer (in `config/initializers`.
|
119
|
+
|
120
|
+
Set the `default_options` on any of the social view helper modules.
|
121
|
+
|
122
|
+
For example:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
# config/initializers/social_buttons.rb
|
126
|
+
SocialButtons::Tweet.default_options = {:via => "myself"}
|
127
|
+
```
|
128
|
+
|
129
|
+
Or even sweeter...
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
# config/initializers/social_buttons.rb
|
133
|
+
SocialButtons.config :tweet do |tweet|
|
134
|
+
tweet.default_options = {:via => "myself"}
|
135
|
+
end
|
136
|
+
|
137
|
+
# or
|
138
|
+
SocialButtons.config(:tweet).default_options = {:via => "myself"}
|
139
|
+
```
|
140
|
+
|
141
|
+
Or simply :)
|
142
|
+
|
143
|
+
```ruby
|
144
|
+
# config/initializers/social_buttons.rb
|
145
|
+
SocialButtons.config do |social|
|
146
|
+
social.tweet do |tweet|
|
147
|
+
tweet.default_options = {:via => "myself"}
|
148
|
+
end
|
149
|
+
|
150
|
+
social.like.default_options = {:via => "myself"}
|
151
|
+
end
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
This little DSL makes the configuration more extensible for the future ;)
|
156
|
+
|
157
|
+
Only the options you specify will be overridden; so if you only specify a new default `:via`, then the other defaults will stay intact.
|
158
|
+
|
159
|
+
## Help
|
160
|
+
|
161
|
+
We have started adding suport for help directly in the api:
|
162
|
+
|
163
|
+
`puts SocialButtons.config(:google_plus).help`
|
164
|
+
|
165
|
+
Should output some help info on how to use that particular method, options available etc. So far only works for Google+ button.
|
166
|
+
|
167
|
+
# TODO
|
168
|
+
|
169
|
+
* Improve specs
|
170
|
+
* Add more options to customize buttons (fx localization on all if available)
|
171
|
+
* Add even more social buttons...
|
172
|
+
|
173
|
+
## Note on Patches/Pull Requests
|
174
|
+
|
175
|
+
* Fork the project.
|
176
|
+
* Make your feature addition or bug fix.
|
177
|
+
* Add tests for it. This is important so I don't break it in a
|
178
|
+
future version unintentionally.
|
179
|
+
* Commit, do not mess with rakefile, version, or history.
|
180
|
+
(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)
|
181
|
+
* Send me a pull request. Bonus points for topic branches.
|
182
|
+
|
183
|
+
## Copyright
|
184
|
+
|
185
|
+
Copyright (c) 2012 Kristian Mandrup & Yuva Kumar
|
186
|
+
Copyright (c) 2010 Jeremy McAnally.
|
187
|
+
|
188
|
+
See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "social-buttons"
|
8
|
+
gem.summary = %Q{Generate new Social Buttons}
|
9
|
+
gem.description = %Q{Generate Social Buttons for your Rails apps}
|
10
|
+
gem.email = "yuva@codemancers.com"
|
11
|
+
gem.homepage = "https://github.com/iffyuva/social-buttons"
|
12
|
+
gem.authors = ["Jeremy McAnally", "Yuva"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'rake/testtask'
|
21
|
+
Rake::TestTask.new(:test) do |test|
|
22
|
+
test.libs << 'lib' << 'test'
|
23
|
+
test.pattern = 'test/**/test_*.rb'
|
24
|
+
test.verbose = true
|
25
|
+
end
|
26
|
+
|
27
|
+
begin
|
28
|
+
require 'rcov/rcovtask'
|
29
|
+
Rcov::RcovTask.new do |test|
|
30
|
+
test.libs << 'test'
|
31
|
+
test.pattern = 'test/**/test_*.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
rescue LoadError
|
35
|
+
task :rcov do
|
36
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
task :test => :check_dependencies
|
41
|
+
|
42
|
+
task :default => :test
|
43
|
+
|
44
|
+
require 'rdoc/task'
|
45
|
+
Rake::RDocTask.new do |rdoc|
|
46
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
47
|
+
|
48
|
+
rdoc.rdoc_dir = 'rdoc'
|
49
|
+
rdoc.title = "tweet-button #{version}"
|
50
|
+
rdoc.rdoc_files.include('README*')
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
52
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.3.6
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'lib', 'tweet-button')
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
def self.names
|
3
|
+
%w{pinit tweet like google_plus}
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.helpers
|
7
|
+
%w{assistant scripter}
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.all
|
11
|
+
names + helpers
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.config name = nil, &block
|
15
|
+
context = name ? "SocialButtons::#{name.to_s.camelize}".constantize : self
|
16
|
+
block_given? ? yield(context) : context
|
17
|
+
end
|
18
|
+
|
19
|
+
# add class method for each social button registered
|
20
|
+
names.each do |name|
|
21
|
+
(class << self; self; end).send :define_method, name do |&block|
|
22
|
+
clazz = "SocialButtons::#{name.to_s.camelize}".constantize
|
23
|
+
block_given? ? clazz.instance_eval(&block) : clazz
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
require "social_buttons/view_helper"
|
29
|
+
require "social_buttons/engine" if defined?(::Rails::Engine)
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
SocialButtons.all.flatten.each do |name|
|
3
|
+
autoload name.to_s.camelize.to_sym, "social_buttons/view_helpers/#{name}"
|
4
|
+
end
|
5
|
+
|
6
|
+
module ViewHelper
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
# Include all Social Buttons into ViewHelper to be made available
|
11
|
+
# to be included into a View as one module (see engine)
|
12
|
+
SocialButtons.names.each do |name|
|
13
|
+
self.send :include, "SocialButtons::#{name.to_s.camelize}".constantize
|
14
|
+
|
15
|
+
attr_accessor :"#{name}_widgetized"
|
16
|
+
alias_method :"#{name}_widgetized?", :"#{name}_widgetized"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def widgetized! name
|
21
|
+
meth = "#{name}_widgetized="
|
22
|
+
self.send(meth, name) if respond_to? meth
|
23
|
+
end
|
24
|
+
|
25
|
+
def widgetized? name
|
26
|
+
meth = "#{name}_widgetized?"
|
27
|
+
self.send(meth) if respond_to? meth
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
module Assistant
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
attr_writer :default_options
|
7
|
+
|
8
|
+
def myname
|
9
|
+
self.name.demodulize
|
10
|
+
end
|
11
|
+
|
12
|
+
def help
|
13
|
+
"Please HELP by filling in the help of the #{myname} button :) (see google+ button code)"
|
14
|
+
end
|
15
|
+
|
16
|
+
def options_to_data_params(opts)
|
17
|
+
params = {}
|
18
|
+
opts.each {|k, v| params["data-#{k}"] = v}
|
19
|
+
params
|
20
|
+
end
|
21
|
+
|
22
|
+
def options_to_query_string(subject, opts)
|
23
|
+
# formulate the url, and then strip the part before first '?'
|
24
|
+
query_params = opts.slice(:url, :media, :description)
|
25
|
+
full_url = subject.url_for(query_params)
|
26
|
+
full_url.sub(/^([^?]*)/, '')
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
|
31
|
+
def help_note
|
32
|
+
"Note: SocialButons will ensure that the button script is only rendered once!"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
module GooglePlus
|
3
|
+
include SocialButtons::Assistant
|
4
|
+
|
5
|
+
autoload :Help, "social_buttons/view_helpers/google_plus/help"
|
6
|
+
|
7
|
+
CLASS = "g-plusone"
|
8
|
+
|
9
|
+
# http://www.google.com/intl/en/webmasters/+1/button/index.html
|
10
|
+
|
11
|
+
# Async script mode:
|
12
|
+
# To only output script
|
13
|
+
# = google_button :script, locale: 'es'
|
14
|
+
|
15
|
+
# To NOT output script
|
16
|
+
# = google_button :locale => 'es', script: false
|
17
|
+
def google_plus_button *args
|
18
|
+
options = args.extract_options!
|
19
|
+
clazz = SocialButtons::GooglePlus
|
20
|
+
return clazz.script(options) if args.first == :script
|
21
|
+
|
22
|
+
use_script = options.delete :script
|
23
|
+
locale = options.delete(:locale) || options.delete(:lang)
|
24
|
+
|
25
|
+
params = clazz.options_to_data_params(clazz.default_options.merge(options))
|
26
|
+
params.merge!(class: CLASS)
|
27
|
+
|
28
|
+
scripter_class = use_script == :async ? clazz::AsyncScripter : clazz::Scripter
|
29
|
+
|
30
|
+
html = "".html_safe
|
31
|
+
html << content_tag(:div, nil, params)
|
32
|
+
html << scripter_class.new(self).script(locale) if use_script
|
33
|
+
html
|
34
|
+
end
|
35
|
+
|
36
|
+
class << self
|
37
|
+
include Help
|
38
|
+
|
39
|
+
def default_options
|
40
|
+
@default_options ||= {
|
41
|
+
annotations: "inline"
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Scripter < SocialButtons::Scripter
|
47
|
+
def script lang = nil
|
48
|
+
return empty_content if widgetized? :google_plus
|
49
|
+
widgetized! :google_plus
|
50
|
+
%q{<script type="text/javascript">
|
51
|
+
#{language lang}
|
52
|
+
(function() {
|
53
|
+
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
|
54
|
+
po.src = 'https://apis.google.com/js/plusone.js';
|
55
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
|
56
|
+
})();
|
57
|
+
</script>}.html_safe
|
58
|
+
end
|
59
|
+
|
60
|
+
def language lang = nil
|
61
|
+
"window.___gcfg = {lang: '#{lang}'};" if lang
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
class AsyncScripter < SocialButtons::Scripter
|
67
|
+
# Place this tag in your head or just before your close body tag
|
68
|
+
def script lang = nil
|
69
|
+
%Q{<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
|
70
|
+
#{language lang}
|
71
|
+
</script>}
|
72
|
+
end
|
73
|
+
|
74
|
+
def language lang = nil
|
75
|
+
"{lang: '#{lang}'}" if lang
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
module GooglePlus
|
3
|
+
module Help
|
4
|
+
# Usage
|
5
|
+
# SocialButtons::Google.help
|
6
|
+
#
|
7
|
+
# SocialButtons.config(:google).help
|
8
|
+
def help
|
9
|
+
%Q{Google+ button (options)
|
10
|
+
#{Help.show_data_attributes}
|
11
|
+
#{Help.other_options}
|
12
|
+
#{Help.async_help}
|
13
|
+
#{help_note}
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
module Help
|
18
|
+
def show_data_attributes
|
19
|
+
"'data-' attributes: #{data_attributes.inspect}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def other_options
|
23
|
+
"options: lang"
|
24
|
+
end
|
25
|
+
|
26
|
+
def data_attributes
|
27
|
+
%w{size href annotation}
|
28
|
+
end
|
29
|
+
|
30
|
+
def async_help
|
31
|
+
%q{Async script mode:
|
32
|
+
To only output script
|
33
|
+
= google_button :script, lang: 'es'
|
34
|
+
|
35
|
+
To NOT output script tag
|
36
|
+
= google_button :lang => 'es', script: false
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
module Like
|
3
|
+
include SocialButtons::Assistant
|
4
|
+
|
5
|
+
CLASS = "fb-like"
|
6
|
+
|
7
|
+
def like_button(app_id, options = {})
|
8
|
+
clazz = SocialButtons::Like
|
9
|
+
params = clazz.options_to_data_params(clazz.default_options.merge(options))
|
10
|
+
params.merge!(class: CLASS)
|
11
|
+
|
12
|
+
html = "".html_safe
|
13
|
+
html << content_tag(:div, nil, id: "fb-root")
|
14
|
+
html << clazz::Scripter.new(self).script(app_id)
|
15
|
+
html << content_tag(:div, nil, params)
|
16
|
+
html
|
17
|
+
end
|
18
|
+
|
19
|
+
# To avoid polluting namespace where module is included with util functions!
|
20
|
+
class << self
|
21
|
+
def default_options
|
22
|
+
@default_options ||= {
|
23
|
+
send: "false",
|
24
|
+
layout: "button_count",
|
25
|
+
width: "450",
|
26
|
+
action: "like",
|
27
|
+
font: "arial",
|
28
|
+
colorscheme: "light"
|
29
|
+
}.merge("show-faces" => "false")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class Scripter < SocialButtons::Scripter
|
34
|
+
def script(app_id)
|
35
|
+
return empty_content if widgetized? :like
|
36
|
+
widgetized! :like
|
37
|
+
"<script src=#{js_sdk(app_id)} type='text/javascript'></script>".html_safe
|
38
|
+
end
|
39
|
+
|
40
|
+
def js_sdk app_id
|
41
|
+
"https://connect.facebook.net/en_US/all.js#xfbml=1&appId=#{app_id}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
module Pinit
|
3
|
+
include SocialButtons::Assistant
|
4
|
+
|
5
|
+
PINIT_CREATE_BUTTON = "http://pinterest.com/pin/create/button/"
|
6
|
+
PINIT_BUTTON_IMAGE = "http://assets.pinterest.com/images/PinExt.png"
|
7
|
+
CLASS = "pin-it-button"
|
8
|
+
TITLE = "Pin It"
|
9
|
+
|
10
|
+
def pinit_button(options = {})
|
11
|
+
clazz = SocialButtons::Pinit
|
12
|
+
default_options = {url: request.url, media: request.url}
|
13
|
+
params = clazz.default_options.merge(clazz.default_options).merge(options)
|
14
|
+
params.merge!(:class => CLASS)
|
15
|
+
|
16
|
+
query_string = clazz.options_to_query_string(self, params)
|
17
|
+
option_params = params.except(:url, :media, :description)
|
18
|
+
pinit_link = PINIT_CREATE_BUTTON + query_string
|
19
|
+
|
20
|
+
html = "".html_safe
|
21
|
+
html << link_to(pinit_link, option_params) do
|
22
|
+
image_tag PINIT_BUTTON_IMAGE, border: ("0" || options[:border]), title: (TITLE || options[:title])
|
23
|
+
end
|
24
|
+
html << clazz::Scripter.new(self).script
|
25
|
+
html
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def default_options
|
30
|
+
@default_options ||= {
|
31
|
+
description: "Pin Me!"
|
32
|
+
}.merge("count-layout" => "none")
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
class Scripter < SocialButtons::Scripter
|
37
|
+
def script
|
38
|
+
return empty_content if widgetized? :pinit
|
39
|
+
widgetized! :pinit
|
40
|
+
"<script src=#{pinit_js} type='text/javascript'></script>".html_safe
|
41
|
+
end
|
42
|
+
|
43
|
+
def pinit_js
|
44
|
+
"https://assets.pinterest.com/js/pinit.js"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
class Scripter
|
3
|
+
attr_accessor :caller, :options
|
4
|
+
|
5
|
+
def initialize caller, options = {}
|
6
|
+
@caller = caller
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def script lang = nil
|
11
|
+
raise NotImplementedError, "Must be implemented by subclass"
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
delegate :widgetized!, :widgetized?, to: :caller
|
17
|
+
|
18
|
+
def empty_content
|
19
|
+
"".html_safe
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module SocialButtons
|
2
|
+
module Tweet
|
3
|
+
include SocialButtons::Assistant
|
4
|
+
|
5
|
+
TWITTER_SHARE_URL = "http://twitter.com/share"
|
6
|
+
CLASS = "twitter-share-button"
|
7
|
+
|
8
|
+
def tweet_button(options = {})
|
9
|
+
clazz = SocialButtons::Tweet
|
10
|
+
params = clazz.options_to_data_params(clazz.default_options.merge(options))
|
11
|
+
params.merge!(class: CLASS)
|
12
|
+
|
13
|
+
html = "".html_safe
|
14
|
+
html << clazz::Scripter.new(self).script
|
15
|
+
html << link_to("Tweet", TWITTER_SHARE_URL, params)
|
16
|
+
html
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def default_options
|
21
|
+
@default_options ||= {
|
22
|
+
url: request.url,
|
23
|
+
via: "tweetbutton",
|
24
|
+
text: "",
|
25
|
+
count: "vertical",
|
26
|
+
lang: "en",
|
27
|
+
related: ""
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Scripter < SocialButtons::Scripter
|
33
|
+
def script
|
34
|
+
return empty_content if widgetized? :tweet
|
35
|
+
widgetized! :tweet
|
36
|
+
|
37
|
+
"<script src=#{twitter_wjs} type='text/javascript'></script>".html_safe
|
38
|
+
end
|
39
|
+
|
40
|
+
def twitter_wjs
|
41
|
+
"http://platform.twitter.com/widgets.js"
|
42
|
+
end
|
43
|
+
end # class
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "social-buttons"
|
8
|
+
s.version = "0.3.6"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jeremy McAnally", "Yuva"]
|
12
|
+
s.date = "2012-08-26"
|
13
|
+
s.description = "Generate Social Buttons for your Rails apps"
|
14
|
+
s.email = "yuva@codemancers.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"CHANGELOG.md",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE",
|
26
|
+
"README.md",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"init.rb",
|
30
|
+
"lib/social_buttons.rb",
|
31
|
+
"lib/social_buttons/engine.rb",
|
32
|
+
"lib/social_buttons/view_helper.rb",
|
33
|
+
"lib/social_buttons/view_helpers/assistant.rb",
|
34
|
+
"lib/social_buttons/view_helpers/google_plus.rb",
|
35
|
+
"lib/social_buttons/view_helpers/google_plus/help.rb",
|
36
|
+
"lib/social_buttons/view_helpers/like.rb",
|
37
|
+
"lib/social_buttons/view_helpers/pinit.rb",
|
38
|
+
"lib/social_buttons/view_helpers/scripter.rb",
|
39
|
+
"lib/social_buttons/view_helpers/tweet.rb",
|
40
|
+
"social-buttons.gemspec",
|
41
|
+
"spec/social_buttons/config_spec.rb",
|
42
|
+
"spec/social_buttons/google_plus_spec.rb",
|
43
|
+
"spec/social_buttons/like_spec.rb",
|
44
|
+
"spec/social_buttons/pinit_spec.rb",
|
45
|
+
"spec/social_buttons/tweet_spec.rb",
|
46
|
+
"spec/spec_helper.rb",
|
47
|
+
"spec/view_helper_config.rb"
|
48
|
+
]
|
49
|
+
s.homepage = "https://github.com/iffyuva/social-buttons"
|
50
|
+
s.require_paths = ["lib"]
|
51
|
+
s.rubygems_version = "1.8.24"
|
52
|
+
s.summary = "Generate new Social Buttons"
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
s.specification_version = 3
|
56
|
+
|
57
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
58
|
+
s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
|
59
|
+
s.add_development_dependency(%q<rspec>, [">= 2.8.0"])
|
60
|
+
s.add_development_dependency(%q<rdoc>, [">= 3.12"])
|
61
|
+
s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
|
62
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
63
|
+
s.add_development_dependency(%q<simplecov>, [">= 0.5"])
|
64
|
+
else
|
65
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
66
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
67
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
68
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
69
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
70
|
+
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
71
|
+
end
|
72
|
+
else
|
73
|
+
s.add_dependency(%q<rails>, [">= 3.0.0"])
|
74
|
+
s.add_dependency(%q<rspec>, [">= 2.8.0"])
|
75
|
+
s.add_dependency(%q<rdoc>, [">= 3.12"])
|
76
|
+
s.add_dependency(%q<bundler>, [">= 1.0.0"])
|
77
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
78
|
+
s.add_dependency(%q<simplecov>, [">= 0.5"])
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SocialButtons do
|
4
|
+
|
5
|
+
# TODO: Generate for each!
|
6
|
+
# SocialButtons.names.each do |name|
|
7
|
+
context 'Tweet' do
|
8
|
+
subject { SocialButtons::Tweet }
|
9
|
+
|
10
|
+
describe 'Tweet' do
|
11
|
+
before :all do
|
12
|
+
SocialButtons::Tweet.default_options = {:via => "myself"}
|
13
|
+
end
|
14
|
+
|
15
|
+
its(:default_options) { should == {:via => "myself"} }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#config' do
|
19
|
+
before :all do
|
20
|
+
SocialButtons.config(:tweet).default_options = {:via => "myself"}
|
21
|
+
end
|
22
|
+
|
23
|
+
its(:default_options) { should == {:via => "myself"} }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#config &block' do
|
27
|
+
before :all do
|
28
|
+
SocialButtons.config(:tweet) {|c| c.default_options = {:via => "myself"} }
|
29
|
+
end
|
30
|
+
|
31
|
+
its(:default_options) { should == {:via => "myself"} }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'view_helper_config'
|
2
|
+
|
3
|
+
describe SocialButtons::ViewHelper do
|
4
|
+
include ControllerTestHelpers,
|
5
|
+
SocialButtons::ViewHelper
|
6
|
+
|
7
|
+
describe '#google_plus_button' do
|
8
|
+
context 'no arguments' do
|
9
|
+
it "should not any args" do
|
10
|
+
expect { google_plus_button }.to_not raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with script and options' do
|
15
|
+
it "should set annotation using option" do
|
16
|
+
output = google_plus_button(:annotation => 'bubble', script: true)
|
17
|
+
output.should match(/bubble/)
|
18
|
+
output.should match(/<script/)
|
19
|
+
|
20
|
+
output = google_plus_button(:annotation => 'none', script: true)
|
21
|
+
output.should match(/none/)
|
22
|
+
output.should_not match(/<script/)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'with script - on next request' do
|
27
|
+
it "should render script again on next request!" do
|
28
|
+
output = google_plus_button(:annotation => 'bubble', script: true)
|
29
|
+
output.should match(/bubble/)
|
30
|
+
output.should match(/<script/)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'view_helper_config'
|
2
|
+
|
3
|
+
describe SocialButtons::ViewHelper do
|
4
|
+
include ControllerTestHelpers,
|
5
|
+
SocialButtons::ViewHelper
|
6
|
+
|
7
|
+
describe '#like_button' do
|
8
|
+
context 'no arguments' do
|
9
|
+
it "should require a Facebook app id" do
|
10
|
+
expect { like_button }.to raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with app_id' do
|
15
|
+
it "should require a Facebook app id" do
|
16
|
+
expect { like_button('128085897213395') }.to_not raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'with options' do
|
21
|
+
it "should set width using option" do
|
22
|
+
output = like_button('128085897213395', :width => '400')
|
23
|
+
output.should match(/width="400"/)
|
24
|
+
output.should match(/<script/)
|
25
|
+
|
26
|
+
output = like_button('128085897213395', :width => '400')
|
27
|
+
output.should_not match(/<script/)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'with script - on next request' do
|
32
|
+
it "should render script again on next request!" do
|
33
|
+
output = like_button('128085897213395', :width => '400')
|
34
|
+
output.should match(/width="400"/)
|
35
|
+
output.should match(/<script/)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'view_helper_config'
|
2
|
+
|
3
|
+
describe SocialButtons::ViewHelper do
|
4
|
+
include ControllerTestHelpers,
|
5
|
+
SocialButtons::ViewHelper
|
6
|
+
|
7
|
+
describe '#pinit_button' do
|
8
|
+
context 'no arguments' do
|
9
|
+
it "should not any args" do
|
10
|
+
expect { pinit_button }.to_not raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with options' do
|
15
|
+
it "should set description using option" do
|
16
|
+
output = pinit_button(:colorscheme => 'dark')
|
17
|
+
output.should match(/dark/)
|
18
|
+
output.should match(/<script/)
|
19
|
+
|
20
|
+
output = pinit_button(:colorscheme => 'dark')
|
21
|
+
output.should_not match(/<script/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with script - on next request' do
|
26
|
+
it "should render script again on next request!" do
|
27
|
+
output = pinit_button(:colorscheme => 'dark')
|
28
|
+
output.should match(/dark/)
|
29
|
+
output.should match(/<script/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'view_helper_config'
|
2
|
+
|
3
|
+
describe SocialButtons::ViewHelper do
|
4
|
+
include ControllerTestHelpers,
|
5
|
+
SocialButtons::ViewHelper
|
6
|
+
|
7
|
+
describe '#tweet_button' do
|
8
|
+
context 'no arguments' do
|
9
|
+
it "should not any args" do
|
10
|
+
expect { tweet_button }.to_not raise_error
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'with options' do
|
15
|
+
it "should set description using option" do
|
16
|
+
output = tweet_button(:text => 'hello')
|
17
|
+
output.should match(/hello/)
|
18
|
+
output.should match(/<script/)
|
19
|
+
|
20
|
+
output = tweet_button(:text => 'hello')
|
21
|
+
output.should_not match(/<script/)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context 'with script - on next request' do
|
26
|
+
it "should render script again on next request!" do
|
27
|
+
output = tweet_button(:text => 'hello')
|
28
|
+
output.should match(/hello/)
|
29
|
+
output.should match(/<script/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rails'
|
4
|
+
require 'json'
|
5
|
+
require 'active_support'
|
6
|
+
require 'action_pack'
|
7
|
+
require 'action_view'
|
8
|
+
require 'action_controller'
|
9
|
+
require 'action_view/template'
|
10
|
+
|
11
|
+
require 'active_support/core_ext/hash'
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'social_buttons'
|
15
|
+
|
16
|
+
SPEC_DIR = File.dirname(__FILE__)
|
17
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'hashie'
|
3
|
+
|
4
|
+
class DummyController
|
5
|
+
def method_missing(meth, *args, &block)
|
6
|
+
meth
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module ControllerTestHelpers
|
11
|
+
|
12
|
+
def self.included(base)
|
13
|
+
base.class_eval do
|
14
|
+
|
15
|
+
include ActionView::Helpers,
|
16
|
+
ActionView::Helpers::CaptureHelper,
|
17
|
+
ActionView::Helpers::JavaScriptHelper,
|
18
|
+
ActionView::Helpers::AssetTagHelper,
|
19
|
+
ActionDispatch::Routing,
|
20
|
+
ActionView::Helpers::UrlHelper
|
21
|
+
|
22
|
+
# allow tabs.create to run by stubbing an output_buffer
|
23
|
+
attr_accessor :output_buffer
|
24
|
+
@output_buffer = ""
|
25
|
+
|
26
|
+
def request
|
27
|
+
Hashie::Mash.new :url => 'www.hello.com'
|
28
|
+
end
|
29
|
+
|
30
|
+
def link_to adr, *args
|
31
|
+
options = args.extract_options!
|
32
|
+
content_tag :a, adr, {:href => adr}.merge(options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def controller
|
36
|
+
@controller ||= DummyController.new
|
37
|
+
end
|
38
|
+
|
39
|
+
def url_for adr, *args
|
40
|
+
"dummy/path/#{adr}/#{args}".html_safe
|
41
|
+
end
|
42
|
+
|
43
|
+
def _routes_context
|
44
|
+
controller
|
45
|
+
end
|
46
|
+
|
47
|
+
# stub content_for for testing
|
48
|
+
def content_for(name, content = nil, &block)
|
49
|
+
# this doesn't exist, and causes errors
|
50
|
+
@_content_for = {} unless defined? @_content_for
|
51
|
+
# we've got to initialize this, so we can concat to it
|
52
|
+
@_content_for[name] = '' if @_content_for[name].nil?
|
53
|
+
# now the rest is the same as in rails
|
54
|
+
content = capture(&block) if block_given?
|
55
|
+
@_content_for[name] << content if content
|
56
|
+
@_content_for[name] unless content
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: social-buttons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.6
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeremy McAnally
|
9
|
+
- Yuva
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-08-26 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rails
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 3.0.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: rspec
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 2.8.0
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.8.0
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rdoc
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '3.12'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: bundler
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.0.0
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.0.0
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: jeweler
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ~>
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 1.8.4
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ~>
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: 1.8.4
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: simplecov
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.5'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.5'
|
111
|
+
description: Generate Social Buttons for your Rails apps
|
112
|
+
email: yuva@codemancers.com
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files:
|
116
|
+
- LICENSE
|
117
|
+
- README.md
|
118
|
+
files:
|
119
|
+
- .document
|
120
|
+
- .rspec
|
121
|
+
- CHANGELOG.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- VERSION
|
128
|
+
- init.rb
|
129
|
+
- lib/social_buttons.rb
|
130
|
+
- lib/social_buttons/engine.rb
|
131
|
+
- lib/social_buttons/view_helper.rb
|
132
|
+
- lib/social_buttons/view_helpers/assistant.rb
|
133
|
+
- lib/social_buttons/view_helpers/google_plus.rb
|
134
|
+
- lib/social_buttons/view_helpers/google_plus/help.rb
|
135
|
+
- lib/social_buttons/view_helpers/like.rb
|
136
|
+
- lib/social_buttons/view_helpers/pinit.rb
|
137
|
+
- lib/social_buttons/view_helpers/scripter.rb
|
138
|
+
- lib/social_buttons/view_helpers/tweet.rb
|
139
|
+
- social-buttons.gemspec
|
140
|
+
- spec/social_buttons/config_spec.rb
|
141
|
+
- spec/social_buttons/google_plus_spec.rb
|
142
|
+
- spec/social_buttons/like_spec.rb
|
143
|
+
- spec/social_buttons/pinit_spec.rb
|
144
|
+
- spec/social_buttons/tweet_spec.rb
|
145
|
+
- spec/spec_helper.rb
|
146
|
+
- spec/view_helper_config.rb
|
147
|
+
homepage: https://github.com/iffyuva/social-buttons
|
148
|
+
licenses: []
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
requirements: []
|
166
|
+
rubyforge_project:
|
167
|
+
rubygems_version: 1.8.24
|
168
|
+
signing_key:
|
169
|
+
specification_version: 3
|
170
|
+
summary: Generate new Social Buttons
|
171
|
+
test_files: []
|