open_graph_helper 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.markdown +9 -0
- data/README.markdown +43 -6
- data/lib/open_graph_helper.rb +31 -6
- data/lib/open_graph_helper/version.rb +1 -1
- metadata +5 -5
data/CHANGELOG.markdown
ADDED
data/README.markdown
CHANGED
@@ -7,7 +7,7 @@ There are only small subsets of tags are supported (for now).
|
|
7
7
|
|
8
8
|
Pull requests are welcome.
|
9
9
|
|
10
|
-
The Facebook Social Plugins
|
10
|
+
The Facebook Social Plugins can be rendered in HTML5 version (default) or `<iframe>` version. Their default options are tuned for Techbang. Override them by passing a Hash; see below.
|
11
11
|
|
12
12
|
## Usage
|
13
13
|
|
@@ -17,7 +17,7 @@ Add this to your `Gemfile`:
|
|
17
17
|
|
18
18
|
If you want to use the edge version on Github, specify the `:git` option.
|
19
19
|
|
20
|
-
gem 'open_graph_helper', :
|
20
|
+
gem 'open_graph_helper', :github => 'techbang/open_graph_helper'
|
21
21
|
|
22
22
|
And run
|
23
23
|
|
@@ -25,9 +25,15 @@ And run
|
|
25
25
|
|
26
26
|
to install this plug-in.
|
27
27
|
|
28
|
-
|
28
|
+
For Social Plugins, OpenGraphHelper provides 2 versions for that: the new `:html5` and legacy `:iframe`.
|
29
29
|
|
30
|
-
If you're
|
30
|
+
`:html5` version is the default option and requires JavaScript SDK. See [Facebook JavaScript SDK](http://developers.facebook.com/docs/reference/javascript/) for more details. If you're using [Facebooker2](https://github.com/mmangino/facebooker2), please include the SDK by `<%= fb_connect_async_js %>`.
|
31
|
+
|
32
|
+
To switch to `:iframe` version, you need an initializer. Name it, say, `open_graph_helper.rb`, with one line of content:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
OpenGraphHelper::SOCIAL_PLUGIN_VERSION = :iframe # HTML5 + JS SDK doesn't need this
|
36
|
+
```
|
31
37
|
|
32
38
|
The last thing: don't forget to add XML namespaces to the `<html>` tag, or `<meta>` tags won't work.
|
33
39
|
|
@@ -61,13 +67,33 @@ og_site_name("IMDb")
|
|
61
67
|
og_description("Lorem Ipsum ...")
|
62
68
|
#=> <meta property="og:description" cotent="Lorem Ipsum ..."/>
|
63
69
|
|
64
|
-
og_fb_admins(
|
65
|
-
#=> <meta property="fb:admins" content="123456
|
70
|
+
og_fb_admins(%w(123456 789012)) # Accepts an Array for multiple admins
|
71
|
+
#=> <meta property="fb:admins" content="123456"/>
|
72
|
+
# <meta property="fb:admins" content="789012"/>
|
66
73
|
|
67
74
|
og_fb_app_id("1234567890")
|
68
75
|
#=> <meta property="fb:app_id" content="1234567890"/>
|
69
76
|
```
|
70
77
|
|
78
|
+
### Note on Multiple-Value (e.g. `fb:admins`)
|
79
|
+
|
80
|
+
According to Open Graph Protocol, multiple-value should be represented as an [Array](http://ogp.me/#array), not separated by a single comma `,` (U+002C).
|
81
|
+
|
82
|
+
This pitfall was found when assigning admins for [Facebook Comments Plug-In](https://developers.facebook.com/docs/reference/plugins/comments/). Although the document says:
|
83
|
+
|
84
|
+
> To add multiple moderators, separate the uids by comma without spaces.
|
85
|
+
|
86
|
+
It does actually not working, and a parser error will be warned by [Open Graph Debugger](https://developers.facebook.com/tools/debug/). A working example should like this:
|
87
|
+
|
88
|
+
```html
|
89
|
+
<meta property="fb:admins" content="123456">
|
90
|
+
<meta property="fb:admins" content="789012">
|
91
|
+
```
|
92
|
+
|
93
|
+
Therefore, OpenGraphHelper's `og_fb_admins` accepts an array, in which situation it maps each element to a single `fb:admins` meta tag, and concatenates them in a single line.
|
94
|
+
|
95
|
+
See this QA: http://stackoverflow.com/a/12007788
|
96
|
+
|
71
97
|
## Facebook Social Plugins
|
72
98
|
|
73
99
|
There are some default options that was optimized for [Techbang](http://www.techbang.com.tw) sites and may not suits for your needs. Override them by passing a Hash as the last argument.
|
@@ -143,3 +169,14 @@ fb_recommendations("www.example.com", :header => true, :colorscheme => "dark")
|
|
143
169
|
#=> <div class="fb-recommendations" data-border-color="#CCC" data-colorscheme="dark" data-header="true" data-height="380" data-site="www.example.com" data-width="300"></div>
|
144
170
|
```
|
145
171
|
|
172
|
+
# License
|
173
|
+
|
174
|
+
This software is released under the MIT License
|
175
|
+
|
176
|
+
Copyright (c) 2011- Techbang
|
177
|
+
|
178
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
179
|
+
|
180
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
181
|
+
|
182
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/open_graph_helper.rb
CHANGED
@@ -4,6 +4,8 @@ require 'open_graph_helper/railtie' if defined?(Rails)
|
|
4
4
|
|
5
5
|
# http://developers.facebook.com/docs/opengraph/
|
6
6
|
module OpenGraphHelper
|
7
|
+
SOCIAL_PLUGIN_VERSION = :html5
|
8
|
+
|
7
9
|
def og_title(content)
|
8
10
|
tag(:meta, { :property => "og:title", :content => content }, true)
|
9
11
|
end
|
@@ -34,8 +36,31 @@ module OpenGraphHelper
|
|
34
36
|
tag(:meta, { :property => "fb:app_id", :content => content }, true)
|
35
37
|
end
|
36
38
|
|
37
|
-
def og_fb_admins(
|
38
|
-
|
39
|
+
def og_fb_admins(admins)
|
40
|
+
# Multiple fb:admins should be specified in separated meta tags
|
41
|
+
# See Issue #3
|
42
|
+
if admins.is_a? Array
|
43
|
+
admins.map { |admin|
|
44
|
+
tag(:meta, { :property => "fb:admins", :content => admin }, true)
|
45
|
+
}.join.html_safe
|
46
|
+
else
|
47
|
+
tag(:meta, { :property => "fb:admins", :content => admins }, true)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def social_plugin(plugin_name, options)
|
52
|
+
case SOCIAL_PLUGIN_VERSION
|
53
|
+
when :html5
|
54
|
+
content_tag(:div, "", :class => "fb-#{plugin_name.to_s}", :data => options)
|
55
|
+
when :iframe
|
56
|
+
width = options.delete(:width)
|
57
|
+
height = options.delete(:height)
|
58
|
+
style = "border:none; overflow:hidden; width:#{width}px; height:#{height}px;"
|
59
|
+
src = "http://www.facebook.com/plugins/#{plugin_name}.php?#{options.to_param}"
|
60
|
+
content_tag(:iframe, "", :src => src, :scrolling => "no", :frameborder => "0", :style => style, :allowtransparency => "true")
|
61
|
+
else
|
62
|
+
raise "Unknown Social Plugin Version: #{SOCIAL_PLUGIN_VERSION}"
|
63
|
+
end
|
39
64
|
end
|
40
65
|
|
41
66
|
# types: button_count, standard, box_count
|
@@ -50,7 +75,7 @@ module OpenGraphHelper
|
|
50
75
|
|
51
76
|
options.merge! custom_options
|
52
77
|
|
53
|
-
|
78
|
+
social_plugin("like", options)
|
54
79
|
end
|
55
80
|
|
56
81
|
def fb_likebox(page_url, custom_options={})
|
@@ -65,7 +90,7 @@ module OpenGraphHelper
|
|
65
90
|
|
66
91
|
options.merge! custom_options
|
67
92
|
|
68
|
-
|
93
|
+
social_plugin("like-box", options)
|
69
94
|
end
|
70
95
|
|
71
96
|
def fb_recommendations(site_url, custom_options={})
|
@@ -81,7 +106,7 @@ module OpenGraphHelper
|
|
81
106
|
|
82
107
|
options.merge! custom_options
|
83
108
|
|
84
|
-
|
109
|
+
social_plugin("recommendations", options)
|
85
110
|
end
|
86
111
|
|
87
112
|
def fb_comments(url, custom_options={})
|
@@ -92,7 +117,7 @@ module OpenGraphHelper
|
|
92
117
|
|
93
118
|
options.merge! custom_options
|
94
119
|
|
95
|
-
|
120
|
+
social_plugin("comments", options)
|
96
121
|
end
|
97
122
|
|
98
123
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_graph_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
default_executable:
|
12
|
+
date: 2013-05-13 00:00:00.000000000 Z
|
14
13
|
dependencies: []
|
15
14
|
description: OpenGraph Helper
|
16
15
|
email:
|
@@ -20,6 +19,7 @@ extensions: []
|
|
20
19
|
extra_rdoc_files: []
|
21
20
|
files:
|
22
21
|
- .gitignore
|
22
|
+
- CHANGELOG.markdown
|
23
23
|
- Gemfile
|
24
24
|
- README.markdown
|
25
25
|
- Rakefile
|
@@ -27,7 +27,6 @@ files:
|
|
27
27
|
- lib/open_graph_helper/railtie.rb
|
28
28
|
- lib/open_graph_helper/version.rb
|
29
29
|
- open_graph_helper.gemspec
|
30
|
-
has_rdoc: true
|
31
30
|
homepage: ''
|
32
31
|
licenses: []
|
33
32
|
post_install_message:
|
@@ -48,8 +47,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
47
|
version: '0'
|
49
48
|
requirements: []
|
50
49
|
rubyforge_project:
|
51
|
-
rubygems_version: 1.
|
50
|
+
rubygems_version: 1.8.25
|
52
51
|
signing_key:
|
53
52
|
specification_version: 3
|
54
53
|
summary: OpenGraph Helper
|
55
54
|
test_files: []
|
55
|
+
has_rdoc:
|