facebook-social_plugins 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (31) hide show
  1. data/README.rdoc +28 -71
  2. data/VERSION +1 -1
  3. data/facebook-social_plugins.gemspec +20 -21
  4. data/lib/facebook-social_plugins.rb +23 -10
  5. data/lib/facebook-social_plugins/helper/open_graph.rb +43 -0
  6. data/lib/facebook-social_plugins/{script_helper.rb → helper/script.rb} +72 -26
  7. data/lib/facebook-social_plugins/helper/view.rb +27 -0
  8. data/lib/facebook-social_plugins/{activity_feed.rb → plugin/activity_feed.rb} +2 -2
  9. data/lib/facebook-social_plugins/{add_to_timeline.rb → plugin/add_to_timeline.rb} +2 -2
  10. data/lib/facebook-social_plugins/{button.rb → plugin/button.rb} +2 -4
  11. data/lib/facebook-social_plugins/{comments.rb → plugin/comments.rb} +2 -2
  12. data/lib/facebook-social_plugins/plugin/facepile.rb +22 -0
  13. data/lib/facebook-social_plugins/{like_box.rb → plugin/like_box.rb} +2 -2
  14. data/lib/facebook-social_plugins/{like_button.rb → plugin/like_button.rb} +1 -1
  15. data/lib/facebook-social_plugins/{live_stream.rb → plugin/live_stream.rb} +2 -2
  16. data/lib/facebook-social_plugins/{login_button.rb → plugin/login_button.rb} +2 -3
  17. data/lib/facebook-social_plugins/{recommendations_box.rb → plugin/recommendations_box.rb} +2 -2
  18. data/lib/facebook-social_plugins/{registration.rb → plugin/registration.rb} +2 -2
  19. data/lib/facebook-social_plugins/{send_button.rb → plugin/send_button.rb} +1 -1
  20. data/lib/facebook-social_plugins/{social_plugin.rb → plugin/social.rb} +2 -4
  21. data/lib/facebook-social_plugins/{subscribe_button.rb → plugin/subscribe_button.rb} +1 -1
  22. data/lib/facebook-social_plugins/{ui_helper.rb → plugin/ui_helper.rb} +1 -1
  23. data/lib/facebook-social_plugins/rails/engine.rb +3 -4
  24. data/spec/facebook-social_plugins/{og_meta_helper_spec.rb → open_graph_helper_spec.rb} +2 -2
  25. data/spec/facebook-social_plugins/script_helper_spec.rb +20 -10
  26. data/spec/facebook-social_plugins/view_helper_spec.rb +2 -2
  27. metadata +21 -22
  28. data/lib/facebook-social_plugins/analytics.rb +0 -13
  29. data/lib/facebook-social_plugins/facepile.rb +0 -37
  30. data/lib/facebook-social_plugins/open_graph/meta_helper.rb +0 -45
  31. data/lib/facebook-social_plugins/view_helper.rb +0 -74
data/README.rdoc CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  The Facebook Social plugins for Rails 3 consist of:
4
4
 
5
- * ViewHelper
6
- * ScriptHelper
5
+ * Helper::View
6
+ * Helper::Script
7
+ * Helper::OpenGraph # see https://developers.facebook.com/docs/opengraph/
7
8
 
8
- The `ViewHelper` contains methods for inserting the HTML5 <div> elements for Facebook social plugins
9
+ The `Helper::View` contains methods for inserting the HTML5 <div> elements for Facebook social plugins
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
+ The `Helper::Script` contains methods for inserting <script> snippets for Facebook integration, such as displaying the Social plugins with the Facebook layout/styling applied etc.
11
12
 
12
13
  == Social plugins
13
14
 
@@ -26,7 +27,7 @@ Currently the following Social plugins are included in this gem
26
27
  * Send Button
27
28
  * Subscribe Button
28
29
 
29
- (see below)
30
+ (see more info below)
30
31
 
31
32
  == Script Helpers
32
33
 
@@ -35,83 +36,39 @@ Currently the following Social plugins are included in this gem
35
36
 
36
37
  The async_init_script requires the Facebook app_id, fx '753632322' and the domain name of the app, fx 'www.example.com'. You can also specify the channel file (will default to channel file in vendor/assets of this gem)
37
38
 
