Module: Flakey::Buffer

Includes:
Base
Defined in:
lib/flakey/buffer.rb

Constant Summary collapse

SHARE_URL =
"https://bufferapp.com/add"

Instance Method Summary collapse

Methods included from Base

#default_url

Instance Method Details

#buffer_button(options = {}, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/flakey/buffer.rb', line 7

def buffer_button(options = {}, &block)
  defaults = {
    url: default_url,
    label: "Buffer",
    target: '_blank',
    class: 'buffer-add-button'
  }
  settings = defaults.merge(options)

  url = "#{SHARE_URL}?url=#{CGI.escape(settings[:url])}"

  if settings.has_key?(:text) && settings[:text] != ''
    url += "&text=#{CGI.escape(settings[:text])}"
  end

  # Delete these so we can pass the settings directly into link_to
  %w[url text].each { |url_key| settings.delete(url_key.to_sym) }

  if block_given?
    link_to(url, settings, &block)
  else
    link_to settings.delete(:label), url, settings
  end
end