Module: Octopress::Social::Disqus

Extended by:
Disqus
Included in:
Disqus
Defined in:
lib/octopress-social/disqus.rb

Defined Under Namespace

Classes: Tag

Constant Summary collapse

DEFAULTS =
{
  'comments_link_text'     => 'Comments',
  'comments_link_title'    => 'View 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/disqus.rb', line 7

def config
  @config
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#disqus_comments(site, item) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/octopress-social/disqus.rb', line 30

def disqus_comments(site, item)
  if item['comments'] != false
    %Q{<div id="disqus_thread"></div>
      <script type="text/javascript">
        var disqus_shortname = '#{config['shortname']}';
        var disqus_url = '#{url}';
        var disqus_identifier = '#{identifier(site, item)}';
        var disqus_title = '#{item['title']}';
        #{embed_script('embed')}
      </script>
      <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript" rel="nofollow">comments powered by Disqus.</a></noscript>
    }
  else
    ''
  end
end


57
58
59
60
61
62
63
64
65
66
67
# File 'lib/octopress-social/disqus.rb', line 57

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

#embed_script(script) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/octopress-social/disqus.rb', line 47

def embed_script(script)
  %Q{(function () {
      var s = document.createElement('script'); s.async = true;
      s.type = 'text/javascript';
      s.src = '//#{config['shortname']}.disqus.com/#{script}.js';
      (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
    }());
  }
end

#identifier(site, item) ⇒ Object



26
27
28
# File 'lib/octopress-social/disqus.rb', line 26

def identifier(site, item)
  item['disqus_identifier'] || url
end

#set_config(site) ⇒ Object



15
16
17
18
19
20
# File 'lib/octopress-social/disqus.rb', line 15

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

#set_url(site, item) ⇒ Object



22
23
24
# File 'lib/octopress-social/disqus.rb', line 22

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