38
- === Channel File
39
-
40
- The channel file addresses some issues with cross domain communication in certain browsers. The contents of the channel.html file can be just a single line:
41
-
42
- <script src="//connect.facebook.net/en_US/all.js"></script>
43
-
44
- === JavaScript SDK
45
-
46
- The JavaScript SDK provides a rich set of client-side functionality for accessing Facebook's server-side API calls. These include all of the features of the REST API, Graph API, and Dialogs. Further, it provides a mechanism for rendering of the XFBML versions of our Social Plugins, and a way for Canvas pages to communicate with Facebook.
47
-
48
- You will need an app ID to initialize the SDK, which you can obtain from the Developer App.
49
-
50
- For example usage, check out Facebook for Websites and the Authentication guide. We also have a JavaScript Test Console which allows you to test and debug common JavaScript SDK methods.
51
-
52
- The JavaScript SDK supports OAuth 2.0.
53
-
54
- *Loading*
55
-
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.
57
-
58
- <script>
59
- window.fbAsyncInit = function() {
60
- FB.init({
61
- appId : 'YOUR_APP_ID', // App ID
62
- channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
63
- status : true, // check login status
64
- cookie : true, // enable cookies to allow the server to access the session
65
- xfbml : true // parse XFBML
66
- });
67
-
68
- // Additional initialization code here
69
- };
70
-
71
- // Load the SDK Asynchronously
72
- (function(d){
73
- var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
74
- if (d.getElementById(id)) {return;}
75
- js = d.createElement('script'); js.id = id; js.async = true;
76
- js.src = "//connect.facebook.net/en_US/all.js";
77
- ref.parentNode.insertBefore(js, ref);
78
- }(document));
79
- </script>
80
- This code loads the SDK asynchronously so it does not block loading other elements of your page.
81
-
82
- *Localization*
83
-
84
- The JavaScript SDK is available in all locales that are supported by Facebook. This list of supported locales is available as an XML file. To change the locale of the SDK to match the locale of your site, change en_US to a supported locale code when loading the SDK. For example, if your site is in Spanish, using the following code to load the SDK will cause all Social Plugins to be rendered in Spanish.
85
-
86
- <script>
87
- (function(d){
88
- var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
89
- js = d.createElement('script'); js.id = id; js.async = true;
90
- js.src = "//connect.facebook.net/es_LA/all.js";
91
- d.getElementsByTagName('head')[0].appendChild(js);
92
- }(document));
93
- </script>
94
-
95
39
  === Configuration scripts*
96
40
 
97
41
  * fb_async_init_script(app_id, domain)
98
42
  * fb_channel_script(locale = :en_US)
99
43
 
100
- === Login and Logout
44
+ === Login
45
+
46
+ * fb_login_click_react(options, &block)
47
+ * fb_login_react(options, &block)
48
+ * fb_onlogin_react(options, &block)
49
+ * fb_onlogin_redirect_to(path, options)
50
+
51
+ === Logout
101
52
 
102
- * fb_logout_and_reload(options = {:ready => false, :selector => '#fb_logout_and_reload'})
103
- * fb_login_and_reload(options = {:ready => false, :selector => '#fb_login_and_reload'})
53
+ * fb_logout_click_react(options, &block)
54
+ * fb_logout_react(options, &block)
55
+ * fb_onlogout_react(options, &block)
56
+ * fb_onlogout_redirect_to(path, options)
57
+
58
+ * fb_login_and_react(options = {:selector => '#fb_login_and_reload'})
104
59
  * fb_logout_and_redirect_to(path, options = {:ready => false})
105
60
 
106
- == Open Graph Meta helper
61
+ == Open Graph Helper
107
62
 
108
63
  Convenience method to generate all header/meta tags for Facebook Open Graph
109
64
 
110
65
  * open_graph_meta(name, namespace, app_id, object_type, options = {})
111
66
 
112
- * og_header(name, namespace) - Open Graph <head> tag
67
+ *<head> tag helper*
68
+
69
+ * og_header(name, namespace)
113
70
 
114
- Open graph <meta> tag helpers
71
+ *<meta> tag helpers*
115
72
 
116
73
  * og_type(app_id, object_type)
117
74
  * og_title(title)
@@ -120,13 +77,13 @@ Open graph <meta> tag helpers
120
77
  * og_desc(desc)
121
78
  * fb_app_id(app_id)
122
79
 
123
- == Extras
80
+ == Extra View helpers
124
81
 
125
82
  * fb_analytics(app_id) # Facebook analytics meta tag
126
83
  * fb_activity(namespace, action) # Open Graph action to perform
127
84
 
128
- * fb_logout(script) # setup FB event handler to trigger on FB logout
129
- * fb_logout_and_redirect_to(path) # setup FB event handler to trigger on FB logout and redirect
85
+ * fb_onlogout(script) # setup FB event handler to trigger on FB logout
86
+ * fb_onlogout_redirect_to(path) # setup FB event handler to trigger on FB logout and redirect
130
87
 
131
88
  == Social plugins
132
89
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -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.3"
8
+ s.version = "0.2.0"
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"]
@@ -28,27 +28,26 @@ Gem::Specification.new do |s|
28
28
  "VERSION",
29
29
  "facebook-social_plugins.gemspec",
30
30
  "lib/facebook-social_plugins.rb",
