Sha256: 25098ab1be4012d4112724aa92747b4b3adf9e0b0db865f7deaabd9c878a45bd

Contents?: true

Size: 1017 Bytes

Versions: 2

Compression:

Stored size: 1017 Bytes

Contents

require 'hocus_pocus/middleware_util'

module HocusPocus
  module Recorder
    class Middleware
      include MiddlewareUtil

      def initialize(app)
        @app = app
      end

      def call(env)
        @app.call(env).tap do |status, headers, body|
          if body.is_a?(ActionDispatch::Response) && body.request.format.html? && (body.request.path !~ %r[^/*hocus_pocus/])
            body.body = insert_text body.body, :before, /<\/head>/i, %Q[<script src="/assets/recorder.js"></script>]
            body.body = insert_text body.body, :after, /<div id="#{HocusPocus::CONTAINER}" .*?>/i, %Q[#{spec_link}<br>#{spec}]
          end
        end
      end

      private
      def spec_link
        %Q[<a href="/hocus_pocus/recorder" data-remote="true">spec</a>]
      end

      def spec
        #FIXME more assertions
        %Q[<div class="spec" style="display:none"><div align="right"><a href="/hocus_pocus/recorder" data-remote="true" data-method="delete">Clear</a></div></div>]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hocus_pocus-0.2.1 engines/recorder/lib/hocus_pocus/recorder/middleware.rb
hocus_pocus-0.2.0 engines/recorder/lib/hocus_pocus/recorder/middleware.rb