Module: ActsAsOpengraphHelper
- Defined in:
- lib/acts_as_opengraph/helper/acts_as_opengraph_helper.rb
Instance Method Summary collapse
-
#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
#like_button_for(obj, options = {}) ⇒ String
Displays the Facebook Like Button in your views.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/acts_as_opengraph/helper/acts_as_opengraph_helper.rb', line 29 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 %(<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 |
#opengraph_meta_tags_for(obj) ⇒ String
Generates the opengraph meta tags for your views
9 10 11 12 13 14 15 16 |
# 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| %(<meta property="#{att[:name].dasherize}" content="#{Rack::Utils.escape_html(att[:value])}"/>) end = .join("\n") .respond_to?(:html_safe) ? .html_safe : end |