facebook_share 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -22,21 +22,24 @@ Then add this to your ApplicationHelper
22
22
 
23
23
  module ApplicationHelper
24
24
  include FacebookShare
25
-
26
- FacebookShare.default_facebook_share_options = {
27
- :framework => :jquery,
28
- :jquery_function => "$",
29
25
 
30
- :app_id => "YOUR_APP_ID",
31
- :status => "false",
32
- :cookie => "false",
33
- :xfbml => "false",
34
-
35
- :selector => '.fb_share',
36
- :locale => "en_US"
37
- }
38
26
  end
39
27
 
28
+ Global configuration (config/initializers/facebook_share.rb ):
29
+
30
+ FacebookShare.default_facebook_share_options = {
31
+ :framework => :jquery,
32
+ :jquery_function => "$",
33
+
34
+ :app_id => "YOUR_APP_ID",
35
+ :status => "false",
36
+ :cookie => "false",
37
+ :xfbml => "false",
38
+
39
+ :selector => '.fb_share',
40
+ :locale => "en_US"
41
+ }
42
+
40
43
  You can ommit *app_id* parameter, if you already have a Facebook Application initialized in your project.
41
44
 
42
45
  Be sure you have <div id="fb-root"></div> in your application layout before you load the Facebook Connect JS
@@ -44,13 +47,15 @@ Be sure you have <div id="fb-root"></div> in your application layout before you
44
47
  Default facebook Share options can be changed with the above code snippet. The options can be also passed to any public method, so you don't have to rely on defaults at any given time.
45
48
 
46
49
  * *framework* - choose a JavaScript framework to work with. For now just **:dojo** and **:jquery** are supported.
