Created
October 5, 2012 08:00
-
-
Save apraditya/3838667 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module OpengraphMethods | |
def og_site_name | |
"the site name" | |
end | |
#def og_title | |
# opengraph_from_method [:title, :full_name], use_postfix: true | |
#end | |
def og_description | |
opengraph_from_method [:logline_text, :about_me] | |
end | |
private | |
def opengraph_from_method(possible_methods, options={}) | |
default_options = {default_text: DEFAULT_TEXT, use_postfix: false} | |
options.reverse_merge! default_options | |
attribute_value = possible_methods.each do |method| | |
break send(method) if respond_to?(method) | |
end | |
if attribute_value.blank? | |
options[:default_text] | |
elsif options[:use_postfix] | |
"#{attribute_value} | #{options[:default_text]}" | |
else | |
attribute_value | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
include OpengraphMethods | |
acts_as_opengraph values: { type: 'movie'}, | |
columns: { title: :og_title, | |
site_name: :og_site_name, | |
description: :og_description | |
} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment