open_graph_helper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'http://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in open_graph_helper.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ require "open_graph_helper"
2
+
3
+ module OpenGraphHelper
4
+ class Railtie < Rails::Railtie
5
+ initializer "open_graph_helper.view_helpers" do
6
+ ActionView::Base.send :include, OpenGraphHelper
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module OpenGraphHelper
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,69 @@
1
+ require "open_graph_helper/version"
2
+ require 'open_graph_helper/railtie' if defined?(Rails)
3
+
4
+ # http://developers.facebook.com/docs/opengraph/
5
+ module OpenGraphHelper
6
+ def og_title(content)
7
+ "<meta property='og:title' content='#{content}'/>"
8
+ end
9
+
10
+ def og_description(content)
11
+ content = html_escape(strip_tags(content))
12
+ "<meta property='og:description' content='#{truncate(content , :length => 100)}'/>"
13
+ end
14
+
15
+ def og_type(content = "article")
16
+ "<meta property='og:type' content='#{content}'/>"
17
+ end
18
+
19
+ # 50x50 px ~ 150x150 px
20
+ def og_image(content)
21
+ "<meta property='og:image' content='#{content}'/>"
22
+ end
23
+
24
+ def og_url(content)
25
+ "<meta property='og:url' content='#{content}'/>"
26
+ end
27
+
28
+ def og_site_name(content)
29
+ "<meta property='og:site_name' content='#{content}'/>"
30
+ end
31
+
32
+ def og_fb_app_id(content)
33
+ tag(:meta, { :property => "fb:app_id", :content => content }, true)
34
+ end
35
+
36
+ def og_fb_admins(content)
37
+ tag(:meta, { :property => "fb:admins", :content => content }, true)
38
+ end
39
+
40
+ # types: icon, icon_link, button, button_count, box_count
41
+ def fb_share_link(share_url, type = "button_count", script = false)
42
+ output = link_to("分享", "http://www.facebook.com/sharer.php", :name => "fb_share", :share_url => share_url, :type => type, :class => "facebook fb-share")
43
+ output << content_tag(:script, "", :src => "http://static.ak.fbcdn.net/connect.php/js/FB.Share", :type => "text/javascript") if script
44
+ output
45
+ end
46
+
47
+ # types: button_count, standard
48
+ def fb_like_iframe(like_url, type = "button_count", size = "85x21")
49
+ width, height = size.split("x")
50
+ src = "http://www.facebook.com/plugins/like.php?href=#{like_url}&locale=zh_TW&layout=#{type}&show_faces=true&action=like&colorscheme=light&width=#{width}&height=#{height}"
51
+ style = "border:none; overflow:hidden; width:#{width}px; height:#{height}px;"
52
+ content_tag(:iframe, "", :src => src, :scrolling => "no", :frameborder => "0", :style => style, :allowtransparency => "true")
53
+ end
54
+
55
+ def fb_likebox_iframe(like_url, size = "240x65")
56
+ width, height = size.split("x")
57
+ src = "http://www.facebook.com/plugins/likebox.php?href=#{like_url}&connections=0&stream=false&header=true&colorscheme=light&width=#{width}&height=#{height}"
58
+ style = "border:none; overflow:hidden; width:#{width}px; height:#{height}px;"
59
+ content_tag(:iframe, "", :src => src, :scrolling => "no", :frameborder => "0", :style => style, :allowtransparency => "true")
60
+ end
61
+
62
+ def fb_recommendation_iframe(site_url, size = "300x380")
63
+ width, height = size.split("x")
64
+ src = "http://www.facebook.com/plugins/recommendations.php?site=#{site_url}&header=false&colorscheme=light&border_color=%23CCCCCC&width=#{width}&height=#{height}"
65
+ style = "border:none; overflow:hidden; width:#{width}px; height:#{height}px;"
66
+ content_tag(:iframe, "", :src => src, :scrolling => "no", :frameborder => "0", :style => style, :allowtransparency => "true")
67
+ end
68
+ end
69
+
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/open_graph_helper/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["xdite"]
6
+ gem.email = ["xdite@techbang.com.tw"]
7
+ gem.description = %q{OpenGraph Helper}
8
+ gem.summary = %q{OpenGraph Helper}
9
+ gem.homepage = ""
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "open_graph_helper"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OpenGraphHelper::VERSION
17
+ end
metadata ADDED
@@ -0,0 +1,74 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_graph_helper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - xdite
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-10-20 00:00:00 +08:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: OpenGraph Helper
23
+ email:
24
+ - xdite@techbang.com.tw
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files: []
30
+
31
+ files:
32
+ - .gitignore
33
+ - Gemfile
34
+ - Rakefile
35
+ - lib/open_graph_helper.rb
36
+ - lib/open_graph_helper/railtie.rb
37
+ - lib/open_graph_helper/version.rb
38
+ - open_graph_helper.gemspec
39
+ has_rdoc: true
40
+ homepage: ""
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ hash: 3
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ requirements: []
67
+
68
+ rubyforge_project:
69
+ rubygems_version: 1.5.2
70
+ signing_key:
71
+ specification_version: 3
72
+ summary: OpenGraph Helper
73
+ test_files: []
74
+