31
- "lib/facebook-social_plugins/activity_feed.rb",
32
- "lib/facebook-social_plugins/add_to_timeline.rb",
33
- "lib/facebook-social_plugins/analytics.rb",
34
- "lib/facebook-social_plugins/button.rb",
35
- "lib/facebook-social_plugins/comments.rb",
36
- "lib/facebook-social_plugins/facepile.rb",
37
- "lib/facebook-social_plugins/like_box.rb",
38
- "lib/facebook-social_plugins/like_button.rb",
39
- "lib/facebook-social_plugins/live_stream.rb",
40
- "lib/facebook-social_plugins/login_button.rb",
41
- "lib/facebook-social_plugins/open_graph/meta_helper.rb",
31
+ "lib/facebook-social_plugins/helper/open_graph.rb",
32
+ "lib/facebook-social_plugins/helper/script.rb",
33
+ "lib/facebook-social_plugins/helper/view.rb",
34
+ "lib/facebook-social_plugins/plugin/activity_feed.rb",
35
+ "lib/facebook-social_plugins/plugin/add_to_timeline.rb",
36
+ "lib/facebook-social_plugins/plugin/button.rb",
37
+ "lib/facebook-social_plugins/plugin/comments.rb",
38
+ "lib/facebook-social_plugins/plugin/facepile.rb",
39
+ "lib/facebook-social_plugins/plugin/like_box.rb",
40
+ "lib/facebook-social_plugins/plugin/like_button.rb",
41
+ "lib/facebook-social_plugins/plugin/live_stream.rb",
42
+ "lib/facebook-social_plugins/plugin/login_button.rb",
43
+ "lib/facebook-social_plugins/plugin/recommendations_box.rb",
44
+ "lib/facebook-social_plugins/plugin/registration.rb",
45
+ "lib/facebook-social_plugins/plugin/send_button.rb",
46
+ "lib/facebook-social_plugins/plugin/social.rb",
47
+ "lib/facebook-social_plugins/plugin/subscribe_button.rb",
48
+ "lib/facebook-social_plugins/plugin/ui_helper.rb",
42
49
  "lib/facebook-social_plugins/rails/engine.rb",
43
- "lib/facebook-social_plugins/recommendations_box.rb",
44
- "lib/facebook-social_plugins/registration.rb",
45
- "lib/facebook-social_plugins/script_helper.rb",
46
- "lib/facebook-social_plugins/send_button.rb",
47
- "lib/facebook-social_plugins/social_plugin.rb",
48
- "lib/facebook-social_plugins/subscribe_button.rb",
49
- "lib/facebook-social_plugins/ui_helper.rb",
50
- "lib/facebook-social_plugins/view_helper.rb",
51
- "spec/facebook-social_plugins/og_meta_helper_spec.rb",
50
+ "spec/facebook-social_plugins/open_graph_helper_spec.rb",
52
51
  "spec/facebook-social_plugins/script_helper_spec.rb",
53
52
  "spec/facebook-social_plugins/view_helper_spec.rb",
54
53
  "spec/spec_helper.rb",
@@ -1,25 +1,38 @@
1
- require 'facebook-social_plugins/button'
1
+ module FacebookSocialPlugins
2
+ module Helper
3
+ end
2
4
 
3
- require 'facebook-social_plugins/analytics'
4
- require 'facebook-social_plugins/open_graph/meta_helper'
5
+ module Plugin
6
+ end
5
7
 
6
- module FacebookSocialPlugins
7
8
  def self.plugins
8
- ['activity_feed', 'add_to_timeline', 'comments', 'facepile', 'like_box', 'like_button',
9
- 'live_stream', 'login_button', 'recommendations_box', 'registration', 'send_button', 'subscribe_button']
9
+ [
10
+ 'activity_feed', 'add_to_timeline', 'comments', 'facepile',
11
+ 'like_box', 'like_button', 'live_stream', 'login_button', 'recommendations_box',
12
+ 'registration', 'send_button', 'subscribe_button'
13
+ ]
14
+ end
15
+
16
+ def self.all_plugins
17
+ ['ui_helper', 'social', 'button'] + plugins
10
18
  end
11
19
 
12
20
  def self.helpers
13
- ['script', 'view']
21
+ ['script', 'view', 'open_graph']
22
+ end
23
+
24
+ def self.plugin name, options
25
+ klass = "FacebookSocialPlugins::Plugin::#{name.to_s.camelize}".constantize
26
+ klass.new(options).render
14
27
  end
15
28
  end
16
29
 
17
- FacebookSocialPlugins.plugins.each do |name|
18
- require "facebook-social_plugins/#{name}"
30
+ FacebookSocialPlugins.all_plugins.each do |name|
31
+ require "facebook-social_plugins/plugin/#{name}"
19
32
  end
20
33
 
21
34
  FacebookSocialPlugins.helpers.each do |name|
22
- require "facebook-social_plugins/#{name}_helper"
35
+ require "facebook-social_plugins/helper/#{name}"
23
36
  end
24
37
 
25
38
  require 'facebook-social_plugins/rails/engine' if defined?(::Rails::Engine)
