From f6bfe59f04c6cf69644666242277592f88d9e19a Mon Sep 17 00:00:00 2001 From: Guillaume Dufloux Date: Fri, 30 Sep 2011 14:19:05 +0200 Subject: [PATCH 1/2] Add use_ssl to configuration --- README.md | 1 + Rakefile | 4 ++++ lib/whereuat/configuration.rb | 1 + lib/whereuat/rack_app.rb | 1 + 4 files changed, 7 insertions(+) diff --git a/README.md b/README.md index aa96289..9a2c906 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Create an initializer to add the Whereuat::RackApp to your middleware stack and Whereuat.configure do |config| config.pivotal_tracker_token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" config.pivotal_tracker_project = 123456 + config.pivotal_tracker_use_ssl = false end Use the following helper somewhere in your application layout (we recommend at the end of the body): diff --git a/Rakefile b/Rakefile index 620c76d..c3db11a 100644 --- a/Rakefile +++ b/Rakefile @@ -45,12 +45,16 @@ if rake_app.top_level_tasks.include?('dev') puts "What pivotal tracker project do you want to test against? (e.g. The digits at the end of http://www.pivotaltracker.com/projects/12345)." project_id = $stdin.gets.chomp + puts "Does your pivotal tracker project use ssl?" + use_ssl = $stdin.gets.chomp.downcase.start_with?('y') + puts "Creating config using your details." pivotal_config.open('w') {|f| f << %{Whereuat.configure do |config| config.pivotal_tracker_token = "#{token}" config.pivotal_tracker_project = #{project_id} + config.pivotal_tracker_use_ssl = #{use_ssl} end }.gsub(/^\s{3,16}/,'') } diff --git a/lib/whereuat/configuration.rb b/lib/whereuat/configuration.rb index 2ef724c..8ac2292 100644 --- a/lib/whereuat/configuration.rb +++ b/lib/whereuat/configuration.rb @@ -2,5 +2,6 @@ module Whereuat class Configuration attr_accessor :pivotal_tracker_token attr_accessor :pivotal_tracker_project + attr_accessor :pivotal_tracker_use_ssl end end diff --git a/lib/whereuat/rack_app.rb b/lib/whereuat/rack_app.rb index e6df2ad..c1a44c8 100644 --- a/lib/whereuat/rack_app.rb +++ b/lib/whereuat/rack_app.rb @@ -11,6 +11,7 @@ class RackApp def initialize(app) @app = app PT::Client.token = config.pivotal_tracker_token + PT::Client.use_ssl = config.pivotal_tracker_use_ssl end def call(env) From c85525f5423d407ee04848438ce87962d0785621 Mon Sep 17 00:00:00 2001 From: Guillaume Dufloux Date: Fri, 30 Sep 2011 14:52:42 +0200 Subject: [PATCH 2/2] Auto insert widget via after_filter --- lib/whereuat/action_controller_ext.rb | 16 ++++++++++++++++ lib/whereuat/configuration.rb | 1 + lib/whereuat/widget.rb | 12 ++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 lib/whereuat/action_controller_ext.rb create mode 100644 lib/whereuat/widget.rb diff --git a/lib/whereuat/action_controller_ext.rb b/lib/whereuat/action_controller_ext.rb new file mode 100644 index 0000000..59bf2f8 --- /dev/null +++ b/lib/whereuat/action_controller_ext.rb @@ -0,0 +1,16 @@ +if Whereuat.configuration.enable_widget + + already_inherited = defined?(ApplicationController) + + [ActionController::Base, already_inherited ? ApplicationController : nil].compact.each do |base| + base.class_eval do + after_filter :render_whereuat + + private + def render_whereuat + Whereuat::Widget.render(response) + end + end + end + +end \ No newline at end of file diff --git a/lib/whereuat/configuration.rb b/lib/whereuat/configuration.rb index 8ac2292..ca4042b 100644 --- a/lib/whereuat/configuration.rb +++ b/lib/whereuat/configuration.rb @@ -3,5 +3,6 @@ class Configuration attr_accessor :pivotal_tracker_token attr_accessor :pivotal_tracker_project attr_accessor :pivotal_tracker_use_ssl + attr_accessor :enable_widget end end diff --git a/lib/whereuat/widget.rb b/lib/whereuat/widget.rb new file mode 100644 index 0000000..ba5e1ad --- /dev/null +++ b/lib/whereuat/widget.rb @@ -0,0 +1,12 @@ +module Whereuat + class Widget + extend Whereuat::Helpers + + def self.render(response) + body = response.body + if response.content_type == "text/html" && position = body.index('') + body.insert(position, whereuat) + end + end + end +end \ No newline at end of file