Sha256: aa2b160d0d0b7048325ce9e7b02916333240c260778bd722044c2253bcdd9d84

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

require "great_pretender/mockup_locator"

module GreatPretender
  module Controller

    def self.included(base)
      base.helper_method :mockup
      base.helper_method :mockups
      base.helper_method :mockup_root
      base.helper GreatPretender::MockupsHelper
    end

    def index
      render template: 'great_pretender/index'
    end

    def show
      if mockup
        render template: mockup.template, layout: mockup.layout
      else
        error_message = I18n.t('great_pretender.not_found') % params[:id]
        raise ActiveRecord::RecordNotFound.new(error_message)
      end
    end

    private

    def mockup
      @great_pretender_mockup ||= mockup_locator.find(params[:id])
    end

    def mockups
      @great_pretender_mockups ||= mockup_locator.mockups
    end

    def mockup_locator
      @great_pretender_mockup_locator ||= MockupLocator.new(view_paths)
    end

    def mockup_root
      @great_pretender_mockup_root ||= mockup_locator.view_paths.first.join(GreatPretender.config.view_path)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
great_pretender-0.0.2 lib/great_pretender/controller.rb
great_pretender-0.0.1 lib/great_pretender/controller.rb