Module: Octopress::Social::Facebook

Extended by:
Facebook
Included in:
Facebook
Defined in:
lib/octopress-social/facebook.rb

Defined Under Namespace

Classes: Tag

Constant Summary collapse

DEFAULTS =
{
  'profile_id'           => nil,
  'app_id'               => nil,
  'layout'               => 'button',
  'action'               => 'like',
  'show_faces'           => false,
  'share'                => false,
  'colorscheme'          => 'light',
  'kid_directed_site'    => false,
  'comment_count'        => 5,
  'share_link_text'      => 'Facebook',
  'share_link_title'     => 'Share on Facebook',
  'profile_link_text'    => 'Friend on Facebook',
  'profile_link_title'   => 'Friend on Facebook',
  'comments_link_text'   => 'Comments',
  'disabled_comments_text' => 'Comments disabled'
}

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/facebook.rb', line 7

def config
  @config
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#facebook_comments(site, item) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/octopress-social/facebook.rb', line 114

def facebook_comments(site, item)
  if item['comments'] != false
    %Q{<div class="fb-comments" id="facebook_comments"
    data-href="#{url}" 
    data-numposts="#{config['comment_count']}" 
    data-colorscheme="#{config['colorscheme']}"
    ></div>}
  else
    ''
  end
end


126
127
128
129
130
131
132
133
134
135
136
# File 'lib/octopress-social/facebook.rb', line 126

def facebook_comments_link(site, item)
  if item['comments'] != false
    link = (item['context'] == 'page' ? '' : url)
    link << '#facebook_comments'
    %Q{<a class="facebook-comments-link" href="#{link}">Comments</a>}
  elsif !config['disabled_comments_text'].empty?
    %Q{<span class="facebook-comments-disabled">#{config['disabled_comments_text']}</span>}
  else
    ''
  end
end

#facebook_follow_button(*args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/octopress-social/facebook.rb', line 73

def facebook_follow_button(*args)
  %Q{<div class="fb-follow" 
    data-href="https://www.facebook.com/#{config['profile_id']}"
    #{width}
    data-layout="#{config['layout']}"
    data-layout="#{config['layout']}"
    data-action="#{config['action']}"
    data-colorscheme="#{config['colorscheme']}">
  </div>}
end

#facebook_like_button(site, item) ⇒ Object



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

def facebook_like_button(site, item)
  %Q{<div class="fb-like"
    data-href="#{url}"
    #{width}
    data-layout="#{config['layout']}"
    data-action="#{config['action']}"
    data-show-faces="#{config['show_faces']}"
    data-colorscheme="#{config['colorscheme']}"
    data-kid-directed-site="#{config['kid_directed_site']}"
    data-share="#{config['share']}"></div>
  }
end


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

def facebook_profile_link(*args)
  %Q{<a
    class="facebook-profile-link"
    href="https://www.facebook.com/#{config['profile_id']}"
    title="#{config['profile_link_title']}"
    >#{config['profile_link_text']}</a>}
end

#facebook_script_tag(*args) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/octopress-social/facebook.rb', line 101

def facebook_script_tag(*args)
  %Q{
    <div id="fb-root"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.0";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
  }
end

#facebook_send_button(site, item) ⇒ Object



84
85
86
87
88
89
90
91
# File 'lib/octopress-social/facebook.rb', line 84

def facebook_send_button(site, item)
  %Q{<div class="fb-send" 
    data-href="#{url}"
    #{width}
    data-colorscheme="#{config['colorscheme']}"
    data-kid-directed-site="#{config['kid_directed_site']}"></div>
  }
end


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/octopress-social/facebook.rb', line 38

def facebook_share_link(site, item)
  if config['app_id']
    %Q{<a class="facebook-share-link" href="https://www.facebook.com/dialog/share?
    app_id=#{config['app_id']}
    &href=#{url}&redirect_uri=#{url}"
    title="#{config['share_link_title']}">#{config['share_link_text']}</a>
    }
  else
    %Q{<a class="facebook-share-link" 
    href="https://www.facebook.com/sharer/sharer.php?u=#{url}" 
    title="#{config['share_link_title']}">#{config['share_link_text']}</a>}
  end
end

#set_config(site) ⇒ Object



27
28
29
30
31
32
# File 'lib/octopress-social/facebook.rb', line 27

def set_config(site)
  @config ||= begin
    config = site['octopress_social'] || site
    DEFAULTS.merge(config['facebook'] || {})
  end
end

#set_url(site, item) ⇒ Object



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

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

#widthObject



93
94
95
96
97
98
99
# File 'lib/octopress-social/facebook.rb', line 93

def width
  if w = config['width']
    %Q{data-width="#{w}"}
  else
    ''
  end
end