acts_as_opengraph 0.0.2.1 → 0.0.3
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/README.markdown
CHANGED
@@ -118,6 +118,18 @@ But that's not the Rails way, so instead of doing that, you can pass an `href` o
|
|
118
118
|
|
119
119
|
See the complete list of allowed attributes and options [here](http://developers.facebook.com/docs/reference/plugins/like/).
|
120
120
|
|
121
|
+
### Using the XFBML version
|
122
|
+
|
123
|
+
The XFBML version is more versatile, but requires use of the JavaScript SDK.
|
124
|
+
|
125
|
+
# app/views/movies/show.html.erb
|
126
|
+
|
127
|
+
# You can use the following helper method to load the JavaScript SDK
|
128
|
+
<%= fb_javascript_include_tag YOUR_APP_ID %>
|
129
|
+
|
130
|
+
# Now you can pass the :xfbml option to the like button helper
|
131
|
+
<%= like_button_for @movie, :xfbml => true %>
|
132
|
+
|
121
133
|
## Note on Patches/Pull Requests
|
122
134
|
|
123
135
|
* Fork the project.
|
@@ -128,6 +140,7 @@ See the complete list of allowed attributes and options [here](http://developers
|
|
128
140
|
## Contributors
|
129
141
|
|
130
142
|
* [Eric Hill](https://github.com/rhizome) - Updated the meta attribute to reflect the current OG spec
|
143
|
+
* [Timo Göllner](https://github.com/TeaMoe) - Integrated Like Button via facebook XFBML tag
|
131
144
|
|
132
145
|
## Copyright
|
133
146
|
|
@@ -14,7 +14,7 @@ module ActsAsOpengraphHelper
|
|
14
14
|
tags = tags.join("\n")
|
15
15
|
tags.respond_to?(:html_safe) ? tags.html_safe : tags
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Displays the Facebook Like Button in your views.
|
19
19
|
#
|
20
20
|
# @param [Object, #opengraph_data] obj An instance of your ActiveRecord model that responds to opengraph_data
|
@@ -30,10 +30,10 @@ module ActsAsOpengraphHelper
|
|
30
30
|
raise(ArgumentError.new, "You need to call acts_as_opengraph on your #{obj.class} model") unless obj.respond_to?(:opengraph_data)
|
31
31
|
href = options[:href] ? options[:href] : obj.opengraph_url
|
32
32
|
return unless href.present?
|
33
|
-
|
33
|
+
|
34
34
|
config = { :layout => :standard, :show_faces => false, :width => 450, :action => :like, :colorscheme => :light }
|
35
35
|
config.update(options) if options.is_a?(Hash)
|
36
|
-
|
36
|
+
|
37
37
|
o_layout = config[:layout].to_sym
|
38
38
|
if o_layout == :standard
|
39
39
|
config[:height] = config[:show_faces].to_s.to_sym == :true ? 80 : 35
|
@@ -42,7 +42,35 @@ module ActsAsOpengraphHelper
|
|
42
42
|
elsif o_layout == :box_count
|
43
43
|
config[:height] = 65
|
44
44
|
end
|
45
|
-
|
46
|
-
|
45
|
+
config[:locale] ||= 'en_US'
|
46
|
+
|
47
|
+
if config[:xfbml]
|
48
|
+
unless @fb_sdk_included
|
49
|
+
content_for :javascripts, fb_javascript_include_tag( config[:locale], config[:appid] )
|
50
|
+
end
|
51
|
+
%(<fb:like href="#{CGI.escape(href)}" layout="#{config[:layout]}" show_faces="#{config[:show_faces]}" action="#{config[:action]}" colorscheme="#{config[:colorscheme]}" width="#{config[:width]}" height="#{config[:height]}" font="#{config[:font]}"></fb:like>)
|
52
|
+
else
|
53
|
+
%(<iframe src="http://www.facebook.com/plugins/like.php?href=#{CGI.escape(href)}&layout=#{config[:layout]}&show_faces=#{config[:show_faces]}&width=#{config[:width]}&action=#{config[:action]}&colorscheme=#{config[:colorscheme]}&height=#{config[:height]}" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:#{config[:width]}px; height:#{config[:height]}px;" allowTransparency="true"></iframe>)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def fb_javascript_include_tag(appid='', locale='en_US')
|
58
|
+
@fb_sdk_included = true
|
59
|
+
async_fb = <<-END
|
60
|
+
<div id="fb-root"></div>
|
61
|
+
<script>
|
62
|
+
window.fbAsyncInit = function() {
|
63
|
+
FB.init({appId: '#{ appid }', status: true, cookie: true,
|
64
|
+
xfbml: true});
|
65
|
+
};
|
66
|
+
(function() {
|
67
|
+
var e = document.createElement('script'); e.async = true;
|
68
|
+
e.src = document.location.protocol +
|
69
|
+
'//connect.facebook.net/#{locale}/all.js';
|
70
|
+
document.getElementById('fb-root').appendChild(e);
|
71
|
+
}());
|
72
|
+
</script>
|
73
|
+
END
|
74
|
+
async_fb.html_safe
|
47
75
|
end
|
48
|
-
end
|
76
|
+
end
|
data/test/opengraph_test.rb
CHANGED
@@ -43,6 +43,7 @@ class MovieTest < Test::Unit::TestCase
|
|
43
43
|
|
44
44
|
GENERATED_LIKE_BUTTON = %(<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt0117500%2F&layout=standard&show_faces=false&width=450&action=like&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>)
|
45
45
|
GENERATED_LIKE_BUTTON_CUSTOM_URL = %(<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fmovies%2F6&layout=standard&show_faces=false&width=450&action=like&colorscheme=light&height=35" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:35px;" allowTransparency="true"></iframe>)
|
46
|
+
GENERATED_LIKE_BUTTON_FBXML = %(<fb:like href=\"http%3A%2F%2Fwww.imdb.com%2Ftitle%2Ftt0117500%2F\" layout=\"standard\" show_faces=\"false\" action=\"like\" colorscheme=\"light\" width=\"450\" height=\"35\" font=\"\"></fb:like>)
|
46
47
|
def setup
|
47
48
|
setup_db
|
48
49
|
assert @movie = Movie.create!(:title => MOVIE_NAME, :description => MOVIE_DESCRIPTION, :imdb => MOVIE_URL)
|
@@ -99,6 +100,9 @@ class MovieTest < Test::Unit::TestCase
|
|
99
100
|
assert_equal GENERATED_LIKE_BUTTON, like_button_for(@movie)
|
100
101
|
assert_equal GENERATED_LIKE_BUTTON_CUSTOM_URL, like_button_for(@movie, :href => "http://example.com/movies/6")
|
101
102
|
|
103
|
+
@fb_sdk_included = true # Tells our helper we've already included the facebook JS SDK
|
104
|
+
assert_equal GENERATED_LIKE_BUTTON_FBXML, like_button_for(@movie, :xfbml => true)
|
105
|
+
|
102
106
|
# There's no way of getting the href attribute for this Book, so it returns nil
|
103
107
|
assert_nil like_button_for(@book)
|
104
108
|
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_opengraph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 25
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 0.0.2.1
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
12
11
|
platform: ruby
|
13
12
|
authors:
|
14
13
|
- Ruben Ascencio
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2011-04-
|
18
|
+
date: 2011-04-18 00:00:00 -07:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
@@ -85,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
84
|
requirements: []
|
86
85
|
|
87
86
|
rubyforge_project: acts_as_opengraph
|
88
|
-
rubygems_version: 1.
|
87
|
+
rubygems_version: 1.3.7
|
89
88
|
signing_key:
|
90
89
|
specification_version: 3
|
91
90
|
summary: ActiveRecord extension that turns your models into graph objects
|