class FacebookSocialPlugins::Plugin::Social
Attributes
options[R]
Public Class Methods
new(options = {})
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 6 def initialize options = {} @options = options validate! end
Public Instance Methods
render()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 11 def render content_tag :div, '', render_options.merge(:class => plugin_class) end
validate!()
click to toggle source
the :special type indicates call to special type validator
# File lib/facebook-social_plugins/plugin/social.rb, line 16 def validate! return if options.empty? valid_options = {} options.each do |key, value| attr_key = find_att_key(key) raise ArgumentError, "Unknown or unsupported attribute #{key}" unless attr_key attributes[attr_key] == :special ? send("validate_#{key.to_s.underscore}", value) : valid?(value, attributes[attr_key]) valid_options[attr_key] = value end @options = valid_options end
Protected Instance Methods
array?(value)
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 90 def array? value value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(Array) end
attributes()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 67 def attributes @attributes ||= {:id => :string, :style => :string} end
boolean?(value)
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 98 def boolean? value value.is_a?(TrueClass) || value.is_a?(FalseClass) end
colorschemes()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 42 def colorschemes ['light', 'dark'] end
find_att_key(key)
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 50 def find_att_key key return key if attributes[key] key = key.to_s.dasherize.to_sym return key if attributes[key] key = key.to_s.underscore.to_sym key if attributes[key] end
fonts()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 38 def fonts ['arial', 'lucida grande', 'segoe ui', 'tahoma', 'trebuchet ms', 'verdana'] end
integer?(value)
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 94 def integer? value value.is_a?(Fixnum) && value > 0 end
layouts()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 30 def layouts ['standard', 'button_count', 'box_count'] end
linktargets()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 46 def linktargets ['_top', '_parent'] end
plugin_class()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 63 def plugin_class raise NotImplementedError, 'Must be implemented by subclass' end
render_options()
click to toggle source
:width => 200 mapped to become ‘data-width’ => 200
# File lib/facebook-social_plugins/plugin/social.rb, line 59 def render_options options.inject({}) {|res, opt| res["data-#{opt.first}"] = opt.last; res} end
sizes()
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 34 def sizes ['small', 'large'] end
string?(value)
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 86 def string? value value.is_a?(String) || value.is_a?(Symbol) end
valid?(value, valid_type)
click to toggle source
# File lib/facebook-social_plugins/plugin/social.rb, line 71 def valid? value, valid_type case valid_type when :string raise ArgumentError, "Must be a String, was #{value}" unless string?(value) when :array raise ArgumentError, "Must be an Array or a String, was #{value}" unless array?(value) when :integer raise ArgumentError, "Must be a Fixnum, was #{value}" unless integer?(value) when :boolean raise ArgumentError, "Must be a Boolean, was #{value}" unless boolean?(value) when Array raise ArgumentError, "Must be a one of #{valid_type.inspect}, was #{value}" unless valid_type.include?(value.to_s) end end