Sha256: 493cae12819cd899f348aabb802d68893150bcb8a51b2a8f551a43aa45fe6353

Contents?: true

Size: 981 Bytes

Versions: 2

Compression:

Stored size: 981 Bytes

Contents

class Shim::PagesController < ActionController::Base
  unloadable
  layout Proc.new { |controller|
    if controller.request.xhr?
      false
    else
      ::Shim.layout 
    end
  }

  rescue_from ActionView::MissingTemplate do |exception|
    if exception.message =~ %r{Missing template #{content_path}}
      # There's probably a better way to put both of these in the same handler,
      # but unless is the best I can com up with for now.
      raise ActionController::RoutingError, "No such page: #{params[:id]}" unless try_index
    else
      raise exception
    end
  end

  def show
    render :template => current_page
  end

  protected

  def current_page
    "#{content_path}#{clean_path}"
  end

  def clean_path
    path = Pathname.new "/#{params[:id]}"
    path.cleanpath.to_s[1..-1]
  end

  def content_path
    ::Shim.content_path
  end

  def try_index
    render :template => "#{current_page}/index"
  rescue ActionView::MissingTemplate 
    false
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
shim-0.1.5 app/controllers/shim/pages_controller.rb
shim-0.1.4 app/controllers/shim/pages_controller.rb