Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

major refactoring and improved script apis - bumped version

  • Loading branch information...
commit a22b7efddbbb24f0452cda0d60acc6910c199996 1 parent 6fb840c
@kristianmandrup authored
Showing with 267 additions and 324 deletions.
  1. +28 −71 README.rdoc
  2. +1 −1  VERSION
  3. +23 −10 lib/facebook-social_plugins.rb
  4. +0 −13 lib/facebook-social_plugins/analytics.rb
  5. +0 −37 lib/facebook-social_plugins/facepile.rb
  6. +43 −0 lib/facebook-social_plugins/helper/open_graph.rb
  7. +72 −26 lib/facebook-social_plugins/{script_helper.rb → helper/script.rb}
  8. +27 −0 lib/facebook-social_plugins/helper/view.rb
  9. +0 −45 lib/facebook-social_plugins/open_graph/meta_helper.rb
  10. +2 −2 lib/facebook-social_plugins/{ → plugin}/activity_feed.rb
  11. +2 −2 lib/facebook-social_plugins/{ → plugin}/add_to_timeline.rb
  12. +2 −4 lib/facebook-social_plugins/{ → plugin}/button.rb
  13. +2 −2 lib/facebook-social_plugins/{ → plugin}/comments.rb
  14. +22 −0 lib/facebook-social_plugins/plugin/facepile.rb
  15. +2 −2 lib/facebook-social_plugins/{ → plugin}/like_box.rb
  16. +1 −1  lib/facebook-social_plugins/{ → plugin}/like_button.rb
  17. +2 −2 lib/facebook-social_plugins/{ → plugin}/live_stream.rb
  18. +2 −3 lib/facebook-social_plugins/{ → plugin}/login_button.rb
  19. +2 −2 lib/facebook-social_plugins/{ → plugin}/recommendations_box.rb
  20. +2 −2 lib/facebook-social_plugins/{ → plugin}/registration.rb
  21. +1 −1  lib/facebook-social_plugins/{ → plugin}/send_button.rb
  22. +2 −4 lib/facebook-social_plugins/{social_plugin.rb → plugin/social.rb}
  23. +1 −1  lib/facebook-social_plugins/{ → plugin}/subscribe_button.rb
  24. +1 −1  lib/facebook-social_plugins/{ → plugin}/ui_helper.rb
  25. +3 −4 lib/facebook-social_plugins/rails/engine.rb
  26. +0 −74 lib/facebook-social_plugins/view_helper.rb
  27. +2 −2 spec/facebook-social_plugins/{og_meta_helper_spec.rb → open_graph_helper_spec.rb}
  28. +20 −10 spec/facebook-social_plugins/script_helper_spec.rb
  29. +2 −2 spec/facebook-social_plugins/view_helper_spec.rb
