Permalink
Browse files

all specs pass

  • Loading branch information...
kristianmandrup committed Apr 3, 2012
1 parent 3d0c8b8 commit e3439c20db3f9eb2a7b36d5165a245f7ae858212
View
@@ -3,7 +3,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 "rails", ">= 3"
+ gem "rspec", ">= 2"
+ gem "rspec-rails", ">= 2.5"
+ gem "shoulda", ">= 0"
+
gem "rdoc", ">= 3.12"
gem "bundler", ">= 1.1.0"
gem "jeweler", ">= 1.8.3"
View
@@ -1,15 +1,76 @@
GEM
remote: http://rubygems.org/
specs:
+ actionmailer (3.2.3)
+ actionpack (= 3.2.3)
+ mail (~> 2.4.4)
+ actionpack (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ builder (~> 3.0.0)
+ erubis (~> 2.7.0)
+ journey (~> 1.0.1)
+ rack (~> 1.4.0)
+ rack-cache (~> 1.2)
+ rack-test (~> 0.6.1)
+ sprockets (~> 2.1.2)
+ activemodel (3.2.3)
+ activesupport (= 3.2.3)
+ builder (~> 3.0.0)
+ activerecord (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ arel (~> 3.0.2)
+ tzinfo (~> 0.3.29)
+ activeresource (3.2.3)
+ activemodel (= 3.2.3)
+ activesupport (= 3.2.3)
+ activesupport (3.2.3)
+ i18n (~> 0.6)
+ multi_json (~> 1.0)
+ arel (3.0.2)
+ builder (3.0.0)
diff-lcs (1.1.3)
+ erubis (2.7.0)
git (1.2.5)
+ hike (1.2.1)
+ i18n (0.6.0)
jeweler (1.8.3)
bundler (~> 1.0)
git (>= 1.2.5)
rake
rdoc
+ journey (1.0.3)
json (1.6.6)
+ mail (2.4.4)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ mime-types (1.18)
multi_json (1.2.0)
+ polyglot (0.3.3)
+ rack (1.4.1)
+ rack-cache (1.2)
+ rack (>= 0.4)
+ rack-ssl (1.3.2)
+ rack
+ rack-test (0.6.1)
+ rack (>= 1.0)
+ rails (3.2.3)
+ actionmailer (= 3.2.3)
+ actionpack (= 3.2.3)
+ activerecord (= 3.2.3)
+ activeresource (= 3.2.3)
+ activesupport (= 3.2.3)
+ bundler (~> 1.0)
+ railties (= 3.2.3)
+ railties (3.2.3)
+ actionpack (= 3.2.3)
+ activesupport (= 3.2.3)
+ rack-ssl (~> 1.3.2)
+ rake (>= 0.8.7)
+ rdoc (~> 3.4)
+ thor (~> 0.14.6)
rake (0.9.2.2)
rdoc (3.12)
json (~> 1.4)
@@ -21,17 +82,40 @@ GEM
rspec-expectations (2.9.0)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
+ rspec-rails (2.9.0)
+ actionpack (>= 3.0)
+ activesupport (>= 3.0)
+ railties (>= 3.0)
+ rspec (~> 2.9.0)
+ shoulda (3.0.1)
+ shoulda-context (~> 1.0.0)
+ shoulda-matchers (~> 1.0.0)
+ shoulda-context (1.0.0)
+ shoulda-matchers (1.0.0)
simplecov (0.6.1)
multi_json (~> 1.0)
simplecov-html (~> 0.5.3)
simplecov-html (0.5.3)
+ sprockets (2.1.2)
+ hike (~> 1.2)
+ rack (~> 1.0)
+ tilt (~> 1.1, != 1.3.0)
+ thor (0.14.6)
+ tilt (1.3.3)
+ treetop (1.4.10)
+ polyglot
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.32)
PLATFORMS
ruby
DEPENDENCIES
bundler (>= 1.1.0)
jeweler (>= 1.8.3)
+ rails (>= 3)
rdoc (>= 3.12)
- rspec (>= 2.8.0)
+ rspec (>= 2)
+ rspec-rails (>= 2.5)
+ shoulda
simplecov
View
@@ -9,10 +9,6 @@ The `ViewHelper` contains methods for inserting the HTML5 <div> elements for Fac
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 = {})
View
@@ -1 +1 @@
-0.0.1
+0.1.0
@@ -1,22 +1,22 @@
-require 'facebook-buttons/social_plugin'
-require 'facebook-buttons/button'
+require 'facebook-social_plugins/button'
-module FacebookButtons
- def self.available
+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']
end
def self.helpers
['script', 'view']
+ end
end
-FacebookButtons.available_buttons.each do |name|
- require "facebook-buttons/#{name}"
+FacebookSocialPlugins.plugins.each do |name|
+ require "facebook-social_plugins/#{name}"
end
-FacebookButtons.available_helpers.each do |name|
- require "facebook-buttons/#{name}_helper"
+FacebookSocialPlugins.helpers.each do |name|
+ require "facebook-social_plugins/#{name}_helper"
end
-require 'facebook-buttons/rails/engine'
+require 'facebook-social_plugins/rails/engine'
@@ -1,12 +1,18 @@
+require 'facebook-social_plugins/social_plugin'
+
module FacebookSocialPlugins
class Button < SocialPlugin
def initialize options = {}
super
end
+ def plugin_class
+ super
+ end
+
# attributes always availabe for a button?
def attributes
- super.merge({:font => :string, :colorscheme => ['light', 'dark']})
+ super.merge(:font => ['arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'], :colorscheme => ['light', 'dark'])
end
end
end
@@ -29,7 +29,7 @@ def plugin_class
# href - the referenced page
# max_rows - max rows to display, 1-10 normally
def attributes
- super.merge(:app_id => :string, :action => :string, :href => :string,
+ super.merge(:'event-app-id' => :string, :action => :string, :href => :string,
:max_rows => :integer, :size => ['small', 'large'], :width => :integer
)
end
@@ -21,7 +21,8 @@ def plugin_class
# 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
+ # 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,
@@ -32,7 +33,7 @@ def plugin_class
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('_')
+ 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
@@ -46,6 +47,5 @@ def stream_types
def story_lines
['oneline', 'multiline']
end
-
end
end
@@ -13,8 +13,8 @@ def plugin_class
# 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)
+ super.merge(:'via-url' => :string, :xid => :string, :'event-app-id' => :string,
+ :height => :integer, :'always-post-to-friends' => :boolean, :width => :integer)
end
end
end
@@ -17,7 +17,7 @@ def plugin_class
# 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)
+ super.merge(:'show-faces' => :boolean, :'max-rows' => :integer, :scope => :array, :width => :integer)
end
end
end
@@ -1,4 +1,4 @@
-module FacebookButtons
+module FacebookSocialPlugins
module ScriptHelper
# app_id - facebook app id, a number/string, fx '753632322'
@@ -21,12 +21,12 @@ def async_init_script app_id, domain, options = {}
}
end
- def facebook_script locale = :en
+ def facebook_script locale = :en_US
%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};
+ js.src = "#{all_script locale}";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
}
@@ -4,7 +4,7 @@ def initialize options = {}
super
end
- def button_class
+ def plugin_class
'fb-send'
end
@@ -15,7 +15,9 @@ def button_class
# 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'])
+ super.merge(:href => :string, :ref => :string, :fb_ref => :string,
+ :fb_source => ['message', 'group', 'email']
+ )
end
end
end
@@ -1,24 +1,42 @@
+require 'facebook-social_plugins/ui_helper'
+
module FacebookSocialPlugins
- class SocialPlugin
+ class SocialPlugin < UiHelper
+
+ attr_reader :options
+
def initialize options = {}
- validate!
@options = options
+ validate!
end
def render
- content_tag :div, render_options.merge(:class => plugin_class)
+ 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?
+ valid_options = {}
options.each do |key, value|
- attributes[key] == :special ? send("validate_#{key}", value) : valid?(value, attributes[key])
+ attr_key = find_att_key(key)
+ raise ArgumentError, "Unknown or unsupported attribute #{key}" unless attr_key
+ attributes[attr_key] == :special ? send("validate_#{key.to_s.underscore}", value) : valid?(value, attributes[attr_key])
+ valid_options[attr_key] = value
end
+ @options = valid_options
end
protected
+ def find_att_key key
+ return key if attributes[key]
+ key = key.to_s.dasherize.to_sym
+ return key if attributes[key]
+ key = key.to_s.underscore.to_sym
+ key if attributes[key]
+ end
+
# :width => 200 mapped to become 'data-width' => 200
def render_options
options.inject({}) {|res, opt| res["data-#{opt.first}"] = opt.last; res}
@@ -35,16 +53,32 @@ def attributes
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)
+ raise ArgumentError, "Must be a String, was #{value}" unless string?(value)
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)
+ raise ArgumentError, "Must be an Array or a String, was #{value}" unless array?(value)
when :integer
- raise ArgumentError, "Must be a Fixnum, was #{value}" unless value.is_a?(Fixnum)
+ raise ArgumentError, "Must be a Fixnum, was #{value}" unless integer?(value)
when :boolean
- raise ArgumentError, "Must be a Boolean, was #{value}" unless value.is_a?(Boolean)
+ raise ArgumentError, "Must be a Boolean, was #{value}" unless boolean?(value)
when Array
raise ArgumentError, "Must be a one of #{valid_type.inspect}, was #{value}" unless valid_type.include?(value.to_s)
end
end
+
+ def string? value
+ value.is_a?(String) || value.is_a?(Symbol)
+ end
+
+ def array? value
+ value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(Array)
+ end
+
+ def integer? value
+ value.is_a?(Fixnum) && value > 0
+ end
+
+ def boolean? value
+ value.is_a?(TrueClass) || value.is_a?(FalseClass)
+ end
end
end
@@ -0,0 +1,10 @@
+module FacebookSocialPlugins
+ class UiHelper
+ include ActionView::Helpers::TagHelper,
+ ActionView::Helpers::UrlHelper,
+ ActionView::Helpers::CaptureHelper,
+ ActionView::Helpers::JavaScriptHelper
+
+ attr_accessor :html, :javascript
+ end
+end
Oops, something went wrong.

0 comments on commit e3439c2

Please sign in to comment.