module Context
  module ControllerHelper

    # Returns the current Context::Page for the given path.
    # Defaults to params[:path] if path is not provided.
    #
    # Can be used within custom actions when you still want to load the Context::Page.
    #
    #   class NewsController < ApplicationController
    #     def index
    #       @page=context_page('news')
    #       @featured=NewItem.featured.first
    #     end
    #   end
    def context_page(path=nil)
      # TODO: Should restrict to published pages
      klasses = [Context::Page] << Context::Page.descendants
      page = nil

      klasses.flatten.each do |klass|
        page = klass.locate(path || params[:path] || request.fullpath)
      end

      page
    end

  end
end

module Context
  module ControllerHelper

    # Returns the current Context::Page for the given path.
    # Defaults to params[:path] if path is not provided.
    #
    # Can be used within custom actions when you still want to load the Context::Page.
    #
    #   class NewsController < ApplicationController
    #     def index
    #       @page=context_page('news')
    #       @featured=NewItem.featured.first
    #     end
    #   end
    def context_page(path=nil)
      # TODO: Should restrict to published pages
      page = Context::Page.locate(path || params[:path] || request.fullpath)
    end

  end
end

Simplify locate code in controller helper
Simplify locate code in controller helper
