def show
      # No page found at the beginning
      @page = nil

      if params[:locale] and Humpyard.config.locales.include? params[:locale].to_sym
        I18n.locale = params[:locale]
      elsif session[:humpyard_locale]
        I18n.locale = session[:humpyard_locale]
      else
        I18n.locale = Humpyard.config.locales.first
      end
      
      # Find page by name
      if not params[:webpath].blank?
        dyn_page_path = false
        parent_page = nil
        params[:webpath].split('/').each do |path_part|
          # Ignore multiple slashes in URLs
          unless(path_part.blank?)
            if(dyn_page_path) 
              dyn_page_path << path_part
            else     
              # Find page by name and parent; parent=nil means page on root level
              @page = Page.with_translated_attribute(:title_for_url, CGI::escape(path_part), I18n.locale).first
              # Raise 404 if no page was found for the URL or subpart
              raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (X4201) [#{path_part}]" if @page.nil?
              raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (X4202)" if not (@page.parent == parent_page or @page.parent == Humpyard::Page.root_page)
              
              parent_page = @page unless @page.is_root_page?
              dyn_page_path = [] if @page.content_data.is_humpyard_dynamic_page? 
            end
          end
        end

        if @page.content_data.is_humpyard_dynamic_page? and dyn_page_path.size > 0
          @sub_page = @page.parse_path(dyn_page_path)
          
          # Raise 404 if no page was found for the sub_page part
          raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (D4201)" if @sub_page.blank?

          @page_partial = "/humpyard/pages/#{@page.content_data_type.split('::').last.underscore.pluralize}/#{@sub_page[:partial]}" if @sub_page[:partial]
          @local_vars = {:page => @page}.merge(@sub_page[:locals]) if @sub_page[:locals] and @sub_page[:locals].class == Hash
          
          # render partial only if request was an AJAX-call
          if request.xhr?
            respond_to do |format|
              format.html {
                render :partial => @page_partial, :locals => @local_vars
              }
            end
            return
          end
        end
        
      # Find page by id
      elsif not params[:id].blank?
        # Render page by id if not webpath was given but an id
        @page = Page.find(params[:id])
      # Find root page
      else
        # Render index page if neither id or webpath was given
        @page = Page.root_page :force_reload => true
        unless @page
          @page = Page.new
          render '/humpyard/pages/welcome'
          return false
        end
      end
      
      # Raise 404 if no page was found
      raise ::ActionController::RoutingError, "No route matches \"#{request.path}\"" if @page.nil? or @page.content_data.is_humpyard_virtual_page?
      
      response.headers['X-Humpyard-Page'] = "#{@page.id}"
      response.headers['X-Humpyard-Modified'] = "#{@page.last_modified}"
      response.headers['X-Humpyard-ServerTime'] = "#{Time.now.utc}"
 
      @page_partial ||= "/humpyard/pages/#{@page.content_data_type.split('::').last.underscore.pluralize}/show"
      @local_vars ||= {:page => @page}

      self.class.layout(@page.template_name)

      if Rails.application.config.action_controller.perform_caching and not @page.always_refresh
        fresh_when :etag => "#{humpyard_user.nil? ? '' : humpyard_user}p#{@page.id}m#{@page.last_modified}", :last_modified => @page.last_modified(:include_pages => true), :public => @humpyard_user.nil?
      end
    end
def show
      # No page found at the beginning
      @page = nil

      if params[:locale] and Humpyard.config.locales.include? params[:locale].to_sym
        I18n.locale = params[:locale]
      elsif session[:humpyard_locale]
        I18n.locale = session[:humpyard_locale]
      else
        I18n.locale = Humpyard.config.locales.first
      end
      
      # Find page by name
      if not params[:webpath].blank?
        dyn_page_path = false
        parent_page = nil
        params[:webpath].split('/').each do |path_part|
          # Ignore multiple slashes in URLs
          unless(path_part.blank?)
            if(dyn_page_path) 
              dyn_page_path << path_part
            else     
              # Find page by name and parent; parent=nil means page on root level
              @page = Page.with_translated_attribute(:title_for_url, CGI::escape(path_part), I18n.locale).first
              # Raise 404 if no page was found for the URL or subpart
              raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (X4201) [#{path_part}]" if @page.nil?
              raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (X4202)" if not (@page.parent == parent_page or @page.parent == Humpyard::Page.root_page)
              
              parent_page = @page unless @page.is_root_page?
              dyn_page_path = [] if @page.content_data.is_humpyard_dynamic_page? 
            end
          end
        end

        if @page.content_data.is_humpyard_dynamic_page? and dyn_page_path.size > 0
          @sub_page = @page.parse_path(dyn_page_path)
          
          # Raise 404 if no page was found for the sub_page part
          raise ::ActionController::RoutingError, "No route matches \"#{request.path}\" (D4201)" if @sub_page.blank?

          @page_partial = "/humpyard/pages/#{@page.content_data_type.split('::').last.underscore.pluralize}/#{@sub_page[:partial]}" if @sub_page[:partial]
          @local_vars = {:page => @page}.merge(@sub_page[:locals]) if @sub_page[:locals] and @sub_page[:locals].class == Hash
          
          # render partial only if request was an AJAX-call
          if request.xhr?
            respond_to do |format|
              format.html {
                render :partial => @page_partial, :locals => @local_vars
              }
            end
            return
          end
        end
        
      # Find page by id
      elsif not params[:id].blank?
        # Render page by id if not webpath was given but an id
        @page = Page.find(params[:id])
      # Find root page
      else
        # Render index page if neither id or webpath was given
        @page = Page.root_page :force_reload => true
        unless @page
          @page = Page.new
          render '/humpyard/pages/welcome'
          return false
        end
      end
      
      # Raise 404 if no page was found
      raise ::ActionController::RoutingError, "No route matches \"#{request.path}\"" if @page.nil? or @page.content_data.is_humpyard_virtual_page?
      
      response.headers['X-Humpyard-Page'] = "#{@page.id}"
      response.headers['X-Humpyard-Modified'] = "#{@page.last_modified}"
      response.headers['X-Humpyard-ServerTime'] = "#{Time.now.utc}"
 
      @page_partial ||= "/humpyard/pages/#{@page.content_data_type.split('::').last.underscore.pluralize}/show"
      @local_vars ||= {:page => @page}

      self.class.layout(@page.template_name)

      if Rails.application.config.action_controller.perform_caching and not @page.always_refresh
        fresh_when :etag => "#{humpyard_user.nil? ? '' : humpyard_user}p#{@page.id}m#{@page.last_modified}", :last_modified => @page.last_modified(:include_pages => true), :public => @humpyard_user.nil?
      end
    end
Render a given page

 When a "webpath" parameter is given it will render the page with that name.
 This is what happens when you call a page with it's pretty URL.

 When no "name" is given and an "id" parameter is given it will render the
 page with the given id.

 When no "name" nor "id" parameter is given it will render the root page.