@@ -0,0 +1,43 @@
1
+ module FacebookSocialPlugins::Helper
2
+ module OpenGraph
3
+ def og_header name, namespace, &block
4
+ content = capture(&block)
5
+ content_tag :head, content, :prefix => "og: http://ogp.me/ns# og_#{name}: http://ogp.me/ns/apps/#{namespace}x#"
6
+ end
7
+
8
+ def fb_app_id app_id
9
+ content_tag :meta, '', :property => "fb:app_id", :content => app_id
10
+ end
11
+
12
+ def og_type namespace, object_type
13
+ content_tag :meta, '', :property => "og:type", :content => "#{namespace}:#{object_type}"
14
+ end
15
+
16
+ def og_title title
17
+ content_tag :meta, '', :property => "og:title", :content => title
18
+ end
19
+
20
+ def og_image href
21
+ content_tag :meta, '', :property => "og:image", :content => href
22
+ end
23
+
24
+ def og_desc desc
25
+ content_tag :meta, '', :property => "og:description", :content => desc
26
+ end
27
+
28
+ def og_url href
29
+ content_tag :meta, '', :property => "og:url", :content => href
30
+ end
31
+
32
+ def open_graph_meta name, namespace, app_id, object_type, options = {}
33
+ content = fb_app_id(app_id) + og_type(namespace, object_type)
34
+ content << og_title(options[:title]) if options[:title]
35
+ content << og_image(options[:img]) if options[:img]
36
+ content << og_image(options[:desc]) if options[:desc]
37
+ content << og_image(options[:url]) if options[:url]
38
+ og_header(name, namespace) do
39
+ content
40
+ end
41
+ end
42
+ end
43
+ end
@@ -1,44 +1,62 @@
1
- module FacebookSocialPlugins
2
- module ScriptHelper
1
+ module FacebookSocialPlugins::Helper
2
+ module Script
3
3
 
4
4
  # can be used inside a js.erb file or similar
5
- def fb_login_and_react options = {:ready => false, :selector => '#fb_login', :success => 'reload();', :failure => ''}
5
+ def fb_login_click_react options = {:selector => '#fb_login'}, &block
6
6
  selector = options[:selector] || '#fb_login'
7
- success = options[:success] || '// on success'
8
- failure = options[:failure] || '// on failure'
7
+ block_content = yield if block
8
+ on_success = options[:on_success] || block_content || '// on success'
9
+ on_fail = options[:on_fail] || '// on failure'
10
+
9
11
  script = %Q{$('#{selector}').click(function() {
10
- FB.login(function(response) {
11
- if (response.authResponse) {
12
- #{success}
13
- } else {
14
- #{failure}
15
- }
16
- });
12
+ #{fb_login_react(options, &block)}
17
13
  return false;
18
- }#{scope_permissions options[:scope]}
14
+ }
19
15
  }
20
16
  options[:ready] ? wrap_ready(script) : script
21
17
  end
22
18
 
