Sha256: d390de48c3e45534dc64950883819046dc4811d097f1e20f3b5982345a22bf45

Contents?: true

Size: 962 Bytes

Versions: 4

Compression:

Stored size: 962 Bytes

Contents

require 'action_controller'

module Hyperstack
  module Internal
    module Component
      class Redirect < StandardError
        attr_reader :url
        def initialize(url)
          @url = url
          super("redirect to #{url}")
        end
      end
    end
  end
end

module ActionController
  # adds render_component helper to ActionControllers
  class Base
    def render_component(*args)
      @component_name = (args[0].is_a? Hash) || args.empty? ? params[:action].camelize : args.shift
      @render_params = args.shift || {}
      options = args[0] || {}
      return if performed?
      render inline: '<%= mount_component @component_name, @render_params %>',
             layout: options.key?(:layout) ? options[:layout].to_s : :default
    rescue Exception => e
      m = /^RuntimeError: Hyperstack::Internal::Component::Redirect (.+) status: (.+)$/.match(e.message)
      raise e unless m
      redirect_to m[1], status: m[2]
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hyper-component-1.0.alpha1.8 lib/hyperstack/internal/component/rails/controller_helper.rb
hyper-component-1.0.alpha1.7 lib/hyperstack/internal/component/rails/controller_helper.rb
hyper-component-1.0.alpha1.6 lib/hyperstack/internal/component/rails/controller_helper.rb
hyper-component-1.0.alpha1.5 lib/hyperstack/internal/component/rails/controller_helper.rb