facebook-social_plugins 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -9,6 +9,25 @@ The `ViewHelper` contains methods for inserting the HTML5 <div> elements for Fac
9
9
 
10
10
  The `ScriptHelper` contains methods for inserting <script> snippets for Facebook integration, such as displaying the Social plugins with the Facebook layout/styling applied etc.
11
11
 
12
+ == Social plugins
13
+
14
+ Currently the following Social plugins are included in this gem
15
+
16
+ * Root
17
+ * Activity Feed
18
+ * Comments
19
+ * Facepile
20
+ * Like Box
21
+ * Like Button
22
+ * Live Stream
23
+ * Login Button
24
+ * Recommendations Box
25
+ * Registration
26
+ * Send Button
27
+ * Subscribe Button
28
+
29
+ (see below)
30
+
12
31
  == Script Helpers
13
32
 
14
33
  * async_init_script(app_id, domain, options = {})
@@ -36,7 +55,6 @@ The JavaScript SDK supports OAuth 2.0.
36
55
 
37
56
  The following code will load and initialize the JavaScript SDK with all common options. Replace YOUR_APP_ID and WWW.YOUR_DOMAIN.COM with the appropriate values. The best place to put this code is right after the opening <body> tag.
38
57
 
39
- <div id="fb-root"></div>
40
58
  <script>
