Sha256: c5f32e93b39de37e1f3608b9c0c608c4ca927dd366df3265df971f2d495dbd83

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require "pakyow/support/core_refinements/string/normalization"

require "pakyow/error"

module Pakyow
  module Presenter
    class Error < Pakyow::Error
    end

    class FrontMatterParsingError < Error
    end

    class UnknownPage < Error
      using Support::Refinements::String::Normalization

      def contextual_message
        <<~MESSAGE
          Pakyow couldn't render a view for `#{String.normalize_path(@context)}`. Try creating a view template for this path:

              frontend/pages#{view_path}.html

            * [Learn about view templates &rarr;](https://pakyow.com/docs/frontend/composition/)
        MESSAGE
      end

      private

      def view_path
        if @context.to_s.empty? || @context.to_s == "/"
          "/index"
        else
          @context
        end
      end
    end

    class ImplicitRenderingError < UnknownPage
      def name
        "Unknown page"
      end

      def contextual_message
        if Pakyow.env?(:prototype)
          super
        else
          <<~MESSAGE
            #{super}

            If you want to call backend code instead, create a controller endpoint that handles this request:

                get "#{@context}" do
                  # your code here
                end

              * [Learn about controllers &rarr;](https://pakyow.com/docs/routing/)
          MESSAGE
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pakyow-presenter-1.0.0.rc5 lib/pakyow/presenter/errors.rb
pakyow-presenter-1.0.0.rc4 lib/pakyow/presenter/errors.rb
pakyow-presenter-1.0.0.rc3 lib/pakyow/presenter/errors.rb