Sha256: ef908fd8020636bd4f8d0c981d243a08f2d2a9646ac3670e13d90ba71fdc0596

Contents?: true

Size: 945 Bytes

Versions: 3

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

module RespondForHelper
  module Formats
    class Html < Base
      self.format = :html

      private

      def perform
        if @behaviour.render?
          perform_render
        elsif @behaviour.redirect?
          perform_redirect
        end

        if @behaviour.flash? && !request.xhr?
          perform_flash
        end
      end

      def perform_render
        render resolve_target(@behaviour.target), @behaviour.options
      end

      def perform_redirect
        redirect_to resolve_target(@behaviour.target), @behaviour.options
      end

      def perform_flash
        key = @behaviour.flash
        flash_content[key] = @controller.respond_for_message(key, @options)
      end

      def flash_content
        if @behaviour.render?
          flash.now
        elsif @behaviour.redirect?
          flash
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
respond_for_helper-1.1.2 lib/respond_for_helper/formats/html.rb
respond_for_helper-1.1.1 lib/respond_for_helper/formats/html.rb
respond_for_helper-1.1.0 lib/respond_for_helper/formats/html.rb