23
- def fb_logout_and_react options = {:ready => false, :selector => '#fb_logout', :success => 'reload();', :failure => ''}
24
- selector = options[:selector] || '#fb_logout'
25
- success = options[:success] || '// on success'
26
- failure = options[:failure] || '// on failure'
19
+ def fb_login_react options = {}, &block
20
+ block_content = yield if block
21
+ on_success = options[:on_success] || block_content || '// on success'
22
+ on_fail = options[:on_fail] || '// on failure'
23
+
24
+ script = %Q{FB.login(function(response) {
25
+ if (response.authResponse) {
26
+ #{on_success}
27
+ } else {
28
+ #{on_fail}
29
+ }
30
+ }#{scope_permissions options[:scope]});
31
+ }
32
+ options[:ready] ? wrap_ready(script) : script
33
+ end
34
+
35
+
36
+ def fb_logout_click_react options = {:selector => '#fb_logout'}, &block
37
+ selector = options[:selector] || '#fb_logout'
38
+ block_content = yield if block
39
+ on_done = options[:on_done] || block_content || '// on done'
27
40
  script = %Q{$('#{selector}').click(function() {
28
- FB.login(function(response) {
29
- if (response.authResponse) {
30
- #{success}
31
- } else {
32
- #{failure}
33
- }
34
- });
41
+ #{fb_logout_react(:on_done => on_done)}
35
42
  return false;
36
43
  }
37
44
  }
38
45
  options[:ready] ? wrap_ready(script) : script
39
46
  end
40
47
 
41
- def fb_logout_and_redirect_to path, options = {:ready => false}
48
+ def fb_logout_react options = {}, &block
49
+ block_content = yield if block
50
+ on_done = options[:on_done] || block_content || '// on done'
51
+
52
+ script = %Q{FB.logout(function(response) {
53
+ #{on_done}
54
+ });
55
+ }
56
+ options[:ready] ? wrap_ready(script) : script
57
+ end
58
+
59
+ def fb_onlogout_redirect_to path, options = {}
42
60
  script = %Q{FB.Event.subscribe("auth.logout", function() {
43
61
  window.location = '#{path}'
44
62
  });
@@ -46,6 +64,34 @@ module FacebookSocialPlugins
46
64
  options[:ready] ? wrap_ready(script) : script
47
65
  end
48
66
 
67
+ def fb_onlogout_react options = {}, &block
68
+ block_content = yield if block
69
+ reaction = options[:reaction] || block_content || ' // on logout'
70
+ script = %Q{FB.Event.subscribe("auth.logout", function() {
71
+ #{reaction}
72
+ });
73
+ }
74
+ options[:ready] ? wrap_ready(script) : script
75
+ end
76
+
77
+ def fb_onlogin_redirect_to path, options = {}
78
+ script = %Q{FB.Event.subscribe("auth.login", function() {
79
+ window.location = '#{path}'
80
+ });
81
+ }
82
+ options[:ready] ? wrap_ready(script) : script
83
+ end
84
+
85
+ def fb_onlogin_react options = {}, &block
86
+ block_content = yield if block
87
+ reaction = options[:reaction] || block_content || ' // on login'
88
+ script = %Q{FB.Event.subscribe("auth.login", function() {
89
+ #{reaction}
90
+ });
91
+ }
92
+ options[:ready] ? wrap_ready(script) : script
93
+ end
94
+
49
95
 
50
96
  # app_id - facebook app id, a number/string, fx '753632322'
51
97
  # domain - fx www.example.com
@@ -110,4 +156,4 @@ module FacebookSocialPlugins
110
156
  "//connect.facebook.net/#{locale}/all.js"
111
157
  end
112
158
  end
113
- end
159
+ end
@@ -0,0 +1,27 @@
1
+ module FacebookSocialPlugins::Helper
2
+ module View
3
+ def fb_root
4
+ content_tag :div, '', :class => "fb-root"
5
+ end
6
+
7
+ def fb_analytics app_id
8
+ content_tag :meta, '', :property => "fb:admins", :content => app_id
9
+ end
10
+
11
+ def fb_activity namespace, action
12
+ content_tag :div, '', :class => "fb-activity", :'data-actions' => "#{namespace}:#{action}"
13
+ end
14
+
15
+ FacebookSocialPlugins.plugins.each do |name|
16
+ define_method :"fb_#{name}" do |options = {}|
17
+ FacebookSocialPlugins.plugin name, options
18
+ end
19
+ end
20
+
21
+ def fb_logout_button options = {}
22
+ content_tag :a, '', {:id => 'fb_logout_and_reload', :href => '#'}.merge(options[:html] || {}) do
23
+ content_tag(:img, '', :id => 'fb_logout_image', :src => "/assets/fb_logout_#{options[:size] || :small}.gif", :alt => "Facebook Logout").html_safe
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
- module FacebookSocialPlugins
2
- class ActivityFeed < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class ActivityFeed < Social
3
3
  def initialize options = {}
4
4
  super
5
5
  end
@@ -1,6 +1,6 @@
1
- module FacebookSocialPlugins
1
+ module FacebookSocialPlugins::Plugin
2
2
  # Also see AddToTimeline.txt of this gem for example of using OpenGraph with this feature.
3
- class AddToTimeline < SocialPlugin
3
+ class AddToTimeline < Social
4
4
  def initialize options = {}
5
5
  super
6
6
  end
@@ -1,7 +1,5 @@
1
- require 'facebook-social_plugins/social_plugin'
2
-
3
- module FacebookSocialPlugins
4
- class Button < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class Button < Social
5
3
  def initialize options = {}
6
4
  super
7
5
  end
@@ -1,5 +1,5 @@
1
- module FacebookSocialPlugins
2
- class Comments < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class Comments < Social
3
3
  def initialize options = {}
4
4
  super
5
5
  end
@@ -0,0 +1,22 @@
1
+ module FacebookSocialPlugins::Plugin
2
+ class Facepile < Social
3
+ def initialize options = {}
4
+ super
5
+ end
6
+
7
+ def plugin_class
8
+ 'fb-facepile'
9
+ end
10
+
11
+ # event-app-id - the app id for the event
12
+ # action - the action to perform, fx 'og_recipebox:planning_to_make'
13
+ # width - the width of the plugin in pixels. Minimum recommended width: 400px.
14
+ # href - the referenced page
15
+ # max_rows - max rows to display, 1-10 normally
16
+ def attributes
17
+ super.merge(:'event-app-id' => :string, :action => :string, :href => :string,
18
+ :max_rows => :integer, :size => sizes, :width => :integer
19
+ )
20
+ end
21
+ end
22
+ end
@@ -1,5 +1,5 @@
1
- module FacebookSocialPlugins
2
- class LikeBox < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class LikeBox < Social
3
3
  def initialize options = {}
4
4
  super
5
5
  end
@@ -1,4 +1,4 @@
1
- module FacebookSocialPlugins
1
+ module FacebookSocialPlugins::Plugin
2
2
  class LikeButton < Button
3
3
  def initialize options = {}
4
4
  super
@@ -1,5 +1,5 @@
1
- module FacebookSocialPlugins
2
- class LiveStream < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class LiveStream < Social
3
3
  def initialize options = {}
4
4
  super
5
5
  end
@@ -1,6 +1,5 @@
1
- module FacebookSocialPlugins
2
- # <div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>
3
- class LoginButton < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class LoginButton < Social
4
3
  def initialize options = {}
5
4
  super
6
5
  end
@@ -1,5 +1,5 @@
1
- module FacebookSocialPlugins
2
- class RecommendationsBox < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class RecommendationsBox < Social
3
3
  def initialize options = {}
4
4
  super
5
5
  end
@@ -1,5 +1,5 @@
1
- module FacebookSocialPlugins
2
- class Registration < SocialPlugin
1
+ module FacebookSocialPlugins::Plugin
2
+ class Registration < Social
3
3
  attr_reader :named_fields
4
4
 
5
5
  # <fb:registration
@@ -1,4 +1,4 @@
1
- module FacebookSocialPlugins
1
+ module FacebookSocialPlugins::Plugin
2
2
  class SendButton < Button
3
3
  def initialize options = {}
4
4
  super
@@ -1,7 +1,5 @@
1
- require 'facebook-social_plugins/ui_helper'
2
-
3
- module FacebookSocialPlugins
4
- class SocialPlugin < UiHelper
1
+ module FacebookSocialPlugins::Plugin
2
+ class Social < UiHelper
5
3
 
6
4
  attr_reader :options
7
5
 
@@ -1,4 +1,4 @@
1
- module FacebookSocialPlugins
1
+ module FacebookSocialPlugins::Plugin
2
2
  class SubscribeButton < Button
3
3
  def initialize options = {}
4
4
  super
@@ -1,4 +1,4 @@
1
- module FacebookSocialPlugins
1
+ module FacebookSocialPlugins::Plugin
2
2
  class UiHelper
3
3
  include ActionView::Helpers::TagHelper,
4
4
  ActionView::Helpers::UrlHelper,
@@ -2,10 +2,9 @@ module FacebookSocialPlugins
2
2
  module Rails
3
3
  class Engine < ::Rails::Engine
4
4
  initializer 'setup rails' do
5
- ActionView::Base.send :include, FacebookSocialPlugins::ViewHelper
6
- ActionView::Base.send :include, FacebookSocialPlugins::ScriptHelper
7
-
8
- ActionView::Base.send :include, FacebookSocialPlugins::OpenGraph::MetaHelper
5
+ FacebookSocialPlugins.helpers.each do |helper|
6
+ ActionView::Base.send :include, "FacebookSocialPlugins::Helper::#{helper.to_s.camelize}".constantize
7
+ end
9
8
  end
10
9
  end
11
10
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FacebookSocialPlugins::OpenGraph::MetaHelper do
3
+ describe FacebookSocialPlugins::Helper::OpenGraph do
4
4
  include ControllerTestHelpers,
5
- FacebookSocialPlugins::OpenGraph::MetaHelper
5
+ FacebookSocialPlugins::Helper::OpenGraph
6
6
 
7
7
  describe 'OpenGraph Meta helper' do
8
8
  it "should write Open Graph meta tags " do
@@ -34,9 +34,9 @@ fb_script_es = %Q{
34
34
  }
35
35
 
36
36
 
37
- describe FacebookSocialPlugins::ScriptHelper do
37
+ describe FacebookSocialPlugins::Helper::Script do
38
38
  include ControllerTestHelpers,
39
- FacebookSocialPlugins::ScriptHelper
39
+ FacebookSocialPlugins::Helper::Script
40
40
 
41
41
  describe '#async_init_script' do
42
42
  it "should create async init script" do
@@ -58,22 +58,32 @@ describe FacebookSocialPlugins::ScriptHelper do
58
58
  end
59
59
 
60
60
  describe '#fb_login_and_react' do
61
- it 'should work' do
62
- output = fb_login_and_react :ready => true, :selector => '#fb_login', :scope => 'email,user_likes'
63
- output.should == "$(function() {\n\t\t$('#fb_login').click(function() { \n\t\tFB.login(function(response) { \n\t\t\tif (response.authResponse) {\n\t\t\t\t// on success\n\t\t\t} else {\n\t\t\t\t// on failure\n\t\t\t}\t\t\t\n\t\t}); \n\t\treturn false;\n }, {scope: 'email,user_likes'}\n\n\t}\n"
61
+ it 'should display basic login script with scoped permissions' do
62
+ output = fb_login_click_react :ready => true, :selector => '#fb_login', :scope => 'email,user_likes'
63
+ output.should == "$(function() {\n\t\t$('#fb_login').click(function() { \n\t\t$(function() {\n\t\tFB.login(function(response) { \n\t\tif (response.authResponse) {\n\t\t\t// on success\n\t\t} else {\n\t\t\t// on failure\n\t\t}\t\t\t\n\t}, {scope: 'email,user_likes'}); \n\n\t}\n\n\t\treturn false;\n }\n\n\t}\n"
64
+ end
65
+
66
+ it 'should display basic login script with console.log for success and failure' do
67
+ output = fb_login_click_react :ready => true, :on_success => "console.log('logged in to facebook');", :on_fail => "console.log('facebook login failure');"
68
+ output.should == "$(function() {\n\t\t$('#fb_login').click(function() { \n\t\t$(function() {\n\t\tFB.login(function(response) { \n\t\tif (response.authResponse) {\n\t\t\tconsole.log('logged in to facebook');\n\t\t} else {\n\t\t\tconsole.log('facebook login failure');\n\t\t}\t\t\t\n\t}); \n\n\t}\n\n\t\treturn false;\n }\n\n\t}\n"
64
69
  end
65
70
  end
66
71
 
67
72
  describe '#fb_logout_and_react' do
68
- it 'should work' do
69
- output = fb_logout_and_react :ready => true, :failure => "console.log('failed FB logout');"
70
- output.should == "$(function() {\n\t\t$('#fb_logout').click(function() { \n\t\tFB.login(function(response) { \n\t\t\tif (response.authResponse) {\n\t\t\t\t// on success\n\t\t\t} else {\n\t\t\t\tconsole.log('failed FB logout');\n\t\t\t}\t\t\t\n\t\t}); \n\t\treturn false;\n \t}\n\n\t}\n"
73
+ it 'should render fb logout script with no reaction' do
74
+ output = fb_logout_click_react :ready => true
75
+ output.should == "$(function() {\n\t\t$('#fb_logout').click(function() { \n\t\tFB.logout(function(response) { \n\t\t// on done\n\t});\n\n\t\treturn false;\n \t}\n\n\t}\n"
76
+ end
77
+
78
+ it 'should render fb logout script with console.log after done' do
79
+ output = fb_logout_click_react :ready => true, :on_done => "console.log('logged out from facebook');"
80
+ output.should == "$(function() {\n\t\t$('#fb_logout').click(function() { \n\t\tFB.logout(function(response) { \n\t\tconsole.log('logged out from facebook');\n\t});\n\n\t\treturn false;\n \t}\n\n\t}\n"
71
81
  end
72
82
  end
73
83
 
74
- describe '#fb_logout_and_redirect_to' do
84
+ describe '#fb_onlogout_redirect_to' do
75
85
  it 'should work' do
76
- output = fb_logout_and_redirect_to('facebook/logout', :ready => true)
86
+ output = fb_onlogout_redirect_to('facebook/logout', :ready => true)
77
87
  output.should == "$(function() {\n\t\tFB.Event.subscribe(\"auth.logout\", function() { \n\twindow.location = 'facebook/logout' \n\t}); \n\n\t}\n"
78
88
  end
79
89
  end
@@ -1,8 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FacebookSocialPlugins::ViewHelper do
3
+ describe FacebookSocialPlugins::Helper::View do
4
4
  include ControllerTestHelpers,
5
- FacebookSocialPlugins::ViewHelper
5
+ FacebookSocialPlugins::Helper::View
6
6
 
7
7
  describe 'Social plugin' do
8
8
  it "should not create plugin if unknown attribute is encountered" do
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.3
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -158,27 +158,26 @@ files:
158
158
  - VERSION
159
159
  - facebook-social_plugins.gemspec
160
160
  - lib/facebook-social_plugins.rb
161
- - lib/facebook-social_plugins/activity_feed.rb
162
- - lib/facebook-social_plugins/add_to_timeline.rb
163
- - lib/facebook-social_plugins/analytics.rb
164
- - lib/facebook-social_plugins/button.rb
165
- - lib/facebook-social_plugins/comments.rb
166
- - lib/facebook-social_plugins/facepile.rb
167
- - lib/facebook-social_plugins/like_box.rb
168
- - lib/facebook-social_plugins/like_button.rb
169
- - lib/facebook-social_plugins/live_stream.rb
170
- - lib/facebook-social_plugins/login_button.rb
171
- - lib/facebook-social_plugins/open_graph/meta_helper.rb
161
+ - lib/facebook-social_plugins/helper/open_graph.rb
162
+ - lib/facebook-social_plugins/helper/script.rb
163
+ - lib/facebook-social_plugins/helper/view.rb
164
+ - lib/facebook-social_plugins/plugin/activity_feed.rb
165
+ - lib/facebook-social_plugins/plugin/add_to_timeline.rb
166
+ - lib/facebook-social_plugins/plugin/button.rb
167
+ - lib/facebook-social_plugins/plugin/comments.rb
168
+ - lib/facebook-social_plugins/plugin/facepile.rb
169
+ - lib/facebook-social_plugins/plugin/like_box.rb
170
+ - lib/facebook-social_plugins/plugin/like_button.rb
171
+ - lib/facebook-social_plugins/plugin/live_stream.rb
172
+ - lib/facebook-social_plugins/plugin/login_button.rb
173
+ - lib/facebook-social_plugins/plugin/recommendations_box.rb
174
+ - lib/facebook-social_plugins/plugin/registration.rb
175
+ - lib/facebook-social_plugins/plugin/send_button.rb
176
+ - lib/facebook-social_plugins/plugin/social.rb
177
+ - lib/facebook-social_plugins/plugin/subscribe_button.rb
178
+ - lib/facebook-social_plugins/plugin/ui_helper.rb
172
179
  - lib/facebook-social_plugins/rails/engine.rb
173
- - lib/facebook-social_plugins/recommendations_box.rb
174
- - lib/facebook-social_plugins/registration.rb
175
- - lib/facebook-social_plugins/script_helper.rb
176
- - lib/facebook-social_plugins/send_button.rb
177
- - lib/facebook-social_plugins/social_plugin.rb
178
- - lib/facebook-social_plugins/subscribe_button.rb
179
- - lib/facebook-social_plugins/ui_helper.rb
180
- - lib/facebook-social_plugins/view_helper.rb
181
- - spec/facebook-social_plugins/og_meta_helper_spec.rb
180
+ - spec/facebook-social_plugins/open_graph_helper_spec.rb
182
181
  - spec/facebook-social_plugins/script_helper_spec.rb
183
182
  - spec/facebook-social_plugins/view_helper_spec.rb
184
183
  - spec/spec_helper.rb
@@ -200,7 +199,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
200
199
  version: '0'
201
200
  segments:
202
201
  - 0
203
- hash: -524476929099474942
202
+ hash: 4144968619467304781
204
203
  required_rubygems_version: !ruby/object:Gem::Requirement
205
204
  none: false
206
205
  requirements:
@@ -1,13 +0,0 @@
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
@@ -1,37 +0,0 @@
1
- module FacebookSocialPlugins
2
-
3
- # The Facepile plugin displays the Facebook profile pictures of users who have connected with your
4
- # page via a global or custom action, or can also be configured to display users that have
5
- # signed up for your site.
6
-
7
- # If you want to display users who have connected to your page via an action, specify with the action parameter
8
-
9
- # <div class="fb-facepile" data-href="http://developers.facebook.com"
10
- # data-action="join" data-size="large" data-max-rows="1" data-width="300"
11
- # data-colorscheme="dark">
12
- # </div>
13
-
14
- # To display users who have liked your page, specify the URL of your page as the href parameter.
15
- # To display users who have signed up for your site, specify your application id as the app_id
16
-
17
- class Facepile < SocialPlugin
18
- def initialize options = {}
19
- super
20
- end
21
-
22
- def plugin_class
23
- 'fb-facepile'
24
- end
25
-
26
- # event-app-id - the app id for the event
27
- # action - the action to perform, fx 'og_recipebox:planning_to_make'
28
- # width - the width of the plugin in pixels. Minimum recommended width: 400px.
29
- # href - the referenced page
30
- # max_rows - max rows to display, 1-10 normally
31
- def attributes
32
- super.merge(:'event-app-id' => :string, :action => :string, :href => :string,
33
- :max_rows => :integer, :size => sizes, :width => :integer
34
- )
35
- end
36
- end
37
- end
@@ -1,45 +0,0 @@
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
@@ -1,74 +0,0 @@
1
- module FacebookSocialPlugins
2
- module ViewHelper
3
- def fb_root
4
- content_tag :div, '', :class => "fb-root"
5
- end
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
-
15
- def fb_activity_feed options = {}
16
- FacebookSocialPlugins::ActivityFeed.new(options).render
17
- end
18
-
19
- def fb_add_to_timeline options = {}
20
- FacebookSocialPlugins::AddToTimeline.new(options).render
21
- end
22
-
23
- def fb_comments options = {}
24
- FacebookSocialPlugins::Comments.new(options).render
25
- end
26
-
27
- def fb_facepile options = {}
28
- FacebookSocialPlugins::Facepile.new(options).render
29
- end
30
-
31
- def fb_like_box options = {}
32
- FacebookSocialPlugins::LikeBox.new(options).render
33
- end
34
-
35
- def fb_like_button options = {}
36
- FacebookSocialPlugins::LikeButton.new(options).render
37
- end
38
-
39
- def fb_live_stream options = {}
40
- FacebookSocialPlugins::LiveStream.new(options).render
41
- end
42
-
43
- def fb_login_button options = {}
44
- FacebookSocialPlugins::LoginButton.new(options).render
45
- end
46
-
47
- def fb_logout_button options = {}
48
- content_tag :a, '', {:id => 'fb_logout_and_reload', :href => '#'}.merge(options[:html] || {}) do
49
- content_tag(:img, '', :id => 'fb_logout_image', :src => "/assets/fb_logout_#{options[:size] || :small}.gif", :alt => "Facebook Logout").html_safe
50
- end
51
- end
52
-
53
- def fb_logout &block
54
- content_tag :script, %Q{FB.Event.subscribe("auth.logout", function() { #{yield} });}
55
- end
56
-
57
- def fb_recommendations_box options = {}
58
- FacebookSocialPlugins::RecommendationsBox.new(options).render
59
- end
60
-
61
- def fb_registration options = {}
62
- FacebookSocialPlugins::Registration.new(options).render
63
- end
64
-
65
- def fb_send_button options = {}
66
- FacebookSocialPlugins::SendButton.new(options).render
67
- end
68
-
69
- def fb_subscribe_button options = {}
70
- FacebookSocialPlugins::SubscribeButton.new(options).render
71
- end
72
- end
73
- end
74
-