From 6a40e502bcd54f911b19100ba70c59960e3291ad Mon Sep 17 00:00:00 2001 From: Alexey Artamonov Date: Mon, 23 May 2011 00:50:54 +0300 Subject: [PATCH 1/2] Added helpers for supporing Disqus Single Sign-on --- disqus.gemspec | 2 ++ lib/disqus.rb | 4 +-- lib/disqus/view_helpers.rb | 4 +-- lib/disqus/widget.rb | 51 ++++++++++++++++++++++++++++++++++++++ test/widget_test.rb | 10 +++++++- 5 files changed, 66 insertions(+), 5 deletions(-) diff --git a/disqus.gemspec b/disqus.gemspec index d713b67..c24e774 100644 --- a/disqus.gemspec +++ b/disqus.gemspec @@ -1,3 +1,5 @@ +require 'lib/disqus/version' + spec = Gem::Specification.new do |s| s.name = "disqus" diff --git a/lib/disqus.rb b/lib/disqus.rb index df1053d..a42990a 100644 --- a/lib/disqus.rb +++ b/lib/disqus.rb @@ -1,4 +1,4 @@ -%w[api author forum post thread version view_helpers widget].each do |file| +%w[api author forum post thread view_helpers widget].each do |file| require File.join(File.dirname(__FILE__), "disqus", file) end @@ -49,4 +49,4 @@ def self.defaults @defaults end -end \ No newline at end of file +end diff --git a/lib/disqus/view_helpers.rb b/lib/disqus/view_helpers.rb index 2fffbcf..9dbf693 100644 --- a/lib/disqus/view_helpers.rb +++ b/lib/disqus/view_helpers.rb @@ -1,9 +1,9 @@ # Shortcuts to access the widgets as simple functions as opposed to using # their full qualified names. -%w[combo comment_counts popular_threads recent_comments thread top_commenters].each do |method| +%w[combo comment_counts popular_threads recent_comments thread top_commenters sso_login sso_logout].each do |method| eval(<<-EOM) def disqus_#{method}(options = {}) Disqus::Widget.#{method}(options) end EOM -end \ No newline at end of file +end diff --git a/lib/disqus/widget.rb b/lib/disqus/widget.rb index b7ba778..a6583b5 100644 --- a/lib/disqus/widget.rb +++ b/lib/disqus/widget.rb @@ -1,3 +1,6 @@ +require 'base64' +require 'openssl' + module Disqus # Disqus Widget generator. @@ -21,6 +24,9 @@ class Widget RECENT = ROOT_PATH + 'recent_comments_widget.js?num_items=%d&avatar_size=%d' POPULAR = ROOT_PATH + 'popular_threads_widget.js?num_items=%d' TOP = ROOT_PATH + 'top_commenters_widget.js?num_items=%d&avatar_size=%d&orientation=%s' + + DIGEST = OpenSSL::Digest::Digest.new('sha1') + class << self # Show the main Disqus thread widget. @@ -34,6 +40,7 @@ def thread(opts = {}) if opts[:developer] s << '' end + s << '
' s << '' s << '