Sha256: 6409eb9537b857c7d8d1b225f105e99b35527d3502e2a04754202958f5ce903d

Contents?: true

Size: 1.19 KB

Versions: 28

Compression:

Stored size: 1.19 KB

Contents

module Unpoly
  module Rails
    ##
    # This adds two methods `#up` and `#up?` to all controllers,
    # helpers and views, allowing the server to inspect the current request
    # for Unpoly-related concerns such as "is this a page fragment update?".
    module Controller

      def self.prepended(base)
        base.helper_method :up, :up?, :unpoly, :unpoly?
        if base.respond_to?(:after_action)
          base.after_action { up.after_action }
        else
          base.after_filter { up.after_action }
        end
      end

      ##
      # TODO: Docs
      def up
        @up_change ||= Change.new(self)
      end

      alias_method :unpoly, :up

      ##
      # :method: up?
      # Returns whether the current request is an
      # [page fragment update](https://unpoly.com/up.replace) triggered by an
      # Unpoly frontend.
      delegate :up?, :unpoly?, to: :up

      ##
      # TODO: Docs
      def redirect_to(target, *args)
        up.no_vary do
          if up?
            target = url_for(target)
            target = up.url_with_field_values(target)
          end
          super(target, *args)
        end
      end

      ::ActionController::Base.prepend(self)

    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
unpoly-rails-3.8.0 lib/unpoly/rails/controller.rb
unpoly-rails-3.8.0.rc1 lib/unpoly/rails/controller.rb
unpoly-rails-3.7.3.2 lib/unpoly/rails/controller.rb
unpoly-rails-3.7.3.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.7.3 lib/unpoly/rails/controller.rb
unpoly-rails-3.7.2 lib/unpoly/rails/controller.rb
unpoly-rails-3.7.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.7.0.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.7.0 lib/unpoly/rails/controller.rb
unpoly-rails-3.6.1.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.6.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.6.0 lib/unpoly/rails/controller.rb
unpoly-rails-3.5.2 lib/unpoly/rails/controller.rb
unpoly-rails-3.5.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.5.0 lib/unpoly/rails/controller.rb
unpoly-rails-3.3.0.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.3.0 lib/unpoly/rails/controller.rb
unpoly-rails-3.2.2.1 lib/unpoly/rails/controller.rb
unpoly-rails-3.2.2 lib/unpoly/rails/controller.rb
unpoly-rails-3.2.1 lib/unpoly/rails/controller.rb