Skip to content

Commit

Permalink
support provider subsitution in urls
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Jun 5, 2011
1 parent 20f83a8 commit c8f03a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Readme.md
Expand Up @@ -17,6 +17,11 @@ Usage

# app/helpers/application_helper.rb
def add_this(options)
# add google analytics tracking
url = request.request_uri
url += url.include?('?') ? '&' : '?'
url += 'utm_source=add_this&utm_medium=%{provider}'

StaticAddthis.icons(options.reverse_merge(
:title => @page_title,
:url => request.request_uri,
Expand Down
3 changes: 2 additions & 1 deletion lib/static_addthis.rb
Expand Up @@ -22,7 +22,8 @@ def self.social_icon(provider, options={})
end

def self.link_to_provider(name, options)
url = CGI.escape(options[:url] || raise('addthis needs :url'))
url = options[:url] || raise('addthis needs :url')
url = CGI.escape(url.gsub('%{provider}', name))
title = CGI.escape(options[:title] || raise('addthis needs :title'))
username = options[:username] || raise('addthis needs :username')
uid = options[:uid] || raise('addthis needs :uid')
Expand Down
4 changes: 4 additions & 0 deletions spec/static_addthis_spec.rb
Expand Up @@ -17,6 +17,10 @@
StaticAddthis.icons(defaults.merge(:providers => ['Twitter'])).should include(">Twitter<")
end

it "overwrites %{provider} in url" do
StaticAddthis.icons(defaults.merge(:providers => ['Twitter'], :url => 'xxx%{provider}yyy')).should include("xxxTwitteryyy")
end

it "ignores unknown providers so i can gsub them" do
result = StaticAddthis.icons(defaults.merge(:providers => ['Foo']))
result.should_not include(">Foo<")
Expand Down

0 comments on commit c8f03a9

Please sign in to comment.