47
- ** *jquery_function* - If you are using jQuery and mapped the jQuery function to a different variable, you can use that to pass a correct jQuery variable name, for example **$j**, **jQuery**, etc.
50
+ * *jquery_function* - If you are using jQuery and mapped the jQuery function to a different variable, you can use that to pass a correct jQuery variable name, for example **$j**, **jQuery**, etc.
48
51
  * *app_id* - your Facebook application ID that will connect your site to Facebook - as described at [FB.init JS SDK](http://developers.facebook.com/docs/reference/javascript/fb.init/)
49
52
  * *status*, *cookie* and *xfbml* - as described at [FB.init JS SDK](http://developers.facebook.com/docs/reference/javascript/fb.init/)
50
53
  * *locale* - Facebook locale code representations, ie. en_US, de_DE, pl_PL, etc. The full list of Facebook supported languages is available in http://www.facebook.com/translations/FacebookLocales.xml or at [Facebook Developer Wiki](http://fbdevwiki.com/wiki/Locales). If your locale has both parts of the string the same, for example "de_DE", "pl_PL", since version 0.0.4 you can put just "de" or "pl", etc. The script **does not** check for validity of given locale.
51
54
  * *selector* - a selector to target Facebook share binding, ".fb_share" by default
52
55
  * any other parameter will be passed to Facebook's **[FB.ui](http://developers.facebook.com/docs/reference/javascript/fb.ui/)** function, so you can use whichever parameters you need, except for *method*, which defaults always to *publish.stream*
53
56
 
57
+ *app_id*, *status*, *cookie*, *xfbml*, *locale*, *selector*, and the various FB.ui parameters also have \_js variants which insert Javascript to calculate the value at runtime. These Javascript snippets must be expressions, not full statements. If a \_js option is present, the non-\_js version of the option is ignored.
58
+
54
59
  ## Usage
55
60
 
56
61
  The simplest usage (given you specified your project's Facebook Application ID) is as follows:
@@ -60,8 +65,14 @@ The simplest usage (given you specified your project's Facebook Application ID)
60
65
 
61
66
  That will produce a link "Share on Facebook" with a class of "fb_share" and a corresponding JavaScript script tags initializing Facebook app and sharing method bind to click on that link. By default gem passes ".fb_share" selector to the Javascript framework of your choice.
62
67
 
68
+ You can find more usage examples at [Railslove blogpost](http://railslove.com/weblog/2011/02/22/introducing-simple-facebook-share-gem/) about this gem.
69
+
63
70
  ## Changelog
64
71
 
72
+ v0.0.6
73
+
74
+ * [[Brent Royal-Gordon](https://github.com/brentdax)] - Added \_js keys
75
+
65
76
  v0.0.5
66
77
 
67
78
  * Added support for [Dojo framework](http://dojotoolkit.org/)
@@ -44,7 +44,9 @@ JS
44
44
  case options[:framework]
45
45
  when :dojo
46
46
  script << <<-JS
47
- dojo.query("#{options[:selector]}").onclick(function(evt){
47
+ if (typeof ___facebook_share_evt != "undefined") dojo.disconnect(___facebook_share_evt);
48
+ var ___facebook_share_obj = dojo.query("#{options[:selector]}")
49
+ , ___facebook_share_evt = dojo.connect(___facebook_share_obj, 'onclick', null, function(evt) {
48
50
  #{facebook_share_code(options)}
49
51
  });
50
52
  JS
@@ -90,11 +92,24 @@ JS
90
92
  options.each do |key, value|
91
93
  # if it's for init script, include only status, cookie and xfbml
92
94
  # if it's for stream.publish, include all except for initial
93
- param_check = ( for_init ) ? FacebookShare::INIT_PARAMS.include?(key.to_s) : !(FacebookShare::REMOVE_PARAMS.include?(key.to_s))
95
+ should_add_param = ( for_init ) ? FacebookShare::INIT_PARAMS.include?(key.to_s) : !(FacebookShare::REMOVE_PARAMS.include?(key.to_s))
96
+
97
+ if key.to_s !~ /_js$/ and options[(key.to_s + "_js").to_sym]
98
+ should_add_param = false
99
+ end
94
100
 
95
- if value && param_check
96
- value_sanitized = value.to_s.gsub(/"/, '\"')
97
- script << ", #{key}: \"#{value_sanitized}\""
101
+ if value && should_add_param
102
+ inserted_key = key.to_s
103
+ inserted_value = value
104
+
105
+ if inserted_key =~ /_js$/
106
+ inserted_key = inserted_key[0, inserted_key.length - 3]
107
+ else
108
+ value_sanitized = inserted_value.to_s.gsub(/"/, '\"')
109
+ inserted_value = %Q("#{value_sanitized}")
110
+ end
111
+
112
+ script << %Q(, #{inserted_key}: #{inserted_value})
98
113
  end
99
114
  end
100
115
  script
@@ -1,3 +1,3 @@
1
1
  module FacebookShare
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -47,6 +47,51 @@ describe FacebookShare do
47
47
  end
48
48
  end
49
49
 
50
+ describe "building params with _js" do
51
+ before(:all) do
52
+ @options = {
53
+ :app_id => "123123123",
54
+
55
+ :selector => "#some_fancy > .selector",
56
+ :display => "popup",
57
+ :link => "http://railslove.com/",
58
+ :link_js => "some_js_url",
59
+ :caption_js => %Q("Railslove " + is_the + " best"),
60
+
61
+ :status => "true",
62
+ :xfbml => "true",
63
+ :cookie => "false"
64
+ }
65
+ end
66
+ context "when not for_init" do
67
+ subject { build_params(@options) }
68
+
69
+ it { should_not match(/app_id/) }
70
+ it { should_not match(/cookies/) }
71
+ it { should_not match(/xfbml/) }
72
+
73
+ it { should match(/display: "popup"/) }
74
+ it { should match(/link: some_js_url/) }
75
+ it { should match(/caption: "Railslove " \+ is_the \+ " best"/) }
76
+
77
+ it { should_not match(/selector: "/) }
78
+ end
79
+
80
+ context "when for_init" do
81
+ subject { build_params(@options, true) }
82
+
83
+ it { should_not match(/app_id/) }
84
+ it { should match(/cookie: "false"/) }
85
+ it { should match(/xfbml: "true"/) }
86
+
87
+ it { should_not match(/display: "popup"/) }
88
+ it { should_not match(/link: some_js_url/) }
89
+ it { should_not match(/caption: "Railslove " \+ is_the \+ " best"/) }
90
+
91
+ it { should_not match(/selector: "/) }
92
+ end
93
+ end
94
+
50
95
  describe "creating init script" do
51
96
  context "when vanilla locale" do
52
97
  subject { facebook_connect_js_tag( :locale => "en_US" ) }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: facebook_share
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Mike Po\xC5\x82tyn"
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-17 00:00:00 +01:00
18
+ date: 2011-08-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency