Sha256: b9faaaa5191f2996ec5471728fcbd8b60cbe6463c5026d24ad394a3c431457da

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 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)
        if up?
          target = url_for(target)
          target = up.url_with_field_values(target)
        end
        super(target, *args)
      end

      ActionController::Base.prepend(self)

    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
unpoly-rails-2.1.0 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.1 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc11 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc10 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc9 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc8 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc7 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc6 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc5 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc4 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc3 lib/unpoly/rails/controller.rb
unpoly-rails-2.0.0.pre.rc2 lib/unpoly/rails/controller.rb