Add req_choice and multi friend selector helpers

This commit is contained in:
Mike Mangino 2010-05-06 10:52:04 -04:00
parent 674b45135a
commit 10f99214e4
7 changed files with 64 additions and 23 deletions

View File

@ -46,5 +46,6 @@ end
require "facebooker2/rails/controller" require "facebooker2/rails/controller"
require "facebooker2/rails/helpers/facebook_connect" require "facebooker2/rails/helpers/facebook_connect"
require "facebooker2/rails/helpers/javascript" require "facebooker2/rails/helpers/javascript"
require "facebooker2/rails/helpers/request_forms"
require "facebooker2/rails/helpers/user" require "facebooker2/rails/helpers/user"
require "facebooker2/rails/helpers" require "facebooker2/rails/helpers"

View File

@ -3,7 +3,31 @@ module Facebooker2
module Helpers module Helpers
include FacebookConnect include FacebookConnect
include Javascript include Javascript
include RequestForms
include User 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 end
end end

View File

@ -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

View File

@ -42,27 +42,6 @@ module Facebooker2
end end
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
end end

View File

@ -1,6 +1,6 @@
require "spec_helper" require "spec_helper"
describe Facebooker2::Rails::Helpers::FacebookConnect, :type=>:helper do describe Facebooker2::Rails::Helpers::FacebookConnect, :type=>:helper do
include Facebooker2::Rails::Helpers::FacebookConnect include Facebooker2::Rails::Helpers
describe "fb_login_and_redirect" do describe "fb_login_and_redirect" do
it "renders a login button" do it "renders a login button" do
fb_login_and_redirect("/").should == fb_login_and_redirect("/").should ==

View File

@ -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 ==
"<fb:req-choice label=\"mylabel\" url=\"myurl\" />"
end
describe "multi friend selector" do
it "renders a multi friend selector" do
fb_multi_friend_selector("my message").should ==
"<fb:multi-friend-selector actiontext=\"my message\" max=\"20\" showborder=\"false\" />"
end
it "allows you to override the default options" do
fb_multi_friend_selector("my message",:max=>5).should =~ /max="5"/
end
end
end

View File

@ -1,6 +1,6 @@
require "spec_helper" require "spec_helper"
describe Facebooker2::Rails::Helpers::User, :type=>:helper do describe Facebooker2::Rails::Helpers::User, :type=>:helper do
include Facebooker2::Rails::Helpers::User include Facebooker2::Rails::Helpers
describe "name" do describe "name" do
it "has an fb_name tag" do it "has an fb_name tag" do
fb_name("1").should == "<fb:name uid=\"1\"></fb:name>" fb_name("1").should == "<fb:name uid=\"1\"></fb:name>"