Sha256: 2af3a58521897a91b4f6da00a6b0a24e272b9bf0b0758daf2120c4e21f0d3e2e

Contents?: true

Size: 1.26 KB

Versions: 2

Compression:

Stored size: 1.26 KB

Contents

module HoptoadNotifier
  module Rails
    module JavascriptNotifier
      def self.included(base) #:nodoc:
        base.send(:after_filter, :insert_hoptoad_javascript_notifier)
      end

      private

      def insert_hoptoad_javascript_notifier
        return unless HoptoadNotifier.configuration.public?
        return unless HoptoadNotifier.configuration.js_notifier

        path = File.join(File.dirname(__FILE__), '..', '..', 'templates', 'javascript_notifier.erb')
        host = HoptoadNotifier.configuration.host.dup
        port = HoptoadNotifier.configuration.port
        host << ":#{port}" unless port == 80

        options = {
          :file          => path,
          :layout        => false,
          :use_full_path => false,
          :locals        => {
            :host        => host,
            :api_key     => HoptoadNotifier.configuration.api_key,
            :environment => HoptoadNotifier.configuration.environment_name
          }
        }

        if @template
          javascript = @template.render(options)
        else
          javascript = render_to_string(options)
        end

        if response.body.respond_to?(:gsub)
          response.body = response.body.gsub(/<(head)>/i, "<\\1>\n" + javascript)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hoptoad_notifier-2.3.5 lib/hoptoad_notifier/rails/javascript_notifier.rb
hoptoad_notifier-2.3.4 lib/hoptoad_notifier/rails/javascript_notifier.rb