Sha256: d511b0f3efb592c31be43faec24b576cf8401d8c6b8fd5b14c286117ff8dbbdd

Contents?: true

Size: 1.54 KB

Versions: 4

Compression:

Stored size: 1.54 KB

Contents

require 'nanoc/toolbox/helpers/blogging_extra'

module Nanoc::Toolbox::Helpers

  # NANOC Helper for Disqus comments
  #
  # This module contains functions for ...
  #
  # @see http://disqus.com/
  module Disqus
    include Nanoc::Toolbox::Helpers::HtmlTag
    include Nanoc::Toolbox::Helpers::BloggingExtra

    # Creates an id out of the page slug that disqus uses for an id
    def disqus_id_for(item, options={})
      id = ''
      id += options[:disqus_id_prefix] if options[:disqus_id_prefix]
      id += slug_for(item)
      id.gsub(/-/, '_')
    end

    # @see http://help.disqus.com/customer/portal/articles/472098-javascript-configuration-variables
    def disqus_js_snippet(variables={})
      configuration_variables = ""

      variables.each do |k, v|
        configuration_variables += "var disqus_#{k} = '#{v}';\n" unless v.nil?
      end

      js_string = <<-EOS
        #{configuration_variables}
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
      EOS

      content_tag('script', js_string, { :type => 'text/javascript' })
    end

    def disqus_nojs_snippet(message=nil)
      message ||= "Please enable JavaScript to view the <a href=\"http://disqus.com/?ref_noscript\">comments powered by Disqus.</a>"
      content_tag('noscript', message)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
nanoc-toolbox-0.1.3 lib/nanoc/toolbox/helpers/disqus.rb
nanoc-toolbox-0.1.2 lib/nanoc/toolbox/helpers/disqus.rb
nanoc-toolbox-0.1.1 lib/nanoc/toolbox/helpers/disqus.rb
nanoc-toolbox-0.1.0 lib/nanoc/toolbox/helpers/disqus.rb