Sha256: ff88fae2d029c28ddb3ffc838382d9e045c55aa0a49d9d1b13f157bf15a4ea6f

Contents?: true

Size: 965 Bytes

Versions: 1

Compression:

Stored size: 965 Bytes

Contents

module SimplePages
  def self.included(base)
    base.send :include, InstanceMethods
  end

  module InstanceMethods
    def show
      respond_to?(page_action) ? executes_page_action : render_page_template
    end

    protected
    def page_action
      @page_action ||= page_permalink params[:id]
    end

    def executes_page_action
      send page_action
      render page_template_path
    rescue ActionView::MissingTemplate
      render 'show'
    end

    def render_page_template
      render page_template_path
    rescue ActionView::MissingTemplate
      render 'not_found', :status => 404
    end

    def page_template_path
      [controller_name, page_locale, page_action].compact * "/"
    end

    def page_locale
      return I18n.locale = params[:locale] if params[:locale]
      return I18n.locale if I18n.locale != I18n.default_locale
    end

    def page_permalink(string)
      URI.unescape(string).parameterize.underscore
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
simple_pages-0.1.0 lib/simple_pages.rb