Sha256: 484dd29c6197bcd502e5762482d74df1c2abfb1557ad7367472191b288fc5717

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 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 [80, 443].include?(port)

        options = {
          :file          => path,
          :layout        => false,
          :use_full_path => false,
          :locals        => {
            :host        => host,
            :secure      => HoptoadNotifier.configuration.secure,
            :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

3 entries across 3 versions & 2 rubygems

Version Path
hoptoad_notifier-2.3.7 lib/hoptoad_notifier/rails/javascript_notifier.rb
riscfuture-hoptoad_notifier-2.3.6 lib/hoptoad_notifier/rails/javascript_notifier.rb
hoptoad_notifier-2.3.6 lib/hoptoad_notifier/rails/javascript_notifier.rb