Module: ActsAsOpengraphHelper
- Defined in:
- lib/acts_as_opengraph/helper/acts_as_opengraph_helper.rb
Instance Method Summary collapse
- #fb_javascript_include_tag(appid = '', locale = 'en_US') ⇒ Object
-
#like_button_for(obj, options = {}) ⇒ String
Displays the Facebook Like Button in your views.
-
#opengraph_meta_tags_for(obj) ⇒ String
Generates the opengraph meta tags for your views.
Instance Method Details
#fb_javascript_include_tag(appid = '', locale = 'en_US') ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/acts_as_opengraph/helper/acts_as_opengraph_helper.rb', line 58 def fb_javascript_include_tag(appid='', locale='en_US') @fb_sdk_included = true async_fb = <<-END <div id="fb-root"></div> <script> window.fbAsyncInit = function() { FB.init({appId: '#{ appid }', status: true, cookie: true, xfbml: true}); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/#{locale}/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script> END async_fb.html_safe end |
#like_button_for(obj, options = {}) ⇒ String
Displays the Facebook Like Button in your views.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/acts_as_opengraph/helper/acts_as_opengraph_helper.rb', line 30 def (obj, = {}) raise(ArgumentError.new, "You need to call acts_as_opengraph on your #{obj.class} model") unless obj.respond_to?(:opengraph_data) href = [:href] ? [:href] : obj.opengraph_url return unless href.present? config = { :layout => :standard, :show_faces => false, :width => 450, :action => :like, :colorscheme => :light } config.update() if .is_a?(Hash) o_layout = config[:layout].to_sym if o_layout == :standard config[:height] = config[:show_faces].to_s.to_sym == :true ? 80 : 35 elsif o_layout == :button_count config[:height] = 21 elsif o_layout == :box_count config[:height] = 65 end config[:locale] ||= 'en_US' if config[:xfbml] unless @fb_sdk_included content_for :javascripts, fb_javascript_include_tag( config[:locale], config[:appid] ) end %(<fb:like href="#{CGI.escape(href)}" layout="#{config[:layout]}" show_faces="#{config[:show_faces]}" action="#{config[:action]}" colorscheme="#{config[:colorscheme]}" width="#{config[:width]}" height="#{config[:height]}" font="#{config[:font]}"></fb:like>) else %(<iframe src="http://www.facebook.com/plugins/like.php?href=#{CGI.escape(href)}&layout=#{config[:layout]}&show_faces=#{config[:show_faces]}&width=#{config[:width]}&action=#{config[:action]}&colorscheme=#{config[:colorscheme]}&height=#{config[:height]}" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:#{config[:width]}px; height:#{config[:height]}px;" allowTransparency="true"></iframe>) end end |
#opengraph_meta_tags_for(obj) ⇒ String
Generates the opengraph meta tags for your views
9 10 11 12 13 14 15 16 17 |
# File 'lib/acts_as_opengraph/helper/acts_as_opengraph_helper.rb', line 9 def (obj) raise(ArgumentError.new, "You need to call acts_as_opengraph on your #{obj.class} model") unless obj.respond_to?(:opengraph_data) = obj.opengraph_data.map do |att| att_name = att[:name] == "og:site_name" ? att[:name] : att[:name].dasherize %(<meta property="#{att_name}" content="#{Rack::Utils.escape_html(att[:value])}"/>) end = .join("\n") .respond_to?(:html_safe) ? .html_safe : end |