tweet-button 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +66 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/lib/tweet-button.rb +55 -0
- data/test/helper.rb +9 -0
- data/test/test_tweet-button.rb +7 -0
- metadata +72 -0
data/.document
ADDED
data/.gitignore
ADDED
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.rdoc
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= tweet-button
|
2
|
+
|
3
|
+
Jeremy McAnally - Intridea
|
4
|
+
|
5
|
+
A gem/plugin to generate those nifty new Twitter buttons.
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
First, include +TweetButton+ into your application helper. After that, using it is as simple as adding a single method call to your views:
|
10
|
+
|
11
|
+
<%= tweet_button %>
|
12
|
+
|
13
|
+
Bam. Done. You'll have a sweet lookin' Tweet button all up in your view.
|
14
|
+
|
15
|
+
Of course, you can customize it. The method takes a few options (any default can be overridden universally; read on...):
|
16
|
+
|
17
|
+
* +:url+ - The URL to share; the default is the current URL.
|
18
|
+
* +:text+ - The text that will appear in the tweet; the default is "Check this out!"
|
19
|
+
* +:via+ - The attribution. Defaults to "tweetbutton", but you should change that.
|
20
|
+
* +:lang+ - Set the language for the tweet (no default).
|
21
|
+
* +:related+ - Related Twitter accounts (no default).
|
22
|
+
* +:count+ - The tweet count box position (values can be "none", "horizontal", or "vertical"; default is "vertical").
|
23
|
+
|
24
|
+
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:
|
25
|
+
|
26
|
+
<%= tweet_button(:via => "peterc", :url => "http://news.ycombinator.com", :text => "AWESOME.")
|
27
|
+
|
28
|
+
Simple enough, eh? Also, this method call will include the Twitter JavaScript into the page (it only does it once, even if you have multiple buttons on the page). To put this wherever you'd like (i.e., your header), then use the +twitter_widgets_js_tag+ method. If you call this method, it will place the tag wherever you call it from (and only place it there; subsequent calls do nothing).
|
29
|
+
|
30
|
+
The gem also supports the custom Twitter share links. To generate one, use the +custom_tweet_button+ (aliased to +custom_tweet_link+ also) method:
|
31
|
+
|
32
|
+
<%= custom_tweet_button %>
|
33
|
+
|
34
|
+
This will generate a link that will link to the share page with the same default options as the standard Tweet Button generator. You can customize your custom link with text as the first argument, the same options as +tweet_button+ (with the exception of the +count+ parameter, which will be ignored) as the second, and HTML options as a third argument. For example:
|
35
|
+
|
36
|
+
<%= custom_tweet_button('Tweet it!', {:via => "myself"}, {:class => "tweet-sharey-thing"})
|
37
|
+
|
38
|
+
== Setting universal defaults
|
39
|
+
|
40
|
+
You can set a new default for any option by setting +default_tweet_button_options+ in your application helper. For example:
|
41
|
+
|
42
|
+
module ApplicationHelper
|
43
|
+
include TweetButton
|
44
|
+
|
45
|
+
TweetButton.default_tweet_button_options = {:via => "myself"}
|
46
|
+
end
|
47
|
+
|
48
|
+
Only the options you specify will be overridden; so if you only specify a new default +:via+ (which you should definitely do), then the other defaults will stay intact.
|
49
|
+
|
50
|
+
== TODO
|
51
|
+
|
52
|
+
Probably add the iframe capability.
|
53
|
+
|
54
|
+
== Note on Patches/Pull Requests
|
55
|
+
|
56
|
+
* Fork the project.
|
57
|
+
* Make your feature addition or bug fix.
|
58
|
+
* Add tests for it. This is important so I don't break it in a
|
59
|
+
future version unintentionally.
|
60
|
+
* Commit, do not mess with rakefile, version, or history.
|
61
|
+
(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)
|
62
|
+
* Send me a pull request. Bonus points for topic branches.
|
63
|
+
|
64
|
+
== Copyright
|
65
|
+
|
66
|
+
Copyright (c) 2010 Jeremy McAnally. 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 = "tweet-button"
|
8
|
+
gem.summary = %Q{Generate new Twitter 'Tweet buttons'}
|
9
|
+
gem.description = %Q{Generate Tweet buttons for your Rails apps}
|
10
|
+
gem.email = "jeremymcanally@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/jm/tweet-button"
|
12
|
+
gem.authors = ["Jeremy McAnally"]
|
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 'rake/rdoctask'
|
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.1.0
|
data/lib/tweet-button.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
module TweetButton
|
2
|
+
TWITTER_SHARE_URL = "http://twitter.com/share"
|
3
|
+
|
4
|
+
def tweet_button(options = {})
|
5
|
+
# Merge user specified overrides into defaults, then convert those to data-* attrs
|
6
|
+
params = options_to_data_params(default_tweet_button_options.merge(options))
|
7
|
+
|
8
|
+
html = ''.html_safe
|
9
|
+
|
10
|
+
unless @widgetized
|
11
|
+
html << tweet_widgets_js_tag
|
12
|
+
end
|
13
|
+
|
14
|
+
html << link_to("Tweet", TWITTER_SHARE_URL, params)
|
15
|
+
end
|
16
|
+
|
17
|
+
class <<self
|
18
|
+
attr_accessor :default_tweet_button_options
|
19
|
+
end
|
20
|
+
|
21
|
+
def default_tweet_button_options
|
22
|
+
{
|
23
|
+
:url => request.url,
|
24
|
+
:via => "tweetbutton",
|
25
|
+
:text => "",
|
26
|
+
:related => "",
|
27
|
+
:count => "vertical",
|
28
|
+
:lang => "en"
|
29
|
+
}.merge(TweetButton.default_tweet_button_options || {})
|
30
|
+
end
|
31
|
+
|
32
|
+
def tweet_widgets_js_tag
|
33
|
+
@widgetized = true
|
34
|
+
'<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>'.html_safe
|
35
|
+
end
|
36
|
+
|
37
|
+
def custom_tweet_button(text = 'Tweet', options = {}, html_options = {})
|
38
|
+
# This line is really long. And it makes me sad.
|
39
|
+
link_to(text, "#{TWITTER_SHARE_URL}?#{options_to_query_string(default_tweet_button_options.merge(options))}", html_options)
|
40
|
+
end
|
41
|
+
|
42
|
+
def options_to_data_params(opts)
|
43
|
+
params = {}
|
44
|
+
opts.each {|k, v| params["data-#{k}"] = v}
|
45
|
+
|
46
|
+
# Make sure the CSS class is there
|
47
|
+
params['class'] = 'twitter-share-button'
|
48
|
+
params
|
49
|
+
end
|
50
|
+
|
51
|
+
# I'm pretty sure this is in the stdlib or Rails somewhere. Too lazy to figure it out now.
|
52
|
+
def options_to_query_string(opts)
|
53
|
+
opts.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}"}.join("&")
|
54
|
+
end
|
55
|
+
end
|
data/test/helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tweet-button
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Jeremy McAnally
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-12 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: Generate Tweet buttons for your Rails apps
|
22
|
+
email: jeremymcanally@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- lib/tweet-button.rb
|
38
|
+
- test/helper.rb
|
39
|
+
- test/test_tweet-button.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/jm/tweet-button
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
segments:
|
54
|
+
- 0
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.3.6
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Generate new Twitter 'Tweet buttons'
|
70
|
+
test_files:
|
71
|
+
- test/helper.rb
|
72
|
+
- test/test_tweet-button.rb
|