View
99 README.rdoc
@@ -2,12 +2,13 @@
The Facebook Social plugins for Rails 3 consist of:
-* ViewHelper
-* ScriptHelper
+* Helper::View
+* Helper::Script
+* Helper::OpenGraph # see https://developers.facebook.com/docs/opengraph/
-The `ViewHelper` contains methods for inserting the HTML5 <div> elements for Facebook social plugins
+The `Helper::View` contains methods for inserting the HTML5 <div> elements for Facebook social plugins
-The `ScriptHelper` contains methods for inserting <script> snippets for Facebook integration, such as displaying the Social plugins with the Facebook layout/styling applied etc.
+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.
== Social plugins
@@ -26,7 +27,7 @@ Currently the following Social plugins are included in this gem
* Send Button
* Subscribe Button
-(see below)
+(see more info below)
== Script Helpers
@@ -35,83 +36,39 @@ Currently the following Social plugins are included in this gem
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)
-=== Channel File
-
-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:
-
-<script src="//connect.facebook.net/en_US/all.js"></script>
-
-=== JavaScript SDK
-
-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.
-
-You will need an app ID to initialize the SDK, which you can obtain from the Developer App.
-
-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.
-
-The JavaScript SDK supports OAuth 2.0.
-
-*Loading*
-
-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.
-
-<script>
- window.fbAsyncInit = function() {
- FB.init({
- appId : 'YOUR_APP_ID', // App ID
- channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
- status : true, // check login status
- cookie : true, // enable cookies to allow the server to access the session
- xfbml : true // parse XFBML
- });
-
- // Additional initialization code here
- };
-
- // Load the SDK Asynchronously
- (function(d){
- var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
- if (d.getElementById(id)) {return;}
- js = d.createElement('script'); js.id = id; js.async = true;
- js.src = "//connect.facebook.net/en_US/all.js";
- ref.parentNode.insertBefore(js, ref);
- }(document));
-</script>
-This code loads the SDK asynchronously so it does not block loading other elements of your page.
-
-*Localization*
-
-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.
-
-<script>
- (function(d){
- var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
- js = d.createElement('script'); js.id = id; js.async = true;
- js.src = "//connect.facebook.net/es_LA/all.js";
- d.getElementsByTagName('head')[0].appendChild(js);
- }(document));
-</script>
-
=== Configuration scripts*
* fb_async_init_script(app_id, domain)
* fb_channel_script(locale = :en_US)
-=== Login and Logout
+=== Login
+
+* fb_login_click_react(options, &block)
+* fb_login_react(options, &block)
+* fb_onlogin_react(options, &block)
+* fb_onlogin_redirect_to(path, options)
+
+=== Logout
-* fb_logout_and_reload(options = {:ready => false, :selector => '#fb_logout_and_reload'})
-* fb_login_and_reload(options = {:ready => false, :selector => '#fb_login_and_reload'})
+* fb_logout_click_react(options, &block)
+* fb_logout_react(options, &block)
+* fb_onlogout_react(options, &block)
+* fb_onlogout_redirect_to(path, options)
+
+* fb_login_and_react(options = {:selector => '#fb_login_and_reload'})
* fb_logout_and_redirect_to(path, options = {:ready => false})
-== Open Graph Meta helper
+== Open Graph Helper
Convenience method to generate all header/meta tags for Facebook Open Graph
* open_graph_meta(name, namespace, app_id, object_type, options = {})
-* og_header(name, namespace) - Open Graph <head> tag
+*<head> tag helper*
+
+* og_header(name, namespace)
-Open graph <meta> tag helpers
+*<meta> tag helpers*
* og_type(app_id, object_type)
* og_title(title)
@@ -120,13 +77,13 @@ Open graph <meta> tag helpers
* og_desc(desc)
* fb_app_id(app_id)
-== Extras
+== Extra View helpers
* fb_analytics(app_id) # Facebook analytics meta tag
* fb_activity(namespace, action) # Open Graph action to perform
-* fb_logout(script) # setup FB event handler to trigger on FB logout
-* fb_logout_and_redirect_to(path) # setup FB event handler to trigger on FB logout and redirect
+* fb_onlogout(script) # setup FB event handler to trigger on FB logout
+* fb_onlogout_redirect_to(path) # setup FB event handler to trigger on FB logout and redirect
== Social plugins
View
2  VERSION
@@ -1 +1 @@
-0.1.3
+0.2.0
View
33 lib/facebook-social_plugins.rb
@@ -1,25 +1,38 @@
-require 'facebook-social_plugins/button'
+module FacebookSocialPlugins
+ module Helper
+ end
-require 'facebook-social_plugins/analytics'
-require 'facebook-social_plugins/open_graph/meta_helper'
+ module Plugin
+ end
-module FacebookSocialPlugins
def self.plugins
- ['activity_feed', 'add_to_timeline', 'comments', 'facepile', 'like_box', 'like_button',
- 'live_stream', 'login_button', 'recommendations_box', 'registration', 'send_button', 'subscribe_button']
+ [
+ 'activity_feed', 'add_to_timeline', 'comments', 'facepile',
+ 'like_box', 'like_button', 'live_stream', 'login_button', 'recommendations_box',
+ 'registration', 'send_button', 'subscribe_button'
+ ]
+ end
+
+ def self.all_plugins
+ ['ui_helper', 'social', 'button'] + plugins
end
def self.helpers
- ['script', 'view']
+ ['script', 'view', 'open_graph']
+ end
+
+ def self.plugin name, options
+ klass = "FacebookSocialPlugins::Plugin::#{name.to_s.camelize}".constantize
+ klass.new(options).render
end
end
-FacebookSocialPlugins.plugins.each do |name|
- require "facebook-social_plugins/#{name}"
+FacebookSocialPlugins.all_plugins.each do |name|
+ require "facebook-social_plugins/plugin/#{name}"
end
FacebookSocialPlugins.helpers.each do |name|
- require "facebook-social_plugins/#{name}_helper"
+ require "facebook-social_plugins/helper/#{name}"
end
require 'facebook-social_plugins/rails/engine' if defined?(::Rails::Engine)
View
13 lib/facebook-social_plugins/analytics.rb
@@ -1,13 +0,0 @@
-module FacebookSocialPlugins
- class Analytics < UiHelper
- attr_reader :app_id
-
- def initialize app_id
- @app_id = app_id
- end
-
- def render
- content_tag :meta, '', :property => "fb:admins", :content => app_id
- end
- end
-end
View
37 lib/facebook-social_plugins/facepile.rb
@@ -1,37 +0,0 @@
-module FacebookSocialPlugins
-
- # The Facepile plugin displays the Facebook profile pictures of users who have connected with your
- # page via a global or custom action, or can also be configured to display users that have
- # signed up for your site.
-
- # If you want to display users who have connected to your page via an action, specify with the action parameter
-
- # <div class="fb-facepile" data-href="http://developers.facebook.com"
- # data-action="join" data-size="large" data-max-rows="1" data-width="300"
- # data-colorscheme="dark">
- # </div>
-
- # To display users who have liked your page, specify the URL of your page as the href parameter.
- # To display users who have signed up for your site, specify your application id as the app_id
-
- class Facepile < SocialPlugin
- def initialize options = {}
- super
- end
-
- def plugin_class
- 'fb-facepile'
- end
-
- # event-app-id - the app id for the event
- # action - the action to perform, fx 'og_recipebox:planning_to_make'
- # width - the width of the plugin in pixels. Minimum recommended width: 400px.
- # href - the referenced page
- # max_rows - max rows to display, 1-10 normally
- def attributes
- super.merge(:'event-app-id' => :string, :action => :string, :href => :string,
- :max_rows => :integer, :size => sizes, :width => :integer
- )
- end
- end
-end
View
43 lib/facebook-social_plugins/helper/open_graph.rb
@@ -0,0 +1,43 @@
+module FacebookSocialPlugins::Helper
+ module OpenGraph
+ def og_header name, namespace, &block
+ content = capture(&block)
+ content_tag :head, content, :prefix => "og: http://ogp.me/ns# og_#{name}: http://ogp.me/ns/apps/#{namespace}x#"
+ end
+
+ def fb_app_id app_id
+ content_tag :meta, '', :property => "fb:app_id", :content => app_id
+ end
+
+ def og_type namespace, object_type
+ content_tag :meta, '', :property => "og:type", :content => "#{namespace}:#{object_type}"
+ end
+
+ def og_title title
+ content_tag :meta, '', :property => "og:title", :content => title
+ end
+
+ def og_image href
+ content_tag :meta, '', :property => "og:image", :content => href
+ end
+
+ def og_desc desc
+ content_tag :meta, '', :property => "og:description", :content => desc
+ end
+
+ def og_url href
+ content_tag :meta, '', :property => "og:url", :content => href
+ end
+
+ def open_graph_meta name, namespace, app_id, object_type, options = {}
+ content = fb_app_id(app_id) + og_type(namespace, object_type)
+ content << og_title(options[:title]) if options[:title]
+ content << og_image(options[:img]) if options[:img]
+ content << og_image(options[:desc]) if options[:desc]
+ content << og_image(options[:url]) if options[:url]
+ og_header(name, namespace) do
+ content
+ end
+ end
+ end
+end
View
98 lib/facebook-social_plugins/script_helper.rb → lib/facebook-social_plugins/helper/script.rb
@@ -1,44 +1,62 @@
-module FacebookSocialPlugins
- module ScriptHelper
+module FacebookSocialPlugins::Helper
+ module Script
# can be used inside a js.erb file or similar
- def fb_login_and_react options = {:ready => false, :selector => '#fb_login', :success => 'reload();', :failure => ''}
+ def fb_login_click_react options = {:selector => '#fb_login'}, &block
selector = options[:selector] || '#fb_login'
- success = options[:success] || '// on success'
- failure = options[:failure] || '// on failure'
+ block_content = yield if block
+ on_success = options[:on_success] || block_content || '// on success'
+ on_fail = options[:on_fail] || '// on failure'
+
script = %Q{$('#{selector}').click(function() {
- FB.login(function(response) {
- if (response.authResponse) {
- #{success}
- } else {
- #{failure}
- }
- });
+ #{fb_login_react(options, &block)}
return false;
- }#{scope_permissions options[:scope]}
+ }
}
options[:ready] ? wrap_ready(script) : script
end
- def fb_logout_and_react options = {:ready => false, :selector => '#fb_logout', :success => 'reload();', :failure => ''}
- selector = options[:selector] || '#fb_logout'
- success = options[:success] || '// on success'
- failure = options[:failure] || '// on failure'
+ def fb_login_react options = {}, &block
+ block_content = yield if block
+ on_success = options[:on_success] || block_content || '// on success'
+ on_fail = options[:on_fail] || '// on failure'
+
+ script = %Q{FB.login(function(response) {
+ if (response.authResponse) {
+ #{on_success}
+ } else {
+ #{on_fail}
+ }
+ }#{scope_permissions options[:scope]});
+}
+ options[:ready] ? wrap_ready(script) : script
+ end
+
+
+ def fb_logout_click_react options = {:selector => '#fb_logout'}, &block
+ selector = options[:selector] || '#fb_logout'
+ block_content = yield if block
+ on_done = options[:on_done] || block_content || '// on done'
script = %Q{$('#{selector}').click(function() {
- FB.login(function(response) {
- if (response.authResponse) {
- #{success}
- } else {
- #{failure}
- }
- });
+ #{fb_logout_react(:on_done => on_done)}
return false;
}
}
options[:ready] ? wrap_ready(script) : script
end
- def fb_logout_and_redirect_to path, options = {:ready => false}
+ def fb_logout_react options = {}, &block
+ block_content = yield if block
+ on_done = options[:on_done] || block_content || '// on done'
+
+ script = %Q{FB.logout(function(response) {
+ #{on_done}
+ });
+}
+ options[:ready] ? wrap_ready(script) : script
+ end
+
+ def fb_onlogout_redirect_to path, options = {}
script = %Q{FB.Event.subscribe("auth.logout", function() {
window.location = '#{path}'
});
@@ -46,6 +64,34 @@ def fb_logout_and_redirect_to path, options = {:ready => false}
options[:ready] ? wrap_ready(script) : script
end
+ def fb_onlogout_react options = {}, &block
+ block_content = yield if block
+ reaction = options[:reaction] || block_content || ' // on logout'
+ script = %Q{FB.Event.subscribe("auth.logout", function() {
+ #{reaction}
+ });
+}
+ options[:ready] ? wrap_ready(script) : script
+ end
+
+ def fb_onlogin_redirect_to path, options = {}
+ script = %Q{FB.Event.subscribe("auth.login", function() {
+ window.location = '#{path}'
+ });
+}
+ options[:ready] ? wrap_ready(script) : script
+ end
+
+ def fb_onlogin_react options = {}, &block
+ block_content = yield if block
+ reaction = options[:reaction] || block_content || ' // on login'
+ script = %Q{FB.Event.subscribe("auth.login", function() {
+ #{reaction}
+ });
+}
+ options[:ready] ? wrap_ready(script) : script
+ end
+
# app_id - facebook app id, a number/string, fx '753632322'
# domain - fx www.example.com
@@ -110,4 +156,4 @@ def all_script locale = :en_US
"//connect.facebook.net/#{locale}/all.js"
end
end
-end
+end
View
27 lib/facebook-social_plugins/helper/view.rb
@@ -0,0 +1,27 @@
+module FacebookSocialPlugins::Helper
+ module View
+ def fb_root
+ content_tag :div, '', :class => "fb-root"
+ end
+
+ def fb_analytics app_id
+ content_tag :meta, '', :property => "fb:admins", :content => app_id
+ end
+
+ def fb_activity namespace, action
+ content_tag :div, '', :class => "fb-activity", :'data-actions' => "#{namespace}:#{action}"
+ end
+
+ FacebookSocialPlugins.plugins.each do |name|
+ define_method :"fb_#{name}" do |options = {}|
+ FacebookSocialPlugins.plugin name, options
+ end
+ end
+
+ def fb_logout_button options = {}
+ content_tag :a, '', {:id => 'fb_logout_and_reload', :href => '#'}.merge(options[:html] || {}) do
+ content_tag(:img, '', :id => 'fb_logout_image', :src => "/assets/fb_logout_#{options[:size] || :small}.gif", :alt => "Facebook Logout").html_safe
+ end
+ end
+ end
+end
View
45 lib/facebook-social_plugins/open_graph/meta_helper.rb
@@ -1,45 +0,0 @@
-module FacebookSocialPlugins
- module OpenGraph
- module MetaHelper
- def og_header name, namespace, &block
- content = capture(&block)
- content_tag :head, content, :prefix => "og: http://ogp.me/ns# og_#{name}: http://ogp.me/ns/apps/#{namespace}x#"
- end
-
- def fb_app_id app_id
- content_tag :meta, '', :property => "fb:app_id", :content => app_id
- end
-
- def og_type namespace, object_type
- content_tag :meta, '', :property => "og:type", :content => "#{namespace}:#{object_type}"
- end
-
- def og_title title
- content_tag :meta, '', :property => "og:title", :content => title
- end
-
- def og_image href
- content_tag :meta, '', :property => "og:image", :content => href
- end
-
- def og_desc desc
- content_tag :meta, '', :property => "og:description", :content => desc
- end
-
- def og_url href
- content_tag :meta, '', :property => "og:url", :content => href
- end
-
- def open_graph_meta name, namespace, app_id, object_type, options = {}
- content = fb_app_id(app_id) + og_type(namespace, object_type)
- content << og_title(options[:title]) if options[:title]
- content << og_image(options[:img]) if options[:img]
- content << og_image(options[:desc]) if options[:desc]
- content << og_image(options[:url]) if options[:url]
- og_header(name, namespace) do
- content
- end
- end
- end
- end
-end
View
4 lib/facebook-social_plugins/activity_feed.rb → ...ok-social_plugins/plugin/activity_feed.rb
@@ -1,5 +1,5 @@
-module FacebookSocialPlugins
- class ActivityFeed < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class ActivityFeed < Social
def initialize options = {}
super
end
View
4 ...acebook-social_plugins/add_to_timeline.rb → ...-social_plugins/plugin/add_to_timeline.rb
@@ -1,6 +1,6 @@
-module FacebookSocialPlugins
+module FacebookSocialPlugins::Plugin
# Also see AddToTimeline.txt of this gem for example of using OpenGraph with this feature.
- class AddToTimeline < SocialPlugin
+ class AddToTimeline < Social
def initialize options = {}
super
end
View
6 lib/facebook-social_plugins/button.rb → lib/facebook-social_plugins/plugin/button.rb
@@ -1,7 +1,5 @@
-require 'facebook-social_plugins/social_plugin'
-
-module FacebookSocialPlugins
- class Button < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class Button < Social
def initialize options = {}
super
end
View
4 lib/facebook-social_plugins/comments.rb → ...acebook-social_plugins/plugin/comments.rb
@@ -1,5 +1,5 @@
-module FacebookSocialPlugins
- class Comments < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class Comments < Social
def initialize options = {}
super
end
View
22 lib/facebook-social_plugins/plugin/facepile.rb
@@ -0,0 +1,22 @@
+module FacebookSocialPlugins::Plugin
+ class Facepile < Social
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-facepile'
+ end
+
+ # event-app-id - the app id for the event
+ # action - the action to perform, fx 'og_recipebox:planning_to_make'
+ # width - the width of the plugin in pixels. Minimum recommended width: 400px.
+ # href - the referenced page
+ # max_rows - max rows to display, 1-10 normally
+ def attributes
+ super.merge(:'event-app-id' => :string, :action => :string, :href => :string,
+ :max_rows => :integer, :size => sizes, :width => :integer
+ )
+ end
+ end
+end
View
4 lib/facebook-social_plugins/like_box.rb → ...acebook-social_plugins/plugin/like_box.rb
@@ -1,5 +1,5 @@
-module FacebookSocialPlugins
- class LikeBox < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class LikeBox < Social
def initialize options = {}
super
end
View
2  lib/facebook-social_plugins/like_button.rb → ...book-social_plugins/plugin/like_button.rb
@@ -1,4 +1,4 @@
-module FacebookSocialPlugins
+module FacebookSocialPlugins::Plugin
class LikeButton < Button
def initialize options = {}
super
View
4 lib/facebook-social_plugins/live_stream.rb → ...book-social_plugins/plugin/live_stream.rb
@@ -1,5 +1,5 @@
-module FacebookSocialPlugins
- class LiveStream < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class LiveStream < Social
def initialize options = {}
super
end
View
5 lib/facebook-social_plugins/login_button.rb → ...ook-social_plugins/plugin/login_button.rb
@@ -1,6 +1,5 @@
-module FacebookSocialPlugins
- # <div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>
- class LoginButton < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class LoginButton < Social
def initialize options = {}
super
end
View
4 ...ook-social_plugins/recommendations_box.rb → ...ial_plugins/plugin/recommendations_box.rb
@@ -1,5 +1,5 @@
-module FacebookSocialPlugins
- class RecommendationsBox < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class RecommendationsBox < Social
def initialize options = {}
super
end
View
4 lib/facebook-social_plugins/registration.rb → ...ook-social_plugins/plugin/registration.rb
@@ -1,5 +1,5 @@
-module FacebookSocialPlugins
- class Registration < SocialPlugin
+module FacebookSocialPlugins::Plugin
+ class Registration < Social
attr_reader :named_fields
# <fb:registration
View
2  lib/facebook-social_plugins/send_button.rb → ...book-social_plugins/plugin/send_button.rb
@@ -1,4 +1,4 @@
-module FacebookSocialPlugins
+module FacebookSocialPlugins::Plugin
class SendButton < Button
def initialize options = {}
super
View
6 lib/facebook-social_plugins/social_plugin.rb → lib/facebook-social_plugins/plugin/social.rb
@@ -1,7 +1,5 @@
-require 'facebook-social_plugins/ui_helper'
-
-module FacebookSocialPlugins
- class SocialPlugin < UiHelper
+module FacebookSocialPlugins::Plugin
+ class Social < UiHelper
attr_reader :options
View
2  ...cebook-social_plugins/subscribe_button.rb → ...social_plugins/plugin/subscribe_button.rb
@@ -1,4 +1,4 @@
-module FacebookSocialPlugins
+module FacebookSocialPlugins::Plugin
class SubscribeButton < Button
def initialize options = {}
super
View
2  lib/facebook-social_plugins/ui_helper.rb → ...cebook-social_plugins/plugin/ui_helper.rb
@@ -1,4 +1,4 @@
-module FacebookSocialPlugins
+module FacebookSocialPlugins::Plugin
class UiHelper
include ActionView::Helpers::TagHelper,
ActionView::Helpers::UrlHelper,
View
7 lib/facebook-social_plugins/rails/engine.rb
@@ -2,10 +2,9 @@ module FacebookSocialPlugins
module Rails
class Engine < ::Rails::Engine
initializer 'setup rails' do
- ActionView::Base.send :include, FacebookSocialPlugins::ViewHelper
- ActionView::Base.send :include, FacebookSocialPlugins::ScriptHelper
-
- ActionView::Base.send :include, FacebookSocialPlugins::OpenGraph::MetaHelper
+ FacebookSocialPlugins.helpers.each do |helper|
+ ActionView::Base.send :include, "FacebookSocialPlugins::Helper::#{helper.to_s.camelize}".constantize
+ end
end
end
end
View
74 lib/facebook-social_plugins/view_helper.rb
@@ -1,74 +0,0 @@
-module FacebookSocialPlugins
- module ViewHelper
- def fb_root
- content_tag :div, '', :class => "fb-root"
- end
-
- def fb_analytics app_id
- FacebookSocialPlugins::Analytics.new(app_id).render
- end
-
- def fb_activity namespace, action
- content_tag :div, '', :class => "fb-activity", :'data-actions' => "#{namespace}:#{action}"
- end
-
- def fb_activity_feed options = {}
- FacebookSocialPlugins::ActivityFeed.new(options).render
- end
-
- def fb_add_to_timeline options = {}
- FacebookSocialPlugins::AddToTimeline.new(options).render
- end
-
- def fb_comments options = {}
- FacebookSocialPlugins::Comments.new(options).render
- end
-
- def fb_facepile options = {}
- FacebookSocialPlugins::Facepile.new(options).render
- end
-
- def fb_like_box options = {}
- FacebookSocialPlugins::LikeBox.new(options).render
- end
-
- def fb_like_button options = {}
- FacebookSocialPlugins::LikeButton.new(options).render
- end
-
- def fb_live_stream options = {}
- FacebookSocialPlugins::LiveStream.new(options).render
- end
-
- def fb_login_button options = {}
- FacebookSocialPlugins::LoginButton.new(options).render
- end
-
- def fb_logout_button options = {}
- content_tag :a, '', {:id => 'fb_logout_and_reload', :href => '#'}.merge(options[:html] || {}) do
- content_tag(:img, '', :id => 'fb_logout_image', :src => "/assets/fb_logout_#{options[:size] || :small}.gif", :alt => "Facebook Logout").html_safe
- end
- end
-
- def fb_logout &block
- content_tag :script, %Q{FB.Event.subscribe("auth.logout", function() { #{yield} });}
- end
-
- def fb_recommendations_box options = {}
- FacebookSocialPlugins::RecommendationsBox.new(options).render
- end
-
- def fb_registration options = {}
- FacebookSocialPlugins::Registration.new(options).render
- end
-
- def fb_send_button options = {}
- FacebookSocialPlugins::SendButton.new(options).render
- end
-
- def fb_subscribe_button options = {}
- FacebookSocialPlugins::SubscribeButton.new(options).render
- end
- end
-end
-
View
4 ...ook-social_plugins/og_meta_helper_spec.rb → ...-social_plugins/open_graph_helper_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
-describe FacebookSocialPlugins::OpenGraph::MetaHelper do
+describe FacebookSocialPlugins::Helper::OpenGraph do
include ControllerTestHelpers,
- FacebookSocialPlugins::OpenGraph::MetaHelper
+ FacebookSocialPlugins::Helper::OpenGraph
describe 'OpenGraph Meta helper' do
it "should write Open Graph meta tags " do
View
30 spec/facebook-social_plugins/script_helper_spec.rb
@@ -34,9 +34,9 @@
}
-describe FacebookSocialPlugins::ScriptHelper do
+describe FacebookSocialPlugins::Helper::Script do
include ControllerTestHelpers,
- FacebookSocialPlugins::ScriptHelper
+ FacebookSocialPlugins::Helper::Script
describe '#async_init_script' do
it "should create async init script" do
@@ -58,22 +58,32 @@
end
describe '#fb_login_and_react' do
- it 'should work' do
- output = fb_login_and_react :ready => true, :selector => '#fb_login', :scope => 'email,user_likes'
- 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"
+ it 'should display basic login script with scoped permissions' do
+ output = fb_login_click_react :ready => true, :selector => '#fb_login', :scope => 'email,user_likes'
+ 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"
+ end
+
+ it 'should display basic login script with console.log for success and failure' do
+ output = fb_login_click_react :ready => true, :on_success => "console.log('logged in to facebook');", :on_fail => "console.log('facebook login failure');"
+ 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"
end
end
describe '#fb_logout_and_react' do
- it 'should work' do
- output = fb_logout_and_react :ready => true, :failure => "console.log('failed FB logout');"
- 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"
+ it 'should render fb logout script with no reaction' do
+ output = fb_logout_click_react :ready => true
+ 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"
+ end
+
+ it 'should render fb logout script with console.log after done' do
+ output = fb_logout_click_react :ready => true, :on_done => "console.log('logged out from facebook');"
+ 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"
end
end
- describe '#fb_logout_and_redirect_to' do
+ describe '#fb_onlogout_redirect_to' do
it 'should work' do
- output = fb_logout_and_redirect_to('facebook/logout', :ready => true)
+ output = fb_onlogout_redirect_to('facebook/logout', :ready => true)
output.should == "$(function() {\n\t\tFB.Event.subscribe(\"auth.logout\", function() { \n\twindow.location = 'facebook/logout' \n\t}); \n\n\t}\n"
end
end
View
4 spec/facebook-social_plugins/view_helper_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
-describe FacebookSocialPlugins::ViewHelper do
+describe FacebookSocialPlugins::Helper::View do
include ControllerTestHelpers,
- FacebookSocialPlugins::ViewHelper
+ FacebookSocialPlugins::Helper::View
describe 'Social plugin' do
it "should not create plugin if unknown attribute is encountered" do
Please sign in to comment.
Something went wrong with that request. Please try again.