Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial version

  • Loading branch information...
commit 002c01220b5ebd7f49f356d0d1962c3dc9398e41 0 parents
@kristianmandrup authored
Showing with 1,099 additions and 0 deletions.
  1. +5 −0 .document
  2. +49 −0 .gitignore
  3. +1 −0  .rspec
  4. +49 −0 AddToTimeline.txt
  5. +11 −0 Gemfile
  6. +37 −0 Gemfile.lock
  7. +20 −0 LICENSE.txt
  8. +281 −0 README.rdoc
  9. +49 −0 Rakefile
  10. +1 −0  VERSION
  11. +22 −0 lib/facebook-social_plugins.rb
  12. +35 −0 lib/facebook-social_plugins/activity_feed.rb
  13. +18 −0 lib/facebook-social_plugins/add_to_timeline.rb
  14. +12 −0 lib/facebook-social_plugins/button.rb
  15. +20 −0 lib/facebook-social_plugins/comments.rb
  16. +37 −0 lib/facebook-social_plugins/facepile.rb
  17. +28 −0 lib/facebook-social_plugins/like_box.rb
  18. +51 −0 lib/facebook-social_plugins/like_button.rb
  19. +21 −0 lib/facebook-social_plugins/live_stream.rb
  20. +26 −0 lib/facebook-social_plugins/login_button.rb
  21. +10 −0 lib/facebook-social_plugins/rails/engine.rb
  22. +41 −0 lib/facebook-social_plugins/recommendations_box.rb
  23. +52 −0 lib/facebook-social_plugins/registration.rb
  24. +48 −0 lib/facebook-social_plugins/script_helper.rb
  25. +22 −0 lib/facebook-social_plugins/send_button.rb
  26. +50 −0 lib/facebook-social_plugins/social_plugin.rb
  27. +27 −0 lib/facebook-social_plugins/subscribe_button.rb
  28. +56 −0 lib/facebook-social_plugins/view_helper.rb
  29. +7 −0 spec/facebook-social_plugins/facebook-buttons_spec.rb
  30. +12 −0 spec/spec_helper.rb
  31. +1 −0  vendor/assets/html/facebook_channel.html
