Add req_choice and multi friend selector helpers
This commit is contained in:
parent
674b45135a
commit
10f99214e4
@ -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"
|
@ -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
|
16
lib/facebooker2/rails/helpers/request_forms.rb
Normal file
16
lib/facebooker2/rails/helpers/request_forms.rb
Normal 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
|
@ -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
|
||||
|
@ -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 ==
|
||||
|
21
spec/helpers/request_forms_spec.rb
Normal file
21
spec/helpers/request_forms_spec.rb
Normal 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
|
@ -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 == "<fb:name uid=\"1\"></fb:name>"
|
||||
|
Loading…
Reference in New Issue
Block a user