mmangino-facebooker 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@ module Facebooker
2
2
 
3
3
  class AdapterBase
4
4
  class UnableToLoadAdapter < Exception; end
5
- require 'active_support'
5
+ require 'active_support/inflector'
6
6
  include ActiveSupport::CoreExtensions::String::Inflections
7
7
  def facebook_path_prefix
8
8
  "/" + (@facebook_path_prefix || canvas_page_name || ENV['FACEBOOK_CANVAS_PATH'] || ENV['FACEBOOKER_RELATIVE_URL_ROOT'])
@@ -43,7 +43,8 @@ module Facebooker
43
43
  set_profile_fbml_without_bebo_adapter(profile_fbml,mobile_fbml, profile_action_fbml, profile_main)
44
44
  end
45
45
  end
46
- alias_method_chain :set_profile_fbml, :bebo_adapter
46
+ alias_method :set_profile_fbml_without_bebo_adapter, :set_profile_fbml
47
+ alias_method :set_profile_fbml, :set_profile_fbml_with_bebo_adapter
47
48
 
48
49
  private
49
50
 
@@ -67,7 +68,8 @@ module Facebooker
67
68
  process_without_bebo_adapter(data)
68
69
  end
69
70
  end
70
- alias_method_chain :process, :bebo_adapter
71
+ alias_method :process_without_bebo_adapter, :process
72
+ alias_method :process, :process_with_bebo_adapter
71
73
  end
72
74
  end
73
- end
75
+ end
@@ -1,7 +1,7 @@
1
1
  require 'facebooker/model'
2
2
  module Facebooker
3
3
  ##
4
- # A simple representation of a photo album.
4
+ # A simple representation of a friend list.
5
5
  class FriendList
6
6
  include Model
7
7
  attr_accessor :flid, :name
@@ -11,4 +11,4 @@ module Facebooker
11
11
  @flid= ( f.nil? ? nil : f.to_i)
12
12
  end
13
13
  end
14
- end
14
+ end
@@ -1,7 +1,6 @@
1
1
  require 'facebooker/model'
2
2
  require 'facebooker/models/affiliation'
3
3
  require 'facebooker/models/work_info'
4
- require 'active_support'
5
4
  module Facebooker
6
5
  #
7
6
  # Holds attributes and behavior for a Facebook User
@@ -307,7 +306,7 @@ module Facebooker
307
306
  ret.each do |hash|
308
307
  user_map.delete(hash)
309
308
  end
310
- unless user_map.blank?
309
+ unless user_map.empty?
311
310
  e=Facebooker::Session::UserRegistrationFailed.new
312
311
  e.failed_users = user_map.values
313
312
  raise e
@@ -111,7 +111,7 @@ module Facebooker
111
111
  # <em> Note: </em> I don't think the block is used here.
112
112
  def fb_multi_friend_selector(message,options={},&block)
113
113
  options = options.dup
114
- tag("fb:multi-friend-selector",stringify_vals(options.merge(:showborder=>false,:actiontext=>message,:max=>20)))
114
+ tag("fb:multi-friend-selector",stringify_vals({:showborder=>false,:actiontext=>message,:max=>20}.merge(options)))
115
115
  end
116
116
 
117
117
  # Render a condensed <fb:multi-friend-selector> with the passed in welcome message
@@ -404,6 +404,11 @@ module Facebooker
404
404
  def protect_against_forgery?
405
405
  @paf ||= ActionController::Base.new.send(:protect_against_forgery?)
406
406
  end
407
+
408
+ # url_for calls in publishers tend to want full paths
409
+ def url_for(options = {})
410
+ super(options.kind_of?(Hash) ? {:only_path => false}.update(options) : options)
411
+ end
407
412
  end
408
413
  ActionController::Routing::Routes.named_routes.install(self.master_helper_module)
409
414
  include self.master_helper_module
@@ -391,7 +391,7 @@ class PublisherTest < Test::Unit::TestCase
391
391
  assert_equal({:src => '/images/image.png', :href => 'raw_string' },
392
392
  TestPublisher.new.image('image.png', 'raw_string'))
393
393
  assert_equal({:src => '/images/image.png', :href => 'http://apps.facebook.com/mike/pokes/do/1' },
394
- TestPublisher.new.image('image.png', {:only_path=>false,:controller => :pokes, :action => :do, :id => 1}))
394
+ TestPublisher.new.image('image.png', {:controller => :pokes, :action => :do, :id => 1}))
395
395
  end
396
396
 
397
397
  def test_action_link
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mmangino-facebooker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Fowler
@@ -115,7 +115,6 @@ files:
115
115
  - lib/facebooker/rails/facebook_pretty_errors.rb
116
116
  - lib/facebooker/rails/facebook_request_fix.rb
117
117
  - lib/facebooker/rails/facebook_session_handling.rb
118
- - lib/facebooker/rails/facebook_url_helper.rb
119
118
  - lib/facebooker/rails/facebook_url_rewriting.rb
120
119
  - lib/facebooker/rails/helpers.rb
121
120
  - lib/facebooker/rails/profile_publisher_extensions.rb
@@ -1,191 +0,0 @@
1
- # Extends the ActionView::Helpers::UrlHelper module. See it for details on
2
- # the usual url helper methods: url_for, link_to, button_to, etc.
3
- #
4
- # Mostly, the changes sanitize javascript into facebook javascript.
5
- # It sanitizes link_to solely by altering the private methods:
6
- # convert_options_to_javascript!, confirm_javascript_function, and
7
- # method_javascript_function. For button_to, it alters button_to
8
- # itself, as well as confirm_javascript_function. No other methods
9
- # need to be changed because of Facebook javascript.
10
- #
11
- # For button_to and link_to, adds alternate confirm options for facebook.
12
- # ==== Options
13
- # * <tt>:confirm => 'question?'</tt> - This will add a JavaScript confirm
14
- # prompt with the question specified.
15
- #
16
- # Example:
17
- # # Generates: <a href="http://rubyforge.org/projects/facebooker" onclick="
18
- # # var dlg = new Dialog().showChoice('Please Confirm', 'Go to Facebooker?').setStyle();
19
- # # var a=this;dlg.onconfirm = function() {
20
- # # document.setLocation(a.getHref());
21
- # # }; return false;">Facebooker</a>
22
- # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>"Go to Facebooker?")
23
- #
24
- # Alternatively, options[:confirm] may be specified.
25
- # See the Facebook page http://wiki.developers.facebook.com/index.php/FBJS.
26
- # These options are:
27
- # <tt>:title</tt>:: Specifies the title of the Facebook dialog. Default is "Please Confirm".
28
- # <tt>:content</tt>:: Specifies the title of the Facebook dialog. Default is "Are you sure?".
29
- #
30
- # Example:
31
- # # Generates: <a href="http://rubyforge.org/projects/facebooker" onclick="
32
- # # var dlg = new Dialog().showChoice('the page says:', 'Go to Facebooker?').setStyle();
33
- # # var a=this;dlg.onconfirm = function() {
34
- # # document.setLocation(a.getHref());
35
- # # }; return false;">Facebooker</a>
36
- # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>{:title=>"the page says:", :content=>"Go to Facebooker?"})
37
- #
38
- # Any other options passed are assumed to be css styles.
39
- # Again, see the Facebook page http://wiki.developers.facebook.com/index.php/FBJS.
40
- #
41
- # Example:
42
- # # Generates: <a href="http://rubyforge.org/projects/facebooker" onclick="
43
- # # var dlg = new Dialog().showChoice('the page says:', 'Are you sure?').setStyle({color: 'pink', width: '200px'});
44
- # # var a=this;dlg.onconfirm = function() {
45
- # # document.setLocation(a.getHref());
46
- # # }; return false;">Facebooker</a>
47
- # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>{:title=>"the page says:, :color=>"pink", :width=>"200px"})
48
- module ActionView
49
- module Helpers
50
- module UrlHelper
51
- # Alters one and only one line of the Rails button_to. See below.
52
- def button_to_with_facebooker(name, options={}, html_options = {})
53
- if !request_comes_from_facebook?
54
- button_to_without_facebooker(name,options,html_options)
55
- else
56
- html_options = html_options.stringify_keys
57
- convert_boolean_attributes!(html_options, %w( disabled ))
58
-
59
- method_tag = ''
60
- if (method = html_options.delete('method')) && %w{put delete}.include?(method.to_s)
61
- method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s)
62
- end
63
-
64
- form_method = method.to_s == 'get' ? 'get' : 'post'
65
-
66
- request_token_tag = ''
67
- if form_method == 'post' && protect_against_forgery?
68
- request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token)
69
- end
70
-
71
- if confirm = html_options.delete("confirm")
72
- # this line is the only change => html_options["onclick"] = "return #{confirm_javascript_function(confirm)}"
73
- html_options["onclick"] = "#{confirm_javascript_function(confirm, 'a.getForm().submit();')}return false;"
74
- end
75
-
76
- url = options.is_a?(String) ? options : self.url_for(options)
77
- name ||= url
78
-
79
- html_options.merge!("type" => "submit", "value" => name)
80
-
81
- "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" +
82
- method_tag + tag("input", html_options) + request_token_tag + "</div></form>"
83
- end
84
- end
85
-
86
- alias_method_chain :button_to, :facebooker
87
-
88
- private
89
-
90
- # Altered to throw an error on :popup and sanitize the javascript
91
- # for Facebook.
92
- def convert_options_to_javascript_with_facebooker!(html_options, url ='')
93
- if !request_comes_from_facebook?
94
- convert_options_to_javascript_without_facebooker!(html_options,url)
95
- else
96
- confirm, popup = html_options.delete("confirm"), html_options.delete("popup")
97
-
98
- method, href = html_options.delete("method"), html_options['href']
99
-
100
- html_options["onclick"] = case
101
- when popup
102
- raise ActionView::ActionViewError, "You can't use :popup"
103
- when method # or maybe (confirm and method)
104
- "#{method_javascript_function(method, url, href, confirm)}return false;"
105
- when confirm # and only confirm
106
- "#{confirm_javascript_function(confirm)}return false;"
107
- else
108
- html_options["onclick"]
109
- end
110
- end
111
- end
112
-
113
- alias_method_chain :convert_options_to_javascript!, :facebooker
114
-
115
-
116
- # Overrides a private method that link_to calls via convert_options_to_javascript! and
117
- # also, button_to calls directly. For Facebook, confirm can be a hash of options to
118
- # stylize the Facebook dialog. Takes :title, :content, :style options. See
119
- # the Facebook page http://wiki.developers.facebook.com/index.php/FBJS for valid
120
- # style formats like "color: 'black', background: 'white'" or like "'color','black'".
121
- #
122
- # == Examples ==
123
- #
124
- # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>"Go to Facebooker?")
125
- # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>{:title=>"the page says:, :content=>"Go to Facebooker?"})
126
- # link_to("Facebooker", "http://rubyforge.org/projects/facebooker", :confirm=>{:title=>"the page says:, :content=>"Go to Facebooker?", :color=>"pink"})
127
- def confirm_javascript_function_with_facebooker(confirm, fun = nil)
128
- if !request_comes_from_facebook?
129
- confirm_javascript_function_without_facebooker(confirm)
130
- else
131
- if(confirm.is_a?(Hash))
132
- confirm_options = confirm.stringify_keys
133
- title = confirm_options.delete("title") || "Please Confirm"
134
- content = confirm_options.delete("content") || "Are you sure?"
135
- style = confirm_options.empty? ? "" : convert_options_to_css(confirm_options)
136
- else
137
- title,content,style = 'Please Confirm', confirm, ""
138
- end
139
-
140
- "var dlg = new Dialog().showChoice('#{escape_javascript(title.to_s)}','#{escape_javascript(content.to_s)}').setStyle(#{style});"+
141
- "var a=this;dlg.onconfirm = function() { #{fun ? fun : 'document.setLocation(a.getHref());'} };"
142
- end
143
- end
144
-
145
- alias_method_chain :confirm_javascript_function, :facebooker
146
-
147
- def convert_options_to_css(options)
148
- key_pair = options.shift
149
- style = "{#{key_pair[0]}: '#{key_pair[1]}'"
150
- for key in options.keys
151
- style << ", #{key}: '#{options[key]}'"
152
- end
153
- style << "}"
154
- end
155
-
156
- # Dynamically creates a form for link_to with method. Calls confirm_javascript_function if and
157
- # only if (confirm && method) for link_to
158
- def method_javascript_function_with_facebooker(method, url = '', href = nil, confirm = nil)
159
- if !request_comes_from_facebook?
160
- method_javascript_function_without_facebooker(method,url,href)
161
- else
162
- action = (href && url.size > 0) ? "'#{url}'" : 'a.getHref()'
163
- submit_function =
164
- "var f = document.createElement('form'); f.setStyle('display','none'); " +
165
- "a.getParentNode().appendChild(f); f.setMethod('POST'); f.setAction(#{action});"
166
-
167
- unless method == :post
168
- submit_function << "var m = document.createElement('input'); m.setType('hidden'); "
169
- submit_function << "m.setName('_method'); m.setValue('#{method}'); f.appendChild(m);"
170
- end
171
-
172
- if protect_against_forgery?
173
- submit_function << "var s = document.createElement('input'); s.setType('hidden'); "
174
- submit_function << "s.setName('#{request_forgery_protection_token}'); s.setValue('#{escape_javascript form_authenticity_token}'); f.appendChild(s);"
175
- end
176
- submit_function << "f.submit();"
177
-
178
- if(confirm)
179
- confirm_javascript_function(confirm, submit_function)
180
- else
181
- "var a=this;" + submit_function
182
- end
183
- end
184
- end
185
-
186
- alias_method_chain :method_javascript_function, :facebooker
187
-
188
- end
189
- end
190
- end
191
-