module Jaap3 module Addthis CONFIG = { :publisher => "" } DEFAULT_OPTIONS = { :script_src => "http://s7.addthis.com/js/200/addthis_widget.js", :secure => false } BOOKMARK_BUTTON_DEFAULTS = { :title => "", :alt => "Bookmark and Share" } FEED_BUTTON_DEFAULTS = { :title => "Subscribe using any feed reader!", :alt => "Subscribe" } EMAIL_BUTTON_DEFAULTS = { :title => "", :alt => "Email" } module Helper def addthis_bookmark_button(*args) url, options = extract_addthis_url_and_options(args) options = BOOKMARK_BUTTON_DEFAULTS.merge(options) s = %Q{} s << %Q{#{options[:alt]}} addthis_tag(s, options) end alias addthis_share_button addthis_bookmark_button def addthis_feed_button(url, *args) options = FEED_BUTTON_DEFAULTS.merge(extract_addthis_options(args)) s = %Q{} s << %Q{#{options[:alt]}} addthis_tag(s, options) end def addthis_email_button(*args) url, options = extract_addthis_url_and_options(args) options = EMAIL_BUTTON_DEFAULTS.merge(options) s = %Q{} s << %Q{#{options[:alt]}} addthis_tag(s, options) end protected def addthis_tag(str, options = {}) s = [%Q{}] s << %Q{} s << str s << %Q{} s << %Q{} s = s * "\n" options[:secure] ? s.gsub(/http:\/\/s[57]\.addthis\.com/, "https://secure.addthis.com") : s end def extract_addthis_url_and_options(args, options = {:page_title => "[TITLE]"}) url = args[0].is_a?(String) ? args.shift : "[URL]" return url, options = extract_addthis_options(args, options) end def extract_addthis_options(args, options = {}) page_title = args[0].is_a?(String) ? args.shift : options[:page_title] options = args[0].is_a?(Hash) ? args.shift : options options[:page_title] = page_title options = CONFIG.merge(DEFAULT_OPTIONS).merge(options) options.symbolize_keys! if options.respond_to?(:symbolize_keys!) return options end end end end