Created
September 28, 2012 08:46
-
-
Save apraditya/3798700 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
class User < ActiveRecord::Base | |
include OpengraphMethods | |
def opengraph_title | |
opengraph_site_name # doesn't create the meta entry | |
# These don't create as well | |
send(:opengraph_site_name) | |
send(:opengraph_site_name).to_s | |
'this one works' | |
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
module OpengraphMethods | |
def opengraph_site_name | |
"TAI" | |
end | |
#def opengraph_title | |
# opengraph_from_method [:title, :full_name], use_postfix: true | |
#end | |
def opengraph_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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment