diff --git a/lib/facebooker2.rb b/lib/facebooker2.rb index fae546e..b91c22b 100644 --- a/lib/facebooker2.rb +++ b/lib/facebooker2.rb @@ -46,5 +46,6 @@ end require "facebooker2/rails/controller" require "facebooker2/rails/helpers/facebook_connect" require "facebooker2/rails/helpers/javascript" +require "facebooker2/rails/helpers/request_forms" require "facebooker2/rails/helpers/user" require "facebooker2/rails/helpers" \ No newline at end of file diff --git a/lib/facebooker2/rails/helpers.rb b/lib/facebooker2/rails/helpers.rb index 4a80c3b..c82853d 100644 --- a/lib/facebooker2/rails/helpers.rb +++ b/lib/facebooker2/rails/helpers.rb @@ -3,7 +3,31 @@ module Facebooker2 module Helpers include FacebookConnect include Javascript + include RequestForms include User + + def fb_stringify_vals(hash) + result={} + hash.each do |key,value| + result[key]=value.to_s + end + result + end + def fb_transform_keys(options,transformation_hash) + new_hash = {} + options.each do |key,value| + new_key = transformation_hash[key]||key + new_hash[new_key]=value + end + new_hash + end + FB_ALWAYS_VALID_OPTION_KEYS = [:class, :style] + + def fb_assert_valid_keys(options,*valid_keys) + unknown_keys = options.keys - [valid_keys + FB_ALWAYS_VALID_OPTION_KEYS].flatten + raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? + end + end end end \ No newline at end of file diff --git a/lib/facebooker2/rails/helpers/request_forms.rb b/lib/facebooker2/rails/helpers/request_forms.rb new file mode 100644 index 0000000..5ac74d4 --- /dev/null +++ b/lib/facebooker2/rails/helpers/request_forms.rb @@ -0,0 +1,16 @@ +module Facebooker2 + module Rails + module Helpers + module RequestForms + def fb_req_choice(label,url) + tag "fb:req-choice",:label=>label,:url=>url + end + + def fb_multi_friend_selector(message,options={},&block) + options = fb_stringify_vals({:showborder=>false,:actiontext=>message,:max=>20}.merge(options.dup)) + tag("fb:multi-friend-selector",options) + end + end + end + end +end \ No newline at end of file diff --git a/lib/facebooker2/rails/helpers/user.rb b/lib/facebooker2/rails/helpers/user.rb index 3236432..50dce5a 100644 --- a/lib/facebooker2/rails/helpers/user.rb +++ b/lib/facebooker2/rails/helpers/user.rb @@ -42,27 +42,6 @@ module Facebooker2 end end - def fb_stringify_vals(hash) - result={} - hash.each do |key,value| - result[key]=value.to_s - end - result - end - def fb_transform_keys(options,transformation_hash) - new_hash = {} - options.each do |key,value| - new_key = transformation_hash[key]||key - new_hash[new_key]=value - end - new_hash - end - FB_ALWAYS_VALID_OPTION_KEYS = [:class, :style] - - def fb_assert_valid_keys(options,*valid_keys) - unknown_keys = options.keys - [valid_keys + FB_ALWAYS_VALID_OPTION_KEYS].flatten - raise(ArgumentError, "Unknown key(s): #{unknown_keys.join(", ")}") unless unknown_keys.empty? - end end end diff --git a/spec/helpers/facebook_connect_spec.rb b/spec/helpers/facebook_connect_spec.rb index 4b47b9d..a6ca74b 100644 --- a/spec/helpers/facebook_connect_spec.rb +++ b/spec/helpers/facebook_connect_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" describe Facebooker2::Rails::Helpers::FacebookConnect, :type=>:helper do - include Facebooker2::Rails::Helpers::FacebookConnect + include Facebooker2::Rails::Helpers describe "fb_login_and_redirect" do it "renders a login button" do fb_login_and_redirect("/").should == diff --git a/spec/helpers/request_forms_spec.rb b/spec/helpers/request_forms_spec.rb new file mode 100644 index 0000000..04d9d71 --- /dev/null +++ b/spec/helpers/request_forms_spec.rb @@ -0,0 +1,21 @@ +require "spec_helper" +describe Facebooker2::Rails::Helpers::RequestForms, :type=>:helper do + include Facebooker2::Rails::Helpers + + it "renders a request choice" do + fb_req_choice("mylabel","myurl").should == + "" + end + + describe "multi friend selector" do + it "renders a multi friend selector" do + fb_multi_friend_selector("my message").should == + "" + end + + it "allows you to override the default options" do + fb_multi_friend_selector("my message",:max=>5).should =~ /max="5"/ + end + + end +end \ No newline at end of file diff --git a/spec/helpers/user_spec.rb b/spec/helpers/user_spec.rb index c389455..a882853 100644 --- a/spec/helpers/user_spec.rb +++ b/spec/helpers/user_spec.rb @@ -1,6 +1,6 @@ require "spec_helper" describe Facebooker2::Rails::Helpers::User, :type=>:helper do - include Facebooker2::Rails::Helpers::User + include Facebooker2::Rails::Helpers describe "name" do it "has an fb_name tag" do fb_name("1").should == ""