Module: Nanoc::Toolbox::Helpers::Disqus
- Includes:
- BloggingExtra, HtmlTag
- Defined in:
- lib/nanoc/toolbox/helpers/disqus.rb
Overview
NANOC Helper for Disqus comments
This module contains functions for …
Instance Method Summary collapse
-
#disqus_id_for(item, options = {}) ⇒ Object
Creates an id out of the page slug that disqus uses for an id.
- #disqus_js_snippet(variables = {}) ⇒ Object
- #disqus_nojs_snippet(message = nil) ⇒ Object
Methods included from BloggingExtra
#act_as_post, #add_post_attributes, #posts_by_date, #recent_posts, #slug_for
Methods included from HtmlTag
#content_tag, #tag, #tag_options
Instance Method Details
#disqus_id_for(item, options = {}) ⇒ Object
Creates an id out of the page slug that disqus uses for an id
15 16 17 18 19 20 |
# File 'lib/nanoc/toolbox/helpers/disqus.rb', line 15 def disqus_id_for(item, ={}) id = '' id += [:disqus_id_prefix] if [:disqus_id_prefix] id += slug_for(item) id.gsub(/-/, '_') end |
#disqus_js_snippet(variables = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/nanoc/toolbox/helpers/disqus.rb', line 23 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 = '//' + 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 |
#disqus_nojs_snippet(message = nil) ⇒ Object
42 43 44 45 |
# File 'lib/nanoc/toolbox/helpers/disqus.rb', line 42 def disqus_nojs_snippet(=nil) ||= "Please enable JavaScript to view the <a href=\"http://disqus.com/?ref_noscript\">comments powered by Disqus.</a>" content_tag('noscript', ) end |