5 .document
@@ -0,0 +1,5 @@
+lib/**/*.rb
+bin/*
+-
+features/**/*.feature
+LICENSE.txt
49 .gitignore
@@ -0,0 +1,49 @@
+# rcov generated
+coverage
+coverage.data
+
+# rdoc generated
+rdoc
+
+# yard generated
+doc
+.yardoc
+
+# bundler
+.bundle
+
+# jeweler generated
+pkg
+
+# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
+#
+# * Create a file at ~/.gitignore
+# * Include files you want ignored
+# * Run: git config --global core.excludesfile ~/.gitignore
+#
+# After doing this, these files will be ignored in all your git projects,
+# saving you from having to 'pollute' every project you touch with them
+#
+# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
+#
+# For MacOS:
+#
+.DS_Store
+
+# For TextMate
+*.tmproj
+tmtags
+
+# For emacs:
+#*~
+#\#*
+#.\#*
+
+# For vim:
+*.swp
+
+# For redcar:
+.redcar
+
+# For rubinius:
+#*.rbc
1  .rspec
@@ -0,0 +1 @@
+--color
49 AddToTimeline.txt
@@ -0,0 +1,49 @@
+<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US">
+
+<head prefix="og: http://ogp.me/ns# og_recipebox: http://ogp.me/ns/apps/YOUR_NAMESPACEx#">
+ <meta property="fb:app_id" content="YOUR_APP_ID" />
+ <meta property="og:type" content="YOUR_NAMESPACE:recipe" />
+ <meta property="og:title" content="Oreo Stuffed Cookies" />
+ <meta property="og:image" content="http://YOUR_URL/cookie.jpg" />
+ <meta property="og:description" content="The Turducken of Cookies" />
+ <meta property="og:url" content="http://YOUR_URL/cookie.html">
+
+ <script type="text/javascript">
+ function postCook()
+ {
+ FB.api('/me/YOUR_NAMESPACE:cook&recipe=http://YOUR_URL/cookie.html','post', function(response) {
+ if (!response || response.error) {
+ alert('Error occured');
+ } else {
+ alert('Post was successful! Action ID: ' + response.id);
+ }
+ });
+ }
+ </script>
+</head>
+
+<body>
+ <div id="fb-root"></div>
+ <script src="http://connect.facebook.net/en_US/all.js"></script>
+ <script>
+ FB.init({
+ appId:'YOUR_APP_ID', cookie:true,
+ status:true, xfbml:true, oauth:true
+ });
+ </script>
+ <fb:add-to-timeline></fb:add-to-timeline>>
+ <h3>
+ <font size="30" face="verdana" color="grey">Stuffed Cookies
+ </font>
+ </h3>
+ <p>
+ <img title="Oreo Stuffed Cookies" src="http://YOUR_URL/cookie.jpg" width="550"/><br />
+ </p>
+
+ <form>
+ <input type="button" value="Cook" onclick="postCook()" />
+ </form>
+
+ <fb:activity actions="YOUR_NAMESPACE:cook"></fb:activity>
+ </body>
+</html>
11 Gemfile
@@ -0,0 +1,11 @@
+source :rubygems
+
+# Add dependencies to develop your gem here.
+# Include everything needed to run rake, tests, features, etc.
+group :development do
+ gem "rspec", ">= 2.8.0"
+ gem "rdoc", ">= 3.12"
+ gem "bundler", ">= 1.1.0"
+ gem "jeweler", ">= 1.8.3"
+ gem "simplecov", ">= 0"
+end
37 Gemfile.lock
@@ -0,0 +1,37 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ diff-lcs (1.1.3)
+ git (1.2.5)
+ jeweler (1.8.3)
+ bundler (~> 1.0)
+ git (>= 1.2.5)
+ rake
+ rdoc
+ json (1.6.6)
+ multi_json (1.2.0)
+ rake (0.9.2.2)
+ rdoc (3.12)
+ json (~> 1.4)
+ rspec (2.9.0)
+ rspec-core (~> 2.9.0)
+ rspec-expectations (~> 2.9.0)
+ rspec-mocks (~> 2.9.0)
+ rspec-core (2.9.0)
+ rspec-expectations (2.9.0)
+ diff-lcs (~> 1.1.3)
+ rspec-mocks (2.9.0)
+ simplecov (0.6.1)
+ multi_json (~> 1.0)
+ simplecov-html (~> 0.5.3)
+ simplecov-html (0.5.3)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ bundler (>= 1.1.0)
+ jeweler (>= 1.8.3)
+ rdoc (>= 3.12)
+ rspec (>= 2.8.0)
+ simplecov
20 LICENSE.txt
@@ -0,0 +1,20 @@
+Copyright (c) 2012 Kristian Mandrup
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
281 README.rdoc
@@ -0,0 +1,281 @@
+= Facebook Social plugins
+
+The Facebook Social plugins for Rails 3 consist of:
+
+* ViewHelper
+* ScriptHelper
+
+The `ViewHelper` 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.
+
+== Status - April 3, 2012
+
+Currently not tested. Specs needed! This is an early beta. Please help make it better :)
+
+== Script Helpers
+
+* async_init_script(app_id, domain, options = {})
+* facebook_script(locale = :en)
+
+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.
+
+<div id="fb-root"></div>
+<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>
+
+== Social plugins
+
+Currently the following Social plugins are included in this gem
+
+* Activity Feed
+* Comments
+* Facepile
+* Like Box
+* Like Button
+* Live Stream
+* Login Button
+* Recommendations Box
+* Registration
+* Send Button
+* Subscribe Button
+
+View methods exposed:
+
+* fb_root
+* fb_activity options = {}
+* fb_add_to_timeline options = {}
+* fb_comments options = {}
+* fb_facepile options = {}
+* fb_like_box options = {}
+* fb_like_button options = {}
+* fb_live_stream options = {}
+* fb_login_button options = {}
+* fb_recommendations_box options = {}
+* fb_registration options = {}
+* fb_send_button options = {}
+* fb_subscribe_button options = {}
+
+=== Activity feed
+
+<div class="fb-activity" data-width="300" data-height="300" data-header="true" data-recommendations="false"></div>
+
+* site - the domain for which to show activity; include just the full domain name, without http:// or a path. The XFBML version defaults to the current domain.
+* action - a comma separated list of actions to show activities for.
+* app_id - will display all actions, custom and global, associated with this app_id.
+* width - the width of the plugin in pixels. Default width: 300px.
+* height - the height of the plugin in pixels. Default height: 300px.
+* header - specifies whether to show the Facebook header.
+* colorscheme - the color scheme for the plugin. Options: 'light', 'dark'
+* font - the font to display in the plugin. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+* border_color - the border color of the plugin.
+* recommendations - specifies whether to always show recommendations in the plugin.
+* linktarget - This specifies the context in which content links are opened.
+* ref - a label for tracking referrals; must be less than 50 characters
+* max_age - a limit on recommendation and creation time of articles that are surfaced in the plugins, the default is 0 (days)
+
+=== Comments
+
+<div class="fb-comments" data-href="http://example.com" data-num-posts="2" data-width="470"></div>
+
+href - the URL for this Comments plugin. News feed stories on Facebook will link to this URL.
+width - the width of the plugin in pixels. Minimum recommended width: 400px.
+colorscheme - the color scheme for the plugin. Options: 'light', 'dark'
+num_posts - the number of comments to show by default. Default: 10. Minimum: 1
+mobile - whether to show the mobile-optimized version. Default: auto-detect.
+
+=== Like box
+
+<div class="fb-like" data-send="true" data-width="450" data-show-faces="true"></div>
+
+* href - the URL to like. The XFBML version defaults to the current page.
+* send - specifies whether to include a Send button with the Like button.
+* layout - there are three options (standard, button_count, box_count)
+* show_faces - specifies whether to display profile photos below the button (standard layout only)
+* width - the width of the Like button.
+* action - the verb to display on the button. Options: 'like', 'recommend'
+* font - the font to display in the button. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+* colorscheme - the color scheme for the like button. Options: 'light', 'dark'
+* ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters
+fb_ref - the ref parameter
+fb_source - the stream type ('home', 'profile', 'search', 'ticker', 'tickerdialog' or 'other') in which the click occurred and the story type ('oneline' or 'multiline'), concatenated with an underscore.
+
+=== Live stream
+
+<div class="fb-live-stream" data-event-app-id="285193711555371" data-width="400" data-height="500" data-always-post-to-friends="true"></div>
+
+=== Login
+
+<div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>
+
+* show-faces - specifies whether to show faces underneath the Login button.
+* width - the width of the plugin in pixels. Default width: 200px.
+* max-rows - the maximum number of rows of profile pictures to display. Default value: 1.
+* scope - a comma separated list of extended permissions.
+
+=== Registration
+
+Async Validation
+
+If you have to check something on your server (e.g. if a username is taken) then you don't have to reply from the validation function right away. You can return null (which is the default return in javascript) and then use the second parameter to reply with any errors. You have 20 seconds before the form submits anyways.
+
+<fb:registration redirect-uri="https://developers.facebook.com/tools/echo"
+ fields='[{"name":"name"},
+ {"name":"username","description":"Username","type":"text"}]'
+ onvalidate="validate_async"></fb:registration>
+
+<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
+<script>
+function validate_async(form, cb) {
+ $.getJSON('https://graph.facebook.com/' + form.username + '?callback=?',
+ function(response) {
+ if (response.error) {
+ // Username isn't taken, let the form submit
+ cb();
+ }
+ cb({username: 'That username is taken'});
+ });
+}
+</script>
+
+=== Add to Timeline
+
+<div class="fb-add-to-timeline"></div>
+
+Add to Timeline lets users create a lasting connection between your app and their Timeline on Facebook. When a user clicks Add to Timeline, your app can publish app specific actions to the user's Timeline. As users engage with your app over time, their actions become more prominently displayed on their Timeline. This can become an important part of how people express themselves on Facebook. The experience for users is seamless and fun and requires little effort for them to personalize their identity.
+
+Add to Timeline plugin is available through the Javascript SDK via the <fb:add-to-timeline> XFBML tag.
+
+There are two different display modes for the Add to Timeline: box (default) and button. You can also configure additional extended permissions for the plugin by adding the perms parameter.
+
+* mode - the display mode - box (default) and button
+* show_faces - whether to show faces
+
+
+=== Facepile
+
+<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>
+
+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
+
+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 parameter.
+
+* 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
+
+=== Recommendations
+
+<div class="fb-recommendations" data-width="300" data-height="300" data-header="true"></div>
+
+* site - the domain to show recommendations for. The XFBML version defaults to the current domain.
+* action - a comma separated list of actions to show recommendations for.
+* app_id - will display recommendations for all types of actions, custom and global, associated with this app_id.
+* width - the width of the plugin in pixels. Default width: 300px.
+* height - the height of the plugin in pixels. Default height: 300px.
+* header - specifies whether to show the Facebook header.
+* colorscheme - the color scheme for the plugin. Options: 'light', 'dark'
+* font - the font to display in the plugin. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+* border_color - the border color of the plugin.
+* linktarget - This specifies the context in which content links are opened. By default all links within the plugin will open a new window. se to _top or _parent.
+* ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters
+* max_age - a limit on recommendation and creation time of articles that are surfaced in the plugins, the default is 0 (days)
+
+=== Send button
+
+<div class="fb-send" data-href="http://example.com"></div>
+
+* href - the URL to send.
+* font - the font to display in the button. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+* colorscheme - the color scheme for the button. Options: 'light', 'dark'
+* ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters
+* fb_ref - the ref parameter
+* fb_source - the story type ('message', 'group', 'email') in which the click occurred.
+
+=== Subscribe button
+
+<div class="fb-subscribe" data-href="https://www.facebook.com/zuck" data-show-faces="true" data-width="450"></div>
+
+* href - profile URL of the user to subscribe to. This must be a facebook.com profile URL.
+* layout - there are three options (standard, button_count, box_count).
+* show_faces - specifies whether to display profile photos below the button (standard layout only)
+* colorscheme - the color scheme for the plugin. Options: 'light' (default) and 'dark'
+* font - the font to display in the plugin. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+* width - the width of the plugin.
+
+== Contributing to facebook-social_plugins
+
+* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
+* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
+* Fork the project.
+* Start a feature/bugfix branch.
+* Commit and push until you are happy with your contribution.
+* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
+* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
+
+== Copyright
+
+Copyright (c) 2012 Kristian Mandrup. See LICENSE.txt for
+further details.
+
49 Rakefile
@@ -0,0 +1,49 @@
+# encoding: utf-8
+
+require 'rubygems'
+require 'bundler'
+begin
+ Bundler.setup(:default, :development)
+rescue Bundler::BundlerError => e
+ $stderr.puts e.message
+ $stderr.puts "Run `bundle install` to install missing gems"
+ exit e.status_code
+end
+require 'rake'
+
+require 'jeweler'
+Jeweler::Tasks.new do |gem|
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
+ gem.name = "facebook-social_plugins"
+ gem.homepage = "http://github.com/kristianmandrup/facebook-social_plugins"
+ gem.license = "MIT"
+ gem.summary = %Q{Facebook social plugins for Rails 3 using HTML5}
+ gem.description = %Q{HTML5 compatible social plugin helpers for Rails 3}
+ gem.email = "kmandrup@gmail.com"
+ gem.authors = ["Kristian Mandrup"]
+ # dependencies defined in Gemfile
+end
+Jeweler::RubygemsDotOrgTasks.new
+
+require 'rspec/core'
+require 'rspec/core/rake_task'
+RSpec::Core::RakeTask.new(:spec) do |spec|
+ spec.pattern = FileList['spec/**/*_spec.rb']
+end
+
+RSpec::Core::RakeTask.new(:rcov) do |spec|
+ spec.pattern = 'spec/**/*_spec.rb'
+ spec.rcov = true
+end
+
+task :default => :spec
+
+require 'rdoc/task'
+Rake::RDocTask.new do |rdoc|
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
+
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = "facebook-buttons #{version}"
+ rdoc.rdoc_files.include('README*')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+end
1  VERSION
@@ -0,0 +1 @@
+0.0.1
22 lib/facebook-social_plugins.rb
@@ -0,0 +1,22 @@
+require 'facebook-buttons/social_plugin'
+require 'facebook-buttons/button'
+
+module FacebookButtons
+ def self.available
+ ['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.helpers
+ ['script', 'view']
+end
+
+FacebookButtons.available_buttons.each do |name|
+ require "facebook-buttons/#{name}"
+end
+
+FacebookButtons.available_helpers.each do |name|
+ require "facebook-buttons/#{name}_helper"
+end
+
+require 'facebook-buttons/rails/engine'
35 lib/facebook-social_plugins/activity_feed.rb
@@ -0,0 +1,35 @@
+module FacebookSocialPlugins
+ class ActivityFeed < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-activity'
+ end
+
+ # site - the domain for which to show activity; include just the full domain name, without http:// or a path. The XFBML version defaults to the current domain.
+ # action - a comma separated list of actions to show activities for.
+ # app_id - will display all actions, custom and global, associated with this app_id.
+ # width - the width of the plugin in pixels. Default width: 300px.
+ # height - the height of the plugin in pixels. Default height: 300px.
+ # header - specifies whether to show the Facebook header.
+ # colorscheme - the color scheme for the plugin. Options: 'light', 'dark'
+ # font - the font to display in the plugin. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+ # border_color - the border color of the plugin.
+ # recommendations - specifies whether to always show recommendations in the plugin. If recommendations is set to true, the plugin will display recommendations in the bottom half.
+ # filter - allows you to filter which URLs are shown in the plugin. The plugin will only include URLs which contain the filter string in the first two path parameters of the URL. If nothing in the first two path parameters of the URL matches the filter, the URL will not be included. For example, if the 'site' parameter is set to 'www.example.com' and the 'filter' parameter was set to '/section1/section2' then only pages which matched 'http://www.example.com/section1/section2/*' would be included in the activity feed section of this plugin. The filter parameter does not apply to any recommendations which may appear in this plugin (see above); Recommendations are based only on 'site' parameter.
+ # linktarget - This specifies the context in which content links are opened. By default all links within the plugin will open a new window. If you want the content links to open in the same window, you can set this parameter to _top or _parent. Links to Facebook URLs will always open in a new window.
+ # ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters and some punctuation (currently +/=-.:_). Specifying a value for the ref attribute adds the 'fb_ref' parameter to the any links back to your site which are clicked from within the plugin. Using different values for the ref parameter for different positions and configurations of this plugin within your pages allows you to track which instances are performing the best.
+ # max_age - a limit on recommendation and creation time of articles that are surfaced in the plugins, the default is 0 (we don’t take age into account). Otherwise the valid values are 1-180, which specifies the number of days.
+
+ def attributes
+ super.merge(
+ :site => :string, :action => :array, :app_id => :string, :width => :integer, :height => :integer,
+ :header => :boolean, :colorscheme => ['light', 'dark'], :font => ['arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'],
+ :border_color => :string, :recommendations => :boolean, :filter => :string, :linktarget => ['_top', '_parent'],
+ :ref => :string, :max_age => :integer, :width => :integer
+ )
+ end
+ end
+end
18 lib/facebook-social_plugins/add_to_timeline.rb
@@ -0,0 +1,18 @@
+module FacebookSocialPlugins
+ # Also see AddToTimeline.txt of this gem for example of using OpenGraph with this feature.
+ class AddToTimeline < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-add-to-timeline'
+ end
+
+ # mode - the display mode - box (default) and button
+ # show_faces - whether to show faces
+ def attributes
+ super.merge(:show_faces => :boolean, :mode => ['box', 'button'])
+ end
+ end
+end
12 lib/facebook-social_plugins/button.rb
@@ -0,0 +1,12 @@
+module FacebookSocialPlugins
+ class Button < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ # attributes always availabe for a button?
+ def attributes
+ super.merge({:font => :string, :colorscheme => ['light', 'dark']})
+ end
+ end
+end
20 lib/facebook-social_plugins/comments.rb
@@ -0,0 +1,20 @@
+module FacebookSocialPlugins
+ class Comments < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-comments'
+ end
+
+ # href - the URL for this Comments plugin. News feed stories on Facebook will link to this URL.
+ # width - the width of the plugin in pixels. Minimum recommended width: 400px.
+ # colorscheme - the color scheme for the plugin. Options: 'light', 'dark'
+ # num_posts - the number of comments to show by default. Default: 10. Minimum: 1
+ # mobile - whether to show the mobile-optimized version. Default: auto-detect.
+ def attributes
+ super.merge(:href => :string, :num_posts => :integer, :mobile => :boolean, :width => :integer)
+ end
+ end
+end
37 lib/facebook-social_plugins/facepile.rb
@@ -0,0 +1,37 @@
+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(:app_id => :string, :action => :string, :href => :string,
+ :max_rows => :integer, :size => ['small', 'large'], :width => :integer
+ )
+ end
+ end
+end
28 lib/facebook-social_plugins/like_box.rb
@@ -0,0 +1,28 @@
+module FacebookSocialPlugins
+ class LikeBox < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-like-box'
+ end
+
+ # href - the URL of the Facebook Page for this Like Box
+ # width - the width of the plugin in pixels. Default width: 300px.
+ # height - the height of the plugin in pixels. The default height varies based on number of faces to display, and whether the stream is displayed. With the stream displayed, and 10 faces the default height is 556px. With no faces, and no stream the default height is 63px.
+ # colorscheme - the color scheme for the plugin. Options: 'light', 'dark'
+ # show_faces - specifies whether or not to display profile photos in the plugin. Default value: true.
+ # stream - specifies whether to display a stream of the latest posts from the Page's wall
+ # header - specifies whether to display the Facebook header at the top of the plugin.
+ # border_color - the border color of the plugin.
+ # force_wall - for Places, specifies whether the stream contains posts from the Place's wall or just checkins from friends. Default value: false.
+
+ def attributes
+ super.merge(
+ :href => :string, :height => :integer, :stream => :boolean, :header => :string,
+ :show_faces => :boolean, :force_wall => :boolean, :width => :integer
+ )
+ end
+ end
+end
51 lib/facebook-social_plugins/like_button.rb
@@ -0,0 +1,51 @@
+module FacebookSocialPlugins
+ class LikeButton < Button
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-like'
+ end
+
+ # href - the URL to like. The XFBML version defaults to the current page.
+ # send - specifies whether to include a Send button with the Like button. This only works with the XFBML version.
+ # layout - there are three options.
+ # standard - displays social text to the right of the button and friends' profile photos below. Minimum width: 225 pixels. Minimum increases by 40px if action is 'recommend' by and increases by 60px if send is 'true'. Default width: 450 pixels. Height: 35 pixels (without photos) or 80 pixels (with photos).
+ # button_count - displays the total number of likes to the right of the button. Minimum width: 90 pixels. Default width: 90 pixels. Height: 20 pixels.
+ # box_count - displays the total number of likes above the button. Minimum width: 55 pixels. Default width: 55 pixels. Height: 65 pixels.
+ # show_faces - specifies whether to display profile photos below the button (standard layout only)
+ # width - the width of the Like button.
+ # action - the verb to display on the button. Options: 'like', 'recommend'
+ # font - the font to display in the button. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+ # colorscheme - the color scheme for the like button. Options: 'light', 'dark'
+ # ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters and some punctuation (currently +/=-.:_). The ref attribute causes two parameters to be added to the referrer URL when a user clicks a link from a stream story about a Like action:
+ # fb_ref - the ref parameter
+ # fb_source - the stream type ('home', 'profile', 'search', 'ticker', 'tickerdialog' or 'other') in which the click occurred and the story type ('oneline' or 'multiline'), concatenated with an underscore. def attributes
+ super.merge(
+ :href => :string, :send => :boolean, :layout => ['standard', 'button_count', 'box_count'],
+ :show_faces => :boolean, :action => ['like', 'recommend'], :ref => :string,
+ :fb_ref => :string, :fb_source => :special, :width => :integer
+ )
+ end
+
+ def validate_fb_source value
+ raise ArgumentError, "The fb_source option must have a [stream type]_[story line] format, was #{value}" unless value =~ /\S+_\S+/
+
+ [stream_type, story_line] = value.split('_')
+ raise ArgumentError, "Not a valid stream type, must be one of #{stream_types}, was #{stream_type}" unless stream_types.include?(stream_type)
+ raise ArgumentError, "Not a valid story line, must be one of #{story_lines}, was #{story_line}" unless story_lines.include?(story_line)
+ end
+
+ private
+
+ def stream_types
+ ['home', 'profile', 'search', 'ticker', 'tickerdialog', 'other']
+ end
+
+ def story_lines
+ ['oneline', 'multiline']
+ end
+
+ end
+end
21 lib/facebook-social_plugins/live_stream.rb
@@ -0,0 +1,21 @@
+module FacebookSocialPlugins
+ class LiveStream < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-live-stream'
+ end
+
+ # event-app-id - the app id for the event
+ # width - the width of the plugin in pixels. Minimum recommended width: 400px.
+ # height - the height of the plugin in pixels. Minimum recommended height: 200px.
+ # always-post-to-friends - whether to always post to friend, default: false
+ def attributes
+ super.merge(:via_url => :string, :xid => :string, :event_app_id => :string,
+ :height => :integer, :always_post_to_friends => :boolean, :width => :integer)
+ end
+ end
+end
+
26 lib/facebook-social_plugins/login_button.rb
@@ -0,0 +1,26 @@
+module FacebookSocialPlugins
+ # <div class="fb-login-button" data-show-faces="true" data-width="200" data-max-rows="1"></div>
+ class LoginButton < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-login-button'
+ end
+
+ # show-faces - specifies whether to show faces underneath the Login button.
+ # width - the width of the plugin in pixels. Default width: 200px.
+ # max-rows - the maximum number of rows of profile pictures to display. Default value: 1.
+ # scope - a comma separated list of extended permissions.
+ # By default the Login button prompts users for their public information.
+ # If your application needs to access other parts of the user's profile that may be
+ # private, your application can request extended permissions.
+ def attributes
+ super.merge(:show_faces => :boolean, :max_rows => :integer, :scope => :array, :width => :integer)
+ end
+ end
+end
+
+
+
10 lib/facebook-social_plugins/rails/engine.rb
@@ -0,0 +1,10 @@
+module FacebookSocialPlugins
+ module Rails
+ class Engine < ::Rails::Engine
+ initializer 'setup rails' do
+ ActionView::Base.send :include, FacebookSocialPlugins::ViewHelper
+ ActionView::Base.send :include, FacebookSocialPlugins::ScriptHelper
+ end
+ end
+ end
+end
41 lib/facebook-social_plugins/recommendations_box.rb
@@ -0,0 +1,41 @@
+module FacebookSocialPlugins
+ class RecommendationsBox < SocialPlugin
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-recommendations'
+ end
+
+ # site - the domain to show recommendations for. The XFBML version defaults to the current domain.
+ # action - a comma separated list of actions to show recommendations for.
+ # app_id - will display recommendations for all types of actions, custom and global, associated with this app_id.
+ # width - the width of the plugin in pixels. Default width: 300px.
+ # height - the height of the plugin in pixels. Default height: 300px.
+ # header - specifies whether to show the Facebook header.
+ # colorscheme - the color scheme for the plugin. Options: 'light', 'dark'
+ # font - the font to display in the plugin. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+ # border_color - the border color of the plugin.
+
+ # linktarget - This specifies the context in which content links are opened.
+ # By default all links within the plugin will open a new window.
+ # If you want the content links to open in the same window, you can set this parameter
+ # to _top or _parent. Links to Facebook URLs will always open in a new window.
+
+ # ref - a label for tracking referrals; must be less than 50 characters and can contain
+ # alphanumeric characters and some punctuation (currently +/=-.:_).
+ # Specifying a value for the ref attribute adds the 'fb_ref' parameter to the any links back to your site
+ # which are clicked from within the plugin. Using different values for the ref parameter for different positions
+ # and configurations of this plugin within your pages allows you to track which instances are performing the best.
+
+ # max_age - a limit on recommendation and creation time of articles that are surfaced in
+ # the plugins, the default is 0 (we don’t take age into account).
+ # Otherwise the valid values are 1-180, which specifies the number of days.
+ def attributes
+ super.merge(:site => :string, :action => :string, :app_id => :string, :height => :integer,
+ :header => :string, :linktarget => ['_top', '_parent'], :ref => :string,
+ :max_age => :integer, :width => :integer)
+ end
+ end
+end
52 lib/facebook-social_plugins/registration.rb
@@ -0,0 +1,52 @@
+module FacebookSocialPlugins
+ class Registration < SocialPlugin
+ attr_reader :named_fields
+
+ # <fb:registration
+ # fields="name,birthday,gender,location,email"
+ # redirect-uri="https://developers.facebook.com/tools/echo/"
+ # width="530">
+ # </fb:registration>
+
+ def initialize options = {}
+ super
+ @named_fields = options[:fields]
+ end
+
+ def plugin_class
+ 'fb-registration'
+ end
+
+ # client_id Your App ID.
+ # redirect_uri The URI that will process the signed_request. It must be prefixed by your Site URL.
+ # fields Comma separated list of Named Fields, or JSON of Custom Fields.
+ # fb_only Optional. (boolean) Only allow users to register by linking their Facebook profile. Use this if you do not have your own registration system. Default: false.
+ # fb_register Optional. (boolean) Allow users to register for Facebook during the registration process. Use this if you do not have your own registration system. Default: false.
+ # width Optional. (int) The width of the iframe in pixels. If the width is < 520 the plugin will render in a small layout.
+ # border_color Optional. The border color of the plugin.
+ # target Optional. The target of the form submission: _top (default), _parent, or _self.
+ def attributes
+ super.merge(:client_id => :string, :redirect_uri => :string, :fields => :string,
+ :fb_only => :boolean, :fb_register => :boolean, :border_color => :string, :target => ['_top', '_parent', '_self']
+ )
+ end
+
+ # Named Fields
+
+ # Specify these in the order you want them to appear in the form. The name field must always be the first field.
+
+ # Field type Description
+ # name Full name of the user
+ # birthday Returned as mm/dd/yyyy
+ # email Email address of user (if the user registers with her Facebook account, this will be a verified email address)
+ # gender Gender of user
+ # location Name and ID of the user's current city
+ # password A newly created password (not their Facebook password)
+ # captcha A test to stop automatic registration
+ # Less common fields:
+
+ # Field type Description
+ # first_name The first name of the user. Useful with view=not_prefilled.
+ # last_name The last name of the user.
+ end
+end
48 lib/facebook-social_plugins/script_helper.rb
@@ -0,0 +1,48 @@
+module FacebookButtons
+ module ScriptHelper
+
+ # app_id - facebook app id, a number/string, fx '753632322'
+ # domain - fx www.example.com
+ # options - status, cookie, xfbml (true|false)
+ # - :channel => 'channel.html'
+ def async_init_script app_id, domain, options = {}
+ %Q{
+ window.fbAsyncInit = function() {
+ FB.init({
+ appId : '#{app_id}', // App ID
+ channelUrl : '//#{domain}/#{options[:channel] || 'assets/facebook_channel'}.html', // Channel File
+ status : #{options[:status] || true}, // check login status
+ cookie : #{options[:cookie] || true}, // enable cookies to allow the server to access the session
+ xfbml : #{options[:xfbml] || true } // parse XFBML
+ });
+
+ // Additional initialization code here
+ };
+}
+ end
+
+ def facebook_script locale = :en
+ %Q{
+(function(d){
+ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
+ js = d.createElement('script'); js.id = id; js.async = true;
+ js.src = #{all_script locale};
+ d.getElementsByTagName('head')[0].appendChild(js);
+ }(document));
+}
+ end
+
+ protected
+
+ # 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 use es_LA
+
+
+ def all_script locale = :en_US
+ "//connect.facebook.net/#{locale}/all.js"
+ end
+ end
+end
22 lib/facebook-social_plugins/send_button.rb
@@ -0,0 +1,22 @@
+module FacebookSocialPlugins
+ class SendButton < Button
+ def initialize options = {}
+ super
+ end
+
+ def button_class
+ 'fb-send'
+ end
+
+ # href - the URL to send.
+ # font - the font to display in the button. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+ # colorscheme - the color scheme for the button. Options: 'light', 'dark'
+ # ref - a label for tracking referrals; must be less than 50 characters and can contain alphanumeric characters and some punctuation (currently +/=-.:_). The ref attribute causes two parameters to be added to the referrer URL when a user clicks a link from a stream story about a Send action:
+ # fb_ref - the ref parameter
+ # fb_source - the story type ('message', 'group', 'email') in which the click occurred.
+ def attributes
+ super.merge(:href => :string, :ref => :string, :fb_ref => :string, :fb_source => ['message', 'group', 'email'])
+ end
+ end
+end
+
50 lib/facebook-social_plugins/social_plugin.rb
@@ -0,0 +1,50 @@
+module FacebookSocialPlugins
+ class SocialPlugin
+ def initialize options = {}
+ validate!
+ @options = options
+ end
+
+ def render
+ content_tag :div, render_options.merge(:class => plugin_class)
+ end
+
+ # the :special type indicates call to special type validator
+ def validate!
+ return if options.empty?
+ options.each do |key, value|
+ attributes[key] == :special ? send("validate_#{key}", value) : valid?(value, attributes[key])
+ end
+ end
+
+ protected
+
+ # :width => 200 mapped to become 'data-width' => 200
+ def render_options
+ options.inject({}) {|res, opt| res["data-#{opt.first}"] = opt.last; res}
+ end
+
+ def plugin_class
+ raise NotImplementedError, 'Must be implemented by subclass'
+ end
+
+ def attributes
+ @attributes ||= {}
+ end
+
+ def valid? value, valid_type
+ case valid_type
+ when :string
+ raise ArgumentError, "Must be a String, was #{value}" unless value.is_a?(String) || value.is_a?(Symbol)
+ when :array
+ raise ArgumentError, "Must be an Array or a String, was #{value}" unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(Array)
+ when :integer
+ raise ArgumentError, "Must be a Fixnum, was #{value}" unless value.is_a?(Fixnum)
+ when :boolean
+ raise ArgumentError, "Must be a Boolean, was #{value}" unless value.is_a?(Boolean)
+ when Array
+ raise ArgumentError, "Must be a one of #{valid_type.inspect}, was #{value}" unless valid_type.include?(value.to_s)
+ end
+ end
+ end
+end
27 lib/facebook-social_plugins/subscribe_button.rb
@@ -0,0 +1,27 @@
+module FacebookSocialPlugins
+ class SubscribeButton < Button
+ def initialize options = {}
+ super
+ end
+
+ def plugin_class
+ 'fb-subscribe'
+ end
+
+ # href - profile URL of the user to subscribe to. This must be a facebook.com profile URL.
+ # layout - there are three options.
+ # standard - displays social text to the right of the button and friends' profile photos below. Minimum width: 225 pixels. Default width: 450 pixels. Height: 35 pixels (without photos) or 80 pixels (with photos).
+ # button_count - displays the total number of subscribers to the right of the button. Minimum width: 90 pixels. Default width: 90 pixels. Height: 20 pixels.
+ # box_count - displays the total number of subscribers above the button. Minimum width: 55 pixels. Default width: 55 pixels. Height: 65 pixels.
+ # show_faces - specifies whether to display profile photos below the button (standard layout only)
+ # colorscheme - the color scheme for the plugin. Options: 'light' (default) and 'dark'
+ # font - the font to display in the plugin. Options: 'arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'
+ # width - the width of the plugin.
+ def attributes
+ super.merge(:href => :string, :layout => ['standard', 'button_count', 'box_count'],
+ :show_faces => :boolean, :width => :integer)
+ end
+ end
+end
+
+
56 lib/facebook-social_plugins/view_helper.rb
@@ -0,0 +1,56 @@
+module FacebookSocialPlugins
+ module ViewHelper
+ def fb_root
+ content_tag :div, :class => "fb-root"
+ end
+
+ def fb_activity 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_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
+
7 spec/facebook-social_plugins/facebook-buttons_spec.rb
@@ -0,0 +1,7 @@
+require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
+
+describe "FacebookButtons" do
+ it "fails" do
+ fail "hey buddy, you should probably rename this file and start specing for real"
+ end
+end
12 spec/spec_helper.rb
@@ -0,0 +1,12 @@
+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
+$LOAD_PATH.unshift(File.dirname(__FILE__))
+require 'rspec'
+require 'facebook-buttons'
+
+# Requires supporting files with custom matchers and macros, etc,
+# in ./support/ and its subdirectories.
+Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
+
+RSpec.configure do |config|
+
+end
1  vendor/assets/html/facebook_channel.html
@@ -0,0 +1 @@
+<script src="//connect.facebook.net/en_US/all.js"></script>
Please sign in to comment.
Something went wrong with that request. Please try again.