Sha256: 24a474b8a2f5bf19f9507d8730f426a7cb33932054b24d1563332df9b0641ac9

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module PageletRails::Concerns::Routes
  extend ActiveSupport::Concern

  included do
    @pagelet_routes = []
  end

  module ClassMethods
    # Define routes inline in controller
    #
    #     pagelet_routes do
    #       resources :users
    #     end
    #
    def pagelet_routes &block
      @pagelet_routes << block
    end

    def pagelet_resources *args, &block
      controller_name = self.controller_name
      @pagelet_routes << Proc.new do
        resources controller_name, *args, &block
      end
    end

    def pagelet_resource *args, &block
      controller_name = self.controller_name
      opts = args.extract_options!
      opts[:controller] ||= controller_name

      @pagelet_routes << Proc.new do
        resource controller_name, *args, opts, &block
      end
    end

    def load_pagelet_routes! context
      @pagelet_routes.each do |proc|
        context.instance_eval(&proc)
      end
    end

    def inherited subklass
      subklass.instance_variable_set(:@pagelet_routes, [])
      super
    end
  end
end


Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
pagelet_rails-0.2.2 lib/pagelet_rails/concerns/routes.rb
pagelet_rails-0.2.1 lib/pagelet_rails/concerns/routes.rb
pagelet_rails-0.2.0 lib/pagelet_rails/concerns/routes.rb
pagelet_rails-0.1.8 lib/pagelet_rails/concerns/routes.rb
pagelet_rails-0.1.7 lib/pagelet_rails/concerns/routes.rb
pagelet_rails-0.1.6 lib/pagelet_rails/concerns/routes.rb
pagelet_rails-0.1.5 lib/pagelet_rails/concerns/routes.rb