Module: Octopress::Social::Email

Extended by:
Email
Included in:
Email
Defined in:
lib/octopress-social/email.rb

Defined Under Namespace

Classes: Tag

Constant Summary collapse

DEFAULTS =
{
  'share_subject'       => ':title by :author',
  'share_message'       => ':title by :author - :url',
  'share_link_text'     => 'Email',
  'share_link_title'    => 'Share via email',
  'contact_link_text'   => 'Email :author',
  'contact_link_title'  => 'Email :author',
  'address'             => nil
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#configObject

Returns the value of attribute config.



7
8
9
# File 'lib/octopress-social/email.rb', line 7

def config
  @config
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/octopress-social/email.rb', line 7

def url
  @url
end

Instance Method Details

#author(item = {}) ⇒ Object



42
43
44
# File 'lib/octopress-social/email.rb', line 42

def author(item={})
  item['author'] || item['site']['author'] || ''
end


30
31
32
# File 'lib/octopress-social/email.rb', line 30

def contact_link_text(item)
  config['contact_link_text'].sub(':author', author(item))
end


34
35
36
# File 'lib/octopress-social/email.rb', line 34

def contact_link_title(item)
  config['contact_link_title'].sub(':author', author(item))
end


71
72
73
74
75
76
# File 'lib/octopress-social/email.rb', line 71

def email_contact_link(site, item)
  %Q{<a
    class="email-contact-link"
    href="mailto:#{config['address']}"
    title="#{contact_link_title(item)}">#{contact_link_text(item)}</a>}
end


65
66
67
68
69
# File 'lib/octopress-social/email.rb', line 65

def email_share_link(site, item)
  %Q{<a class="email-share-link" 
    href="mailto:?subject=#{subject(site, item)}&body=#{message(site, item)}"
    title="#{config['share_link_title']}">#{config['share_link_text']}</a>}
end

#message(site, item) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/octopress-social/email.rb', line 55

def message(site, item)
  name = author(item)
  author_var = (name.empty? ? 'by :author' : ':author')
  ERB::Util.url_encode (item['email_share_message'] || config['share_message'])
    .sub(':title', item['title'] || '')
    .sub(author_var, name)
    .sub(':url', url)
    .strip
end

#set_config(site) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/octopress-social/email.rb', line 19

def set_config(site)
  @config ||= begin
    config = site['octopress_social'] || site
    if config['email'] && config['email'].is_a?(String) && config['email'].include?('@')
      DEFAULTS.merge({'address' => config['email']} || {})
    else
      DEFAULTS.merge(config['email'] || {})
    end
  end
end

#set_url(site, item) ⇒ Object



38
39
40
# File 'lib/octopress-social/email.rb', line 38

def set_url(site, item)
  @url = Social.full_url(site, item)
end

#subject(site, item) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/octopress-social/email.rb', line 46

def subject(site, item)
  name = author(item)
  author_var = (name.empty? ? 'by :author' : ':author')
  ERB::Util.url_encode (item['email_share_subject'] || config['share_subject'])
    .sub(':title', item['title'] || '')
    .sub(author_var, name)
    .strip
end