41
59
  window.fbAsyncInit = function() {
42
60
  FB.init({
@@ -74,10 +92,33 @@ The JavaScript SDK is available in all locales that are supported by Facebook. T
74
92
  }(document));
75
93
  </script>
76
94
 
95
+ == Open Graph Meta helper
96
+
97
+ Convenience method to generate all header/meta tags for Facebook Open Graph
98
+
99
+ * open_graph_meta(name, namespace, app_id, object_type, options = {})
100
+
101
+ * og_header(name, namespace) - Open Graph <head> tag
102
+
103
+ Open graph <meta> tag helpers
104
+
105
+ * og_type(app_id, object_type)
106
+ * og_title(title)
107
+ * og_image(image_url)
108
+ * og_url(href)
109
+ * og_desc(desc)
110
+ * fb_app_id(app_id)
111
+
112
+ == Extras
113
+
114
+ * fb_analytics(app_id) # Facebook analytics meta tag
115
+ * fb_activity(namespace, action) # Open Graph action to perform
116
+
77
117
  == Social plugins
78
118
 
79
119
  Currently the following Social plugins are included in this gem
80
120
 
121
+ * Root
81
122
  * Activity Feed
82
123
  * Comments
83
124
  * Facepile
@@ -93,18 +134,26 @@ Currently the following Social plugins are included in this gem
93
134
  View methods exposed:
94
135
 
95
136
  * fb_root
96
- * fb_activity options = {}
97
- * fb_add_to_timeline options = {}
98
- * fb_comments options = {}
99
- * fb_facepile options = {}
100
- * fb_like_box options = {}
101
- * fb_like_button options = {}
102
- * fb_live_stream options = {}
103
- * fb_login_button options = {}
104
- * fb_recommendations_box options = {}
105
- * fb_registration options = {}
106
- * fb_send_button options = {}
107
- * fb_subscribe_button options = {}
137
+ * fb_activity (options = {})
138
+ * fb_add_to_timeline (options = {})
139
+ * fb_comments (options = {})
140
+ * fb_facepile (options = {})
141
+ * fb_like_box (options = {})
142
+ * fb_like_button (options = {})
143
+ * fb_live_stream (options = {})
144
+ * fb_login_button (options = {})
145
+ * fb_recommendations_box (options = {})
146
+ * fb_registration (options = {})
147
+ * fb_send_button (options = {})
148
+ * fb_subscribe_button (options = {})
149
+
150
+ Note: You don't have to worry about dashed or underscored properties. Conversions will be handled automatically. The Facebook Social plugins API is (sadly) not very consistent when it comes to attribute names.
151
+
152
+ === Facebook root
153
+
154
+ <div id="fb-root"></div>
155
+
156
+ A Facebook placeholder div
108
157
 
109
158
  === Activity feed
110
159
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "facebook-social_plugins"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
@@ -30,6 +30,7 @@ Gem::Specification.new do |s|
30
30
  "lib/facebook-social_plugins.rb",
31
31
  "lib/facebook-social_plugins/activity_feed.rb",
32
32
  "lib/facebook-social_plugins/add_to_timeline.rb",
33
+ "lib/facebook-social_plugins/analytics.rb",
33
34
  "lib/facebook-social_plugins/button.rb",
34
35
  "lib/facebook-social_plugins/comments.rb",
35
36
  "lib/facebook-social_plugins/facepile.rb",
@@ -37,6 +38,7 @@ Gem::Specification.new do |s|
37
38
  "lib/facebook-social_plugins/like_button.rb",
38
39
  "lib/facebook-social_plugins/live_stream.rb",
39
40
  "lib/facebook-social_plugins/login_button.rb",
41
+ "lib/facebook-social_plugins/open_graph/meta_helper.rb",
40
42
  "lib/facebook-social_plugins/rails/engine.rb",
41
43
  "lib/facebook-social_plugins/recommendations_box.rb",
42
44
  "lib/facebook-social_plugins/registration.rb",
@@ -46,6 +48,7 @@ Gem::Specification.new do |s|
46
48
  "lib/facebook-social_plugins/subscribe_button.rb",
47
49
  "lib/facebook-social_plugins/ui_helper.rb",
48
50
  "lib/facebook-social_plugins/view_helper.rb",
51
+ "spec/facebook-social_plugins/og_meta_helper_spec.rb",
49
52
  "spec/facebook-social_plugins/script_helper_spec.rb",
50
53
  "spec/facebook-social_plugins/view_helper_spec.rb",
51
54
  "spec/spec_helper.rb",
@@ -0,0 +1,14 @@
1
+ module FacebookSocialPlugins
2
+ class Analytics < UiHelper
3
+ attr_reader :app_id
4
+
5
+ def initialize app_id
6
+ @app_id = app_id
7
+ end
8
+
9
+ def render
10
+ content_tag :meta, '', :property => "fb:admins", :content => app_id
11
+ end
12
+ end
13
+ end
14
+
@@ -0,0 +1,45 @@
1
+ module FacebookSocialPlugins
2
+ module OpenGraph
3
+ module MetaHelper
4
+ def og_header name, namespace, &block
5
+ content = capture(&block)
6
+ content_tag :head, content, :prefix => "og: http://ogp.me/ns# og_#{name}: http://ogp.me/ns/apps/#{namespace}x#"
7
+ end
8
+
9
+ def fb_app_id app_id
10
+ content_tag :meta, '', :property => "fb:app_id", :content => app_id
11
+ end
12
+
13
+ def og_type namespace, object_type
14
+ content_tag :meta, '', :property => "og:type", :content => "#{namespace}:#{object_type}"
15
+ end
16
+
17
+ def og_title title
18
+ content_tag :meta, '', :property => "og:title", :content => title
19
+ end
20
+
21
+ def og_image href
22
+ content_tag :meta, '', :property => "og:image", :content => href
23
+ end
24
+
25
+ def og_desc desc
26
+ content_tag :meta, '', :property => "og:description", :content => desc
27
+ end
28
+
29
+ def og_url href
30
+ content_tag :meta, '', :property => "og:url", :content => href
31
+ end
32
+
33
+ def open_graph_meta name, namespace, app_id, object_type, options = {}
34
+ content = fb_app_id(app_id) + og_type(namespace, object_type)
35
+ content << og_title(options[:title]) if options[:title]
36
+ content << og_image(options[:img]) if options[:img]
37
+ content << og_image(options[:desc]) if options[:desc]
38
+ content << og_image(options[:url]) if options[:url]
39
+ og_header(name, namespace) do
40
+ content
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -4,6 +4,8 @@ module FacebookSocialPlugins
4
4
  initializer 'setup rails' do
5
5
  ActionView::Base.send :include, FacebookSocialPlugins::ViewHelper
6
6
  ActionView::Base.send :include, FacebookSocialPlugins::ScriptHelper
7
+
8
+ ActionView::Base.send :include, FacebookSocialPlugins::OpenGraph::MetaHelper
7
9
  end
8
10
  end
9
11
  end
@@ -1,9 +1,17 @@
1
1
  module FacebookSocialPlugins
2
2
  module ViewHelper
3
3
  def fb_root
4
- content_tag :div, :class => "fb-root"
4
+ content_tag :div, '', :class => "fb-root"
5
5
  end
6
6
 
7
+ def fb_analytics app_id
8
+ FacebookSocialPlugins::Analytics.new(app_id).render
9
+ end
10
+
11
+ def fb_activity namespace, action
12
+ content_tag :div, '', :class => "fb-activity", :'data-actions' => "#{namespace}:#{action}"
13
+ end
14
+
7
15
  def fb_activity_feed options = {}
8
16
  FacebookSocialPlugins::ActivityFeed.new(options).render
9
17
  end
@@ -1,5 +1,8 @@
1
1
  require 'facebook-social_plugins/button'
2
2
 
3
+ require 'facebook-social_plugins/analytics'
4
+ require 'facebook-social_plugins/open_graph/meta_helper'
5
+
3
6
  module FacebookSocialPlugins
4
7
  def self.plugins
5
8
  ['activity_feed', 'add_to_timeline', 'comments', 'facepile', 'like_box', 'like_button',
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe FacebookSocialPlugins::OpenGraph::MetaHelper do
4
+ include ControllerTestHelpers,
5
+ FacebookSocialPlugins::OpenGraph::MetaHelper
6
+
7
+ describe 'OpenGraph Meta helper' do
8
+ it "should write Open Graph meta tags " do
9
+ output = open_graph_meta 'team_builder', 'team', '1234', 'recipe'
10
+ output.should == "<head prefix=\"og: http://ogp.me/ns# og_team_builder: http://ogp.me/ns/apps/teamx#\"><meta content=\"1234\" property=\"fb:app_id\"></meta><meta content=\"team:recipe\" property=\"og:type\"></meta></head>"
11
+ end
12
+
13
+ it "should write Open Graph meta tags with title, image and url" do
14
+ output = open_graph_meta 'team_builder', 'team', '1234', 'recipe', :title => 'my recipe', :img => 'recipe.png', :url => 'http://hello.html', :desc => 'My recipe is good'
15
+ output.should == "<head prefix=\"og: http://ogp.me/ns# og_team_builder: http://ogp.me/ns/apps/teamx#\"><meta content=\"1234\" property=\"fb:app_id\"></meta><meta content=\"team:recipe\" property=\"og:type\"></meta><meta content=\"my recipe\" property=\"og:title\"></meta><meta content=\"recipe.png\" property=\"og:image\"></meta><meta content=\"My recipe is good\" property=\"og:image\"></meta><meta content=\"http://hello.html\" property=\"og:image\"></meta></head>"
16
+ end
17
+ end
18
+ end
@@ -10,6 +10,20 @@ describe FacebookSocialPlugins::ViewHelper do
10
10
  end
11
11
  end
12
12
 
13
+ describe 'Analytics meta tag' do
14
+ it "should create :meta" do
15
+ output = fb_analytics 12345
16
+ output.should == "<meta content=\"12345\" property=\"fb:admins\"></meta>"
17
+ end
18
+ end
19
+
20
+ describe 'Facebook Root placeholder' do
21
+ it "should create :root div" do
22
+ output = fb_root
23
+ output.should == "<div class=\"fb-root\"></div>"
24
+ end
25
+ end
26
+
13
27
  describe 'Activity Feed' do
14
28
  it "should create :activity div" do
15
29
  output = fb_activity_feed :site => 'www.example.com'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook-social_plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -160,6 +160,7 @@ files:
160
160
  - lib/facebook-social_plugins.rb
161
161
  - lib/facebook-social_plugins/activity_feed.rb
162
162
  - lib/facebook-social_plugins/add_to_timeline.rb
163
+ - lib/facebook-social_plugins/analytics.rb
163
164
  - lib/facebook-social_plugins/button.rb
164
165
  - lib/facebook-social_plugins/comments.rb
165
166
  - lib/facebook-social_plugins/facepile.rb
@@ -167,6 +168,7 @@ files:
167
168
  - lib/facebook-social_plugins/like_button.rb
168
169
  - lib/facebook-social_plugins/live_stream.rb
169
170
  - lib/facebook-social_plugins/login_button.rb
171
+ - lib/facebook-social_plugins/open_graph/meta_helper.rb
170
172
  - lib/facebook-social_plugins/rails/engine.rb
171
173
  - lib/facebook-social_plugins/recommendations_box.rb
172
174
  - lib/facebook-social_plugins/registration.rb
@@ -176,6 +178,7 @@ files:
176
178
  - lib/facebook-social_plugins/subscribe_button.rb
177
179
  - lib/facebook-social_plugins/ui_helper.rb
178
180
  - lib/facebook-social_plugins/view_helper.rb
181
+ - spec/facebook-social_plugins/og_meta_helper_spec.rb
179
182
  - spec/facebook-social_plugins/script_helper_spec.rb
180
183
  - spec/facebook-social_plugins/view_helper_spec.rb
181
184
  - spec/spec_helper.rb
@@ -195,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
195
198
  version: '0'
196
199
  segments:
197
200
  - 0
198
- hash: -878790020969817621
201
+ hash: 3268721776078467836
199
202
  required_rubygems_version: !ruby/object:Gem::Requirement
200
203
  none: false
201
204
  requirements: