eukaliptus 0.8.4 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,7 +37,7 @@ Your rails application must be using jQuery as it will be the default JS library
37
37
 
38
38
  Just behind the <body> tag in your application.html.erb write:
39
39
 
40
- <%= fb_login %>
40
+ <%= fb_init %>
41
41
 
42
42
  This generates the necessary JS code to perform request to Eukaliptus that fixes cookies security problems involved in running iframe applications in Safari and IE6+
43
43
 
@@ -0,0 +1,54 @@
1
+ <div id="fb-root"></div>
2
+ <script type="text/javascript">
3
+ window.fbAsyncInit = function() {
4
+ FB.init({
5
+ appId: '<%= Facebook::APP_ID.to_s %>',
6
+ status: true,
7
+ cookie: true,
8
+ xfbml: true
9
+ });
10
+
11
+ FB.Canvas.setAutoResize(100);
12
+ };
13
+
14
+ (function() {
15
+ var e = document.createElement('script'); e.async = true;
16
+ e.src = document.location.protocol +
17
+ '//connect.facebook.net/<%= locale %>/all.js';
18
+ document.getElementById('fb-root').appendChild(e);
19
+ }());
20
+
21
+ var login = function(targetUrl, perms) {
22
+ if (perms == null) {
23
+ perms = "<%= perms %>"
24
+ }
25
+ FB.login(function(response) {
26
+ if (response.session) {
27
+ fixSession(JSON.stringify(response.session), targetUrl);
28
+ } else {
29
+ //pending to do when not logged in
30
+ }
31
+ }, {perms: perms});
32
+ }
33
+
34
+ var fixSession = function(fbSession, targetUrl) {
35
+ $("body").prepend('<form id="fixSession"></form>');
36
+
37
+ var f = $('form')[0];
38
+ f.method = 'POST';
39
+ f.action = "/cookie_fix";
40
+ var m = document.createElement('input');
41
+ m.setAttribute('type', 'hidden');
42
+ m.setAttribute('name', '_session_id');
43
+ m.setAttribute('value', fbSession);
44
+ f.appendChild(m);
45
+
46
+ m = document.createElement('input');
47
+ m.setAttribute('type', 'hidden');
48
+ m.setAttribute('name', 'redirect_to');
49
+ m.setAttribute('value', targetUrl);
50
+ f.appendChild(m);
51
+
52
+ f.submit();
53
+ }
54
+ </script>
@@ -1,3 +1,3 @@
1
1
  module Eukaliptus
2
- VERSION = "0.8.4"
2
+ VERSION = "0.8.7"
3
3
  end
@@ -1,74 +1,47 @@
1
1
  module Eukaliptus
2
2
  module FacebookHelpers
3
+ #Deprecated
4
+ def fb_login(perms = %w{email publish_stream})
5
+ raise 'fb_login is a deprecated method. Please use use fb_init instead.'
6
+ end
7
+
3
8
  # Renders the HTML + JS that enables the app to log in to Facebook using
4
9
  # the Javascript method.
5
10
  #
6
11
  # Accepts the permissions that your application needs to work.
12
+ # Use the second parameter to inject some JS that will be executed in fbAsyncInit.
7
13
  #
8
- # Use it one time in your layout header or use it in several app places
14
+ # Use it one time in your layout header for all pages, or add it to individual templates
9
15
  # to ask the user for different permissions depending on the context, page, etc.
10
- def fb_login(perms = %w{email publish_stream})
11
- js = <<-DATA
12
- <div id="fb-root"></div>
13
- <script type="text/javascript">
14
- window.fbAsyncInit = function() {
15
- FB.init({
16
- appId: '#{Facebook::APP_ID.to_s}',
17
- status: true,
18
- cookie: true,
19
- xfbml: true
20
- });
21
-
22
- FB.Canvas.setAutoResize(100);
23
- };
24
-
25
- (function() {
26
- var e = document.createElement('script'); e.async = true;
27
- e.src = document.location.protocol +
28
- '//connect.facebook.net/es_ES/all.js';
29
- document.getElementById('fb-root').appendChild(e);
30
- }());
31
-
32
- var login = function(targetUrl, perms) {
33
- if (perms == null) {
34
- perms = "#{perms.join(',')}"
35
- }
36
- FB.login(function(response) {
37
- if (response.session) {
38
- fixSession(JSON.stringify(response.session), targetUrl);
39
- } else {
40
- //pending to do when not logged in
41
- }
42
- }, {perms: perms});
43
- }
44
-
16
+ def fb_init(options = {})
17
+ perms = (options[:perms] || %w{email publish_stream}).join(",")
18
+ locale = options[:locale] || "en_US"
45
19
 
46
-
47
- function fixSession(fbSession, targetUrl) {
48
- $("body").prepend('<form id="fixSession"></form>');
49
-
50
- var f = $('form')[0];
51
- f.method = 'POST';
52
- f.action = "/cookie_fix";
53
- var m = document.createElement('input');
54
- m.setAttribute('type', 'hidden');
55
- m.setAttribute('name', '_session_id');
56
- m.setAttribute('value', fbSession);
57
- f.appendChild(m);
58
-
59
- m = document.createElement('input');
60
- m.setAttribute('type', 'hidden');
61
- m.setAttribute('name', 'redirect_to');
62
- m.setAttribute('value', targetUrl);
63
- f.appendChild(m);
64
-
65
- f.submit();
66
- }
67
- </script>
68
- DATA
20
+ template = Erubis::Eruby.new File.new(File.dirname(__FILE__) + "/../templates/fb_init.erb").read
21
+ js = template.result(:perms => perms, :locale => locale)
69
22
 
70
23
  js.html_safe
71
24
  end
25
+
26
+ def with_fb(script = nil, &script_block)
27
+ code = script_block.try(:call) || script || ""
28
+ scriptlet = <<-DATA
29
+ <script>
30
+ (function() {
31
+ var oldFBInit = window.fbAsyncInit;
32
+ var fn = function() {
33
+ if (typeof(oldFBInit) === "function") {
34
+ oldFBInit();
35
+ }
36
+ #{code}
37
+ }
38
+
39
+ typeof(FB) !== "undefined" ? fn() : (window.fbAsyncInit = fn);
40
+ }())
41
+ </script>
42
+ DATA
43
+ scriptlet.html_safe
44
+ end
72
45
 
73
46
  # Function to create a new FB.ui dialog link
74
47
  def fb_ui(name, options ={})
metadata CHANGED
@@ -1,62 +1,59 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: eukaliptus
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.8.7
4
5
  prerelease:
5
- version: 0.8.4
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - season
9
9
  - victorcoder
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
-
14
- date: 2011-06-20 00:00:00 +02:00
13
+ date: 2011-06-25 00:00:00.000000000 +02:00
15
14
  default_executable:
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
18
17
  name: koala
19
- prerelease: false
20
- requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirement: &2156881700 !ruby/object:Gem::Requirement
21
19
  none: false
22
- requirements:
20
+ requirements:
23
21
  - - ~>
24
- - !ruby/object:Gem::Version
22
+ - !ruby/object:Gem::Version
25
23
  version: 1.0.0
26
24
  type: :runtime
27
- version_requirements: *id001
28
- - !ruby/object:Gem::Dependency
29
- name: minitest
30
25
  prerelease: false
31
- requirement: &id002 !ruby/object:Gem::Requirement
26
+ version_requirements: *2156881700
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: &2156881280 !ruby/object:Gem::Requirement
32
30
  none: false
33
- requirements:
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: "0"
31
+ requirements:
32
+ - - ! '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
37
35
  type: :development
38
- version_requirements: *id002
39
- - !ruby/object:Gem::Dependency
40
- name: rack-test
41
36
  prerelease: false
42
- requirement: &id003 !ruby/object:Gem::Requirement
37
+ version_requirements: *2156881280
38
+ - !ruby/object:Gem::Dependency
39
+ name: rack-test
40
+ requirement: &2156880800 !ruby/object:Gem::Requirement
43
41
  none: false
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: "0"
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
48
46
  type: :development
49
- version_requirements: *id003
50
- description: Eukaliptus is a set of helpers and bug fixes for browsers to help you build Facebook iframe applications or user fan tabs.
51
- email:
47
+ prerelease: false
48
+ version_requirements: *2156880800
49
+ description: Eukaliptus is a set of helpers and bug fixes for browsers to help you
50
+ build Facebook iframe applications or user fan tabs.
51
+ email:
52
52
  - victorcoder@gmail.com
53
53
  executables: []
54
-
55
54
  extensions: []
56
-
57
55
  extra_rdoc_files: []
58
-
59
- files:
56
+ files:
60
57
  - .gitignore
61
58
  - Gemfile
62
59
  - LICENSE.txt
@@ -68,6 +65,7 @@ files:
68
65
  - lib/eukaliptus/middleware.rb
69
66
  - lib/eukaliptus/railtie.rb
70
67
  - lib/eukaliptus/request.rb
68
+ - lib/eukaliptus/templates/fb_init.erb
71
69
  - lib/eukaliptus/version.rb
72
70
  - lib/eukaliptus/view_helpers/facebook_helpers.rb
73
71
  - lib/generators/eukaliptus/config_generator.rb
@@ -78,33 +76,31 @@ files:
78
76
  - test/view_helpers/facebook_helpers_test.rb
79
77
  has_rdoc: true
80
78
  homepage: http://github.com/seasonlabs/eukaliptus
81
- licenses:
79
+ licenses:
82
80
  - MIT
83
81
  post_install_message:
84
82
  rdoc_options: []
85
-
86
- require_paths:
83
+ require_paths:
87
84
  - lib
88
- required_ruby_version: !ruby/object:Gem::Requirement
85
+ required_ruby_version: !ruby/object:Gem::Requirement
89
86
  none: false
90
- requirements:
91
- - - ">="
92
- - !ruby/object:Gem::Version
93
- version: "0"
94
- required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
92
  none: false
96
- requirements:
97
- - - ">="
98
- - !ruby/object:Gem::Version
99
- version: "0"
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
100
97
  requirements: []
101
-
102
98
  rubyforge_project: eukaliptus
103
- rubygems_version: 1.6.1
99
+ rubygems_version: 1.6.2
104
100
  signing_key:
105
101
  specification_version: 3
106
102
  summary: Eukaliptus Facebook API Helpers
107
- test_files:
103
+ test_files:
108
104
  - test/middleware_test.rb
109
105
  - test/test_helper.rb
110
106
  - test/view_helpers/facebook_helpers_test.rb